@font-face {
  font-family: "UKIJ";
  src: url("fonts/UKIJ_MacEkranBold.ttf") format("truetype");
  font-weight: 100 900;
}

:root {
  --red:     #c0392b;
  --red-lt:  #fadbd8;
  --blue:    #1a6fa8;
  --blue-lt: #d6eaf8;
  --tan:     #b8956a;
  --tan-lt:  #f5ece0;
  --black:   #1c1c1c;

  --bg:      #ece6dc;
  --surface: #fdf8f2;
  --border:  #d5c8b5;
  --text:    #2c2415;
  --muted:   #7a6a55;

  --radius:  8px;

  /* Both scripts share one size — add Cyrillic later as a third .card-cyrillic */
  --font-card: clamp(10px, 1.7vw, 16px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: "UKIJ", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.7s ease;
}
body[data-turn="red"]  { background: #f0dbd8; }
body[data-turn="blue"] { background: #d8e6f0; }

/* ── Lobby ──────────────────────────────── */

.lobby-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.lobby-inner {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.lobby-title {
  font-family: "UKIJ", serif;
  font-size: 2.4rem;
  color: #3a2c14;
  direction: rtl;
  text-align: center;
  line-height: 1.2;
}

.lobby-sub {
  font-size: 0.85rem;
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-top: -14px;
}

.lobby-profile {
  width: 100%;
}

.lobby-name-input {
  width: 100%;
  padding: 10px 14px;
  font-size: 1rem;
  font-family: inherit;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-align: center;
  outline: none;
}
.lobby-name-input:focus { border-color: var(--tan); }

.lobby-actions {
  display: flex;
  gap: 10px;
  width: 100%;
}

.btn-lobby {
  flex: 1;
  padding: 12px;
  font-size: 0.95rem;
  font-weight: 700;
  font-family: inherit;
  border-radius: var(--radius);
  cursor: pointer;
  border: 2px solid transparent;
  transition: opacity 0.15s;
}
.btn-lobby:hover { opacity: 0.85; }

.btn-lobby-outline {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
.btn-lobby-outline:hover { border-color: var(--tan); }

.lobby-join {
  display: flex;
  gap: 8px;
  width: 100%;
}

.lobby-code-input {
  flex: 1;
  padding: 8px 12px;
  font-size: 0.95rem;
  font-family: monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  outline: none;
}
.lobby-code-input:focus { border-color: var(--tan); }

.btn-lobby-sm {
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: inherit;
  border: none;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--surface);
  cursor: pointer;
}
.btn-lobby-sm:hover { opacity: 0.85; }

.lobby-games {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.lobby-games-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.btn-lobby-refresh {
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: var(--muted);
  padding: 0 4px;
  line-height: 1;
}
.btn-lobby-refresh:hover { color: var(--text); }

.lobby-games-list { padding: 4px 0; }

.lobby-loading,
.lobby-empty {
  padding: 16px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}

.lobby-game-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.lobby-game-row:last-child { border-bottom: none; }

.lobby-game-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.lobby-game-code-badge {
  font-family: monospace;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text);
}

.lobby-game-turn {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
}
.lobby-turn-red  { background: var(--red-lt);  color: var(--red); }
.lobby-turn-blue { background: var(--blue-lt); color: var(--blue); }

.lobby-game-players {
  font-size: 0.75rem;
  color: var(--muted);
  display: flex;
  gap: 5px;
}
.lobby-count-red  { color: var(--red);  font-weight: 700; }
.lobby-count-blue { color: var(--blue); font-weight: 700; }

.lobby-join-btn { white-space: nowrap; }

.lobby-password-row {
  width: 100%;
}
.lobby-password-input {
  font-size: 0.9rem;
  color: var(--muted);
}
.lobby-password-input::placeholder { color: var(--muted); opacity: 0.8; }

.lobby-lock {
  font-size: 0.8rem;
  line-height: 1;
}

.lobby-settings {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.lobby-settings-toggle {
  display: block;
  padding: 9px 14px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  list-style: none;
}
.lobby-settings-toggle::-webkit-details-marker { display: none; }
.lobby-settings[open] .lobby-settings-toggle { border-bottom: 1px solid var(--border); }
.timer-presets {
  display: flex;
  gap: 8px;
  padding: 10px 8px 4px;
}
.timer-preset-btn {
  flex: 1;
  padding: 6px 0;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.timer-preset-btn:hover { border-color: var(--ink); color: var(--ink); }
.timer-preset-btn.active { border-color: var(--ink); background: var(--ink); color: var(--bg); }

.lobby-settings-grid {
  display: flex;
  gap: 0;
  padding: 10px 8px;
}
.lobby-setting {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 0 4px;
  border-right: 1px solid var(--border);
}
.lobby-setting:last-child { border-right: none; }
.lobby-setting-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--muted);
  text-transform: uppercase;
}
.lobby-setting-select {
  width: 100%;
  padding: 5px 6px;
  font-size: 0.85rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text);
  text-align: center;
  cursor: pointer;
}

/* ── Password prompt overlay ────────────── */

.pwd-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.pwd-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 32px 28px 24px;
  width: min(340px, 90vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.35);
}

.pwd-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.pwd-error {
  font-size: 0.85rem;
  color: var(--red);
  font-weight: 600;
  margin-top: -6px;
}

.pwd-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  align-items: center;
}

/* ── Back button ────────────────────────── */

.btn-back {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  white-space: nowrap;
}
.btn-back:hover { color: var(--text); }

/* ── App ────────────────────────────────── */

.app {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 12px 48px;
}

/* ── Header ─────────────────────────────── */

header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 0 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

.app-title {
  font-family: "UKIJ", serif;
  font-size: 1.4rem;
  color: #3a2c14;
  direction: rtl;
  flex-shrink: 0;
}

.spy-badge {
  background: #d4ac0d;
  color: #1a1200;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  padding: 3px 8px;
  border-radius: 4px;
  flex-shrink: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.game-code {
  display: flex;
  align-items: baseline;
  gap: 5px;
}
.code-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--muted);
}
.code-value {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  font-variant-numeric: tabular-nums;
}

/* ── Controls bar ───────────────────────── */

.controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
}

.controls-center {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 5px;
  flex-shrink: 0;
}

.controls-center-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.round-timer-track {
  height: 5px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.round-timer-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s linear;
  width: 0%;
}

.reserve-panel {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}

.reserve-panel-header {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.reserve-panel-red  .reserve-panel-header { justify-content: flex-start; }
.reserve-panel-blue .reserve-panel-header { justify-content: flex-end; }

.reserve-panel-label {
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--muted);
  white-space: nowrap;
}
.reserve-panel-time {
  font-size: 1.05rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.reserve-panel-red  .reserve-panel-time { color: var(--red); }
.reserve-panel-blue .reserve-panel-time { color: var(--blue); }
.reserve-panel-time.reserve-low { color: #b05a00 !important; }

.reserve-track {
  height: 5px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.reserve-track-rtl { transform: scaleX(-1); }

.reserve-track-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.6s linear;
  width: 100%;
}
.reserve-fill-red  { background: var(--red); }
.reserve-fill-blue { background: var(--blue); }

.btn-play-pause {
  width: 36px;
  height: 36px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--text);
  border: none;
  font-size: 1rem;
  color: var(--surface);
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.btn-play-pause:hover    { opacity: 0.8; }
.btn-play-pause:disabled { opacity: 0.35; cursor: default; }

/* ── Main 3-column area ─────────────────── */

.main-area {
  display: grid;
  grid-template-columns: 170px 1fr 170px;
  gap: 10px;
  align-items: start;
}

.board-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.spectators-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.75rem;
  color: var(--muted);
}

.spectators-label {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--muted);
  opacity: 0.7;
  margin-right: 2px;
}

.spectator-chip {
  padding: 1px 8px;
  border-radius: 20px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--muted);
}

/* ── Sidebars ────────────────────────────── */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-header {
  padding: 10px 8px 8px;
  border-radius: var(--radius);
  text-align: center;
  border: 2px solid;
}
.sidebar-header-red  { background: var(--red-lt);  border-color: var(--red);  }
.sidebar-header-blue { background: var(--blue-lt); border-color: var(--blue); }

.sidebar-score {
  font-size: 2.6rem;
  font-weight: 800;
  line-height: 1;
}
.sidebar-red  .sidebar-score { color: var(--red); }
.sidebar-blue .sidebar-score { color: var(--blue); }

.sidebar-team-name {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  color: var(--muted);
  margin-top: 3px;
}

.sidebar-reserve {
  font-size: 0.72rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  margin-top: 2px;
  opacity: 0.85;
}
.sidebar-reserve.reserve-low { color: #b05a00; opacity: 1; }

.sidebar-players {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 2px 0;
}

.sidebar-players .player-chip {
  display: block;
  text-align: center;
}

/* ── Game log ────────────────────────────── */

.sidebar-log {
  display: flex;
  flex-direction: column;
  gap: 1px;
  font-size: 0.76rem;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 2px;
}

.log-round {
  border-top: 1px solid var(--border);
  padding-top: 4px;
  margin-top: 3px;
}
.log-round:first-child { border-top: none; padding-top: 0; margin-top: 0; }

.log-clue {
  display: flex;
  flex-direction: column;
  padding: 1px 0;
}

.log-by {
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 600;
}

.log-clue > span:last-child {
  font-weight: 800;
  color: var(--text);
  letter-spacing: 0.03em;
}

.log-reveal {
  display: flex;
  flex-direction: column;
  padding: 1px 0 1px 4px;
  color: var(--muted);
}

.log-reveal-card {
  display: flex;
  align-items: center;
  gap: 5px;
}

.log-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.log-dot-red   { background: var(--red); }
.log-dot-blue  { background: var(--blue); }
.log-dot-tan   { background: var(--tan); }
.log-dot-black { background: #555; }

.log-reveal-word { color: var(--text); }
.log-reveal.log-wrong .log-reveal-word { color: var(--muted); text-decoration: line-through; }

.log-pass {
  font-size: 0.7rem;
  color: var(--muted);
  font-style: italic;
  padding: 2px 0;
}

/* ── Round timer ────────────────────────── */

@keyframes blink { to { opacity: 0.35; } }

.round-timer {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.round-timer-type {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--muted);
  min-width: 80px;
  text-align: right;
}

.round-timer-display {
  font-size: 2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  line-height: 1;
  transition: color 0.3s;
  min-width: 70px;
}

.round-timer-display.timer-urgent  { color: var(--red); }
.round-timer-display.timer-reserve { color: #b05a00; }
.round-timer-display.timer-done    { color: var(--red); animation: blink 0.7s ease-in-out infinite alternate; }

/* ── Role picker overlay ────────────────── */

.role-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.role-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 32px 28px 24px;
  width: min(360px, 90vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.35);
}

.role-game-code {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--muted);
}
.role-game-code span {
  color: var(--text);
  font-size: 1rem;
}

.role-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.role-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
}

.role-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 10px;
  border-radius: 10px;
  border: 2px solid transparent;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.1s, box-shadow 0.15s;
}
.role-btn:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(0,0,0,0.15); }

.role-team-label {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}
.role-name-label {
  font-size: 0.92rem;
  font-weight: 600;
}

.role-spy.role-red  { background: var(--red);    color: #fff; border-color: var(--red); }
.role-spy.role-blue { background: var(--blue);   color: #fff; border-color: var(--blue); }
.role-ops.role-red  { background: var(--red-lt); color: var(--red);  border-color: var(--red); }
.role-ops.role-blue { background: var(--blue-lt); color: var(--blue); border-color: var(--blue); }

.picker-name-input {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  outline: none;
  text-align: center;
}
.picker-name-input:focus { border-color: var(--blue); }
.picker-name-input.error { border-color: var(--red); animation: shake 0.3s; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%       { transform: translateX(-5px); }
  75%       { transform: translateX(5px); }
}

/* ── Player chips ────────────────────────────── */

.player-chip {
  display: block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1.5px solid transparent;
  white-space: nowrap;
  text-align: center;
}

.sidebar-red  .player-chip { background: var(--red-lt);  color: var(--red);  border-color: var(--red);  }
.sidebar-blue .player-chip { background: var(--blue-lt); color: var(--blue); border-color: var(--blue); }
.player-chip.player-spy  { font-weight: 800; }
.player-chip.player-me   { border-width: 2px; text-decoration: underline; text-underline-offset: 2px; }
.player-chip.player-host { border-style: dashed; }

.players-section-divider {
  height: 1px;
  background: var(--border);
  margin: 3px 0;
}

.role-spectate {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.role-spectate:hover { color: var(--text); }

/* ── Shared button base ─────────────────── */

button { cursor: pointer; border: none; font-family: inherit; transition: opacity 0.15s; }
button:hover { opacity: 0.85; }

.btn-dark {
  padding: 7px 14px;
  background: var(--text);
  color: var(--surface);
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
}


.btn-outline {
  padding: 7px 14px;
  background: transparent;
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
}
.btn-outline:hover { background: var(--bg); opacity: 1; }
.btn-outline.active {
  background: #d4ac0d;
  color: #1a1200;
  border-color: #c49b00;
}

/* ── Turn bar ───────────────────────────── */

.turn-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  min-height: 44px;
  flex-wrap: wrap;
  transition: border-left-color 0.3s;
}

.turn-bar[data-team="red"]  { border-left-color: var(--red); }
.turn-bar[data-team="blue"] { border-left-color: var(--blue); }

.turn-main {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.turn-badge {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.68rem;
  font-weight: 800;
  white-space: nowrap;
  background: var(--border);
  color: var(--muted);
  transition: background 0.3s, color 0.3s;
}
.turn-badge[data-team="red"]  { background: var(--red);  color: #fff; }
.turn-badge[data-team="blue"] { background: var(--blue); color: #fff; }

.turn-status {
  font-size: 0.9rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.turn-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.clue-form {
  display: flex;
  align-items: center;
  gap: 6px;
}

.clue-word-input {
  width: 140px;
  padding: 5px 10px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 0.88rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.clue-word-input:focus { border-color: var(--blue); }

.clue-count-input {
  width: 54px;
  padding: 5px 6px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 0.88rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  text-align: center;
  outline: none;
}
.clue-count-input:focus { border-color: var(--blue); }

.btn-sm { padding: 5px 12px; font-size: 0.82rem; }

.btn-pass {
  padding: 5px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  font-family: inherit;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-pass:hover { background: var(--bg); color: var(--text); }

/* ── Game message ───────────────────────── */

.game-message {
  text-align: center;
  padding: 10px 16px;
  background: #fef9e7;
  border: 1.5px solid #f0c030;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 10px;
}

/* ── Board ──────────────────────────────── */

.board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.board-card {
  aspect-ratio: 3 / 2;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px 6px;
  gap: 1px;
  cursor: pointer;
  user-select: none;
  overflow: hidden;
  transition: transform 0.1s, box-shadow 0.15s;
}
.board-card:hover:not(.revealed) {
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(0,0,0,0.13);
}

.board-card.votable { cursor: crosshair; }
.board-card.voted-by-me { box-shadow: 0 0 0 2.5px var(--tan); }

.vote-badges {
  position: absolute;
  bottom: 3px; left: 3px; right: 3px;
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  pointer-events: none;
}

.vote-badge {
  background: var(--tan);
  color: #fff;
  font-size: 0.5rem;
  font-weight: 600;
  border-radius: 3px;
  padding: 1px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.vote-badge-mine {
  outline: 1.5px solid var(--ink);
}

.card-reveal-btn {
  position: absolute;
  top: 3px; right: 3px;
  width: 20px; height: 20px;
  background: rgba(0,0,0,0.18);
  border: none;
  border-radius: 4px;
  font-size: 0.7rem;
  line-height: 1;
  cursor: pointer;
  color: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.55;
  transition: opacity 0.12s;
}
.card-reveal-btn:hover { opacity: 1; background: rgba(0,0,0,0.3); }

.board-card { position: relative; }

.vote-hint {
  font-size: 0.78rem;
  color: var(--tan);
  font-style: italic;
  padding: 0 4px;
}

/* Both scripts same size — Cyrillic will be a third sibling with same class */
.card-arabic,
.card-latin {
  font-size: var(--font-card);
  line-height: 1.25;
  text-align: center;
  word-break: break-word;
}

.card-arabic {
  font-family: "UKIJ", serif;
  font-weight: 700;
  direction: rtl;
}

.card-latin {
  font-weight: 600;
  letter-spacing: 0.01em;
  color: #5a4830;
}

/* ── Revealed states ────────────────────── */

.board-card.revealed { cursor: default; }
.board-card.revealed:hover { transform: none; box-shadow: none; }

.board-card.revealed.color-red   { background: var(--red);   border-color: var(--red);   color: white; }
.board-card.revealed.color-blue  { background: var(--blue);  border-color: var(--blue);  color: white; }
.board-card.revealed.color-tan   { background: var(--tan);   border-color: var(--tan);   color: #2c1800; }
.board-card.revealed.color-black { background: var(--black); border-color: var(--black); color: white; }

.board-card.revealed.color-red   .card-latin,
.board-card.revealed.color-blue  .card-latin,
.board-card.revealed.color-black .card-latin { color: rgba(255,255,255,0.65); }
.board-card.revealed.color-tan   .card-latin { color: rgba(0,0,0,0.5); }

/* ── Spymaster tints ────────────────────── */

.board-card.spy-red   { background: var(--red-lt);  border: 2px solid var(--red);  }
.board-card.spy-blue  { background: var(--blue-lt); border: 2px solid var(--blue); }
.board-card.spy-tan   { background: var(--tan-lt);  border: 2px solid var(--tan);  }
.board-card.spy-black { background: #d8d8d8;        border: 2px solid #555;        }


/* ── Responsive ─────────────────────────── */

@media (max-width: 800px) {
  .main-area {
    grid-template-columns: 1fr;
  }
  .sidebar {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }
  .sidebar-header  { flex: 0 0 auto; }
  .sidebar-players { flex: 1 1 auto; flex-direction: row; flex-wrap: wrap; }
  .sidebar-log     { flex: 1 1 100%; max-height: 120px; }
  .sidebar-red  { order: 2; }
  .sidebar-blue { order: 3; }
  .board-wrap   { order: 1; }
}

@media (max-width: 600px) {
  /* Header: hide title so game code + New Game button have room */
  .app-title { display: none; }

  /* Controls bar: collapse to just the center timer */
  .controls {
    grid-template-columns: 1fr;
    padding: 8px 12px;
  }
  .controls .reserve-panel { display: none; }
  .round-timer-display { font-size: 1.6rem; }
  .round-timer-type    { font-size: 0.6rem; min-width: 64px; }

  /* Main area: board full-width on top, sidebars side-by-side below */
  .main-area {
    grid-template-columns: 1fr 1fr;
  }
  .board-wrap   { grid-column: 1 / -1; grid-row: 1; }
  .sidebar-red  { grid-column: 1;      grid-row: 2; }
  .sidebar-blue { grid-column: 2;      grid-row: 2; }

  /* Sidebar: column layout within each half-width panel */
  .sidebar         { flex-direction: column; gap: 4px; }
  .sidebar-header  { display: flex; flex-direction: row; align-items: center;
                     gap: 8px; padding: 6px 10px; text-align: left; }
  .sidebar-score   { font-size: 1.5rem; line-height: 1; flex-shrink: 0; }
  .sidebar-team-name { font-size: 0.6rem; flex: 1; }
  .sidebar-reserve { margin-top: 0; flex-shrink: 0; }
  .sidebar-players { flex: 0 0 auto; flex-direction: row; flex-wrap: wrap; }
  .sidebar-log     { display: none; }
  .spectators-bar  { display: none; }

  /* Board cards */
  .board { gap: 4px; }
  .board-card { gap: 0; padding: 2px 3px; }
  :root { --font-card: clamp(7px, 2.3vw, 12px); }
}

/* ── Auth overlay ────────────────────────── */

.auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  z-index: 200;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
  text-align: center;
}

.auth-tabs {
  display: flex;
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.auth-tab {
  flex: 1;
  padding: 9px;
  font-size: 0.88rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.auth-tab + .auth-tab { border-left: 1.5px solid var(--border); }
.auth-tab.auth-tab-active { background: var(--text); color: var(--surface); }

.auth-name-row { width: 100%; }

.auth-oauth {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.btn-oauth {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1.5px solid var(--border);
  transition: opacity 0.15s, box-shadow 0.15s;
}
.btn-oauth:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.12); opacity: 0.92; }

.btn-google {
  background: var(--surface);
  color: var(--text);
}

.btn-apple {
  background: #1c1c1e;
  color: #fff;
  border-color: #1c1c1e;
}

.auth-error {
  font-size: 0.85rem;
  color: var(--red);
  font-weight: 600;
  text-align: center;
  margin-top: -4px;
}

.auth-divider {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  position: relative;
  width: 100%;
  text-align: center;
}
.auth-divider::before,
.auth-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: var(--border);
}
.auth-divider::before { left: 0; }
.auth-divider::after  { right: 0; }

/* ── Lobby user indicator ─────────────────── */

.lobby-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--muted);
  width: 100%;
  justify-content: flex-end;
}

.auth-text-btn {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 0;
}
.auth-text-btn:hover { color: var(--red); opacity: 1; }
.script-toggle-btn { font-size: 1rem; font-weight: 700; }

/* ── Lobby mode toggle ────────────────────── */

.lobby-mode {
  display: flex;
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.mode-btn {
  flex: 1;
  padding: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.mode-btn + .mode-btn { border-left: 1.5px solid var(--border); }
.mode-btn.mode-btn-active { background: var(--text); color: var(--surface); }

/* ── Lobby user section ───────────────────── */

.lobby-user {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.lobby-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 1.5px solid var(--border);
  flex-shrink: 0;
}

.lobby-user-details {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1;
  min-width: 0;
  font-size: 0.82rem;
  color: var(--text);
  overflow: hidden;
}

.lobby-user-medal {
  font-size: 0.72rem;
  color: var(--muted);
}

/* ── Ranked badge (in-game header) ─────────── */

.ranked-badge {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #d4ac0d;
  background: #1a1200;
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Role picker ranked message ─────────────── */

.role-ranked-msg {
  font-size: 0.82rem;
  color: var(--red);
  text-align: center;
  padding: 4px 0;
}

/* ── Profile overlay ─────────────────────────── */

.profile-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
  padding: 16px;
}

.profile-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 32px 28px 24px;
  width: min(360px, 90vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.35);
  position: relative;
}

.profile-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
  padding: 2px 4px;
}
.profile-close:hover { color: var(--text); opacity: 1; }

.profile-avatar-img {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
  border: 2.5px solid var(--border);
}

#profile-view {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.profile-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.profile-name-text {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}

.profile-medal-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.profile-medal-badge {
  font-size: 1rem;
  font-weight: 700;
}

.profile-mmr-val {
  font-size: 0.82rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.profile-stats {
  display: flex;
  gap: 0;
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.profile-stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 8px;
  gap: 3px;
  border-right: 1.5px solid var(--border);
}
.profile-stat:last-child { border-right: none; }

.profile-stat-value {
  font-size: 1.3rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.profile-stat-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--muted);
  text-transform: uppercase;
}

.profile-edit-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.profile-edit-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
}

/* ── Ranks table ─────────────────────────── */

.ranks-table {
  display: flex;
  flex-direction: column;
  padding: 6px 0;
}

.rank-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.rank-row:last-child { border-bottom: none; }

.rank-emoji { font-size: 1.1rem; flex-shrink: 0; width: 24px; text-align: center; }

.rank-name {
  flex: 1;
  font-weight: 600;
  color: var(--text);
}

.rank-pct {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  min-width: 80px;
  text-align: right;
}

.rank-mmr {
  font-size: 0.7rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-width: 110px;
  text-align: right;
}

.rank-row-lion .rank-name { color: var(--tan); font-weight: 700; }

/* ── MMR Summary overlay ─────────────────────────────────────────────── */

.mmr-summary-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
  padding: 16px;
}

.mmr-summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  max-width: 480px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}

.mmr-summary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.mmr-summary-header h3 { margin: 0; font-size: 1rem; color: var(--text); }

.mmr-summary-rows { display: flex; flex-direction: column; gap: 6px; }

.mmr-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 0.83rem;
  background: var(--bg);
}
.mmr-team-red  { border-left: 3px solid var(--red); }
.mmr-team-blue { border-left: 3px solid var(--blue); }

.mmr-name  { flex: 1; font-weight: 600; color: var(--text); }
.mmr-mmr   { color: var(--muted); font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.mmr-delta { font-weight: 700; font-variant-numeric: tabular-nums; min-width: 36px; text-align: right; }
.mmr-gain  { color: #2e7d32; }
.mmr-loss  { color: var(--red); }
.mmr-breakdown { font-size: 0.7rem; color: var(--muted); white-space: nowrap; }

/* Uyghur text elements — suppress uppercase so Latin script keeps initial caps */
[data-u] { text-transform: none; letter-spacing: 0; }
