:root {
  --bg: #f6f4ef; --panel: #ffffff; --ink: #1f2328; --muted: #6b6f76; --line: #e3dfd6;
  --accent: #2f6f5e; --accent-ink: #ffffff; --soft: #eef4f1; --warn: #b4442c; --gold: #d99a00;
  --cell: 30px; --n: 15;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #16181b; --panel: #1f2226; --ink: #e8e6e1; --muted: #9a9ea5; --line: #33373d;
    --accent: #5fb39b; --accent-ink: #0f1412; --soft: #22302b; --warn: #e07a62; --gold: #ffc861; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }

/* ---------- header */
header { padding: 16px 24px 6px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
header .brand { flex: 1; min-width: 220px; }
header h1 { margin: 0; font-size: 22px; letter-spacing: .2px; }
header p { margin: 2px 0 0; color: var(--muted); }
.account { display: flex; align-items: center; gap: 8px; position: relative; }
.offline-pill { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--soft); color: var(--muted); }
.profile { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 999px; padding: 3px 12px 3px 3px; cursor: pointer; font: inherit; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 700; font-size: 13px; letter-spacing: .02em; }
.stars { font-weight: 700; font-variant-numeric: tabular-nums; }
.stars b { color: var(--gold); }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.14); padding: 6px; min-width: 210px; z-index: 30; }
.menu .who { padding: 8px 10px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu .who b { color: var(--ink); display: block; font-size: 14px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; color: var(--ink); font: inherit; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--soft); }

main > section { min-width: 0; }
main { display: grid; grid-template-columns: 370px minmax(0, 1fr); gap: 20px; padding: 14px 24px 40px; align-items: start; }
@media (max-width: 900px) { main { grid-template-columns: 1fr; padding: 12px 16px 40px; } header { padding: 14px 16px 4px; } }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.panel + .panel { margin-top: 14px; }
.panel h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 9px; padding: 3px; margin-bottom: 14px; }
.tabs button { border: 0; background: transparent; color: var(--ink); padding: 8px; border-radius: 7px; font: inherit; cursor: pointer; }
.tabs button.active { background: var(--panel); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }

label { display: block; font-weight: 600; font-size: 13px; margin: 10px 0 4px; }
label .hint { font-weight: 400; color: var(--muted); }
input[type=text], input[type=number], input[type=email], input[type=password], textarea, select {
  width: 100%; font: inherit; color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; margin: 8px 0 0; }
.check input:disabled + span { opacity: .5; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.seg button { font: inherit; font-size: 13px; padding: 7px 4px; border: 1px solid var(--line); background: var(--panel);
  color: var(--ink); border-radius: 8px; cursor: pointer; }
.seg button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.desc { color: var(--muted); font-size: 13px; margin: 6px 0 0; min-height: 2.9em; }

details { margin-top: 12px; }
summary { cursor: pointer; color: var(--muted); font-size: 13px; }

.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  border-radius: 8px; padding: 8px 12px; cursor: pointer; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn:disabled:hover { border-color: var(--line); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.big { width: 100%; padding: 11px; font-size: 16px; margin-top: 14px; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.danger { color: var(--warn); }
.btn[aria-pressed=true] { background: var(--soft); border-color: var(--accent); }
.btnrow { display: flex; gap: 8px; margin-top: 10px; }
.btnrow > .btn { flex: 1; margin-top: 0; }
.linkbtn { border: 0; background: none; color: var(--accent); font: inherit; padding: 0; cursor: pointer; text-decoration: underline; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chipgroup { margin-bottom: 10px; }
.chipgroup .gl { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--soft); border-radius: 999px;
  padding: 3px 4px 3px 10px; font-size: 13px; font-weight: 600; letter-spacing: .03em; }
.chip button { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; padding: 0 4px; }
.chip.off { opacity: .45; text-decoration: line-through; }
.pick { border: 2px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 999px; padding: 3px 10px;
  font: 600 13px/1.4 inherit; letter-spacing: .03em; cursor: pointer; }
.pick.on { border-color: var(--c, var(--accent)); background: color-mix(in srgb, var(--c, var(--accent)) 25%, var(--panel)); }
.pick:disabled { opacity: .4; cursor: default; }
.note { font-size: 12.5px; color: var(--muted); margin: 8px 0 0; }
.note.signup { background: var(--soft); border-radius: 8px; padding: 8px 10px; color: var(--ink); }
.error { color: var(--warn); font-weight: 600; }

/* ---------- actions (after Start) */
.actions .ttl { font: 600 18px/1.3 Georgia, "Times New Roman", serif; margin: 0; }
.actions .meta { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
.badge { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: var(--soft); color: var(--accent); font-weight: 600; }
.badge.warn { color: var(--warn); }

/* ---------- puzzle */
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }
.toolbar .tbcheck { margin: 0 0 0 4px; font-size: 13px; }
.stats { font-size: 13px; color: var(--muted); }
.sheet { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 22px; }
.sheet h2 { margin: 0 0 2px; font-size: 24px; text-align: center; font-family: Georgia, "Times New Roman", serif; }
.sheet .sub { text-align: center; color: var(--muted); margin: 0 0 14px; font-size: 14px; }
.sheet .sub.preview { color: var(--accent); font-weight: 600; }
.boardwrap { display: flex; justify-content: center; }
.board { position: relative; touch-action: none; user-select: none; -webkit-user-select: none; }
.board.live { cursor: crosshair; }
.grid { display: grid; grid-template-columns: repeat(var(--n), var(--cell)); grid-auto-rows: var(--cell);
  border: 2px solid var(--ink); border-radius: 4px; }
.grid span { display: flex; align-items: center; justify-content: center; font-weight: 600;
  font-size: calc(var(--cell) * .56); font-family: "Courier New", ui-monospace, monospace; }
/* row / column labels (a b c … across, 1 2 3 … down); --lbl matches LABEL_CELLS in app.js */
.boardwrap { --lbl: calc(var(--cell) * .8); }
.boardcol { display: flex; flex-direction: column; }
/* owner name under the board, lined up with its left edge */
.boardfoot { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-top: 6px; padding-left: calc(var(--lbl) + 2px); }
.byline { margin: 0; font: italic 14px/1.3 Georgia, "Times New Roman", serif; color: var(--muted); }
.boardfoot .site { font-size: 12.5px; color: var(--muted); text-decoration: none; white-space: nowrap; }
.boardfoot .site:hover { color: var(--accent); text-decoration: underline; }
/* "Show same letters": every copy of the tapped letter gets a ring */
.overlay circle.same { fill: none; stroke: var(--accent); stroke-width: .08; }
.lblboard { display: grid; grid-template-columns: var(--lbl) auto; grid-template-rows: var(--lbl) auto; }
.collabels { display: grid; grid-template-columns: repeat(var(--n), var(--cell)); padding: 0 2px; }
.rowlabels { display: grid; grid-auto-rows: var(--cell); padding: 2px 0; }
.collabels span, .rowlabels span { display: flex; align-items: center; color: var(--muted); line-height: 1;
  font-size: max(8px, calc(var(--cell) * .34)); font-variant-numeric: tabular-nums; user-select: none; }
.collabels span { justify-content: center; align-items: flex-end; padding-bottom: 3px; }
.rowlabels span { justify-content: flex-end; padding-right: 5px; }
.overlay { position: absolute; inset: 2px; width: calc(100% - 4px); height: calc(100% - 4px); pointer-events: none; }
.wordlist { list-style: none; padding: 0; margin: 18px auto 0; columns: auto var(--colw, 130px); column-gap: 14px; max-width: 760px; }
.wordlist li { font-weight: 600; letter-spacing: .05em; padding: 2px 0; break-inside: avoid; font-size: 14px; white-space: nowrap; }
.wordlist li .w { display: inline-block; padding: 1px 7px; border-radius: 999px; }
/* same colour as the word's mark on the board */
.wordlist li .w.mk { background: color-mix(in srgb, var(--mk) var(--mo, 40%), transparent); }
.wordlist li.found .w { text-decoration: line-through; }
.wordlist li.found .w:not(.mk) { color: var(--muted); }
/* start:end address of a solved word, e.g. f20:u5 (only with "Show address of solved words") */
.wordlist .addr { display: none; margin-left: 2px; font-size: 12px; font-weight: 500; letter-spacing: 0; color: var(--muted); font-variant-numeric: tabular-nums; }
.wordlist.addrs li.found .addr { display: inline; }
@media (max-width: 420px) { .wordlist li { white-space: normal; overflow-wrap: anywhere; } }
.wordlist li .star { color: var(--accent); }
.footnote { text-align: center; color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }
.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 9px 16px; border-radius: 999px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 70; max-width: calc(100vw - 32px); }
.toast.show { opacity: .95; }

/* ---------- solved */
.solved-msg { color: var(--accent); font-size: 17px; margin-right: 10px; }
.sheet.solved .sub { animation: solved-in .45s ease-out both; }
.listwrap { position: relative; }
.sheet.solved .listwrap { min-height: 120px; overflow: hidden; }
.listwrap .wordlist { position: relative; z-index: 1; }
.sheet.solved .listwrap::before {
  content: 'SOLVED'; position: absolute; inset: 0; z-index: 0; display: flex; align-items: center; justify-content: center;
  font: 900 clamp(44px, 8vw, 96px)/1 Georgia, "Times New Roman", serif; letter-spacing: .12em;
  color: var(--accent); opacity: .14; transform: rotate(-8deg); pointer-events: none;
  animation: stamp .5s cubic-bezier(.2, .7, .3, 1.4) both; }
@keyframes stamp { from { opacity: 0; transform: rotate(-8deg) scale(1.8); } to { opacity: .14; transform: rotate(-8deg) scale(1); } }
@keyframes solved-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Celebration (from Killer Sudoku): full-viewport canvas + a glow on the board. */
.celebration { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
.board.celebrating { animation: board-glow 2.6s cubic-bezier(.2, .7, .3, 1) forwards; border-radius: 4px; }
.board.celebrating::after { content: ''; position: absolute; inset: 0; z-index: 3; pointer-events: none; border-radius: 4px;
  background: radial-gradient(circle at 50% 50%, rgba(255, 213, 74, .42), rgba(255, 157, 63, .16) 42%, rgba(255, 157, 63, 0) 68%);
  animation: board-flash 1.1s ease-out forwards; }
@keyframes board-glow { 0% { box-shadow: none; } 18% { box-shadow: 0 0 0 3px rgba(255, 213, 74, .85), 0 0 46px 12px rgba(244, 180, 0, .5); } 100% { box-shadow: none; } }
@keyframes board-flash { 0% { opacity: 0; transform: scale(.35); } 22% { opacity: 1; } 100% { opacity: 0; transform: scale(1.7); } }
@media (prefers-reduced-motion: reduce) {
  .board.celebrating::after { animation: none; opacity: 0; }
  .sheet.solved .listwrap::before, .sheet.solved .sub { animation: none; }
}

/* ---------- dialogs */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--panel); color: var(--ink);
  width: min(460px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog .dlg { padding: 20px; }
dialog h2 { margin: 0 0 6px; font-size: 19px; }
dialog .close { position: absolute; top: 10px; right: 12px; border: 0; background: none; font-size: 22px; color: var(--muted); cursor: pointer; }
dialog .section { margin-top: 14px; }
dialog .section > .lbl { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.share-preview { width: 100%; border: 1px solid var(--line); border-radius: 8px; margin-top: 12px; background: #fff; }
.linkrow { display: flex; gap: 6px; }
.linkrow input { flex: 1; font-size: 13px; }
.plist { list-style: none; margin: 10px 0 0; padding: 0; max-height: 60vh; overflow: auto; }
.plist li { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; display: flex; gap: 10px; align-items: center; }
.plist li .info { flex: 1; min-width: 0; }
.plist li .info b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plist li .info span { font-size: 12.5px; color: var(--muted); }
#dlgPuzzles { width: min(560px, calc(100vw - 32px)); }

/* ---------- offline lock */
.lock { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: grid; place-items: center; padding: 24px; }
.lock .box { max-width: 420px; text-align: center; }
.lock h2 { margin: 0 0 8px; }
.lock p { color: var(--muted); }

#printArea { display: none; }

.site-foot { text-align: center; color: var(--muted); font-size: 14px; padding: 4px 16px 32px; }
.site-foot a { color: var(--accent); font-weight: 600; }

@media print {
  @page { margin: 0.45in; }
  body { background: #fff; color: #000; }
  header, main, .site-foot, .toast, dialog, .lock { display: none !important; }
  #printArea { display: block; }
  #printArea .sheet { border: 0; padding: 0; break-after: page; --cell: calc(7.4in / (var(--n) + .8)) !important; }
  #printArea, #printArea * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #printArea .sheet:last-child { break-after: auto; }
  :root { --ink: #000; --muted: #444; }
  .sheet.solved .listwrap::before { animation: none; }
}
