/* ==========================================================================
   Game screen
   ========================================================================== */

/* ------------------------------------------------------------- round bar -- */

.round-bar {
  height: 4px;
  flex: none;
  background: rgb(255 255 255 / 0.06);
}
.round-bar span {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: left;
  background: linear-gradient(90deg, var(--mint), var(--sky));
  transition: transform 200ms linear, background 600ms var(--ease);
}
.round-bar.is-low span { background: linear-gradient(90deg, var(--warn), var(--brand)); }
.round-bar.is-critical span {
  background: linear-gradient(90deg, var(--danger), var(--brand));
  animation: pulse-bar 900ms ease-in-out infinite;
}

@keyframes pulse-bar { 50% { opacity: 0.45; } }

/* ---------------------------------------------------------------- topbar -- */

.topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px clamp(12px, 2vw, 20px);
  border-bottom: 1px solid var(--line-soft);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.topbar-right { justify-content: flex-end; }
.topbar-mid { display: flex; align-items: center; gap: 10px; }

.mini-mark { font-size: 1.3rem; line-height: 1; }
.round-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-dim);
  white-space: nowrap;
}

.clock {
  font-family: var(--mono);
  font-size: 1.25rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}
.clock.is-low { color: var(--warn); }
.clock.is-critical { color: var(--danger); animation: tick-pop 1s var(--ease) infinite; }

@keyframes tick-pop { 50% { transform: scale(1.12); } }

.code-chip { font-family: var(--mono); letter-spacing: 0.16em; }

/* ------------------------------------------------------------ game grid --- */

.game-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr) 288px;
  gap: 14px;
  padding: 14px clamp(12px, 2vw, 20px) 16px;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 14px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  background: rgb(255 255 255 / 0.028);
  backdrop-filter: blur(10px);
}

.panel-title {
  flex: none;
  margin-bottom: 10px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* ----------------------------------------------------------- scoreboard --- */

.scoreboard { flex: 1; min-height: 0; overflow-y: auto; display: grid; gap: 6px; align-content: start; }

.sb-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgb(255 255 255 / 0.035);
  border: 1px solid transparent;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.sb-row .avatar { width: 32px; height: 32px; font-size: 1rem; border-radius: 10px; }
.sb-main { flex: 1; min-width: 0; display: grid; }
.sb-name {
  font-size: 0.88rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sb-sub { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-faint); }
.sb-score { font-family: var(--mono); font-size: 1rem; font-weight: 800; font-variant-numeric: tabular-nums; }

.sb-row.is-drawer {
  background: color-mix(in srgb, var(--violet) 16%, transparent);
  border-color: color-mix(in srgb, var(--violet) 42%, transparent);
}
.sb-row.is-drawer .sb-sub { color: var(--violet); }

.sb-row.is-active {
  background: color-mix(in srgb, var(--sky) 16%, transparent);
  border-color: color-mix(in srgb, var(--sky) 55%, transparent);
  transform: translateX(2px);
}
.sb-row.is-active .sb-sub { color: var(--sky); }
.sb-row.is-active::before {
  content: "";
  position: absolute;
  left: -1px; top: 10%;
  width: 3px; height: 80%;
  border-radius: 999px;
  background: var(--sky);
}

.sb-row.is-offline { opacity: 0.4; }

/* The "you" marker is a real element so it can be translated. */
.sb-you { display: none; }
.sb-row.is-you .sb-you {
  display: inline;
  margin-left: 6px;
  font-style: normal;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.sb-gain {
  position: absolute;
  right: 10px; top: -4px;
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--mint);
  animation: float-up 1200ms var(--ease) forwards;
  pointer-events: none;
}
.sb-gain.is-down { color: var(--danger); }
@keyframes float-up {
  from { opacity: 0; transform: translateY(6px); }
  25%  { opacity: 1; transform: translateY(-2px); }
  to   { opacity: 0; transform: translateY(-18px); }
}

/* ---------------------------------------------------------------- stage --- */

.stage {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  min-width: 0;
}

/* word tiles */

.word-strip { flex: none; display: grid; justify-items: center; gap: 6px; }

.word-tiles {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}

.tile {
  display: grid;
  place-items: center;
  width: clamp(24px, 3.1vw, 38px);
  height: clamp(32px, 4vw, 48px);
  border-radius: 9px;
  background: rgb(255 255 255 / 0.05);
  border-bottom: 2px solid var(--line);
  font-family: var(--mono);
  font-size: clamp(1rem, 2.1vw, 1.5rem);
  font-weight: 800;
  /* Uppercased in JS, not CSS - see `upper()`: ß must stay one glyph. */
  color: var(--text-faint);
}
.tile.is-space { width: clamp(10px, 1.4vw, 16px); background: none; border-bottom-color: transparent; }
.tile.is-open {
  color: var(--ink);
  background: linear-gradient(160deg, #fff8ef, #ffe1c9);
  border-bottom-color: var(--brand);
  animation: tile-flip 420ms var(--ease);
}
.tile.is-secret {
  color: var(--ink);
  background: linear-gradient(160deg, var(--mint), #7ef0c0);
  border-bottom-color: #0f9c6c;
}

@keyframes tile-flip {
  from { transform: rotateX(-90deg) scale(0.8); opacity: 0; }
}

.word-meta {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-faint);
  text-align: center;
}
.word-meta b { color: var(--text-dim); }
.word-meta .meta-cost b { color: var(--danger); }

/* canvas */

/*
 * The board is sized in JS so every client shows the same 1600x1050 bitmap at
 * the same aspect ratio - a stretched board would distort the drawing.
 */
.canvas-area {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
}

.canvas-shell {
  position: relative;
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #fdfcfa;
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--line-soft);
}

#board {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}
#board.is-drawing { cursor: crosshair; }
#board.is-filling { cursor: cell; }

.canvas-veil {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  text-align: center;
  background: rgb(13 11 20 / 0.86);
  backdrop-filter: blur(6px);
  animation: fade-in 200ms var(--ease);
}
.canvas-veil[hidden] { display: none; }
.veil-inner { display: grid; gap: 10px; justify-items: center; max-width: 460px; }
.veil-kicker {
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.veil-title {
  font-size: clamp(1.5rem, 4vw, 2.4rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  text-wrap: balance;
}
.veil-body { display: grid; gap: 12px; justify-items: center; color: var(--text-dim); font-size: 0.92rem; }
.veil-body .btn-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.secret-word {
  font-family: var(--mono);
  font-size: clamp(1.6rem, 5vw, 2.6rem);
  font-weight: 800;
  letter-spacing: 0.06em;
  background: linear-gradient(120deg, var(--brand-2), var(--rose));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.react-layer { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.react-pop {
  position: absolute;
  bottom: 8%;
  font-size: 2rem;
  animation: react-rise 2.2s var(--ease) forwards;
}
@keyframes react-rise {
  from { opacity: 0; transform: translateY(20px) scale(0.6); }
  20%  { opacity: 1; transform: translateY(0) scale(1.1); }
  to   { opacity: 0; transform: translateY(-160px) scale(0.9) rotate(12deg); }
}

/* -------------------------------------------------------------- toolbar --- */

.toolbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line-soft);
  background: rgb(255 255 255 / 0.03);
}
.toolbar[hidden] { display: none; }

.swatches { display: flex; flex-wrap: wrap; gap: 5px; max-width: 340px; }
.swatch {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.25);
  transition: transform 140ms var(--ease), box-shadow 140ms var(--ease);
}
.swatch:hover { transform: translateY(-2px) scale(1.06); }
.swatch.is-on { box-shadow: 0 0 0 2px var(--text), inset 0 0 0 1px rgb(0 0 0 / 0.25); transform: translateY(-2px); }

.tool-group { display: flex; gap: 5px; }

.tool-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: rgb(255 255 255 / 0.05);
  font-size: 1.05rem;
  color: var(--text-dim);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), transform 140ms var(--ease);
}
.tool-btn:hover { background: rgb(255 255 255 / 0.12); color: var(--text); }
.tool-btn:active { transform: scale(0.94); }
.tool-btn.is-on { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #23150f; }
.tool-btn i { display: block; background: currentColor; border-radius: 50%; }
.tool-danger:hover { background: color-mix(in srgb, var(--danger) 30%, transparent); color: #fff; }

/* ----------------------------------------------------------- guess dock --- */

.guess-dock {
  flex: none;
  display: grid;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line-soft);
  background: rgb(255 255 255 / 0.03);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.guess-dock[hidden] { display: none; }
.guess-dock.is-mine {
  border-color: color-mix(in srgb, var(--sky) 60%, transparent);
  background: color-mix(in srgb, var(--sky) 10%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--sky) 14%, transparent);
}

.turn-strip { display: flex; align-items: center; gap: 12px; }

.turn-ring {
  position: relative;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 50%;
  background:
    conic-gradient(var(--ring-color, var(--sky)) calc(var(--ring, 1) * 360deg), rgb(255 255 255 / 0.09) 0);
  transition: background 200ms linear;
}
.turn-ring::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: var(--surface-0);
}
.turn-ring-num {
  position: relative;
  z-index: 1;
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.turn-text { flex: 1; min-width: 0; font-size: 0.95rem; font-weight: 700; }
.turn-text b { color: var(--sky); }
.turn-text .dim { color: var(--text-faint); font-weight: 600; }

.on-deck { display: flex; gap: 4px; align-items: center; }
.on-deck li {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 9px;
  background: rgb(255 255 255 / 0.06);
  font-size: 0.85rem;
  opacity: 0.75;
}

.guess-form { display: flex; gap: 8px; }
.guess-form input { flex: 1; height: 48px; }
.guess-form .btn { flex: none; min-width: 100px; min-height: 48px; }

/* letter pad */

/*
 * Auto-fitting rather than a fixed column count: the pad holds 26 Latin keys
 * or 33 Cyrillic ones depending on the room's word language, and has to stay
 * tappable on a phone either way.
 */
.letterpad {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(var(--key-min, 34px), 1fr));
  gap: 4px;
}

.key {
  height: 34px;
  border-radius: 9px;
  background: rgb(255 255 255 / 0.055);
  font-family: var(--mono);
  font-size: 0.86rem;
  font-weight: 800;
  color: var(--text-dim);
  /* Uppercased in JS along with everything else that shows a letter. */
  transition: background 140ms var(--ease), color 140ms var(--ease), transform 140ms var(--ease);
}
.key:hover:not(:disabled) { background: rgb(255 255 255 / 0.14); color: var(--text); transform: translateY(-1px); }
.key:active:not(:disabled) { transform: scale(0.93); }
.key:disabled { cursor: not-allowed; }
.key.is-hit {
  background: color-mix(in srgb, var(--mint) 32%, transparent);
  color: #d8fff0;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--mint) 55%, transparent);
}
.key.is-miss {
  background: rgb(255 255 255 / 0.02);
  color: var(--text-faint);
  text-decoration: line-through;
  opacity: 0.55;
}
.key.is-idle:disabled { opacity: 0.5; }

/* ----------------------------------------------------------------- feed --- */

.feed {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.feed-item {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 7px 10px;
  border-radius: 12px;
  background: rgb(255 255 255 / 0.03);
  font-size: 0.84rem;
  color: var(--text-dim);
  line-height: 1.4;
  animation: feed-in 260ms var(--ease);
  word-break: break-word;
}
.feed-item b { color: var(--text); font-weight: 700; white-space: nowrap; }
.feed-item .mono {
  font-family: var(--mono);
  font-weight: 800;
  color: var(--text);
}
.feed-item .pts { margin-left: auto; font-weight: 800; color: var(--mint); white-space: nowrap; }
.feed-item .pts.is-down { color: var(--danger); }

.feed-item[data-kind="letterHit"] { background: color-mix(in srgb, var(--mint) 14%, transparent); }
.feed-item[data-kind="solved"] {
  background: linear-gradient(120deg, color-mix(in srgb, var(--brand) 26%, transparent), color-mix(in srgb, var(--brand-2) 18%, transparent));
  color: var(--text);
}
.feed-item[data-kind="letterMiss"], .feed-item[data-kind="wordMiss"] { opacity: 0.72; }
.feed-item[data-kind="timeout"] { opacity: 0.6; font-style: italic; }
.feed-item[data-kind="turnStart"], .feed-item[data-kind="drawStart"], .feed-item[data-kind="roundEnd"],
.feed-item[data-kind="gameStart"], .feed-item[data-kind="gameEnd"] {
  background: none;
  justify-content: center;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

@keyframes feed-in { from { opacity: 0; transform: translateY(6px); } }

.reactions { flex: none; display: flex; gap: 5px; margin-top: 10px; justify-content: space-between; }
.reaction {
  flex: 1;
  height: 34px;
  border-radius: 11px;
  background: rgb(255 255 255 / 0.05);
  font-size: 1.05rem;
  transition: transform 140ms var(--ease), background 140ms var(--ease);
}
.reaction:hover { background: rgb(255 255 255 / 0.13); transform: translateY(-2px); }
.reaction:active { transform: scale(0.9); }

/* --------------------------------------------------------- mobile tabs --- */

.mobile-tabs { display: none; }

@media (max-width: 1080px) {
  .game-grid { grid-template-columns: 200px minmax(0, 1fr); }
  .panel-feed { display: none; }
}

@media (max-width: 820px) {
  .game-grid {
    grid-template-columns: minmax(0, 1fr);
    padding: 10px 10px 6px;
  }

  .panel-players, .panel-feed { display: none; }
  body[data-tab="players"] .panel-players { display: flex; }
  body[data-tab="feed"] .panel-feed { display: flex; }
  body[data-tab="players"] .stage, body[data-tab="feed"] .stage { display: none; }

  .mobile-tabs {
    flex: none;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    padding: 6px 10px calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line-soft);
  }
  .tab {
    height: 40px;
    border-radius: 12px;
    font-size: 0.84rem;
    font-weight: 700;
    color: var(--text-faint);
    background: rgb(255 255 255 / 0.04);
  }
  .tab.is-on { background: rgb(255 255 255 / 0.13); color: var(--text); }

  .toolbar { gap: 8px; padding: 8px; }
  .swatches { max-width: none; }
  .letterpad { --key-min: 30px; }
  .guess-form .btn { min-width: 84px; }
  .topbar-left .round-label { display: none; }
}
