:root {
  --ink: #11110f;
  --felt: #263c33;
  --felt-dark: #18271f;
  --bone: #eee1bd;
  --brass: #b79657;
  --signal: #e23222;
  --chalk: #f5f1e8;
  --muted: #a9aaa2;
  --line: rgba(245, 241, 232, .15);
  font-family: "Space Grotesk", system-ui, sans-serif;
  color: var(--chalk);
  background: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--ink); }
body { min-height: 100vh; }
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible, .cell:focus-visible {
  outline: 3px solid var(--chalk);
  outline-offset: 2px;
}
[hidden] { display: none !important; }

.masthead {
  height: 58px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding: 0 22px;
}
.brand { color: var(--chalk); text-decoration: none; font-size: 12px; letter-spacing: .12em; font-weight: 700; }
.working-title { font-size: 12px; letter-spacing: .16em; }
.working-title em { color: var(--signal); font-size: 9px; font-style: normal; vertical-align: top; margin-left: 3px; }
.connection { justify-self: end; color: var(--muted); font: 11px ui-monospace, monospace; }
.connection::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #6f716b; margin-right: 6px; }
.connection[data-state="open"]::before { background: #68b17c; }
.connection[data-state="reconnecting"]::before, .connection[data-state="lost"]::before { background: var(--brass); }

main { min-height: calc(100vh - 58px); }
.entry {
  min-height: calc(100vh - 58px);
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 460px);
  align-items: center;
  gap: clamp(40px, 8vw, 130px);
  max-width: 1180px;
  margin: auto;
  padding: 48px 30px;
}
.entry-copy { position: relative; }
.entry-copy::before {
  content: "";
  position: absolute;
  width: 82px;
  height: 82px;
  border: 1px solid var(--signal);
  border-radius: 50%;
  top: -55px;
  left: -30px;
  opacity: .65;
}
.eyebrow { margin: 0 0 10px; color: var(--brass); text-transform: uppercase; letter-spacing: .16em; font-size: 10px; font-weight: 700; }
h1 { max-width: 720px; margin: 0; font-size: clamp(48px, 8vw, 104px); line-height: .9; letter-spacing: -.065em; }
.entry-copy > p:last-child { max-width: 480px; margin: 28px 0 0; color: #c9c9c1; font-size: 17px; line-height: 1.55; }
.entry-card { border: 1px solid var(--line); padding: 26px; background: #151512; box-shadow: 12px 12px 0 var(--felt-dark); }
label { display: block; margin-bottom: 8px; color: var(--muted); font-size: 12px; }
input { width: 100%; border: 1px solid #41413d; border-radius: 0; background: var(--ink); color: var(--chalk); padding: 13px 14px; }
button { border: 1px solid #4a4a45; background: #20201d; padding: 10px 15px; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--chalk); }
button:disabled { opacity: .4; cursor: default; }
button.primary { border-color: var(--signal); background: var(--signal); font-weight: 700; }
.entry-card > .primary { width: 100%; margin-top: 12px; }
.or { display: flex; align-items: center; gap: 10px; color: #777871; font-size: 10px; text-transform: uppercase; letter-spacing: .12em; margin: 22px 0; }
.or::before, .or::after { content: ""; height: 1px; flex: 1; background: #343430; }
.join-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
#room-code { text-transform: uppercase; letter-spacing: .18em; font-family: ui-monospace, monospace; }
.inline-error { min-height: 18px; color: #ef756a; font-size: 12px; margin: 10px 0 0; }

.table { max-width: 1240px; margin: 0 auto; padding: 22px; }
.table-top { display: grid; grid-template-columns: 160px 1fr; gap: 24px; align-items: start; margin-bottom: 18px; }
.room-code { padding: 0; border: 0; background: none; font: 700 22px ui-monospace, monospace; letter-spacing: .16em; }
.players { list-style: none; display: grid; grid-template-columns: repeat(4, minmax(110px, 1fr)); gap: 8px; margin: 0; padding: 0; }
.player { min-height: 58px; border: 1px solid var(--line); padding: 9px 11px; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; }
.player.is-turn { border-color: var(--brass); background: rgba(183, 150, 87, .07); }
.player-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 650; font-size: 13px; }
.player-score { font: 700 19px ui-monospace, monospace; grid-row: span 2; }
.player-meta { color: var(--muted); font-size: 10px; }
.player-meta::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #70716d; display: inline-block; margin-right: 5px; }
.player.connected .player-meta::before { background: #68b17c; }
.lobby { min-height: 440px; border: 1px solid var(--line); display: grid; place-content: center; justify-items: center; gap: 20px; background: radial-gradient(circle at 50% 45%, #1d2d26, #121310 60%); }
.lobby p { color: var(--muted); }

.game { display: grid; grid-template-columns: minmax(0, 1fr) 150px; gap: 18px; align-items: start; }
.board-wrap { width: min(100%, calc(100vh - 280px)); min-width: 0; aspect-ratio: 1; margin: 0 auto; padding: 8px; background: #0d1712; border: 1px solid #405349; box-shadow: 0 18px 45px rgba(0, 0, 0, .38); }
.board { width: 100%; height: 100%; display: grid; grid-template-columns: repeat(15, 1fr); grid-template-rows: repeat(15, 1fr); gap: 1px; background: #101a15; }
.cell { position: relative; border: 0; padding: 0; min-width: 0; background: var(--felt); color: rgba(245, 241, 232, .54); font-size: clamp(5px, .65vw, 9px); line-height: 1; text-transform: uppercase; }
.cell::after { content: attr(data-mark); position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.cell[data-premium="TW"] { background: #7b302a; }
.cell[data-premium="DW"] { background: #694840; }
.cell[data-premium="TL"] { background: #31566a; }
.cell[data-premium="DL"] { background: #3b5b5a; }
.cell.centre::before { content: "✦"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 15px; color: var(--bone); }
.cell.has-tile::after { display: none; }
.tile { position: relative; display: grid; place-items: center; aspect-ratio: 1; min-width: 0; padding: 0; border: 1px solid #c7b37f; background: var(--bone); color: #1e1a14; box-shadow: inset 0 -3px 0 rgba(75, 54, 23, .18), 0 2px 2px rgba(0, 0, 0, .32); font-weight: 760; font-size: clamp(16px, 2.2vw, 29px); user-select: none; -webkit-user-select: none; touch-action: none; }
.tile .points { position: absolute; right: 9%; bottom: 7%; font: 700 clamp(6px, .7vw, 10px) ui-monospace, monospace; }
.cell .tile { width: 92%; height: 92%; margin: 4%; }
.cell .tile.staged { transform: translateY(-3px); outline: 2px solid var(--chalk); box-shadow: 0 5px 0 #8b774d, 0 8px 8px rgba(0,0,0,.35); }
.rack .tile { width: clamp(42px, 6vw, 64px); }
.rack .tile.selected { outline: 3px solid var(--signal); transform: translateY(-5px); }
.rack .tile.exchange-selected { outline: 3px solid var(--brass); }
.tile.dragging { opacity: .35; }
.drag-ghost { position: fixed; z-index: 50; width: 54px; pointer-events: none; transform: translate(-50%, -50%) rotate(-3deg); }
.turn-panel { border-top: 2px solid var(--brass); padding: 16px 4px; display: grid; gap: 6px; }
.turn-panel strong { font-size: 19px; }
.turn-panel span:last-child { color: var(--muted); font-size: 12px; }

.tray { position: relative; z-index: 10; margin-top: 16px; padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); border: 1px solid #403e37; background: rgba(17, 17, 15, .96); backdrop-filter: blur(16px); }
.rack-head { display: flex; justify-content: space-between; align-items: center; }
.text-button { border: 0; background: none; padding: 4px; color: var(--muted); font-size: 11px; }
.rack { min-height: 66px; display: flex; align-items: center; justify-content: center; gap: clamp(4px, .8vw, 8px); margin: 6px 0; }
.move-message { min-height: 18px; margin: 5px 0 8px; text-align: center; color: var(--muted); font-size: 12px; }
.move-message.error { color: #ef756a; }
.actions { display: flex; justify-content: center; gap: 7px; }
.actions .primary { min-width: 130px; }
.result { border: 1px solid var(--brass); padding: 26px; margin-top: 18px; }
.result h2 { margin: 0 0 12px; }
.result ol { margin: 0; padding-left: 22px; }

.blank-dialog { width: min(390px, calc(100vw - 28px)); border: 1px solid var(--brass); background: #171713; color: var(--chalk); padding: 24px; }
.blank-dialog::backdrop { background: rgba(0,0,0,.7); }
.blank-dialog h2 { margin: 0 0 18px; }
.blank-letters { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-bottom: 16px; }
.blank-letters button { padding: 9px 0; background: var(--bone); color: var(--ink); font-weight: 700; }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 80; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; background: var(--chalk); color: var(--ink); padding: 9px 13px; font-size: 12px; transition: .18s ease; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 760px) {
  .masthead { grid-template-columns: 1fr auto; padding: 0 13px; }
  .working-title { display: none; }
  .entry { grid-template-columns: 1fr; align-content: center; gap: 45px; padding: 50px 18px; }
  h1 { font-size: clamp(52px, 17vw, 80px); }
  .entry-copy::before { left: -8px; }
  .entry-card { padding: 20px; box-shadow: 7px 7px 0 var(--felt-dark); }
  .table { padding: 14px 8px 180px; }
  .table-top { grid-template-columns: 110px 1fr; gap: 8px; margin-bottom: 10px; }
  .room-code { font-size: 17px; }
  .players { display: flex; overflow-x: auto; gap: 5px; padding-bottom: 4px; }
  .player { flex: 0 0 114px; min-height: 50px; padding: 7px; }
  .game { display: block; }
  .board-wrap { width: 100%; max-width: calc(100vh - 310px); min-width: 342px; padding: 4px; overflow: hidden; }
  .cell { font-size: 5px; }
  .cell.centre::before { font-size: 10px; }
  .turn-panel { margin: 9px 4px 0; padding: 8px 0; grid-template-columns: auto 1fr auto; align-items: baseline; gap: 9px; }
  .turn-panel .eyebrow { margin: 0; }
  .turn-panel strong { font-size: 15px; }
  .tray { position: fixed; left: 0; right: 0; bottom: 0; margin: 0; border-width: 1px 0 0; padding: 10px 8px calc(9px + env(safe-area-inset-bottom)); }
  .rack { min-height: 54px; margin: 3px 0; }
  .rack .tile { width: min(12.5vw, 48px); font-size: 19px; }
  .actions { gap: 4px; }
  .actions button { padding: 8px 9px; font-size: 12px; }
  .actions .primary { min-width: 104px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
