/* Theme picker, drawing editor controls, expanded drawing view, touch tuning. */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Theme picker */
.theme-picker { position: relative; display: flex; }
.theme-button { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; border: 1px solid var(--line); color: var(--muted); transition: color .15s, background .15s, border-color .15s; }
.theme-button:hover, .theme-button[aria-expanded="true"] { color: var(--blue); background: var(--tint); border-color: var(--tint-line); }
.theme-button svg { width: 18px; height: 18px; }
.theme-sun { display: none; }
[data-theme="dark"] .theme-sun { display: block; }
[data-theme="dark"] .theme-moon { display: none; }
.theme-menu { position: absolute; right: 0; top: calc(100% + 8px); z-index: 40; min-width: 210px; padding: 6px; display: flex; flex-direction: column; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 14px 40px #1b2d5926; }
[data-theme="dark"] .theme-menu { box-shadow: 0 14px 40px #0009; }
.theme-menu button { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 42px; padding: 9px 12px; border-radius: 8px; font-size: .875rem; color: var(--text-2); text-align: left; }
.theme-menu button span { color: var(--faint); font-size: 1rem; }
.theme-menu button:hover { background: var(--tint); color: var(--ink); }
.theme-menu button[aria-checked="true"] { color: var(--blue); font-weight: 650; background: var(--tint); }
.theme-menu button[aria-checked="true"] span { color: var(--blue); }
.theme-button:focus-visible, .editor-tool:focus-visible, .editor-icon:focus-visible { outline-offset: 2px; }
.theme-menu button:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }

/* Drawing editor controls */
.editor-controls { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; padding: 14px 26px 0; }
.drawing-modes { display: inline-flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--tint); border: 1px solid var(--line); }
.editor-tool { display: inline-flex; align-items: center; gap: 7px; min-height: 36px; padding: 6px 14px; border-radius: 7px; font-size: .82rem; font-weight: 600; color: var(--muted); transition: color .15s, background .15s, box-shadow .15s; }
.editor-tool svg { width: 16px; height: 16px; }
.editor-tool:hover:not(:disabled) { color: var(--ink); }
.editor-tool[aria-pressed="true"] { background: var(--surface); color: var(--blue); box-shadow: 0 1px 3px #20263522; }
[data-theme="dark"] .editor-tool[aria-pressed="true"] { background: var(--tint-strong); box-shadow: none; }
.editor-history { display: flex; gap: 6px; }
.editor-icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 9px; border: 1px solid var(--line); color: var(--muted); transition: color .15s, background .15s, border-color .15s; }
.editor-icon svg { width: 18px; height: 18px; }
.editor-icon:hover:not(:disabled) { color: var(--blue); background: var(--tint); border-color: var(--tint-line); }
.editor-icon:disabled { opacity: .35; }
.collapse-icon, .is-expanded .expand-icon { display: none; }
.is-expanded .collapse-icon { display: block; }

/* The graph. Its viewBox follows its rendered pixel size (see curve-editor.js),
   so CSS alone decides how much room it gets. */
.graph-wrap { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; cursor: crosshair; }
.graph-wrap[data-mode="shape"] { cursor: ns-resize; }
.graph-wrap.is-locked { cursor: default; touch-action: auto; }
#graph { aspect-ratio: 720 / 350; height: auto; cursor: inherit; }
.graph-wrap.is-locked #graph { touch-action: auto; }
#graph.pointer-focus { outline: none; }
#graph:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; border-radius: 6px; }
.graph-grid-line { stroke: var(--grid); }
.curve-stop { stop-color: var(--blue); }
.graph-label { font-size: 12px; }
.axis-letter { font-size: 15px; }
.cursor-halo { fill: var(--blue); fill-opacity: .1; stroke: var(--blue); stroke-opacity: .35; stroke-width: 1.5; pointer-events: none; }
.is-drawing .cursor-halo { fill-opacity: .16; }
#drawing-instruction { flex: 1; min-width: 0; }
/* Reference marker (x_marker): a moved axis at zero, or a dashed line elsewhere. */
.marker-line { fill: none; stroke: var(--muted); stroke-width: 1.4; stroke-dasharray: 2 5; stroke-linecap: round; opacity: .75; pointer-events: none; }
.marker-label { fill: var(--text-2); font-size: 12px; font-weight: 650; letter-spacing: .01em; pointer-events: none; }
/* The movable zero: the y-axis is dragged by its ends (handle above, foot below),
   outside the drawing area. Left of it is negative, washed faintly. */
.negative-region { fill: var(--ink); opacity: .035; pointer-events: none; }
[data-theme="dark"] .negative-region { opacity: .05; }
.axis-handle { cursor: ew-resize; outline: none; }
.axis-grip { fill: var(--surface); stroke: var(--axis); stroke-width: 1.4; transition: stroke .15s, fill .15s; }
.axis-grip-arrows { fill: none; stroke: var(--muted); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; transition: stroke .15s; }
.axis-hover .axis-grip, .is-moving-axis .axis-grip, .axis-handle:focus-visible .axis-grip { stroke: var(--blue); fill: var(--tint); }
.axis-hover .axis-grip-arrows, .is-moving-axis .axis-grip-arrows, .axis-handle:focus-visible .axis-grip-arrows { stroke: var(--blue); }
.axis-handle:focus-visible .axis-grip { stroke-width: 2.5; }
.is-moving-axis #axis-main { stroke: var(--blue); }
.graph-wrap.axis-hover, .graph-wrap.is-moving-axis { cursor: ew-resize; }
.axis-name { fill: var(--text-2); font-size: 12px; font-weight: 650; pointer-events: none; }
.axis-sign { fill: var(--faint); font-size: 13px; font-weight: 600; pointer-events: none; }
.answer-zero { fill: none; stroke: var(--green); stroke-width: 2; stroke-dasharray: 5 5; stroke-linecap: round; pointer-events: none; }
/* A halo keeps the y letter legible when the axis sits inside the plot. */
.axis-letter { paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }

@media (max-width: 1000px) { .editor-controls { padding: 14px 20px 0; } }
@media (max-width: 760px) { #graph { aspect-ratio: 16 / 10; } }
/* Comfortable finger targets wherever the primary pointer is a finger. */
@media (pointer: coarse) {
  .editor-tool { min-height: 42px; padding-inline: 16px; }
  .editor-icon, .theme-button { width: 44px; height: 44px; }
  .control-point { r: 5; }
}
@media (max-width: 520px) {
  .editor-controls { padding: 12px 12px 0; }
  .graph-wrap { padding: 10px 2px 0; }
  #graph { aspect-ratio: 5 / 4; }
  .editor-tool { padding-inline: 11px; }
  .editor-history { gap: 4px; }
  .editor-icon { width: 42px; height: 42px; }
}

/* Expanded drawing view: the same card, moved into a full-screen dialog. */
#drawing-dialog { width: 100%; max-width: none; height: 100%; max-height: none; margin: 0; padding: 0; border: 0; border-radius: 0; background: var(--paper); box-shadow: none; overflow: hidden; }
#drawing-dialog[open] { display: flex; }
#drawing-dialog::backdrop { background: var(--paper); }
html:has(#drawing-dialog[open]) { overflow: hidden; }
.drawing-card.is-expanded { flex: 1; display: flex; flex-direction: column; min-height: 0; width: 100%; max-width: 1240px; margin: 0 auto; border: 0; border-radius: 0; box-shadow: none; }
.is-expanded .drawing-toolbar { display: none; }
.is-expanded .graph-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.is-expanded #graph { flex: 1; min-height: 0; height: 100%; aspect-ratio: auto; }
.is-expanded .x-label { margin-bottom: 12px; }
.is-expanded .drawing-hint { padding-bottom: 12px; }
@media (min-width: 900px) and (min-height: 600px) {
  #drawing-dialog { padding: 28px; }
  .drawing-card.is-expanded { border: 1px solid var(--line); border-radius: var(--radius); }
}
@media (orientation: portrait) and (max-width: 600px) {
  .is-expanded #drawing-instruction::after { content: " Turn your phone sideways for a wider canvas."; }
}
/* Landscape phones: give nearly all of the height to the canvas. */
@media (max-height: 520px) {
  .is-expanded .editor-controls { padding-top: 8px; }
  .is-expanded .y-label, .is-expanded #drawing-instruction { display: none; }
  .is-expanded .graph-wrap { padding-top: 4px; }
  .is-expanded .x-label { margin: 0 20px 4px; font-size: .72rem; }
  .is-expanded .drawing-hint { border: 0; padding-bottom: 0; }
  .is-expanded .guess-actions { padding: 8px 20px 10px; }
  .is-expanded .guess-actions .button { min-height: 40px; padding: 9px 16px; }
}

/* Share result */
.share-button { margin-top: 18px; gap: 9px; }
.share-button svg { width: 17px; height: 17px; }
.result-card > .share-button + .text-button { display: flex; }

/* Next puzzle: shown above the scenario once today's puzzle is finished.
   The bottom note's quiet style (clock glyph, muted text, tabular digits), larger. */
.next-puzzle { display: flex; align-items: center; gap: 18px; margin-bottom: 20px; padding: 20px 26px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.next-puzzle-mark { flex-shrink: 0; width: 44px; height: 44px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 12px; color: var(--muted); font-size: 1.45rem; line-height: 1; }
.next-puzzle-clock { display: flex; flex-direction: column; gap: 5px; }
.next-puzzle-clock .eyebrow { margin: 0; }
.next-puzzle-time { font-size: 2.1rem; font-weight: 600; line-height: 1.05; letter-spacing: -.02em; font-variant-numeric: tabular-nums; color: var(--ink); }
.next-puzzle-time .sep { padding: 0 .08em; font-weight: 400; color: var(--faint); }
.next-puzzle-clock .button { align-self: flex-start; margin-top: 4px; }
.next-puzzle-note { margin: 0 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; text-align: right; font-size: .8rem; line-height: 1.55; color: var(--muted); }
.next-puzzle-note span:first-child { color: var(--text-2); font-weight: 600; }
@media (max-width: 520px) {
  .next-puzzle { flex-wrap: wrap; gap: 14px; padding: 18px 20px; margin-bottom: 16px; }
  .next-puzzle-mark { width: 38px; height: 38px; font-size: 1.25rem; }
  .next-puzzle-time { font-size: 1.85rem; }
  .next-puzzle-note { margin: 0; width: 100%; align-items: flex-start; text-align: left; padding-top: 12px; border-top: 1px solid var(--line-soft); }
}

/* Leaderboard */
.leaderboard-bar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px 20px; margin-bottom: 16px; }
.leaderboard-tabs { display: inline-flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--tint); border: 1px solid var(--line); }
.leaderboard-tabs a { padding: 7px 16px; border-radius: 7px; font-size: .85rem; font-weight: 600; color: var(--muted); min-height: 36px; display: inline-flex; align-items: center; }
.leaderboard-tabs a:hover { color: var(--ink); }
.leaderboard-tabs a[aria-current="page"] { background: var(--surface); color: var(--blue); box-shadow: 0 1px 3px #20263522; }
[data-theme="dark"] .leaderboard-tabs a[aria-current="page"] { background: var(--tint-strong); box-shadow: none; }
.leaderboard-you { margin: 0; font-size: .85rem; color: var(--muted); }
.leaderboard-you strong { color: var(--ink); font-weight: 650; }
.leaderboard-you .text-button { font-size: .85rem; }
.leaderboard-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.leaderboard { width: 100%; border-collapse: collapse; font-size: .92rem; }
.leaderboard th { padding: 14px 24px; text-align: left; font-size: .7rem; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; color: var(--faint); border-bottom: 1px solid var(--line); }
.leaderboard td { padding: 14px 24px; border-bottom: 1px solid var(--line-soft); }
.leaderboard tbody tr:last-child td { border-bottom: 0; }
.leaderboard .lb-rank { width: 72px; }
.leaderboard .lb-solved { width: 110px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.leaderboard .lb-points { width: 120px; text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; }
.leaderboard td.lb-points small { font-weight: 400; color: var(--faint); }
.lb-rank-badge { display: inline-grid; place-items: center; min-width: 30px; height: 30px; padding: 0 6px; border-radius: 999px; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--muted); }
.lb-rank-badge.is-top { color: var(--blue); background: var(--tint); border: 1px solid var(--tint-line); }
.lb-name { font-weight: 600; overflow-wrap: anywhere; }
.lb-you { margin-left: 8px; padding: 2px 8px; border-radius: 999px; font-size: .68rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--blue); background: var(--tint); vertical-align: middle; }
.leaderboard-row.is-you td { background: var(--surface-soft); }
.leaderboard-gap td { padding: 4px 24px; text-align: center; color: var(--faint); letter-spacing: .3em; }
.leaderboard-note { margin: 12px 4px 0; font-size: .78rem; color: var(--faint); }
.leaderboard-note + .history-join, .empty-state + .history-join { margin-top: 26px; }
.next-puzzle-note .text-button { font-size: .8rem; padding: 2px 0 0; }
.nickname-hint { margin: -6px 0 8px; font-size: .78rem; }
.nickname-skip { display: block; margin: 14px auto 0; color: var(--muted); font-weight: 500; }
@media (max-width: 520px) {
  .leaderboard th, .leaderboard td { padding: 12px 14px; }
  .leaderboard .lb-rank { width: 52px; }
  .leaderboard .lb-solved { display: none; }
  .leaderboard .lb-points { width: 84px; }
  .leaderboard-bar { align-items: flex-start; flex-direction: column; }
}

/* Five header controls need icons-only a little earlier than the base layout did. */
@media (max-width: 620px) { .nav-link span, .desktop-only { display: none; } nav { gap: 18px; } }
@media (max-width: 380px) {
  .header-inner { padding-left: 12px; padding-right: 12px; gap: 8px; }
  nav { gap: 11px; }
  .brand { font-size: 1.45rem; }
  .brand svg { width: 23px; height: 21px; margin-right: 5px; }
  .theme-button { width: 36px; height: 36px; }
  .button-small { padding: 8px 10px; }
}
.site-header .button-small { white-space: nowrap; }
@media (max-width: 420px) { nav { gap: 12px; } .site-header .button-small { padding-left: 11px; padding-right: 11px; } }
@media (max-width: 340px) { nav { gap: 8px; } .header-inner { gap: 6px; } }

/* Reporting a name: a quiet flag that appears with the row's hover or focus. */
.lb-name-cell { display: flex; align-items: center; gap: 8px; }
.lb-report { margin-left: auto; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; color: var(--faint); opacity: 0; transition: opacity .15s, color .15s, background .15s; }
.lb-report svg { width: 15px; height: 15px; }
.leaderboard-row:hover .lb-report, .lb-report:focus-visible { opacity: 1; }
.lb-report:hover:not(:disabled) { color: var(--rose); background: var(--rose-tint); }
.lb-report.is-reported { opacity: 1; color: var(--rose); cursor: default; }
.lb-report:focus-visible { outline-offset: 1px; }
@media (pointer: coarse) { .lb-report { opacity: .55; width: 36px; height: 36px; } }
.report-actions { display: flex; gap: 10px; margin-top: 22px; }
.report-actions .button { flex: 1; }
