/* Wordrush — Kirbo's Games branding: dark navy, cyan accent #25CBE5, Manrope + Fira Code. */

:root {
  --navy-900: #070c16;
  --navy-800: #0b1220;
  --navy-700: #101a2c;
  --navy-600: #16233a;
  --navy-500: #1e2d48;
  --line: #24354f;
  --cyan: #25cbe5;
  --cyan-dim: #1497ad;
  --cyan-glow: rgba(37, 203, 229, 0.35);
  --gold: #f0b45a;
  --rose: #ff6b8a;
  --green: #49d99a;
  --text: #e8eefb;
  --muted: #93a3bf;
  --tile-bg: #f3e6c8;
  --tile-bg2: #e2cfa6;
  --tile-ink: #1b2437;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  font-synthesis-weight: none;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: Manrope, "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(37, 203, 229, 0.10), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(240, 180, 90, 0.07), transparent 55%),
    var(--navy-800);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

code, .mono, .tile-letter { font-family: "Fira Code", ui-monospace, monospace; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 50;
  background: var(--cyan); color: var(--navy-900);
  padding: 0.6rem 1rem; border-radius: 0 0 var(--radius-sm) 0; font-weight: 700;
}
.skip-link:focus { left: 0; }

/* ---------------------------------------------------------------- topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.75rem clamp(0.75rem, 3vw, 1.5rem);
  border-bottom: 1px solid var(--line);
  background: rgba(11, 18, 32, 0.85);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 20;
}

.brand { display: flex; align-items: center; gap: 0.65rem; text-decoration: none; color: inherit; }
.brand-mark {
  display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(145deg, var(--cyan), var(--cyan-dim));
  color: var(--navy-900); font-weight: 800; font-size: 0.85rem; letter-spacing: 0.02em;
  box-shadow: 0 0 0 1px rgba(37, 203, 229, 0.5), 0 6px 18px var(--cyan-glow);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-size: 1.05rem; letter-spacing: 0.01em; }
.brand-text small { color: var(--muted); font-size: 0.7rem; letter-spacing: 0.06em; text-transform: uppercase; }

.topnav { display: flex; gap: 0.5rem; align-items: center; }

/* ---------------------------------------------------------------- buttons */
.btn {
  font: inherit; font-size: 0.88rem; font-weight: 600;
  padding: 0.55rem 0.95rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--navy-600); color: var(--text);
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 0.4rem;
  transition: transform 120ms ease, background 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--navy-500); border-color: #33507a; }
.btn:active:not(:disabled) { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(145deg, var(--cyan), var(--cyan-dim));
  color: var(--navy-900); border-color: transparent; font-weight: 700;
}
.btn.primary:hover:not(:disabled) { box-shadow: 0 8px 22px var(--cyan-glow); }
.btn.ghost { background: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--navy-600); }
.btn[aria-pressed="false"] { color: var(--muted); }
.btn:focus-visible, .sq:focus-visible, .tile:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--cyan); outline-offset: 2px;
}

/* ---------------------------------------------------------------- layout */
main { padding: clamp(0.75rem, 2.5vw, 1.5rem); max-width: 1180px; margin: 0 auto; }
.panel { animation: rise 320ms ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

h1 { font-size: clamp(1.7rem, 4.5vw, 2.4rem); margin: 0.4rem 0 0.5rem; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; letter-spacing: 0.01em; }
.lede { color: var(--muted); max-width: 62ch; margin: 0 0 1.25rem; line-height: 1.55; }

/* ---------------------------------------------------------------- lobby */
.lobby-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.card {
  background: linear-gradient(180deg, var(--navy-700), var(--navy-800));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem; display: flex; flex-direction: column; gap: 0.5rem;
  box-shadow: var(--shadow);
}
.card label { font-size: 0.78rem; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.card input, .card select {
  font: inherit; padding: 0.6rem 0.7rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--navy-900); color: var(--text);
}
.card input { text-transform: none; }
#join-code { text-transform: uppercase; letter-spacing: 0.18em; font-family: "Fira Code", monospace; }
.card button { margin-top: 0.4rem; }

.status { margin: 1rem 0 0; min-height: 1.3em; color: var(--cyan); font-weight: 600; font-size: 0.9rem; }
.status.error { color: var(--rose); }

/* ---------------------------------------------------------------- scores */
.game { display: flex; flex-direction: column; gap: 1rem; }
.scorebar {
  display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: stretch; justify-content: space-between;
}
.seats { display: flex; flex-wrap: wrap; gap: 0.5rem; flex: 1 1 auto; }
.seat {
  flex: 1 1 130px; min-width: 120px;
  background: var(--navy-700); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 0.5rem 0.7rem; display: flex; flex-direction: column; gap: 0.15rem;
  transition: border-color 200ms ease, box-shadow 200ms ease, transform 200ms ease;
}
.seat .seat-name { font-weight: 700; font-size: 0.92rem; display: flex; align-items: center; gap: 0.4rem; }
.seat .seat-sub { font-size: 0.72rem; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.seat .seat-score { font-size: 1.35rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.seat.active { border-color: var(--cyan); box-shadow: 0 0 0 1px var(--cyan), 0 8px 24px var(--cyan-glow); }
.seat.active .seat-score { color: var(--cyan); }
.seat.you .seat-name::after {
  content: "you"; font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.08em;
  background: var(--navy-500); color: var(--cyan); border-radius: 999px; padding: 0.1rem 0.4rem;
}
.seat.offline { opacity: 0.6; }
.seat.offline .seat-sub::after { content: " · offline"; color: var(--gold); }

.scorebar-side { display: flex; gap: 0.5rem; align-items: stretch; }
.pouch {
  background: var(--navy-700); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 0.4rem 0.7rem; display: flex; flex-direction: column; justify-content: center; min-width: 66px;
}
.pouch-label { font-size: 0.65rem; color: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; }
.pouch-count { font-size: 1.2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.turncard {
  background: linear-gradient(145deg, var(--navy-600), var(--navy-700));
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 0.4rem 0.9rem; display: flex; align-items: center;
  font-weight: 700; font-size: 0.9rem; min-width: 130px; justify-content: center; text-align: center;
  transition: color 200ms ease, border-color 200ms ease;
}
.turncard.mine { color: var(--cyan); border-color: var(--cyan); box-shadow: 0 0 0 1px var(--cyan-glow); }
.turncard.waiting { color: var(--muted); }

/* ---------------------------------------------------------------- board */
.boardwrap { display: flex; justify-content: center; }

.board {
  --cell: clamp(20px, min(5.6vw, 4.1vh), 42px);
  display: grid;
  grid-template-columns: repeat(15, var(--cell));
  grid-template-rows: repeat(15, var(--cell));
  gap: 2px;
  padding: 6px;
  background: linear-gradient(160deg, var(--navy-600), var(--navy-900));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow), inset 0 0 60px rgba(37, 203, 229, 0.05);
  touch-action: manipulation;
}

.sq {
  position: relative;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  background: var(--navy-700);
  display: grid; place-items: center;
  font-size: 0.68em; color: var(--muted);
  cursor: pointer;
  transition: background 140ms ease, box-shadow 140ms ease, transform 140ms ease;
  padding: 0; font-family: inherit;
}
.sq:hover { background: var(--navy-500); }
.sq.tw { background: #7a2e3f; color: #ffd9e1; }
.sq.dw { background: #6b3a2a; color: #ffe3cf; }
.sq.tl { background: #2b4a7a; color: #d6e6ff; }
.sq.dl { background: #245f6e; color: #d3f4fb; }
.sq.star { background: linear-gradient(145deg, var(--cyan), var(--cyan-dim)); color: var(--navy-900); font-weight: 800; }

.sq.target { box-shadow: 0 0 0 2px var(--cyan), 0 0 18px var(--cyan-glow); z-index: 2; }
.sq.legal-hint { box-shadow: inset 0 0 0 2px rgba(73, 217, 154, 0.8); }
.sq.pending { background: #214a5c; }

/* ---------------------------------------------------------------- tiles */
.tile {
  position: relative;
  width: calc(var(--cell, 40px) - 2px);
  height: calc(var(--cell, 40px) - 2px);
  border-radius: 5px;
  background: linear-gradient(160deg, var(--tile-bg), var(--tile-bg2));
  color: var(--tile-ink);
  display: grid; place-items: center;
  font-weight: 800;
  font-size: calc(var(--cell, 40px) * 0.46);
  line-height: 1;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18), 0 2px 4px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  font-family: "Fira Code", ui-monospace, monospace;
  transition: transform 140ms ease, box-shadow 140ms ease;
  user-select: none;
}
.tile:hover { transform: translateY(-2px); box-shadow: inset 0 -2px 0 rgba(0,0,0,0.18), 0 6px 12px rgba(0,0,0,0.4); }
.tile .tile-val {
  position: absolute; right: 3px; bottom: 1px;
  font-size: calc(var(--cell, 40px) * 0.24); font-weight: 700; opacity: 0.65;
}
.tile.blank { background: linear-gradient(160deg, #dcdff0, #b9c0da); }
.tile.blank::after {
  content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(45deg, rgba(0,0,0,0.07) 0 3px, transparent 3px 6px);
  border-radius: 5px;
}
.tile.selected { transform: translateY(-4px) scale(1.04); box-shadow: 0 0 0 2px var(--cyan), 0 10px 18px var(--cyan-glow); }
.tile.on-board { cursor: default; }
.tile.on-board:hover { transform: none; }
.tile.just-played { animation: tileDrop 380ms cubic-bezier(0.22, 1.4, 0.4, 1) both; }
@keyframes tileDrop {
  0% { transform: translateY(-70%) scale(0.7) rotate(-8deg); opacity: 0; }
  60% { transform: translateY(4%) scale(1.06) rotate(1deg); opacity: 1; }
  100% { transform: none; }
}
.tile.pending-tile { animation: tileSettle 260ms cubic-bezier(0.22, 1.3, 0.4, 1) both; }
@keyframes tileSettle { from { transform: scale(1.22) translateY(-6px); } to { transform: none; } }

/* ---------------------------------------------------------------- rack */
.controls { display: grid; gap: 1rem; grid-template-columns: minmax(0, 1fr) minmax(260px, 340px); }
@media (max-width: 860px) { .controls { grid-template-columns: 1fr; } }

.rackwrap {
  background: linear-gradient(180deg, var(--navy-700), var(--navy-800));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.9rem; box-shadow: var(--shadow);
}
.rack {
  --cell: clamp(34px, 8vw, 46px);
  display: flex; flex-wrap: wrap; gap: 0.4rem; min-height: var(--cell);
}
.rack.small { --cell: 30px; }
.rackhint { font-size: 0.76rem; color: var(--muted); margin: 0.6rem 0 0; }

/* ---------------------------------------------------------------- staging */
.staging {
  background: linear-gradient(180deg, var(--navy-700), var(--navy-800));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0.9rem; display: flex; flex-direction: column; gap: 0.7rem; box-shadow: var(--shadow);
}
.pending {
  display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap;
  border-bottom: 1px dashed var(--line); padding-bottom: 0.6rem;
}
.pending-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.pending-words { font-weight: 700; font-size: 0.95rem; flex: 1 1 auto; word-break: break-word; }
.pending-words.invalid { color: var(--rose); }
.pending-words.valid { color: var(--green); }
.pending-score { font-weight: 800; font-size: 1.15rem; font-variant-numeric: tabular-nums; color: var(--cyan); }
.pending-score.bump { animation: scoreBump 480ms cubic-bezier(0.22, 1.4, 0.4, 1); }
@keyframes scoreBump {
  0% { transform: scale(1); }
  40% { transform: scale(1.45); color: var(--gold); }
  100% { transform: scale(1); }
}
.stage-buttons { display: flex; flex-wrap: wrap; gap: 0.45rem; }

.exchange-tray { border-top: 1px dashed var(--line); padding-top: 0.7rem; display: flex; flex-direction: column; gap: 0.6rem; }
.exchange-tray p { margin: 0; font-size: 0.82rem; color: var(--muted); }

/* ---------------------------------------------------------------- legend */
.legend { display: flex; flex-wrap: wrap; gap: 0.9rem; font-size: 0.75rem; color: var(--muted); align-items: center; }
.legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
.legend .sq { width: 16px; height: 16px; cursor: default; font-size: 0; }

/* ---------------------------------------------------------------- floaters */
.floater {
  position: fixed; z-index: 60; pointer-events: none;
  font-weight: 800; font-size: 1.5rem; color: var(--gold);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
  animation: floatUp 1100ms cubic-bezier(0.22, 1, 0.4, 1) both;
  font-variant-numeric: tabular-nums;
}
@keyframes floatUp {
  0% { opacity: 0; transform: translate(-50%, 0) scale(0.7); }
  25% { opacity: 1; transform: translate(-50%, -18px) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -70px) scale(1); }
}
.floater.minor { font-size: 1.05rem; color: var(--cyan); }

/* ---------------------------------------------------------------- invite & result */
.invite {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  margin: 1rem auto 0; max-width: 1180px; padding: 0.6rem 1rem;
  background: var(--navy-700); border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 0.82rem;
}
.invite span { color: var(--muted); text-transform: uppercase; letter-spacing: 0.07em; font-size: 0.7rem; }
.invite input {
  flex: 1 1 240px; font: inherit; font-size: 0.8rem;
  padding: 0.4rem 0.55rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--navy-900); color: var(--cyan);
  font-family: "Fira Code", monospace;
}

.result {
  margin-top: 1.5rem; background: linear-gradient(180deg, var(--navy-700), var(--navy-800));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 1.4rem; box-shadow: var(--shadow);
}
.result table { width: 100%; border-collapse: collapse; margin: 0.8rem 0 1.2rem; }
.result th, .result td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--line); }
.result th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); }
.result td.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.result tr.winner td { color: var(--gold); }
.result .tag { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--cyan); }

/* ---------------------------------------------------------------- dialog */
dialog.rules {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: linear-gradient(180deg, var(--navy-700), var(--navy-800));
  color: var(--text); max-width: 640px; padding: 1.4rem; box-shadow: var(--shadow);
}
dialog.rules::backdrop { background: rgba(4, 8, 16, 0.7); backdrop-filter: blur(3px); }
dialog.rules h2 { font-size: 1.2rem; }
dialog.rules h3 { font-size: 0.95rem; margin-top: 1.2rem; }
dialog.rules ol, dialog.rules ul { line-height: 1.6; padding-left: 1.2rem; }
dialog.rules li { margin-bottom: 0.4rem; }
dialog.rules form { margin-top: 1.2rem; text-align: right; }

/* ---------------------------------------------------------------- reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .panel { animation: none; }
  .tile:hover { transform: none; }
}

/* ---------------------------------------------------------------- small screens */
@media (max-width: 620px) {
  .topbar { padding: 0.6rem 0.7rem; }
  .brand-text small { display: none; }
  .topnav .btn { padding: 0.45rem 0.6rem; font-size: 0.8rem; }
  .board { --cell: clamp(18px, 6.05vw, 30px); gap: 1px; padding: 4px; }
  .controls { gap: 0.7rem; }
  .stage-buttons .btn { flex: 1 1 auto; justify-content: center; }
  .seat { flex: 1 1 46%; min-width: 0; }
  .seat .seat-score { font-size: 1.15rem; }
  .turncard { min-width: 0; font-size: 0.82rem; }
}
