/* Word Tiles — theme follows the Boggle/Scattergories suites; board is our own. */
:root {
  --bg: #1f2933;
  --panel: #111827;
  --text: #f9fafb;
  --muted: #cbd5e1;
  --accent: #93c5fd;
  --gold: #f59e0b;
  --ok: #4ade80;
  --err: #f87171;

  --cell: #2b3645;
  --grid: #0b1220;
  --tw: #c2410c;
  --dw: #7c3aed;
  --tl: #15803d;
  --dl: #0369a1;
  --tile: #fde68a;
  --tile-edge: #d4a72c;
  --tile-text: #3b2305;
  --tile-new: #bfdbfe;
  --tile-new-edge: #60a5fa;
  --tile-last: #fbbf24;
}
*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: system-ui, sans-serif; }
body { display: flex; justify-content: center; padding: env(safe-area-inset-top) 10px env(safe-area-inset-bottom); }
main { width: min(100%, 560px); padding: 14px 0 28px; }

h1 { margin: 0 0 2px; font-size: clamp(1.4rem, 6vw, 2rem); }
h2 { margin: 4px 0 10px; font-size: 1.2rem; }
.sub { color: var(--muted); font-size: .85rem; margin-bottom: 12px; }
.topbar { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.back { color: var(--accent); text-decoration: none; font-size: .85rem; white-space: nowrap; }

.panel {
  background: color-mix(in srgb, var(--panel) 92%, white);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 16px; padding: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
  margin-bottom: 12px;
}
.panel.tight { padding: 8px; }

/* Controls */
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.lbl { font-size: .8rem; color: var(--muted); }
.seg {
  height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,.12); background: rgba(255,255,255,.06);
  color: var(--muted); font: inherit; font-size: .85rem; cursor: pointer;
}
.seg.active { background: rgba(147,197,253,.2); border-color: var(--accent); color: var(--accent); }
.btn {
  height: 44px; padding: 0 16px; border-radius: 10px; border: none;
  background: #2563eb; color: #fff; font: inherit; font-size: .95rem; cursor: pointer;
}
.btn:active { opacity: .85; }
.btn:disabled { opacity: .4; cursor: default; }
.btn.ghost { background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.12); color: var(--text); }
.btn.wide { width: 100%; }
.btn.ghost.active { border-color: var(--accent); color: var(--accent); }
.btn.danger { background: rgba(248,113,113,.15); border: 1px solid rgba(248,113,113,.35); color: var(--err); }
.btn.small { height: 34px; padding: 0 12px; font-size: .85rem; }
input.text {
  height: 44px; border-radius: 10px; border: 1px solid rgba(255,255,255,.15);
  background: rgba(255,255,255,.07); color: var(--text); font: inherit;
  padding: 0 12px; outline: none; width: 100%;
}
input.text:focus { border-color: rgba(147,197,253,.5); }
.name-inputs { display: grid; gap: 8px; margin-bottom: 12px; }

.message { text-align: center; font-size: .9rem; min-height: 1.5em; color: var(--muted); }
.message.ok { color: var(--ok); }
.message.err { color: var(--err); }
.center { text-align: center; }
.spacer { height: 8px; }

/* Menu cards */
.menu { display: grid; gap: 10px; }
.menu a {
  display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--text);
  background: color-mix(in srgb, var(--panel) 92%, white);
  border: 1px solid rgba(255,255,255,.1); border-radius: 14px; padding: 14px;
  transition: border-color .15s, transform .15s;
}
.menu a:hover { border-color: rgba(255,255,255,.2); transform: translateY(-1px); }
.menu .icon { font-size: 1.5rem; width: 34px; text-align: center; flex-shrink: 0; }
.menu .m-name { font-weight: 700; }
.menu .m-desc { color: var(--muted); font-size: .8rem; margin-top: 1px; }

/* Scores strip */
.scores { display: flex; gap: 6px; flex-wrap: wrap; align-items: stretch; margin-bottom: 8px; }
.score-pill {
  flex: 1 1 0; min-width: 0; padding: 6px 8px; border-radius: 10px;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1);
  display: flex; flex-direction: column; align-items: center;
}
.score-pill .nm { font-size: .78rem; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-pill .pts { font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.score-pill.turn { border-color: var(--gold); background: rgba(245,158,11,.12); }
.score-pill.turn .nm { color: var(--gold); }
.score-pill.me .nm::after { content: ' (you)'; }
.bag-pill { flex: 0 0 auto; justify-content: center; }
.status { text-align: center; font-size: .9rem; color: var(--muted); margin: 2px 0 8px; min-height: 1.3em; }
.status.mine { color: var(--gold); font-weight: 700; }

/* Board */
.board-wrap { width: 100%; overflow: auto; border-radius: 8px; overscroll-behavior: contain; }
.wt-board {
  display: grid; grid-template-columns: repeat(15, 1fr); grid-template-rows: repeat(15, 1fr); gap: 2px;
  background: var(--grid); padding: 2px; width: 100%; aspect-ratio: 1;
  container-type: inline-size; user-select: none; -webkit-user-select: none;
}
.board-wrap.zoomed { aspect-ratio: 1; }
.board-wrap.zoomed .wt-board { width: 190%; }
.cell {
  position: relative; background: var(--cell); border-radius: 3px;
  display: flex; align-items: center; justify-content: center;
  font-size: 2.3cqw; font-weight: 700; color: rgba(255,255,255,.85); letter-spacing: -.02em;
  min-width: 0; min-height: 0; overflow: hidden;
}
.cell.T { background: var(--tw); }
.cell.D, .cell.star { background: var(--dw); }
.cell.t { background: var(--tl); }
.cell.d { background: var(--dl); }
.cell.star { font-size: 4.2cqw; }

.tile, .cell.has {
  background: var(--tile); color: var(--tile-text);
  box-shadow: inset 0 -.5cqw 0 var(--tile-edge);
}
.cell.has { font-size: 4.3cqw; font-weight: 800; }
.cell.has .v { position: absolute; right: 7%; bottom: 3%; font-size: 1.9cqw; font-weight: 700; }
.cell.has.blank .l { color: var(--dw); }
.cell.has.last { background: var(--tile-last); }
.cell.has.new { background: var(--tile-new); box-shadow: inset 0 0 0 .4cqw var(--tile-new-edge); cursor: grab; touch-action: none; }
.cell.has.word-bad { box-shadow: inset 0 0 0 .4cqw var(--err); }
.cell.drop-ok { outline: 2px solid var(--gold); outline-offset: -2px; }

/* Rack */
.rack {
  display: flex; gap: 6px; justify-content: center; align-items: center;
  min-height: 62px; margin: 10px 0 8px; padding: 6px;
  background: rgba(0,0,0,.18); border-radius: 12px;
}
.rtile {
  position: relative; width: min(12.5vw, 54px); aspect-ratio: 1; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: min(7vw, 1.8rem); font-weight: 800; cursor: grab; touch-action: none;
  border-bottom: 4px solid var(--tile-edge);
  transition: transform .1s;
}
.rtile .v { position: absolute; right: 8%; bottom: 4%; font-size: .45em; }
.rtile.sel { transform: translateY(-7px); box-shadow: 0 0 0 3px var(--accent); }
.rtile.pick { opacity: .45; }
.rtile.pick.on { opacity: 1; box-shadow: 0 0 0 3px var(--gold); }
.rtile.dragging { opacity: .3; }
.rack.off .rtile { cursor: default; }
.drag-ghost {
  position: fixed; z-index: 1000; pointer-events: none;
  width: 48px; height: 48px; margin: -30px 0 0 -24px;
  transform: scale(1.1); box-shadow: 0 8px 18px rgba(0,0,0,.45);
}

/* Preview line + action buttons */
.preview { text-align: center; font-size: .92rem; min-height: 1.5em; color: var(--muted); margin: 6px 0; }
.preview.ok { color: var(--ok); }
.preview.err { color: var(--err); }
.actions { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 6px; }
.actions .btn { padding: 0 6px; font-size: .9rem; }
.actions-2 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-top: 6px; }
.actions-2 .btn { height: 38px; font-size: .85rem; padding: 0 6px; }

/* Move log */
.log { list-style: none; padding: 0; margin: 0; font-size: .85rem; color: var(--muted); max-height: 220px; overflow: auto; }
.log li { padding: 5px 2px; border-bottom: 1px solid rgba(255,255,255,.06); }
.log li:first-child { color: var(--text); }

/* Final scores */
.final { list-style: none; padding: 0; margin: 0 0 10px; }
.final li { display: flex; justify-content: space-between; padding: 8px 4px; border-bottom: 1px solid rgba(255,255,255,.08); }
.final li.win { color: var(--gold); font-weight: 700; }
.final .adj { color: var(--muted); font-size: .8rem; margin-left: 6px; font-weight: 400; }

/* Modals + pass-and-play hand-off */
.modal-back {
  position: fixed; inset: 0; z-index: 900; background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal { width: min(100%, 420px); }
.modal .btns { display: flex; gap: 8px; margin-top: 12px; }
.modal .btns .btn { flex: 1; }
.letter-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.letter-grid button {
  aspect-ratio: 1; border: none; border-radius: 8px; font: inherit; font-weight: 800; font-size: 1.2rem;
  background: var(--tile); color: var(--tile-text); cursor: pointer;
}
.pick-rack { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.handoff {
  position: fixed; inset: 0; z-index: 800; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; text-align: center; gap: 14px;
}
.handoff .who { font-size: 2rem; font-weight: 800; color: var(--gold); }
.handoff .last { color: var(--muted); max-width: 360px; }

/* Online bits */
.code-display { font-size: 2.4rem; font-weight: 800; letter-spacing: .35em; text-align: center; color: var(--accent); margin: 8px 0; }
.code-chip { font-weight: 800; letter-spacing: .2em; color: var(--accent); }
.player-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 10px 0; }
.player-pill { padding: 6px 14px; border-radius: 18px; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.12); font-size: .9rem; }
.game-list { display: grid; gap: 8px; }
.game-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px;
  background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.1); cursor: pointer;
}
.game-row .info { flex: 1; min-width: 0; }
.game-row .who { font-size: .85rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-row.mine { border-color: var(--gold); }
.game-row.mine .st { color: var(--gold); font-weight: 700; }
.game-row .forget { background: none; border: none; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: 4px 6px; }
