/* Crossword and mini crossword pages (/crossword/, /mini/). The board sets --n to its grid size. */
:root {
  --green: #6aaa64; --red: #d0473e;
  --color-tone-1: #1a1a1b; --color-tone-2: #787c7e; --color-tone-3: #878a8c; --color-tone-4: #d3d6da;
  --color-tone-5: #edeff1; --color-tone-6: #f6f7f8; --color-tone-7: #ffffff; --opacity-50: rgba(255, 255, 255, 0.5);
  --color-background: var(--color-tone-7);
  --cell-bg: #ffffff; --block: #1a1a1b; --line: #9a9c9e; --frame: #1a1a1b;
  --hl-word: #a7d8ff; --hl-sel: #ffda00; --hl-cross: #e7f4ff;
  --pencil: #8b8d90; --checked: #2b5aa6; --revealed: #d0473e;
  --header-height: 50px; --max-width: 1080px;
  /* Phones: the info line, clue bar, tools and keyboard stay on screen (--fixed tall, besides the header) and the grid
     fills the rest. */
  --vh: 100vh; --kbd-h: clamp(144px, calc(var(--vh) * .22), 190px); --fixed: calc(132px + var(--kbd-h));
  font-family: 'Clear Sans', 'Helvetica Neue', Arial, sans-serif; font-size: 16px;
}
@supports (height: 100dvh) { :root { --vh: 100dvh; } }
.nightmode {
  --color-tone-1: #d7dadc; --color-tone-2: #818384; --color-tone-3: #565758; --color-tone-4: #3a3a3c;
  --color-tone-5: #272729; --color-tone-6: #1a1a1b; --color-tone-7: #121213; --opacity-50: rgba(0, 0, 0, 0.5);
  --cell-bg: #2a2a2c; --block: #0a0a0b; --line: #4a4a4d; --frame: #6a6c6e;
  --hl-word: #2f5d80; --hl-sel: #a88c12; --hl-cross: #23303b;
  --pencil: #8f9194; --checked: #8db6f2; --revealed: #ff7a70;
}
* { box-sizing: border-box; }
html { height: 100%; }
body { height: 100%; margin: 0; padding: 0; overflow: hidden; background: var(--color-background); color: var(--color-tone-1); -webkit-tap-highlight-color: transparent; }
button { font-family: inherit; color: inherit; }

#game { width: 100%; max-width: var(--max-width); margin: 0 auto; height: 100%; display: flex; flex-direction: column; padding-bottom: env(safe-area-inset-bottom); }
header { position: relative; display: flex; justify-content: space-between; align-items: center; height: var(--header-height); border-bottom: 1px solid var(--color-tone-4); padding: 0 16px; flex-shrink: 0; }
header .menu { display: flex; z-index: 1; }
header .title { position: absolute; left: 0; right: 0; text-align: center; font-weight: 700; font-size: 32px; letter-spacing: 0.15rem; text-transform: uppercase; pointer-events: none; }
header .title a { pointer-events: auto; color: inherit; text-decoration: none; }
/* Phones: a slimmer header leaves more room for the grid. */
@media (max-width: 600px) { :root { --header-height: 44px; } header .title { font-size: 24px; letter-spacing: .08rem; } }
@media (max-width: 400px) { header .title { font-size: 22px; letter-spacing: 0.08rem; } }
button.icon { background: none; border: none; cursor: pointer; padding: 0 4px; height: 40px; display: flex; align-items: center; }
button.icon svg { width: 24px; height: 24px; display: block; fill: var(--color-tone-1); }
.menu button.icon + button.icon { margin-left: 4px; }

#main { flex: 1; min-height: 0; display: flex; gap: 24px; padding: 0 8px; }
#play { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#tabs { display: flex; gap: 6px; padding: 10px 4px 0; flex-shrink: 0; }
#tabs button { flex: 1; border: 0; background: var(--color-tone-5); border-radius: 4px; height: 34px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 4px; }
#tabs button[aria-selected="true"] { background: var(--color-tone-1); color: var(--color-tone-7); }
#tabs .tick { width: 14px; height: 14px; border-radius: 50%; background: var(--green); display: none; }
#tabs .tick svg { width: 14px; height: 14px; fill: #fff; display: block; }
#tabs button.solved .tick { display: inline-block; }
#info { display: flex; justify-content: space-between; align-items: center; padding: 8px 6px 6px; font-size: 14px; color: var(--color-tone-2); flex-shrink: 0; }
#info .num { font-weight: 700; color: var(--color-tone-1); }
/* Small pill buttons for secondary actions (instead of underlined text). */
.chip { display: inline-flex; align-items: center; justify-content: center; gap: 2px; height: 30px; padding: 0 12px; border: 0; border-radius: 999px; background: var(--color-tone-5); color: var(--color-tone-1); font: inherit; font-size: 13px; font-weight: 700; line-height: 1; text-decoration: none; cursor: pointer; white-space: nowrap; vertical-align: middle; }
.chip:hover { background: var(--color-tone-4); }
.chip[hidden] { display: none; }
.chip svg { width: 16px; height: 16px; fill: currentColor; margin-right: -4px; }
.chip.ghost { background: none; box-shadow: inset 0 0 0 1px var(--color-tone-4); color: var(--color-tone-2); font-weight: 400; }
.chip.ghost:hover { color: var(--color-tone-1); }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
#to-today { height: 24px; padding: 0 8px 0 10px; margin: -4px 0 -4px 6px; font-size: 12px; }   /* in the info line, without making it taller */
#timerbox { display: flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; }
#pause { border: 0; background: none; cursor: pointer; padding: 2px; display: flex; }
#pause svg { width: 20px; height: 20px; fill: var(--color-tone-2); }

#top { flex-shrink: 0; display: flex; flex-direction: column; }
#board-wrap { flex: 0 0 auto; display: flex; align-items: center; justify-content: center; }
#board { --n: 15; --fit: calc(var(--vh) - var(--header-height) - var(--fixed) - env(safe-area-inset-bottom));
  --size: min(calc(100vw - 16px), max(var(--fit), 280px), 600px);
  width: var(--size); height: var(--size); display: grid; grid-template-columns: repeat(15, 1fr); grid-template-rows: repeat(15, 1fr);
  border: 2px solid var(--frame); background: var(--line); gap: 1px; position: relative; user-select: none; -webkit-user-select: none; touch-action: manipulation; outline: none; }
.cell { position: relative; background: var(--cell-bg); display: flex; align-items: flex-end; justify-content: center; cursor: pointer; overflow: hidden; }
.cell.block { background: var(--block); cursor: default; }
.cell.cross { background: var(--hl-cross); }
.cell.word { background: var(--hl-word); }
.cell.sel { background: var(--hl-sel); }
.cell .n { position: absolute; top: 1px; left: 2px; font-size: calc(var(--size) / var(--n) * 0.3); line-height: 1; pointer-events: none; }
.cell .l { font-size: calc(var(--size) / var(--n) * 0.62); line-height: 1; padding-bottom: calc(var(--size) / var(--n) * 0.08); font-weight: 500; text-transform: uppercase; pointer-events: none; }
.cell.pencil .l { color: var(--pencil); font-weight: 400; }
.cell.ok .l { color: var(--checked); }
.cell.bad::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to top right, transparent calc(50% - 1px), var(--red) calc(50% - 1px), var(--red) calc(50% + 1px), transparent calc(50% + 1px)); pointer-events: none; }
.cell.rev::before { content: ""; position: absolute; top: 0; right: 0; border-style: solid; border-width: 0 calc(var(--size) / var(--n) * 0.28) calc(var(--size) / var(--n) * 0.28) 0; border-color: transparent var(--revealed) transparent transparent; }
#board.won .cell:not(.block) { animation: wave 600ms ease-in-out both; animation-delay: calc(var(--d) * 18ms); }
@keyframes wave { 40% { background: var(--green); color: #fff; } }
#paused { position: absolute; inset: 0; background: var(--color-background); display: none; flex-direction: column; gap: 14px; align-items: center; justify-content: center; z-index: 5; }
#board.is-paused #paused { display: flex; }
#paused p { margin: 0; font-weight: 700; font-size: 18px; text-transform: uppercase; letter-spacing: .05em; }

#cluebar { display: flex; align-items: stretch; margin: 10px 0 0; min-height: 52px; background: var(--hl-word); border-radius: 4px; flex-shrink: 0; color: #1a1a1b; }
.nightmode #cluebar { color: var(--color-tone-1); }
#cluebar button { border: 0; background: none; width: 40px; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
#cluebar button svg { width: 24px; height: 24px; fill: currentColor; }
#clue-text { flex: 1; display: flex; align-items: center; gap: 8px; font-size: 16px; line-height: 1.25; padding: 6px 2px; cursor: pointer; }
#clue-text b { flex-shrink: 0; }
#clue-text .hint, .list li .hint { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; background: rgba(0,0,0,.12); border-radius: 3px; padding: 2px 5px; flex-shrink: 0; }
.nightmode #clue-text .hint, .nightmode .list li .hint { background: rgba(255,255,255,.14); }

#tools { display: flex; gap: 8px; padding: 8px 0 4px; flex-shrink: 0; position: relative; }
.tool { border: 1px solid var(--color-tone-4); background: var(--color-tone-6); border-radius: 4px; height: 36px; padding: 0 12px; display: flex; align-items: center; gap: 5px; font-size: 14px; font-weight: 700; cursor: pointer; }
.tool svg { width: 18px; height: 18px; fill: var(--color-tone-1); }
.tool[aria-pressed="true"] { background: var(--color-tone-1); color: var(--color-tone-7); border-color: var(--color-tone-1); }
.tool[aria-pressed="true"] svg { fill: var(--color-tone-7); }
.tool:disabled { opacity: .35; cursor: default; }
#tools .spacer { flex: 1; }
.pop { position: absolute; bottom: 44px; z-index: 50; background: var(--color-background); border: 1px solid var(--color-tone-4); border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.18); display: none; flex-direction: column; min-width: 150px; padding: 4px 0; }
.pop.open { display: flex; }
.pop button { border: 0; background: none; text-align: left; padding: 10px 16px; font-size: 15px; cursor: pointer; }
.pop button:hover { background: var(--color-tone-5); }

#kbd { flex: 1 1 auto; min-height: 150px; max-height: 210px; display: flex; flex-direction: column; justify-content: flex-end; gap: 6px; padding: 6px 0 8px; touch-action: manipulation; }
#kbd .row { flex: 1; max-height: 58px; display: flex; gap: 5px; justify-content: center; }
#kbd button { flex: 1; max-width: 44px; height: 100%; border: 0; border-radius: 4px; background: var(--color-tone-4); font-size: 17px; font-weight: 700; cursor: pointer; padding: 0; display: flex; align-items: center; justify-content: center; -webkit-tap-highlight-color: rgba(0,0,0,.3); }
#kbd button.wide { flex: 1.6; max-width: 70px; }
@media (min-width: 600px) { #kbd button { max-width: 60px; font-size: 19px; } #kbd button.wide { max-width: 96px; } }
#kbd button svg { width: 24px; height: 24px; fill: var(--color-tone-1); }

/* Phones and tablets: the grid is as big as the screen allows. The week strip and level tabs scroll away above it
   (crossword.js brings the whole grid into view when you play) and the info line stays; tablets have room for all of it. */
@media (max-width: 899px) {
  #top { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
  #info { position: sticky; top: 0; z-index: 6; background: var(--color-background); height: 28px; padding: 4px 6px 0; }
  #board-wrap { flex: 1 0 auto; }
  #cluebar { margin-top: 6px; min-height: 58px; }
  #clue-text { font-size: 15px; padding: 4px 2px; }
  #tools { padding: 6px 0 0; }
  .tool { height: 34px; }
  #kbd { flex: none; height: var(--kbd-h); min-height: 0; max-height: none; padding: 6px 0; }
}
@media (min-width: 600px) and (max-width: 899px) { #board { --size: min(calc(100vw - 16px), max(calc(var(--fit) - 108px), 400px), 600px); } }
@media (max-width: 420px) { #tools { gap: 6px; } .tool { padding: 0 9px; } }

/* Clue lists: beside the grid on wide screens, a sheet from the bottom (the Clues button) on narrow ones. */
#lists { display: none; gap: 20px; min-width: 0; }
.list { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.list h3 { margin: 0 0 6px; padding-bottom: 6px; border-bottom: 1px solid var(--color-tone-4); font-size: 13px; text-transform: uppercase; letter-spacing: .05em; }
.list ol { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.list li { display: flex; align-items: baseline; gap: 8px; padding: 6px 8px; font-size: 15px; line-height: 1.3; cursor: pointer; border-left: 6px solid transparent; border-radius: 2px; }
.list li b { min-width: 22px; text-align: right; flex-shrink: 0; }
.list li.cur { background: var(--hl-word); color: #1a1a1b; }
.nightmode .list li.cur { color: var(--color-tone-1); }
.list li.crossing { border-left-color: var(--hl-word); }
.list li.filled { color: var(--color-tone-2); }
.list li.cur.filled { color: #1a1a1b; }
.nightmode .list li.cur.filled { color: var(--color-tone-1); }
#lists-close { display: none; }
#clues-btn { display: flex; }
body.show-lists #lists { display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: 62dvh; z-index: 1500; background: var(--color-background);
  border-top: 1px solid var(--color-tone-4); border-radius: 12px 12px 0 0; box-shadow: 0 -6px 24px rgba(0,0,0,.18); padding: 40px 12px calc(12px + env(safe-area-inset-bottom)); flex-direction: row; }
body.show-lists #lists-close { display: block; position: absolute; top: 6px; right: 8px; border: 0; background: none; cursor: pointer; padding: 6px; }
#lists-close svg { width: 24px; height: 24px; fill: var(--color-tone-1); display: block; }
@media (max-width: 520px) { body.show-lists #lists { flex-direction: column; } }

/* Wide screens: clue lists beside the grid. With a mouse there's no on-screen keyboard. */
@media (min-width: 900px) {
  #main { padding: 0 16px; }
  #play { flex: 0 0 auto; width: min(600px, calc(100dvh - var(--header-height) - 400px)); min-width: 360px; }
  #board { --size: min(600px, calc(100dvh - var(--header-height) - 400px)); }
  #lists, body.show-lists #lists { display: flex; position: static; height: auto; flex: 1; padding: 14px 0 16px; box-shadow: none; border: 0; border-radius: 0; z-index: auto; flex-direction: row; }
  body.show-lists #lists-close, #clues-btn { display: none; }
}
@media (min-width: 900px) and (pointer: fine) {
  #play { width: min(600px, calc(100dvh - var(--header-height) - 240px)); }
  #board { --size: min(600px, calc(100dvh - var(--header-height) - 240px)); }
  #kbd { display: none; }
}
.rate-list { list-style: none; margin: 0; padding: 0; }
.rate-list li { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--color-tone-4); font-size: 14px; }
.rate-list li span { flex: 1; }
.vote { border: 1px solid var(--color-tone-4); background: var(--color-tone-6); border-radius: 4px; width: 34px; height: 30px; cursor: pointer; font-size: 15px; line-height: 1; flex-shrink: 0; }
.vote[aria-pressed="true"] { background: var(--color-tone-1); border-color: var(--color-tone-1); }
.vote-row { display: flex; justify-content: center; align-items: center; gap: 10px; margin-top: 12px; font-size: 14px; }

/* Toasts */
#toaster { position: fixed; top: 10%; left: 50%; transform: translateX(-50%); z-index: 4000; display: flex; flex-direction: column; align-items: center; pointer-events: none; }
.toast { margin: 8px; background: var(--color-tone-1); color: var(--color-tone-7); padding: 14px 16px; border-radius: 4px; font-weight: 700; font-size: 14px; transition: opacity 300ms; text-align: center; max-width: 90vw; }

/* Modals */
.overlay { position: fixed; inset: 0; z-index: 2000; display: none; align-items: center; justify-content: center; background: var(--opacity-50); }
.overlay.open { display: flex; }
.modal { position: relative; width: min(440px, calc(100% - 32px)); max-height: calc(100% - 32px); overflow-y: auto; padding: 22px 20px; border-radius: 8px; background: var(--color-background); border: 1px solid var(--color-tone-6); box-shadow: 0 4px 23px rgba(0,0,0,.2); animation: slideIn 200ms; }
@keyframes slideIn { from { transform: translateY(30px); opacity: 0; } }
.modal .close { position: absolute; top: 12px; right: 12px; border: 0; background: none; cursor: pointer; }
.modal .close svg { width: 24px; height: 24px; fill: var(--color-tone-1); display: block; }
.modal h2 { margin: 0 0 12px; font-size: 16px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; text-align: center; }
.modal h3 { margin: 18px 0 8px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; text-align: center; }
.modal p, .modal li { font-size: 14px; line-height: 1.5; }
.modal ul { padding-left: 20px; margin: 8px 0; }
.modal hr { border: 0; border-top: 1px solid var(--color-tone-4); margin: 16px 0; }
.big-time { text-align: center; font-size: 44px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 4px 0 0; }
.sub { text-align: center; color: var(--color-tone-2); font-size: 14px; margin: 2px 0 0; }
.modal .actions { display: flex; gap: 10px; align-items: stretch; margin-top: 18px; }
.btn { flex: 1; border: 0; border-radius: 4px; background: var(--green); color: #fff; font-weight: 700; font-size: 16px; text-transform: uppercase; cursor: pointer; padding: 12px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.btn svg { width: 22px; height: 22px; fill: #fff; }
.btn.ghost { background: var(--color-tone-5); color: var(--color-tone-1); }
table.stats { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
table.stats th, table.stats td { padding: 8px 4px; text-align: center; border-bottom: 1px solid var(--color-tone-4); }
table.stats th { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
table.stats td:first-child, table.stats th:first-child { text-align: left; color: var(--color-tone-2); font-size: 13px; }
.setting { display: flex; justify-content: space-between; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--color-tone-4); gap: 12px; }
.setting .t { font-size: 18px; }
.setting .d { font-size: 12px; color: var(--color-tone-2); margin-top: 2px; }
.switch { width: 32px; height: 20px; border-radius: 999px; background: var(--color-tone-3); border: 0; position: relative; cursor: pointer; padding: 0; flex-shrink: 0; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform 150ms; }
.switch[aria-checked="true"] { background: var(--green); }
.switch[aria-checked="true"]::after { transform: translateX(12px); }
.levels { margin: 8px 0; padding: 0; list-style: none; }
.levels li { margin: 6px 0; }
a.text { color: inherit; }
.credit { font-size: 12px !important; color: var(--color-tone-2); text-align: center; }
