:root {
  --deep: #08131f;
  --deep-2: #0d2135;
  --ocean: #123a5c;
  --ocean-lit: #1d5c8a;
  --parchment: #f2e3bd;
  --gold: #e0a83c;
  --gold-soft: #f2cd7c;
  --straw: #d8b26a;
  --crimson: #b3372f;
  --foam: #e9f4ff;

  --radius: clamp(0.9rem, 0.6rem + 1vw, 1.5rem);
  --pad: clamp(1rem, 0.5rem + 2.5vw, 2.25rem);
  --fs-base: clamp(0.95rem, 0.88rem + 0.32vw, 1.08rem);
  --fs-hero: clamp(1.5rem, 0.8rem + 4vw, 3rem);

  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

/* атрибут hidden должен побеждать display из компонентных правил */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-base);
  color: var(--foam);
  background: var(--deep);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ---------- фон ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  color: var(--ocean-lit);
  background:
    radial-gradient(120% 80% at 50% -10%, #16456d 0%, transparent 60%),
    linear-gradient(180deg, var(--deep) 0%, var(--deep-2) 45%, #061019 100%);
}

.backdrop__compass {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(140vmin, 60rem);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  opacity: .1;
  animation: spin 120s linear infinite;
}

.backdrop__rays {
  position: absolute;
  inset: -20%;
  opacity: 0;
  transition: opacity .25s ease;
  background: repeating-conic-gradient(from 0deg at 50% 45%,
    rgba(224,168,60,.10) 0deg 1.6deg, transparent 1.6deg 7deg);
  mask-image: radial-gradient(closest-side, #000 20%, transparent 78%);
}

.backdrop__waves {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 200%;
  height: clamp(6rem, 14vh, 12rem);
}

.wave { fill: rgba(29, 92, 138, .35); }
.wave--2 { fill: rgba(179, 55, 47, .22); }
.wave--1 { animation: drift 18s linear infinite; }
.wave--2 { animation: drift 26s linear infinite reverse; }

body.is-dragging .backdrop__rays { opacity: 1; }

@keyframes spin { to { transform: translate(-50%, -50%) rotate(360deg); } }
@keyframes drift { to { transform: translateX(-50%); } }

/* ---------- каркас ---------- */
.shell {
  position: relative;
  z-index: 1;
  width: min(100% - 2rem, 62rem);
  margin-inline: auto;
  min-height: 100dvh;
  padding: max(0.75rem, env(safe-area-inset-top)) 0 max(0.75rem, env(safe-area-inset-bottom));
  padding-inline: max(0px, env(safe-area-inset-left)) max(0px, env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
}

/* сцена занимает всё свободное место и центрирует содержимое по вертикали,
   а подвал остаётся прижатым к низу */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(.8rem, 0.4rem + 1.2vw, 1.6rem);
  padding-block: clamp(.3rem, 1vh, 1rem);
}

/* ---------- герой ---------- */
.hero { text-align: center; display: grid; gap: .2rem; justify-items: center; }

.hat {
  width: clamp(6rem, 18vw, 10rem);
  filter: drop-shadow(0 12px 24px rgba(0,0,0,.55));
  animation: bob 5s ease-in-out infinite;
  transform-origin: 50% 90%;
}

body.is-dragging .hat { animation: hop .5s ease-in-out infinite; }

@keyframes bob { 0%,100% { transform: translateY(0) rotate(-1.2deg); } 50% { transform: translateY(-.5rem) rotate(1.2deg); } }
@keyframes hop { 0%,100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-1.1rem) scale(1.08) rotate(-3deg); } }

.hero__title {
  margin: 0;
  max-width: 100%;
  font-size: var(--fs-hero);
  font-weight: 900;
  letter-spacing: .07em;
  line-height: 1;
  text-wrap: balance;
  background: linear-gradient(180deg, var(--gold-soft), var(--gold) 55%, #b6791d);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 rgba(0,0,0,.35));
}

.hero__tagline { margin: .2rem 0 0; opacity: .78; line-height: 1.5; }

.hero__domain {
  margin: .3rem 0 0;
  font-family: var(--mono);
  font-size: clamp(.72rem, .65rem + .3vw, .9rem);
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--gold-soft);
  opacity: .75;
}

.hero__domain::before,
.hero__domain::after {
  content: "";
  display: inline-block;
  width: clamp(1.5rem, 6vw, 3rem);
  height: 1px;
  vertical-align: middle;
  background: linear-gradient(90deg, transparent, var(--gold));
  margin-inline: .7rem;
}

.hero__domain::after { background: linear-gradient(90deg, var(--gold), transparent); }

/* ---------- вкладки ---------- */
.tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  gap: .4rem;
  padding: .35rem;
  background: rgba(8, 19, 31, .6);
  border: 1px solid rgba(224, 168, 60, .18);
  border-radius: 999px;
  backdrop-filter: blur(6px);
}

.tab {
  font: inherit;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--foam);
  background: transparent;
  border: 0;
  border-radius: 999px;
  padding: .6rem 1rem;
  cursor: pointer;
  transition: background .18s ease, color .18s ease;
}

.tab:hover { background: rgba(224, 168, 60, .12); }

.tab.is-active {
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  color: #24170a;
}

/* ---------- панели ---------- */
.panel { display: grid; gap: .6rem; }

.drop {
  position: relative;
  display: grid;
  place-items: center;
  min-height: clamp(9rem, 26vh, 15rem);
  padding: var(--pad);
  text-align: center;
  border: 2px dashed rgba(224, 168, 60, .38);
  border-radius: var(--radius);
  background: rgba(18, 58, 92, .22);
  cursor: pointer;
  transition: border-color .18s ease, background .18s ease, transform .18s ease;
}

.drop:hover, .drop:focus-visible { border-color: var(--gold); background: rgba(18, 58, 92, .34); outline: none; }

body.is-dragging .drop {
  border-color: var(--gold);
  border-style: solid;
  background: rgba(224, 168, 60, .12);
  transform: scale(1.01);
}

.drop__inner { display: grid; gap: .3rem; justify-items: center; }
.drop__anchor { width: clamp(2.5rem, 8vw, 3.5rem); color: var(--gold); }
.drop__title { margin: .3rem 0 0; font-weight: 700; }
.drop__hint { margin: 0; opacity: .6; font-size: .9em; }

.picked { margin: 0; color: var(--gold-soft); font-size: .92em; word-break: break-all; }

.editor {
  width: 100%;
  font-family: var(--mono);
  font-size: .95em;
  color: var(--foam);
  background: rgba(6, 16, 25, .75);
  border: 1px solid rgba(224, 168, 60, .25);
  border-radius: var(--radius);
  padding: var(--pad);
  resize: vertical;
  min-height: 8rem;
}

.editor:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.counter { margin: 0; opacity: .55; font-size: .85em; justify-self: end; }

/* ---------- управление ---------- */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  align-items: end;
  justify-content: center;
}

.field { display: grid; gap: .25rem; justify-items: center; }
.field__label { font-size: .82em; opacity: .65; letter-spacing: .06em; text-transform: uppercase; }

.select {
  font: inherit;
  color: var(--foam);
  background: rgba(6, 16, 25, .8);
  border: 1px solid rgba(224, 168, 60, .3);
  border-radius: .7rem;
  padding: .55rem .8rem;
  cursor: pointer;
}

.btn {
  font: inherit;
  font-weight: 800;
  letter-spacing: .05em;
  border: 0;
  border-radius: .8rem;
  padding: .75rem 1.4rem;
  cursor: pointer;
  color: #24170a;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  transition: transform .12s ease, filter .18s ease, opacity .18s ease;
}

.btn:active { transform: translateY(1px) scale(.99); }
.btn[disabled] { opacity: .55; cursor: progress; }

.btn--gold {
  background: linear-gradient(180deg, var(--gold-soft), var(--gold) 60%, #bd8420);
  box-shadow: 0 6px 0 -2px rgba(120, 80, 12, .7), 0 10px 22px rgba(0,0,0,.4);
}

.btn--ghost {
  color: var(--gold-soft);
  background: transparent;
  border: 1px solid var(--gold);
  box-shadow: none;
  padding: .55rem 1rem;
}

.btn--ghost:hover { background: rgba(224, 168, 60, .14); }

/* ---------- прогресс ---------- */
.progress { display: grid; gap: .4rem; }

.progress__track {
  height: .7rem;
  border-radius: 999px;
  background: rgba(6, 16, 25, .8);
  border: 1px solid rgba(224, 168, 60, .25);
  overflow: hidden;
}

.progress__fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--ocean-lit), var(--gold) 70%, var(--gold-soft));
  background-size: 200% 100%;
  transition: width .18s ease;
  animation: flow 2.4s linear infinite;
}

@keyframes flow { to { background-position: -200% 0; } }

.progress__text { margin: 0; font-size: .85em; opacity: .7; text-align: center; }

/* ---------- wanted-постер ---------- */
.wanted {
  position: relative;
  display: grid;
  gap: .8rem;
  justify-items: center;
  text-align: center;
  padding: calc(var(--pad) * 1.2) var(--pad);
  background:
    radial-gradient(80% 60% at 50% 0%, rgba(224, 168, 60, .16), transparent 70%),
    linear-gradient(180deg, #f7ecd0, var(--parchment) 60%, #e2cfa2);
  color: #2a1d0c;
  border-radius: var(--radius);
  border: 3px double #8d6c2f;
  box-shadow: 0 20px 50px rgba(0,0,0,.45);
  overflow: hidden;
}

/* позиционируем содержимое, чтобы абсолютный трек не перекрывал заголовок */
.wanted > * { position: relative; }

.wanted__trail { position: absolute; inset: 0 0 auto; width: 100%; height: 4rem; color: #b3372f; opacity: .3; }
.wanted__kicker { margin: 0; font-size: .8em; letter-spacing: .35em; color: #8d6c2f; }
.wanted__name { margin: 0; font-size: clamp(1.3rem, 1rem + 2vw, 2.1rem); word-break: break-word; }
.wanted__meta { margin: 0; opacity: .75; font-size: .9em; }

.wanted__burn {
  margin: -.2rem 0 0;
  padding: .45rem .8rem;
  font-size: .85em;
  font-weight: 700;
  color: #7a1f19;
  background: rgba(179, 55, 47, .12);
  border: 1px dashed #b3372f;
  border-radius: .6rem;
}

.linkbox {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  width: 100%;
  justify-content: center;
}

.linkbox__input {
  flex: 1 1 14rem;
  min-width: 0;
  font: inherit;
  font-family: var(--mono);
  font-size: .95em;
  color: #2a1d0c;
  background: rgba(255, 255, 255, .75);
  border: 1px dashed #8d6c2f;
  border-radius: .7rem;
  padding: .6rem .8rem;
  text-align: center;
}

.wanted .btn--ghost { color: #7a1f19; border-color: #7a1f19; }
.wanted .btn--ghost:hover { background: rgba(179, 55, 47, .12); }

.wanted .btn--gold {
  color: #2a1d0c;
  box-shadow: 0 5px 0 -2px rgba(120, 80, 12, .55);
}

.row { display: flex; flex-wrap: wrap; gap: .6rem; justify-content: center; }

.snippet {
  width: 100%;
  max-height: 22rem;
  overflow: auto;
  margin: 0;
  padding: var(--pad);
  text-align: left;
  font-family: var(--mono);
  font-size: .9em;
  color: #2a1d0c;
  background: rgba(255, 255, 255, .72);
  border: 1px solid rgba(141, 108, 47, .4);
  border-radius: .8rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.again { color: #7a1f19; font-weight: 700; text-decoration: none; border-bottom: 1px dashed currentColor; }

/* ---------- 404 ---------- */
.missing { display: grid; gap: .6rem; justify-items: center; text-align: center; padding: var(--pad); }
.missing__compass { width: clamp(6rem, 22vw, 9rem); color: var(--gold); opacity: .8; animation: wobble 3.5s ease-in-out infinite; }
.missing h2 { margin: 0; }
.missing p { margin: 0; opacity: .7; }

@keyframes wobble { 0%,100% { transform: rotate(-6deg); } 50% { transform: rotate(8deg); } }

/* ---------- подвал ---------- */
.foot {
  margin-top: 0;
  padding-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: .4rem 1.2rem;
  justify-content: center;
  text-align: center;
  font-size: .82em;
  opacity: .5;
  border-top: 1px solid rgba(224, 168, 60, .14);
}

.foot b { color: var(--gold-soft); font-weight: 700; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(1.25rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .6rem 1.1rem .6rem .7rem;
  background: linear-gradient(180deg, #f7ecd0, var(--parchment));
  color: #2a1d0c;
  font-weight: 700;
  border-radius: 999px;
  border: 2px solid #8d6c2f;
  box-shadow: 0 14px 34px rgba(0,0,0,.5);
  animation: rise .28s ease;
}

.toast__skull { width: 1.7rem; height: 1.7rem; color: var(--crimson); }

@keyframes rise { from { opacity: 0; transform: translate(-50%, 1rem); } }

/* ---------- доступность ---------- */
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}