/* Layout: one-screen app. Phones stack clue bar / board / keyboard; wide
   screens put the board beside two scrolling clue columns. */
:root {
  /* Palette from dfrancour.dev: cool neutrals, purple accent. */
  --bg: oklch(98% 0.005 220);
  --surface: #ffffff;
  --ink: oklch(18% 0.008 220);
  --muted: oklch(52% 0.02 220);
  --border: oklch(88% 0.012 220);
  --hover: oklch(95% 0.008 220);
  --grid-line: oklch(18% 0.008 220);
  --cell: #ffffff;
  --block: oklch(18% 0.008 220);
  --word: oklch(92% 0.05 310);
  --sel: oklch(89% 0.14 92);
  --linked: oklch(96% 0.025 310);
  --accent: oklch(45% 0.18 310);
  --accent-hover: oklch(50% 0.2 310);
  --accent-ink: #ffffff;
  --wrong: oklch(55% 0.19 25);
  --right: oklch(45% 0.18 310);
  --overlay: oklch(18% 0.008 220 / 0.45);
  --key: oklch(93% 0.01 220);
  --key-ink: oklch(18% 0.008 220);
  --shadow: 0 1px 2px oklch(18% 0.008 220 / 0.06), 0 8px 28px oklch(18% 0.008 220 / 0.12);
  --radius: 8px;
  --font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-grid: ui-sans-serif, system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-clue: var(--font-ui);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: oklch(18% 0.008 220); --surface: oklch(24% 0.012 220); --ink: oklch(95% 0.008 220);
    --muted: oklch(68% 0.018 220); --border: oklch(32% 0.015 220); --hover: oklch(28% 0.012 220);
    --grid-line: oklch(10% 0.005 220); --cell: oklch(24% 0.012 220); --block: oklch(10% 0.005 220);
    --word: oklch(36% 0.09 310); --sel: oklch(55% 0.12 88); --linked: oklch(29% 0.045 310);
    --accent: oklch(72% 0.15 310); --accent-hover: oklch(78% 0.14 310); --accent-ink: oklch(15% 0.01 310);
    --wrong: oklch(70% 0.17 25); --right: oklch(78% 0.13 310);
    --overlay: oklch(5% 0 0 / 0.6); --key: oklch(30% 0.012 220); --key-ink: oklch(95% 0.008 220);
    --shadow: 0 1px 2px oklch(0% 0 0 / 0.3), 0 8px 28px oklch(0% 0 0 / 0.45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: oklch(18% 0.008 220); --surface: oklch(24% 0.012 220); --ink: oklch(95% 0.008 220);
  --muted: oklch(68% 0.018 220); --border: oklch(32% 0.015 220); --hover: oklch(28% 0.012 220);
  --grid-line: oklch(10% 0.005 220); --cell: oklch(24% 0.012 220); --block: oklch(10% 0.005 220);
  --word: oklch(36% 0.09 310); --sel: oklch(55% 0.12 88); --linked: oklch(29% 0.045 310);
  --accent: oklch(72% 0.15 310); --accent-hover: oklch(78% 0.14 310); --accent-ink: oklch(15% 0.01 310);
  --wrong: oklch(70% 0.17 25); --right: oklch(78% 0.13 310);
  --overlay: oklch(5% 0 0 / 0.6); --key: oklch(30% 0.012 220); --key-ink: oklch(95% 0.008 220);
  --shadow: 0 1px 2px oklch(0% 0 0 / 0.3), 0 8px 28px oklch(0% 0 0 / 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 var(--font-ui);
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input[type="checkbox"] { accent-color: var(--accent); }

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 150ms, border-color 150ms;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn.quiet { border-color: transparent; background: transparent; }

/* ---------- home ---------- */

.home {
  min-height: 100%;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 48px;
  padding: 32px max(16px, env(safe-area-inset-left, 0px)) calc(48px + env(safe-area-inset-bottom, 0px));
}
.has-rooms .home { align-content: start; padding-top: clamp(32px, 9vh, 88px); }
.hero { display: grid; justify-items: center; gap: 24px; }
.wordmark {
  --size: clamp(30px, 9.5vw, 64px);
  display: grid;
  grid-template-columns: repeat(9, var(--size));
  grid-auto-rows: var(--size);
  gap: 1px;
  margin: 0 0 8px;
  padding: 0;
  background: var(--grid-line);
  border: 2px solid var(--grid-line);
  font: 500 calc(var(--size) * 0.56) / 1 var(--font-grid);
}
.has-rooms .wordmark { --size: clamp(28px, 8.5vw, 52px); }
.wordmark span {
  position: relative;
  display: grid;
  place-items: center;
  padding-top: calc(var(--size) * 0.12);
  background: var(--word);
}
.wordmark span:first-child { background: var(--sel); }
.wordmark i {
  position: absolute; top: 2px; left: 3px;
  font: normal 500 calc(var(--size) * 0.24) / 1 var(--font-grid);
}
.tagline { margin: 0; color: var(--muted); text-align: center; text-wrap: balance; }
.btn.open { padding: 12px 28px; font-size: 1.05rem; box-shadow: 0 1px 2px oklch(18% 0.008 220 / 0.12); }
.home .status { min-height: 1.4em; margin: -8px 0 -24px; color: var(--wrong); text-align: center; max-width: 36ch; }
.dropzone {
  position: fixed; inset: 12px; z-index: 10;
  display: grid; place-items: center;
  border: 2px dashed var(--accent); border-radius: 16px;
  background: color-mix(in oklch, var(--bg) 85%, transparent);
  color: var(--accent); font-size: 1.2rem; font-weight: 600;
  pointer-events: none;
}

/* the rooms this browser has played */
.shelf { width: min(920px, 100%); display: grid; gap: 12px; }
.shelf h2 {
  margin: 0; padding: 0 4px; font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted);
}
.cards, .rows { list-style: none; margin: 0; padding: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr)); gap: 12px; }
.card, .row { position: relative; }
.card-link {
  display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 18px; align-items: center;
  height: 100%; padding: 14px 16px 14px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  color: inherit; text-decoration: none;
  transition: border-color 150ms, box-shadow 150ms;
}
.card-link:hover { border-color: color-mix(in oklch, var(--accent) 45%, var(--border)); box-shadow: var(--shadow); }
.card-body { display: grid; gap: 2px; min-width: 0; }
.card-title {
  font-weight: 700; line-height: 1.25; padding-right: 24px; margin-bottom: 2px;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
}
.card-byline, .card-status { color: var(--muted); font-size: 0.82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta {
  display: flex; align-items: center; gap: 10px; margin: 8px 0 4px;
  font-size: 0.8rem; font-weight: 600; font-variant-numeric: tabular-nums;
}
.card-meta span:last-child { color: var(--muted); font-weight: 500; }
.bar { flex: 1; height: 5px; border-radius: 3px; background: var(--hover); overflow: hidden; }
.bar span { display: block; height: 100%; width: calc(var(--p) * 100%); border-radius: inherit; background: var(--accent); }
.card-status.live { color: var(--ink); }
.card-status i {
  display: inline-block; width: 8px; height: 8px; margin-right: 3px; border-radius: 50%;
  background: var(--pc); vertical-align: 1px;
}
.card-status i:last-of-type { margin-right: 7px; }

.rows { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.row + .row { border-top: 1px solid var(--border); }
.row-link {
  display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 14px; align-items: center;
  padding: 10px 48px 10px 12px; color: inherit; text-decoration: none;
  transition: background-color 150ms;
}
a.row-link:hover { background: var(--hover); }
.row-link.gone { opacity: 0.55; }
.row-body { min-width: 0; }
.row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-detail { color: var(--muted); font-size: 0.82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-date { color: var(--muted); font-size: 0.82rem; white-space: nowrap; }
.row .thumb-box { width: 40px; height: 40px; }

.thumb-box { width: 88px; height: 88px; display: grid; place-items: center; }
.thumb { width: 100%; height: 100%; display: block; }
.thumb .bg { fill: var(--grid-line); }
.thumb rect { fill: var(--cell); }
.thumb rect.f { fill: color-mix(in srgb, var(--accent) 45%, var(--cell)); }

.forget {
  position: absolute; top: 8px; right: 8px;
  width: 28px; height: 28px; border: 0; border-radius: 50%;
  display: grid; place-items: center;
  background: transparent; color: var(--muted); font-size: 1.15rem; line-height: 1;
  cursor: pointer; opacity: 0; transition: opacity 150ms, background-color 150ms;
}
.row .forget { top: 50%; right: 10px; transform: translateY(-50%); }
.forget:hover { background: var(--hover); color: var(--ink); }
.card:hover .forget, .row:hover .forget, .forget:focus-visible { opacity: 1; }
@media (hover: none) { .forget { opacity: 1; } }

/* ---------- game shell ---------- */

.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px max(12px, env(safe-area-inset-left, 0px));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-width: 0;
}
.topbar .back { text-decoration: none; color: var(--muted); padding: 4px 6px; font-size: 1.2rem; line-height: 1; }
.topbar .titles { min-width: 0; flex: 1; }
.topbar .title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .byline { color: var(--muted); font-size: 0.8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.timer { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 4.5em; text-align: center; }
.tools { display: flex; gap: 4px; flex-wrap: nowrap; }
.players { display: flex; gap: 2px; }
.dot {
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 0.7rem; font-weight: 700; color: #fff;
  background: var(--pc, var(--muted));
}
.chat-btn { position: relative; }
.badge {
  position: absolute; top: -6px; right: -6px;
  min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px;
  background: var(--wrong); color: #fff; font-size: 0.7rem; display: grid; place-items: center;
}

.main {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  min-height: 0;
}
.board-col { display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0; min-width: 0; }

.cluebar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  background: var(--word);
  min-height: 3.2em;
}
.cluebar button { border: 0; background: transparent; padding: 8px 14px; font-size: 1.3rem; cursor: pointer; }
.cluebar .text { padding: 6px 2px; font-family: var(--font-clue); font-size: 1.02rem; line-height: 1.3; cursor: pointer; }
.cluebar .num { font-family: var(--font-ui); font-weight: 700; margin-right: 6px; }

.board-wrap {
  container-type: size;
  position: relative;
  display: grid;
  place-items: start center;
  padding: 8px;
  min-height: 0;
}
.board {
  --w: 15; --h: 15;
  container-type: inline-size;
  width: min(100cqw, 100cqh * var(--w) / var(--h));
  aspect-ratio: var(--w) / var(--h);
  display: grid;
  grid-template-columns: repeat(var(--w), minmax(0, 1fr));
  grid-template-rows: repeat(var(--h), minmax(0, 1fr));
  border: 2px solid var(--grid-line);
  background: var(--grid-line);
  gap: 1px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.cell {
  position: relative;
  background: var(--cell);
  cursor: pointer;
  overflow: hidden;
  font-family: var(--font-grid);
}
.cell.block { background: var(--block); cursor: default; }
.cell.void { background: var(--bg); }
/* Puzzle colors are chosen for white squares; soften them in dark mode. */
.cell.shaded { background: color-mix(in srgb, var(--cbg) 70%, var(--cell)); }
.cell.linked { background: var(--linked); }
.cell.peer-word { background: color-mix(in srgb, var(--pc) 16%, var(--cell)); }
.cell.word { background: var(--word); }
.cell.sel { background: var(--sel); }
.cell.peer-cell::after {
  content: ""; position: absolute; inset: 0;
  box-shadow: inset 0 0 0 calc(100cqw / var(--w) * 0.08) var(--pc);
  pointer-events: none;
}
.cell .n {
  position: absolute; top: 1px; left: 2px;
  font-size: calc(100cqw / var(--w) * 0.27);
  line-height: 1;
  pointer-events: none;
}
.cell .v {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  padding-top: calc(100cqw / var(--w) * 0.14);
  font-size: calc(100cqw / var(--w) * 0.6);
  font-weight: 500;
  line-height: 1;
  pointer-events: none;
}
.cell .v.rebus { font-size: calc(100cqw / var(--w) * 0.3); letter-spacing: -0.02em; }
.cell.rebus-edit .v { color: var(--accent); }
.cell.circle::before {
  content: ""; position: absolute; inset: 1px; border-radius: 50%;
  border: 1px solid var(--muted); pointer-events: none;
}
/* Bars: drawn inside the square, since the next square would paint over them. */
.cell.wall-r { box-shadow: inset calc(-0.06 * 100cqw / var(--w)) 0 0 var(--grid-line); }
.cell.wall-b { box-shadow: inset 0 calc(-0.06 * 100cqw / var(--w)) 0 var(--grid-line); }
.cell.wall-r.wall-b {
  box-shadow: inset calc(-0.06 * 100cqw / var(--w)) 0 0 var(--grid-line), inset 0 calc(-0.06 * 100cqw / var(--w)) 0 var(--grid-line);
}
.cell.wrong .v { color: var(--wrong); }
.cell.wrong::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(to top right, transparent calc(50% - 1px), var(--wrong) calc(50% - 1px), var(--wrong) calc(50% + 1px), transparent calc(50% + 1px));
  opacity: 0.8;
}
.cell.right .v { color: var(--right); }
.cell.revealed::after {
  content: ""; position: absolute; top: 0; right: 0; pointer-events: none;
  border-style: solid;
  border-width: 0 calc(100cqw / var(--w) * 0.28) calc(100cqw / var(--w) * 0.28) 0;
  border-color: transparent var(--wrong) transparent transparent;
}
.cell .v[style] { font-weight: 600; }

.paused {
  position: absolute; inset: 8px;
  display: grid; place-items: center; align-content: center; gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  text-align: center;
}

/* clue lists */
.clues {
  display: none;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  min-height: 0;
  padding: 8px 16px 8px 8px;
}
.clues section { display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0; }
.clues h2 {
  margin: 0; padding: 6px 8px; font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase;
  border-bottom: 1px solid var(--border); color: var(--muted);
}
.clues ol { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; overscroll-behavior: contain; }
.clues li {
  display: grid; grid-template-columns: 2.2em minmax(0, 1fr);
  padding: 5px 8px; border-left: 4px solid transparent; cursor: pointer;
  font-family: var(--font-clue); line-height: 1.3;
}
.clues li b { font-family: var(--font-ui); text-align: right; padding-right: 8px; }
.clues li.done { color: var(--muted); }
.clues li.cross { border-left-color: var(--word); }
.clues li.active { background: var(--word); }

/* on-screen keyboard */
.kbd {
  display: grid;
  gap: 6px;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  border-top: 1px solid var(--border);
}
.kbd .row { display: flex; gap: 5px; justify-content: center; }
.kbd button {
  flex: 1 1 0; max-width: 46px; min-width: 0;
  height: 46px; border: 0; border-radius: 6px;
  background: var(--key); color: var(--key-ink);
  font-size: 1.15rem; font-weight: 500; cursor: pointer;
  -webkit-user-select: none; user-select: none;
}
.kbd button.wide { max-width: 68px; flex-grow: 1.5; font-size: 0.85rem; }
.kbd button:active { background: var(--border); }

/* menus, sheets, modals, toasts */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30;
  min-width: 190px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid; gap: 2px;
}
.menu button { text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--hover); }
.menu .sep { height: 1px; background: var(--border); margin: 4px 0; }
.menu label { display: flex; gap: 8px; align-items: center; padding: 8px 10px; cursor: pointer; }

.sheet {
  position: fixed; z-index: 40; right: 0; top: 0; bottom: 0;
  width: min(380px, 100%);
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}
.sheet header { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.sheet header h2 { margin: 0; font-size: 1rem; }
.chat-wrap { display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0; }
.chat-log { overflow-y: auto; padding: 10px 12px; display: grid; align-content: start; gap: 8px; }
.chat-log .m { line-height: 1.35; overflow-wrap: anywhere; }
.chat-log .m b { color: var(--pc); margin-right: 6px; }
.chat-log .m time { color: var(--muted); font-size: 0.75rem; margin-left: 6px; }
.chat-form { display: flex; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--border); }
.chat-form input {
  flex: 1; min-width: 0; font: inherit; font-size: 16px; color: var(--ink);
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg);
}
.who { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 0.85rem; }
.who span { display: inline-flex; align-items: center; gap: 5px; }
.who i { width: 10px; height: 10px; border-radius: 50%; background: var(--pc); display: inline-block; }

.clue-sheet .clues { display: grid; grid-template-columns: minmax(0, 1fr); overflow-y: auto; padding: 0 0 8px; }
.clue-sheet .clues section { display: block; }
.clue-sheet .clues ol { overflow: visible; }

.scrim { position: fixed; inset: 0; background: var(--overlay); z-index: 35; }
.modal {
  position: fixed; z-index: 50; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(420px, calc(100% - 32px));
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
  padding: 24px;
  display: grid; gap: 14px;
}
.modal h2 { margin: 0; font-size: 1.3rem; text-wrap: balance; }
.modal p { margin: 0; color: var(--muted); }
.modal input {
  font: inherit; font-size: 16px; color: var(--ink); padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg);
}
.modal input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.big-time { font-size: 3rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.done-detail { color: var(--muted); margin: -6px 0 0; }

.toast {
  position: fixed; z-index: 60; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow);
  max-width: calc(100% - 32px); text-align: center;
}
.banner { background: var(--wrong); color: #fff; text-align: center; font-size: 0.85rem; padding: 4px 8px; }

/* phones: compact tool labels */
@media (max-width: 559px) {
  .tools .label-long, .wide-only { display: none; }
  .topbar { gap: 4px; }
  .topbar .btn { padding: 6px 7px; }
  .players { display: none; }
}
@media (min-width: 560px) {
  .tools .label-short, .narrow-only { display: none; }
}

/* wide screens: board beside clue columns */
@media (min-width: 900px) {
  .main { grid-template-columns: minmax(0, 1.15fr) minmax(320px, 1fr); grid-template-rows: minmax(0, 1fr); }
  .main > .clues { display: grid; }
  .clues-btn { display: none; }
  .board-col { padding: 8px 0 8px 8px; }
}

@media (prefers-reduced-motion: no-preference) {
  .toast { animation: rise 160ms ease-out; }
  .card-status.live i { animation: breathe 2.4s ease-in-out infinite; }
  @keyframes breathe { 50% { opacity: 0.35; } }
  @keyframes rise { from { transform: translate(-50%, 8px); opacity: 0; } to { transform: translateX(-50%); opacity: 1; } }
}
