/* 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; }
}
