:root {
  --paper: #f4efe6;
  --paper-2: #ebe3d4;
  --card: #fffdf8;
  --ink: #24201c;
  --ink-2: #6b6259;
  --line: #d8cfbf;
  --red: #c8553d;
  --red-soft: #f2d6cc;
  --blue: #2f6690;
  --blue-soft: #d2e0ec;
  --neutral: #d9cbb0;
  --trap: #24201c;
  --gap: 6px;
  --radius: 10px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }

/* ---------- общие элементы ---------- */
.logo { font-weight: 800; font-size: 22px; letter-spacing: -0.02em; text-decoration: none; }
.logo span { color: var(--red); }
.logo.big { font-size: 56px; margin: 8px 0 0; }
.muted { color: var(--ink-2); }
.center { text-align: center; }

.btn {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 10px 16px;
  min-height: 44px;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}
.btn:hover { border-color: var(--ink-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: 14px; }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn.danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn.ghost { background: transparent; color: var(--ink-2); font-weight: 500; }
.btn.wide { width: 100%; }
.linkish { background: none; border: 0; padding: 4px; cursor: pointer; text-decoration: underline dotted; color: var(--ink); }

.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 8px 14px; min-height: 40px; cursor: pointer; font-weight: 600;
}
.chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 16px; }

.input {
  border: 1px solid var(--line); background: var(--card); border-radius: 10px;
  padding: 10px 12px; min-height: 44px; min-width: 0;
}
.input.small { padding: 6px 10px; min-height: 36px; font-size: 14px; }
.input:focus, .btn:focus-visible, .chip:focus-visible, .cell:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.error-line { color: var(--red); font-weight: 600; }
.confirm { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.confirm-q { font-weight: 700; font-size: 14px; }

/* ---------- главная ---------- */
.home { max-width: 520px; margin: 0 auto; padding: 24px 16px 48px; }
.tagline { font-size: 18px; color: var(--ink-2); margin: 4px 0 24px; }
.card-panel { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 16px; }
.card-panel h2 { margin: 0 0 8px; font-size: 18px; }
.label { font-weight: 700; font-size: 14px; color: var(--ink-2); }
.rules { margin: 0; padding-left: 20px; }
.rules li { margin: 6px 0; }

/* ---------- комната ---------- */
.room { max-width: 1200px; margin: 0 auto; padding: 8px 12px 32px; padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; gap: 10px; padding: 4px 0 8px; }
.topbar .score { margin-left: auto; font-weight: 800; font-size: 20px; display: flex; gap: 4px; align-items: baseline; }
.sc.t-red { color: var(--red); }
.sc.t-blue { color: var(--blue); }
.sc-sep { color: var(--ink-2); }
.banner { background: #fbe9c6; border: 1px solid #e8c98a; border-radius: 10px; padding: 8px 12px; margin-bottom: 8px; font-size: 14px; }

.layout { display: grid; gap: 16px; }
@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
}

.status {
  border-radius: 12px; padding: 10px 14px; margin-bottom: 8px;
  background: var(--card); border: 1px solid var(--line); border-left: 6px solid var(--ink-2);
  display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline;
}
.status.t-red { border-left-color: var(--red); }
.status.t-blue { border-left-color: var(--blue); }
.status.win.t-red { background: var(--red-soft); }
.status.win.t-blue { background: var(--blue-soft); }
.status .clue { font-size: 18px; }
.status .tries { margin-left: auto; color: var(--ink-2); font-size: 14px; }

.clue-form { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.clue-form .input { flex: 1 1 160px; }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper .num { min-width: 24px; text-align: center; font-weight: 800; font-size: 20px; }

.key-bar, .turn-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin: 8px 0; font-size: 14px; }

/* ---------- поле ---------- */
.board {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: var(--gap);
}
@media (max-width: 599px) and (orientation: portrait) {
  .board { grid-template-columns: repeat(var(--cols-narrow), minmax(0, 1fr)); }
}

.cell {
  position: relative;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: var(--radius);
  aspect-ratio: 3 / 2;
  min-width: 0;
  padding: 4px;
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  font-size: clamp(12px, 3.4vw, 19px);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .01em;
  line-height: 1.1;
  text-align: center;
  color: var(--ink);
  box-shadow: 0 1px 0 var(--line);
  cursor: default;
  transition: transform .08s ease, background .2s ease;
  overflow: hidden;
}
.cell { container-type: inline-size; }
.cell .word { overflow-wrap: anywhere; }
.cell.w-long { font-size: clamp(10px, 2.9vw, 17px); }
.cell.w-xlong { font-size: clamp(9px, 2.5vw, 15px); }
/* Шрифт под ширину карточки и длину слова, чтобы слово помещалось в одну строку.
   Браузеры без container queries оставят правила выше. */
.cell .word { font-size: clamp(9px, calc((100cqi - 6px) / (var(--len, 6) * 0.74)), 19px); }
/* Плотная сетка (6 столбцов) на телефоне: строчные буквы уже заглавных. */
@media (max-width: 599px) {
  .board.dense .cell { padding: 2px; text-transform: none; letter-spacing: 0; }
  .board.dense .cell .word { font-size: clamp(8px, calc((100cqi - 2px) / (var(--len, 6) * 0.6)), 14px); }
}
.cell:disabled { opacity: 1; }
.cell.pickable { cursor: pointer; }
.cell.pickable:hover { transform: translateY(-1px); border-color: var(--ink-2); }
.cell.armed { outline: 3px solid var(--ink); outline-offset: 1px; }
.hint-tap { font-size: 9px; font-weight: 600; text-transform: none; color: var(--ink-2); margin-top: 2px; }

/* открытые карточки */
.cell.open { color: #fff; border-color: transparent; box-shadow: none; }
.cell.open .word { opacity: .85; }
.cell.open.c-red { background: var(--red); }
.cell.open.c-blue { background: var(--blue); }
.cell.open.c-neutral { background: var(--neutral); color: var(--ink); }
.cell.open.c-trap { background: var(--trap); }

/* конец партии: неоткрытые показываем бледно */
.cell.ended.c-red { background: var(--red-soft); }
.cell.ended.c-blue { background: var(--blue-soft); }
.cell.ended.c-neutral { background: var(--paper-2); }
.cell.ended.c-trap { background: #8a837b; color: #fff; }

/* ключ капитана */
.cell.k-red { background: var(--red-soft); box-shadow: inset 6px 0 0 var(--red); }
.cell.k-blue { background: var(--blue-soft); box-shadow: inset 6px 0 0 var(--blue); }
.cell.k-neutral { background: var(--paper-2); }
.cell.k-trap { background: repeating-linear-gradient(45deg, #3a342e, #3a342e 6px, #24201c 6px, #24201c 12px); color: #fff; }

/* ---------- боковая панель ---------- */
.you { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 10px; }
.role-tag { font-size: 13px; font-weight: 700; padding: 2px 10px; border-radius: 999px; background: var(--paper-2); }
.role-tag.t-red { background: var(--red); color: #fff; }
.role-tag.t-blue { background: var(--blue); color: #fff; }
.name-form { display: inline-flex; gap: 6px; }

.teams { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.team { background: var(--card); border: 1px solid var(--line); border-top: 5px solid; border-radius: 12px; padding: 10px; min-width: 0; }
.team.t-red { border-top-color: var(--red); }
.team.t-blue { border-top-color: var(--blue); }
.team h3 { margin: 0 0 6px; font-size: 16px; display: flex; justify-content: space-between; }
.team.t-red h3 { color: var(--red); }
.team.t-blue h3 { color: var(--blue); }
.team .left { font-weight: 800; }
.seat { font-size: 14px; display: flex; flex-direction: column; margin-bottom: 6px; }
.seat-label { font-size: 12px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
.seat-name { font-weight: 700; overflow-wrap: anywhere; }
.seat-free { color: var(--ink-2); font-style: italic; }
.held { color: var(--ink-2); font-weight: 400; }
.team-actions { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.team-actions .btn { white-space: normal; }
.team.t-red .team-btn { border-color: var(--red); color: var(--red); }
.team.t-blue .team-btn { border-color: var(--blue); color: var(--blue); }
.players { list-style: none; margin: 8px 0 0; padding: 0; font-size: 14px; }
.players li { padding: 2px 0; overflow-wrap: anywhere; }
.players li.off { opacity: .5; }

.observers { font-size: 14px; margin: 10px 0; display: flex; flex-wrap: wrap; gap: 4px; align-items: baseline; }
.new-game { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 12px 0; }
.tabs { display: flex; gap: 8px; margin: 8px 0; }
.log { list-style: none; padding: 0; margin: 0; font-size: 14px; max-height: 260px; overflow: auto; }
.log li { padding: 4px 0 4px 8px; border-left: 3px solid var(--line); margin-bottom: 2px; }
.log li.t-red { border-left-color: var(--red); }
.log li.t-blue { border-left-color: var(--blue); }

.toast {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 12px;
  max-width: calc(100vw - 32px); font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.2); z-index: 10;
}

@media (max-width: 380px) {
  .topbar .btn { padding: 6px 10px; font-size: 13px; }
  :root { --gap: 4px; --radius: 8px; }
}
/* Телефон: фиксированная высота вместо пропорций — иначе карточки распирают сетку. */
@media (max-width: 599px) {
  .cell { aspect-ratio: auto; height: 58px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .cell { aspect-ratio: auto; height: 44px; }
}

/* ---------- звонок ---------- */
.voice { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; margin-bottom: 8px; }
.voice-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.voice-toggle { margin-left: auto; font-size: 14px; }
.small-text { font-size: 13px; }
.voice-note { margin: 6px 0 0; font-size: 14px; }
.btn.mic-on { background: #2e7d4f; border-color: #2e7d4f; color: #fff; }
.voice-people { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 14px; }
.voice-people li { display: inline-flex; align-items: center; gap: 6px; }
.voice-people .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); transition: background .15s, box-shadow .15s; }
.voice-people li.speaking .dot { background: #2e9e5b; box-shadow: 0 0 0 4px rgba(46, 158, 91, .25); }
.voice-people li.speaking .vname { font-weight: 700; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
