/* Zriddle, "Colour Tiles" look: white page, soft grey squares, every value a
   coloured tile with a white icon. Mobile first. All colours are variables. */

@font-face { font-family: 'Jakarta'; src: url('../fonts/plus-jakarta-sans.woff2') format('woff2'); font-weight: 500 800; font-display: swap; }
@font-face { font-family: 'Icons'; src: url('../fonts/noto-emoji-subset.woff2') format('woff2'); font-weight: 500; font-display: block; }

:root {
  --bg: #ffffff;
  --ink: #0f172a;
  --muted: #55607a;
  --soft: #f1f3f8;      /* empty squares, chips, quiet buttons */
  --soft2: #f6f7fb;     /* clue cards */
  --line: #e3e6ef;
  --accent: #4f46e5;
  --accent-ink: #ffffff;
  --good: #10b981;
  --warn: #f59e0b;
  --r: 16px;
  --body: 'Jakarta', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light;
}
:root[data-theme='dark'] {
  --bg: #0e1016; --ink: #f3f4f8; --muted: #a3abc0; --soft: #1b1e29; --soft2: #171a23; --line: #2a2e3c;
  --accent: #818cf8; --accent-ink: #0e1016;
  color-scheme: dark;
}
.rowhead, .cell.set, .opt { --tint: var(--t); --fg: var(--f); }
@media (prefers-color-scheme: dark) {
  :root[data-theme='auto'] {
    --bg: #0e1016; --ink: #f3f4f8; --muted: #a3abc0; --soft: #1b1e29; --soft2: #171a23; --line: #2a2e3c;
    --accent: #818cf8; --accent-ink: #0e1016;
    color-scheme: dark;
  }
  :root[data-theme='auto'] .rowhead, :root[data-theme='auto'] .cell.set, :root[data-theme='auto'] .opt { --tint: var(--td); --fg: var(--m); }
}
:root[data-theme='dark'] .rowhead, :root[data-theme='dark'] .cell.set, :root[data-theme='dark'] .opt { --tint: var(--td); --fg: var(--m); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body { font-family: var(--body); font-weight: 500; background: var(--bg); color: var(--ink); overscroll-behavior: none; -webkit-text-size-adjust: 100%; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; touch-action: manipulation; }
[hidden] { display: none !important; }
.ic { display: inline-grid; place-items: center; width: 1.25em; height: 1.25em; flex: none; }
.ic svg { width: 100%; height: 100%; }

#app {
  height: 100dvh; max-width: 560px; margin: 0 auto; display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
}

/* ---------- text and links under the game (scroll down) ---------- */
.about { max-width: 560px; margin: 0 auto; padding: 28px 16px 40px; color: var(--muted); font-size: 15px; line-height: 1.6; border-top: 1px solid var(--line); }
.about h1 { font-size: 19px; font-weight: 800; color: var(--ink); margin: 0 0 8px; letter-spacing: -0.3px; }
.about p { margin: 0 0 16px; }
.about nav { display: flex; flex-wrap: wrap; gap: 8px; }
.about h2 { font-size: 16px; font-weight: 800; color: var(--ink); margin: 20px 0 6px; }
.about p a { color: var(--accent); font-weight: 700; }
.about nav a { color: var(--ink); font-weight: 700; text-decoration: none; background: var(--soft); border-radius: 999px; padding: 11px 15px; }

/* ---------- top ---------- */
.top { display: flex; align-items: center; justify-content: space-between; padding: 8px 0 4px; }
.top-right { display: flex; gap: 2px; }
.top-nav { display: none; }
.top-nav a { color: var(--muted); font-weight: 700; font-size: 15px; text-decoration: none; padding: 10px 12px; border-radius: 12px; white-space: nowrap; }
.top-nav a:hover, .top-nav a[aria-current='page'] { color: var(--ink); background: var(--soft); }
.icon-btn { width: 42px; height: 42px; border-radius: 12px; font-size: 19px; display: grid; place-items: center; color: var(--ink); }
.icon-btn:active { background: var(--soft); }

.logo { display: flex; align-items: center; line-height: 1; }
.logo img { display: block; height: 42px; width: auto; }
.logo.wiggle img { animation: wiggle 0.7s ease; }
@keyframes wiggle { 20% { transform: rotate(-5deg) scale(1.06); } 50% { transform: rotate(4deg) scale(1.08); } 80% { transform: rotate(-2deg) scale(1.03); } }

.sub { display: flex; justify-content: space-between; align-items: center; font-size: 13px; padding: 0 0 10px; gap: 8px; }
.meta { display: flex; align-items: center; gap: 8px; min-width: 0; }
.day-btn { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; padding: 7px 8px 7px 11px; border-radius: 999px; background: var(--soft); white-space: nowrap; }
.day-btn b { font-weight: 800; }
.new-btn { gap: 6px; padding: 7px 12px 7px 9px; }
.theme-name { color: var(--muted); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; padding: 7px 11px; border-radius: 999px; background: var(--soft); white-space: nowrap; }

.tabs { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; padding: 3px; border-radius: 13px; background: var(--soft); margin-bottom: 10px; }
.tab { display: inline-flex; align-items: center; justify-content: center; gap: 3px; padding: 8px 2px; border-radius: 10px; font-weight: 700; font-size: 13px; color: var(--muted); white-space: nowrap; }
.tab .ic { color: var(--good); font-size: 12px; }
.tab.on { background: var(--ink); color: var(--bg); }

/* ---------- play area ---------- */
.play { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.board-wrap { flex: none; position: relative; }
/* Before a puzzle is revealed: board and clues blurred, a card with one button on top. */
.cover { position: absolute; inset: 0; z-index: 2; display: grid; justify-items: center; align-items: start; padding: 26px 8px 0; }
.cover[hidden] { display: none; }
.cover-card { width: min(340px, 100%); background: var(--bg); border: 1px solid var(--line); border-radius: 22px; padding: 20px 20px 16px; text-align: center; box-shadow: 0 14px 44px rgba(15, 23, 42, 0.16); }
.cover-card h2 { margin: 2px 0 4px; font-size: 21px; font-weight: 800; letter-spacing: -0.3px; }
.cover-kicker { margin: 0; font-size: 12px; font-weight: 800; letter-spacing: 0.8px; text-transform: uppercase; color: var(--accent); }
.cover-size { margin: 0 0 14px; font-size: 14px; font-weight: 600; color: var(--muted); }
.cover-btn { width: 100%; }
.cover-note { margin: 10px 0 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.waiting .board, .waiting .clue-wrap > * { filter: blur(11px); opacity: 0.55; pointer-events: none; user-select: none; }
.waiting .clue-wrap { overflow: hidden; }
.waiting .bar { opacity: 0.4; pointer-events: none; }
.clue-wrap { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 2px 0 12px; overscroll-behavior: contain; }

.board { display: grid; grid-template-columns: 24px repeat(var(--n, 5), minmax(0, 1fr)); gap: 5px; }
.loading { grid-column: 1 / -1; text-align: center; padding: 60px 0; font-weight: 700; color: var(--muted); }
.colhead { text-align: center; font-size: 13px; font-weight: 700; color: var(--muted); line-height: 1.2; }
.rowhead { display: grid; place-items: center; border-radius: 9px; background: var(--tint); color: var(--fg); }
.rowhead span { writing-mode: vertical-rl; transform: rotate(180deg); font-size: 10px; font-weight: 800; letter-spacing: 0.7px; text-transform: uppercase; white-space: nowrap; }

.cell {
  position: relative; height: clamp(58px, 10.4dvh, 88px); border-radius: 14px; background: var(--soft);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; overflow: hidden; min-width: 0;
}
.cell:active { transform: scale(0.96); }
.cell.set { background: var(--tint); }
.cell .lbl { font-size: 11px; font-weight: 700; max-width: 94%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 1.2; }
.cell.flash { animation: flash 0.9s ease 3; }
@keyframes flash { 50% { box-shadow: 0 0 0 3px var(--accent); } }
.cell.won { animation: pop 0.5s ease var(--wd) both; }
@keyframes pop { 0% { transform: scale(1); } 45% { transform: scale(1.12); } 100% { transform: scale(1); } }

/* ---------- tiles: one value ---------- */
.tile {
  --s: 25px;
  display: inline-grid; place-items: center; width: var(--s); height: var(--s); flex: none;
  border-radius: calc(var(--s) * 0.3); background: var(--m); color: #fff;
  font-family: 'Icons', 'Noto Emoji', sans-serif; font-weight: 500; font-size: calc(var(--s) * 0.62); line-height: 1;
  font-style: normal; font-variant-emoji: text; user-select: none; -webkit-user-select: none;
}
.tile.letter { font-family: var(--body); font-weight: 800; font-size: calc(var(--s) * 0.5); }
.tile.letter.two { font-size: calc(var(--s) * 0.4); letter-spacing: -0.3px; }
.tile.swatch { box-shadow: inset 0 0 0 1.5px rgba(15, 23, 42, 0.14); }
.tile.big { --s: 46px; }
.tile.gone { display: none; }

.minis { display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: 4px; padding: 2px; max-width: 62px; }
.board[data-n='6'] .minis { gap: 3px; max-width: 52px; }
.board[data-n='6'] .minis .tile { --s: 21px; }
.board[data-n='6'] .cell .tile.big { --s: 38px; }
.board[data-n='4'] .minis .tile, .board[data-n='3'] .minis .tile { --s: 28px; }
.board[data-n='3'] .minis { max-width: 100px; }
.board[data-n='4'] .minis { max-width: 68px; } /* two 28px tiles side by side */
.minis.one .tile { --s: 34px; opacity: 0.55; }
/* five rows: slightly shorter squares so the clues keep some room */
.board[data-k='5'] .cell { height: clamp(52px, 8.7dvh, 74px); }
.board[data-k='5'] .minis { gap: 3px; }
.board[data-k='5'] .minis .tile { --s: 21px; }
.board[data-k='5'] .cell .tile.big { --s: 38px; }
.board[data-k='5'] .minis.one .tile { --s: 30px; }

/* ---------- clues ---------- */
.intro { margin: 0 2px 10px; font-size: 13.5px; color: var(--muted); font-weight: 600; }
.clues { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.clue {
  display: flex; gap: 10px; align-items: flex-start; background: var(--soft2); border-radius: var(--r);
  padding: 11px 13px; font-size: 16px; line-height: 1.75; cursor: pointer; user-select: none; -webkit-user-select: none;
}
.clue .num { font-size: 12px; font-weight: 800; min-width: 22px; height: 22px; line-height: 22px; text-align: center; border-radius: 7px; background: var(--line); color: var(--muted); margin-top: 3px; flex: none; }
.clue.struck { color: var(--muted); opacity: 0.6; }
.clue.struck .txt { text-decoration: line-through; }
.clue.struck .tile { filter: grayscale(1); opacity: 0.6; }
.clue.flash { box-shadow: 0 0 0 2.5px var(--accent); }
.chip { display: inline; white-space: nowrap; font-weight: 800; }
.chip .tile { --s: 24px; margin: 0 5px 0 2px; vertical-align: middle; position: relative; top: -1.5px; }

/* ---------- practice coach ---------- */
.coach { background: var(--accent); color: var(--accent-ink); border-radius: var(--r); padding: 11px 13px 13px; margin: 0 0 10px; position: sticky; top: 0; z-index: 5; }
.coach p { margin: 4px 0 0; font-size: 15.5px; line-height: 1.45; font-weight: 600; }
.coach-top { display: flex; justify-content: space-between; align-items: center; font-size: 11.5px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.6px; opacity: 0.9; }
.coach-skip { font-weight: 800; text-decoration: underline; padding: 6px 4px; font-size: 13px; }
.coach-go { margin-top: 10px; background: var(--accent-ink); color: var(--accent); padding: 11px 26px; }
.tutoring .tabs, .tutoring .sub, .tutoring .intro { display: none; }
.tutoring .cell.flash { animation: flash 0.9s ease infinite; }
.tut-btn { margin: 4px 0 8px; }

/* ---------- bottom bar and buttons ---------- */
.bar { display: grid; grid-template-columns: 1fr 1.5fr 1fr; gap: 8px; padding: 8px 0 max(14px, env(safe-area-inset-bottom)); flex: none; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 14px 12px; border-radius: 14px; font-weight: 700; font-size: 15px; background: var(--soft); }
a.btn { text-decoration: none; color: inherit; }
.btn:active { transform: scale(0.97); }
.btn-hint, .btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: #e11d48; color: #fff; }
.btn.big { padding: 15px 16px; font-size: 16px; flex: 1; }
.btn.wide { width: 100%; margin-top: 12px; }
.row { display: flex; gap: 10px; margin-top: 14px; }

.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); font-weight: 600; font-size: 14.5px; padding: 12px 16px; border-radius: 14px;
  max-width: min(92vw, 480px); text-align: center; opacity: 0; pointer-events: none; transition: 0.2s; z-index: 40;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- sheets ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.scrim { position: absolute; inset: 0; background: rgba(8, 10, 20, 0.5); animation: fade 0.18s; }
.sheet {
  position: relative; width: min(100%, 560px); max-height: 84dvh; display: flex; flex-direction: column; background: var(--bg);
  border-radius: 24px 24px 0 0; padding: 8px 16px max(18px, env(safe-area-inset-bottom)); animation: rise 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.05);
}
.sheet.tall { max-height: 92dvh; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 6px; }
.sheet-head h2 { font-weight: 800; font-size: 20px; letter-spacing: -0.3px; margin: 0; }
.sheet-body { overflow-y: auto; padding: 2px 0 4px; }
.sheet-body p { margin: 8px 0; font-size: 15.5px; line-height: 1.5; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(100%); } }
@media (min-width: 700px) {
  .sheet-wrap { align-items: center; }
  .sheet { border-radius: 24px; box-shadow: 0 20px 60px rgba(8, 10, 20, 0.3); }
}

.modes { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px; background: var(--soft); border-radius: 13px; padding: 3px; }
.mode { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 6px; border-radius: 10px; font-weight: 700; font-size: 14.5px; white-space: nowrap; color: var(--muted); }
.mode.on { background: var(--ink); color: var(--bg); }
.opts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.opts[data-n='4'] { grid-template-columns: repeat(2, 1fr); }
.opt { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 12px 4px 9px; min-height: 104px; border-radius: 16px; background: var(--soft); }
.opt:active { transform: scale(0.96); }
.opt .tile.big { --s: 50px; }
.opt-name { font-weight: 700; font-size: 14px; text-align: center; line-height: 1.15; }
.opt-note { font-size: 11px; color: var(--muted); font-weight: 600; min-height: 13px; }
.opt.here { background: var(--tint); box-shadow: inset 0 0 0 2.5px var(--m); }
.opt.crossed .tile, .opt.used .tile { filter: grayscale(1); opacity: 0.3; }
.opt.crossed { background: color-mix(in srgb, #f59e0b 22%, var(--soft)); box-shadow: inset 0 0 0 2px #f59e0b; }
.opt.crossed .opt-note { color: color-mix(in srgb, #b45309 70%, var(--ink)); font-weight: 800; }
.opt.crossed .opt-name { opacity: 0.45; text-decoration: line-through; }
.opt.used .opt-name { opacity: 0.55; }
.picker-tip b { font-weight: 800; color: var(--ink); }
.picker-tip { color: var(--muted); font-size: 13px !important; text-align: center; font-weight: 600; }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 6px 0 12px; }
.result .times { text-align: center; margin-top: -8px; }
.stat { background: var(--soft); border-radius: 16px; padding: 12px 4px; text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); }
.stat b { display: block; font-weight: 800; font-size: 25px; letter-spacing: -0.5px; color: var(--ink); font-variant-numeric: tabular-nums; }
.stats table { width: 100%; border-collapse: collapse; font-size: 14px; }
.stats th, .stats td { padding: 9px 4px; text-align: center; border-bottom: 1px solid var(--line); }
.stats tbody th { text-align: left; }
.stats thead th { font-size: 11.5px; color: var(--muted); }
.small { font-size: 13px !important; color: var(--muted); text-align: center; font-weight: 600; }
.share { background: var(--soft); border-radius: 16px; padding: 14px; margin: 0; font-family: var(--body); font-size: 15px; line-height: 1.25; text-align: center; white-space: pre-wrap; }
.share { display: grid; justify-items: center; gap: 14px; padding: 20px 14px; }
.share-logo { display: block; height: 44px; width: auto; }
.share .share-head, .share .share-meta { margin: 0; font-weight: 700; }
.share .share-url { margin: 0; font-weight: 800; font-size: 17px; letter-spacing: 0.2px; }
.share-grid { margin: 0; font-family: var(--body); font-size: 22px; line-height: 1.3; letter-spacing: 2px; }
.result { display: grid; gap: 18px; padding-top: 6px; }
.sheet .result > * { margin: 0; }
.countdown { font-variant-numeric: tabular-nums; color: var(--ink); }

.days { display: grid; gap: 6px; }
.day { display: grid; grid-template-columns: 74px 1fr auto; align-items: center; text-align: left; padding: 13px 14px; border-radius: 14px; background: var(--soft); font-weight: 600; font-size: 14.5px; }
.day b { font-weight: 800; }
.day.on { background: var(--ink); color: var(--bg); }
.day .dots { font-size: 12px; letter-spacing: 2px; color: var(--good); }

.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 0; font-weight: 600; font-size: 15.5px; border-bottom: 1px solid var(--line); }
.set-row input { width: 24px; height: 24px; accent-color: var(--accent); }
.set-row .modes { flex: 1; max-width: 290px; }

.help-step { display: flex; gap: 13px; align-items: flex-start; padding: 9px 0; }
.help-tile { --s: 44px !important; }
.help-step b { font-size: 16px; font-weight: 800; }
.help-step p { margin: 2px 0 0; font-size: 14.5px; color: var(--muted); }

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 50; }
.confetti span { position: absolute; top: -30px; border-radius: 4px; animation: fall var(--t) cubic-bezier(0.3, 0.6, 0.6, 1) var(--dl) forwards; }
@keyframes fall { to { transform: translate(var(--dx), 105dvh) rotate(540deg); } }

@media (max-height: 640px) {
  .cell { height: 52px; }
  .cell .tile.big { --s: 30px; }
  .cell .lbl { font-size: 9.5px; }
  .minis .tile { --s: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- tablets and bigger: the board grows to use the screen ----------
   Square height comes from the screen height and the number of rows; the
   tiles inside size themselves from the square (container units). */
@media (min-width: 700px) {
  /* The game is only as tall as its board and clues (never taller than the
     screen), so the text under it moves up on short puzzles. */
  #app { max-width: 780px; padding-left: 24px; padding-right: 24px; height: auto; max-height: 100dvh; }
  .about { margin-top: 20px; }
  .top { padding-top: 14px; }
  .logo img { height: 50px; }
  .board { gap: 7px; grid-template-columns: 30px repeat(var(--n, 5), minmax(0, 1fr)); }
  .colhead { font-size: 15px; }
  .rowhead span { font-size: 11.5px; }
  .board .cell, .board[data-k='5'] .cell {
    height: clamp(84px, calc((100dvh - 250px) * 0.6 / var(--k, 4)), 150px);
    container-type: size; border-radius: 18px;
  }
  .board .cell .minis { max-width: none; width: 100%; gap: 5cqmin; padding: 0 4cqw; }
  .board .cell .minis .tile { --s: min(27cqh, 36cqw); }
  .board .cell .minis.one .tile { --s: min(44cqh, 50cqw); }
  .board .cell .tile.big { --s: min(54cqh, 62cqw); }
  .board .cell .lbl { font-size: clamp(11px, 12cqh, 17px); }
  .clue { font-size: 17px; }
  .tabs, .bar { max-width: 560px; width: 100%; margin-left: auto; margin-right: auto; }
}
/* wide screens: board on the left, clues on the right */
@media (min-width: 1000px) {
  #app { max-width: min(1560px, 100%); padding-left: 32px; padding-right: 32px; }
  .top-nav { display: flex; gap: 2px; margin: 0 14px 0 auto; }
  /* Two columns. Left: sizes, board, then Undo / Hint / Reset right under the
     board. Right: the clues, running the full height. */
  #app {
    display: grid; column-gap: 34px; align-content: start;
    grid-template-columns: minmax(0, 1.55fr) minmax(320px, 540px);
    grid-template-rows: auto auto auto auto auto minmax(0, 1fr);
  }
  .top, .sub { grid-column: 1 / -1; }
  .play { display: contents; }
  .tabs { grid-column: 1; grid-row: 3; }
  .board-wrap { grid-column: 1; grid-row: 4; min-width: 0; }
  .bar { grid-column: 1; grid-row: 5; padding: 16px 0 0 43px; max-width: 603px; }
  .clue-wrap { grid-column: 2; grid-row: 3 / 7; min-height: 0; padding-bottom: 24px; }
  /* The text and links under the game: full width, text left, links right. */
  .about {
    max-width: min(1560px, 100%); padding: 36px 32px 56px; font-size: 16px;
    display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(320px, 540px); column-gap: 34px; align-items: start;
  }
  .about > * { grid-column: 1; max-width: 720px; }
  .about > nav { grid-column: 2; grid-row: 1 / span 30; align-self: start; }
  .about h1 { font-size: 22px; }
  .board { gap: 9px; grid-template-columns: 34px repeat(var(--n, 5), minmax(0, 1fr)); }
  .board .cell, .board[data-k='5'] .cell {
    height: clamp(84px, calc((100dvh - 250px) / var(--k, 4) - 9px), 190px);
    border-radius: 20px;
  }
  .board .cell .minis .tile { --s: min(30cqh, 26cqw); }
  .board .cell .minis.one .tile { --s: min(46cqh, 40cqw); }
  .board .cell .tile.big { --s: min(56cqh, 50cqw); }
}
