/* ZOOM — Kid Dream Game.
   Визуальный контракт САС (CAC_Site_Agent_02_Visual §3–4):
   navy/белое поле, оранжевая вспышка — редко и точечно, нейтральный гротеск,
   радикальный воздух, mobile-first. Лицо карты — геймплей, оно живёт по своим
   законам (full-bleed, blur-подложка) и не считается «картинкой на витрине». */

:root {
  --paper: #f8f9fb;
  --navy: #1b2e5a;
  --ink: #1b2e5a;
  --muted: #5f6780; /* контраст к --paper ≥ 4.5:1 (AA) */
  --muted-line: #8a90a6; /* тот же тон, но только для волосяных линий */
  --flash: #e67b19;
  --line: #e2e5ee;
  --navy-rgb: 27, 46, 90;
  --navy-900: #0f1a2e;
  --navy-800: #0d1728;
  --navy-300: #c8d2e4;
  /* Служебный семафор разбора: только рамка/точка, никогда заливка блока. */
  --ok: #2f7d5c;
  --warn: #b4453a;

  /* Прототип идёт на системном гротеске: файлов Inter в проекте нет, и
     объявлять его в стеке значило бы притворяться, что типографика совпадает
     с витриной. При выкладке рядом с cac.az — самохостинг Inter (канон 02 §2). */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --fs-display: clamp(1.9rem, 6vw, 3.2rem);
  --fs-h2: clamp(1.3rem, 3.6vw, 1.9rem);
  --fs-body: 1.0625rem;
  --fs-caption: 0.875rem;
  --lh-tight: 1.12;
  --lh-body: 1.6;

  --space-1: 0.5rem;
  --space-2: 1rem;
  --space-3: 1.5rem;
  --space-4: 2.5rem;
  --space-5: 4rem;
  --radius: 14px;
  --measure: 62ch;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body { overscroll-behavior-y: none; }

h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; line-height: var(--lh-tight); margin: 0; }
h1 { font-size: var(--fs-display); }
h2 { font-size: var(--fs-h2); }
p { margin: 0 0 var(--space-2); max-width: var(--measure); }

.accent { color: var(--flash); }
.muted { color: var(--muted); }
.caption { font-size: var(--fs-caption); color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.hidden { display: none !important; }

/* --- Каркас --------------------------------------------------------------- */

.wrap {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(1.5rem, 6vw, 3.5rem) clamp(1.1rem, 5vw, 2rem) 4rem;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  margin-bottom: var(--space-4);
}
.brand b { font-weight: 700; letter-spacing: 0.18em; font-size: 0.9rem; }
.brand span { font-size: 0.78rem; color: var(--muted); letter-spacing: 0.14em; text-transform: uppercase; }

/* Переключатель локали AZ · RU · EN — тихий, как и вся типографика. */
.langs { margin-left: auto; display: flex; gap: 0.1rem; align-items: center; }
.lang {
  appearance: none;
  border: 0;
  background: none;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--muted);
  padding: 0.35rem 0.45rem;
  cursor: pointer;
  border-radius: 6px;
}
.lang.is-on { color: var(--navy); background: #eceff5; }

.screen { display: none; }
.screen.is-active { display: block; animation: fade 240ms cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.stack > * + * { margin-top: var(--space-3); }
.row { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.row.tight { gap: 0.5rem; }
.spacer { flex: 1; }

hr.rule { border: 0; border-top: 1px solid var(--line); margin: var(--space-4) 0; }

/* --- Формы и кнопки ------------------------------------------------------- */

label.field { display: block; margin-bottom: var(--space-3); }
label.field > span {
  display: block;
  font-size: var(--fs-caption);
  color: var(--muted);
  letter-spacing: 0.04em;
  margin-bottom: 0.4rem;
}

input[type="text"], input[type="number"], select {
  width: 100%;
  padding: 0.85rem 1rem;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 160ms;
}
input:focus, select:focus { border-color: var(--navy); }
input.code-input {
  text-transform: uppercase;
  letter-spacing: 0.34em;
  font-size: 1.5rem;
  font-weight: 600;
  text-align: center;
}

.btn {
  appearance: none;
  border: 1px solid var(--navy);
  background: var(--navy);
  color: #fff;
  font: inherit;
  font-weight: 600;
  padding: 0.85rem 1.5rem;
  border-radius: 999px;
  cursor: pointer;
  min-height: 48px;
  transition: opacity 160ms, transform 160ms;
}
.btn:active { transform: scale(0.985); }
.btn[disabled] { opacity: 0.35; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--navy); }
.btn.quiet { background: transparent; color: var(--muted); border-color: transparent; padding-inline: 0.5rem; }
.btn.danger { background: transparent; color: var(--warn); border-color: var(--line); }
.btn.wide { width: 100%; }
/* --flash никогда не заливка блока (канон 02 §3): акцент — точкой. */
.btn.flash {
  background: transparent;
  color: var(--navy);
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
}
.btn.flash::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--flash);
  flex: none;
}

/* --- Код комнаты ---------------------------------------------------------- */

.code-badge {
  display: inline-flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 1rem 1.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.code-badge b {
  font-size: clamp(2rem, 11vw, 3.4rem);
  letter-spacing: 0.22em;
  font-weight: 700;
  line-height: 1;
}
.code-badge small { font-size: 0.72rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }

/* --- Список игроков ------------------------------------------------------- */

.roster { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 0.6rem; }
.chip {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.7rem 0.85rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 0.95rem;
  min-width: 0;
}
.chip .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.is-off { opacity: 0.45; }
.chip.is-flagged { border-color: var(--flash); }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: none; }
.metric.is-warn { border-color: var(--warn); }
.dot.seen { background: var(--muted); }
.dot.done { background: var(--ok); }

.mini { font-size: 0.72rem; color: var(--muted); letter-spacing: 0.06em; }
.chip .mini { flex: none; }

/* --- Табло / метрики ------------------------------------------------------ */

.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 0.6rem; }
.metric { padding: 1rem; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.metric b { display: block; font-size: 1.7rem; font-weight: 600; line-height: 1.1; }
.metric small { display: block; font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin-top: 0.3rem; }
.metric.hero b { color: var(--flash); font-size: 2.4rem; }

.timer-big { font-size: clamp(2.4rem, 13vw, 4rem); font-weight: 600; letter-spacing: 0.02em; line-height: 1; }

/* --- Лента разбора -------------------------------------------------------- */

.ribbon { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 0.4rem; }
.slot {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.5rem 0.55rem;
  background: #fff;
  font-size: 0.78rem;
  line-height: 1.35;
}
.slot .pos { font-weight: 700; }
.slot .who { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slot.ok { border-color: var(--ok); }
.slot.bad { border-color: var(--warn); }
.slot.empty { background: #f2f3f7; color: var(--muted); }

table.board { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.board th, table.board td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--line); }
table.board th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 500; }
table.board td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- Уведомления ---------------------------------------------------------- */

.toasts { position: fixed; left: 0; right: 0; bottom: 1rem; display: flex; flex-direction: column; align-items: center; gap: 0.4rem; z-index: 90; pointer-events: none; }
.toast {
  background: var(--navy);
  color: #fff;
  padding: 0.7rem 1.1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  max-width: min(92vw, 480px);
  box-shadow: 0 10px 30px rgba(27, 46, 90, 0.22);
  animation: fade 200ms;
}
.toast.warn { background: var(--warn); }

/* --- ЭКРАН КАРТЫ (full-bleed, §7 брифа) ----------------------------------- */

.cardscreen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  background: #0f1a2e;
  color: #fff;
  overflow: hidden;
  z-index: 40;
}
.cardscreen.is-active { display: flex; }

/* Подложка — размытая увеличенная копия той же картинки. Чёрных полос нет. */
.blurbg {
  position: absolute;
  inset: -12%;
  background-position: center;
  background-size: cover;
  filter: blur(38px) saturate(1.15) brightness(0.62);
  transform: scale(1.15);
  transition: background-image 200ms;
  z-index: 0;
}
.blurbg.is-back { background-image: linear-gradient(140deg, #1f3a5f, #0d1728); filter: none; transform: none; }

.cardtop, .cardbottom { position: relative; z-index: 3; flex: none; }
.cardtop {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: calc(env(safe-area-inset-top, 0px) + 0.6rem) 0.9rem 0.6rem;
  background: linear-gradient(#0d1728cc, #0d172800);
}
.cardtop .t-clock { font-size: 1.05rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.cardtop .t-hint { font-size: 0.74rem; color: #c8d2e4; flex: 1; line-height: 1.3; }
.cardtop .t-win { font-size: 0.95rem; font-weight: 700; color: var(--flash); font-variant-numeric: tabular-nums; }

.stage {
  position: relative;
  z-index: 2;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  display: grid;
  place-items: center;
}

/* Пока показана рубашка — лицо не должно просвечивать по краям от неё. */
.stage.is-covered .zoomimg { visibility: hidden; }

.zoomimg {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  will-change: transform;
  transform-origin: center center;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
  display: block;
}

.cardback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 1rem;
  cursor: pointer;
}
.cardback img { max-width: min(78vw, 380px); max-height: 100%; border-radius: 12px; box-shadow: 0 24px 60px rgba(var(--navy-rgb), 0.5); }
.cardback .tap {
  position: absolute;
  bottom: 8%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.82rem;
  color: #d6deec;
  background: #0f1a2eaa;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  white-space: nowrap;
}

.cardbottom {
  padding: 0.7rem 0.9rem calc(env(safe-area-inset-bottom, 0px) + 0.8rem);
  background: linear-gradient(#0d172800, #0d1728e0 34%);
  display: flex;
  gap: 0.6rem;
  align-items: center;
}
.pick-btn {
  flex: 1;
  min-height: 52px;
  border-radius: 14px;
  border: 1px solid #ffffff33;
  background: #ffffff14;
  color: #fff;
  font: inherit;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  cursor: pointer;
}
.pick-btn b { font-size: 1.35rem; }

.cardbottom .btn { min-height: 52px; padding-inline: 1.3rem; }

.zoomhint {
  position: absolute;
  z-index: 3;
  top: 0.5rem;
  right: 0.7rem;
  font-size: 0.72rem;
  color: #ffffffcc;
  background: #0f1a2e99;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  opacity: 0;
  transition: opacity 200ms;
}
.zoomhint.show { opacity: 1; }

/* --- Шторка выбора номера ------------------------------------------------- */

.sheet-back {
  position: fixed;
  inset: 0;
  background: #0b1424b8;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms;
}
.sheet-back.is-open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 51;
  background: var(--paper);
  color: var(--ink);
  border-radius: 20px 20px 0 0;
  padding: 1rem 1rem calc(env(safe-area-inset-bottom, 0px) + 1rem);
  transform: translateY(102%);
  transition: transform 260ms cubic-bezier(0.22, 1, 0.36, 1);
  max-height: 86dvh;
  overflow: auto;
}
.sheet.is-open { transform: none; }
.sheet h2 { margin-bottom: 0.25rem; }
.sheet .grab { width: 42px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 0.9rem; }

.numpad { display: grid; grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); gap: 0.5rem; margin: 1rem 0 1.2rem; }
.num {
  min-height: 54px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  font: inherit;
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--ink);
  cursor: pointer;
}
.num.is-sel { background: var(--navy); border-color: var(--navy); color: #fff; }

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

/* =========================================================================
   Правки по ревью канона 02 и мобильного UX.
   ========================================================================= */

/* Волосяные линии и вторичные точки — прежний светлый тон; текст — новый. */
.dot.seen { background: var(--muted-line); }
.chip.is-flagged { border-color: var(--muted-line); }

/* Видимый фокус: без него ведущий с клавиатуры не понимает, где находится. */
:focus-visible {
  outline: 2px solid var(--flash);
  outline-offset: 2px;
  border-radius: 4px;
}
.cardscreen :focus-visible,
.sheet :focus-visible { outline-color: #fff; }

/* Один громкий элемент на экран: код комнаты — герой, заголовок уступает. */
#scr-wait h1 { font-size: var(--fs-h2); }
#scr-monitor .code-badge b { font-size: 1.6rem; }

/* Мера текста — не только для абзацев. */
ul, ol { max-width: var(--measure); }

/* Таблицы на 380px не должны распирать страницу. */
.scrollx { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.scrollx table.board { min-width: 480px; }
@media (max-width: 560px) {
  .scrollx table.board { min-width: 0; }
  #lbTable .opt { display: none; }
}

/* Главные кнопки раунда — в досягаемости большого пальца на телефоне. */
@media (max-width: 720px) {
  .sticky-actions {
    position: sticky;
    bottom: 0;
    background: linear-gradient(rgba(248, 249, 251, 0), var(--paper) 40%);
    padding: 1rem 0 calc(env(safe-area-inset-bottom, 0px) + 0.6rem);
    z-index: 5;
  }
}

/* Миниатюры кадров в ленте разбора: обсуждать стык по картинке, а не по номеру. */
.slot .thumb {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 4px;
  margin: 0.35rem 0;
  background: var(--line);
}
.ribbon.compact .slot { text-align: center; }

.talk li { margin-bottom: 0.2rem; }

/* --- Экран карты: читаемость и состояние ответа --------------------------- */

/* Подсказки лежат поверх произвольной картинки — фон должен быть непрозрачным. */
.cardtop { background: var(--navy-800); }
.cardtop .t-hint { color: var(--navy-300); }
.cardtop .t-win.is-warning { color: var(--flash); }
.cardback .tap { background: var(--navy-900); color: #fff; }
.zoomhint { background: var(--navy-900); color: #fff; }

.cardbottom { flex-direction: column; align-items: stretch; gap: 0.45rem; }
.cardbottom-row { display: flex; gap: 0.6rem; align-items: center; }
/* Выбор подтверждаем плотностью, а не цветом: оранжевый на этом экране
   уже занят обратным отсчётом окна (канон 02 §3 — одна вспышка). */
.pick-btn.is-set { border-color: #ffffff66; background: #ffffff24; }
.pick-btn .chev { opacity: 0.6; font-size: 0.9rem; }
.pick-btn.is-sent { border-color: var(--ok); }

/* Главная кнопка на тёмном экране: navy на navy её не видно. */
.btn.card-go {
  background: #fff;
  color: var(--navy);
  border-color: #fff;
  padding-inline: 1.3rem;
}
.btn.card-go[disabled] {
  opacity: 1;
  background: #ffffff26;
  color: #ffffff8c;
  border-color: #ffffff33;
}

/* Состояние ответа живёт постоянно, а не 4 секунды тоста. */
.answerline {
  margin: 0;
  min-height: 1.1rem;
  font-size: 0.8rem;
  color: var(--navy-300);
  text-align: center;
}
.answerline.is-sent { color: #9fd2b8; }
.answerline.is-closing { color: var(--flash); font-weight: 600; }
.answerline.is-conflict { color: #f0b1a6; font-weight: 600; }

/* Безопасные зоны в альбомной ориентации, не только сверху и снизу. */
.cardtop, .cardbottom {
  padding-left: max(0.9rem, env(safe-area-inset-left));
  padding-right: max(0.9rem, env(safe-area-inset-right));
}

/* --- Шторка выбора номера -------------------------------------------------- */

/* dvh знают не все: без запасного vh шторка при N=30 уезжала за верх экрана. */
.sheet { max-height: 86vh; overscroll-behavior: contain; visibility: hidden; }
.sheet.is-open { visibility: visible; }
@supports (height: 1dvh) { .sheet { max-height: 86dvh; } }
.sheet #sheetClose { position: sticky; bottom: 0; }

/* Переключатель локали — палец, а не мышь. */
.lang { min-width: 44px; min-height: 44px; }

/* Постоянная плашка вместо стопки одинаковых тостов «нет связи». */
.offline {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  z-index: 95;
  padding: 0.5rem 1rem calc(0.5rem + env(safe-area-inset-top, 0px));
  background: var(--warn);
  color: #fff;
  font-size: 0.85rem;
  text-align: center;
  transform: translateY(-110%);
  transition: transform 200ms;
}
body.is-offline .offline { transform: none; }

/* Шапка не должна ломаться на две строки из-за переключателя языка. */
.brand { flex-wrap: nowrap; }
.brand span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
