/* Color Timer. Colours are tokens on :root; the dark look is the default and the light look follows the device. */
:root {
  --bg: #0f1218; --panel: #171b24; --panel2: #1d2230; --text: #e9ecf3; --muted: #8d97ab; --line: #2a3142; --danger: #ff9a8a; --accent: #5b9bff; --accent-ink: #07101f;
  --face: #1b2130; --well: #10141c; --tick: #5d6a85; --tick-strong: #aab4cb; --label: #c4cce0;
  --hand: #ffffff; --hand-edge: rgba(0, 0, 0, .6); --knob: #ffffff;
  --c-red: #e5484d; --c-orange: #f2994a; --c-green: #3ecf8e; --c-blue: #4ea1ff; --c-purple: #9b7cf6;
  --done: #ff6b6b; --over: #ff5fb0;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f4f7; --panel: #ffffff; --panel2: #e9ecf2; --text: #161a22; --muted: #5d667a; --line: #d5dae4; --danger: #c2392b; --accent: #2f6fdd; --accent-ink: #ffffff;
    --face: #ffffff; --well: #eef0f5; --tick: #9aa4b8; --tick-strong: #4d576c; --label: #3a4358;
    --hand: #161a22; --hand-edge: rgba(255, 255, 255, .85); --knob: #161a22;
    --c-red: #d6343a; --c-orange: #e07b1f; --c-green: #1fa56c; --c-blue: #2f7fe0; --c-purple: #7a58e0;
    --done: #d6343a; --over: #d12a86;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; transition: background-color .8s ease; }
/* Narrow side margins so the timer uses the screen: 8px each side, less than that on a phone. */
main { max-width: 720px; margin: 0 auto; padding: max(52px, calc(env(safe-area-inset-top) + 40px)) max(8px, env(safe-area-inset-right)) 56px max(8px, env(safe-area-inset-left)); }
h1 { font-size: 1.25rem; margin: 0 0 .75rem; text-align: center; }
h2 { font-size: 1rem; margin: 0 0 .75rem; }
section { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 1rem .9rem; margin: .75rem 0; }
.hint { color: var(--muted); font-size: .85rem; margin: .4rem 0 0; }
.hint.center { text-align: center; margin-top: .9rem; }
.status { min-height: 1.4em; color: var(--muted); font-size: .85rem; margin: .6rem 0 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button { font: inherit; color: inherit; border: 1px solid var(--line); background: var(--panel2); border-radius: 10px; padding: .45em .9em; min-height: 2.5rem; cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.danger { color: var(--danger); }
button.big { min-height: 3rem; min-width: 7.5rem; font-size: 1.05rem; padding: .5em 1.2em; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .6rem; }

input[type="text"], select { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: .5em .75em; min-height: 2.5rem; }
input[type="text"] { flex: 1; min-width: 0; }
select { width: 100%; max-width: 100%; }
input[type="text"][aria-invalid="true"] { border-color: var(--danger); }
.field { margin: 0 0 1rem; }
.field:last-child { margin-bottom: 0; }
.field > label, .label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .3rem; }
.field.two { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
@media (max-width: 430px) { .field.two { grid-template-columns: 1fr; } }
.inline { display: flex; gap: .5rem; }
.check { display: flex; align-items: center; gap: .6rem; padding: .35rem 0; min-height: 2.25rem; cursor: pointer; }
.check input { width: 1.15rem; height: 1.15rem; accent-color: var(--accent); flex: none; }

.chips { display: flex; flex-wrap: wrap; gap: .45rem; }
.chips button { min-width: 3.4rem; padding: .35em .7em; }
.swatches { display: flex; flex-wrap: wrap; gap: .6rem; }
.swatch { width: 2.5rem; height: 2.5rem; min-height: 0; padding: 0; border-radius: 50%; border: 2px solid var(--line); background: var(--sw); position: relative; }
.swatch[aria-checked="true"] { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--text); }
.swatch.shift { background: linear-gradient(135deg, var(--c-green) 0 34%, var(--c-orange) 34% 67%, var(--c-red) 67%); }

/* ---------- the timer ---------- */
.stage { text-align: center; padding: 1rem .5rem 1.1rem; }
.dial-wrap { width: min(100%, 560px, 64vh); aspect-ratio: 1; margin: 0 auto; }
#dial { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; cursor: pointer; --wedge: var(--c-green); }
#dial.locked { cursor: default; }
.face { fill: var(--face); }
.rim { fill: none; stroke: var(--line); stroke-width: 2; }
.well { fill: var(--well); }
.wedge { fill: var(--wedge); stroke: none; }
.tick { stroke: var(--tick); stroke-width: 1.5; stroke-linecap: round; }
.tick.major { stroke: var(--tick-strong); stroke-width: 3; }
.label-n { fill: var(--label); font: 600 20px system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; text-anchor: middle; dominant-baseline: central; font-variant-numeric: tabular-nums; pointer-events: none; }
.hand-edge { stroke: var(--hand-edge); stroke-width: 8; stroke-linecap: round; }
.hand-line { stroke: var(--hand); stroke-width: 4; stroke-linecap: round; }
.knob { fill: var(--knob); stroke: var(--hand-edge); stroke-width: 3; }
.hub { fill: var(--knob); stroke: var(--hand-edge); stroke-width: 3; }
.grab { fill: transparent; cursor: grab; }
#dial.locked .grab { cursor: default; }
#dial.dragging, #dial.dragging .grab { cursor: grabbing; }
#hand { outline: none; }
#hand:focus-visible .knob { stroke: var(--accent); stroke-width: 5; }

.side { margin-top: .9rem; }
.time { font-size: clamp(2.6rem, 14vw, 4.2rem); font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.state { color: var(--muted); min-height: 1.5em; margin-top: .15rem; }
.over { color: var(--over); font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: .1rem; }
.controls { display: flex; justify-content: center; gap: .6rem; margin-top: .9rem; flex-wrap: wrap; }

/* ---------- time is up, and the time since ---------- */
/* The hand carries on past 12 and the space it sweeps is shaded in the "over" colour, which no countdown colour uses, so it cannot be mistaken for time still left. */
.is-done .time { color: var(--done); }
.is-done .rim { stroke: var(--done); stroke-width: 4; } /* 4 is as thick as the dial's own edge allows: any more is clipped */
.over-base { fill: var(--over); opacity: .3; }
.over-hatch { fill: url(#hatch); }
.hatch-bar { fill: var(--over); }
#dial.in-over .knob { fill: var(--over); }
#dial.in-over .hand-line { stroke: var(--over); }
#dial.ov-solid .over-hatch, #dial.ov-pulse .over-hatch, #dial.ov-blink .over-hatch { display: none; }
#dial.ov-stripes .over-base { opacity: .2; }
#dial.ov-solid .over-base { opacity: .5; }
#dial.ov-pulse .over-base, #dial.ov-blink .over-base { opacity: .6; }
.ripples { pointer-events: none; }
.ripple { fill: none; stroke: var(--done); stroke-width: 5; vector-effect: non-scaling-stroke; opacity: 0; transform-box: fill-box; transform-origin: center; }
.flash { position: fixed; inset: 0; background: var(--done); opacity: 0; pointer-events: none; z-index: 2147482000; }
/* Motion only for people who have not asked for less. Without it the shading is still there, just still. */
@media (prefers-reduced-motion: no-preference) {
  .is-done .rim { animation: rim-pulse 1.2s ease-in-out infinite; }
  #dial.ov-stripes .over-hatch { animation: soft-pulse 2.4s ease-in-out infinite; }
  #dial.ov-pulse .over-base { animation: base-pulse 1.8s ease-in-out infinite; }
  #dial.ov-blink .over-base { animation: blink 1s steps(1, end) infinite; }
  #dial.ripple-go .ripple { animation: ripple 2.4s ease-out 2 both; }
  #dial.ripple-go .ripple.r2 { animation-delay: .45s; }
  #dial.ripple-go .ripple.r3 { animation-delay: .9s; }
  .flash.go { animation: flash 1.5s ease-in-out 3; }
  @keyframes rim-pulse { 50% { opacity: .35; } }
  @keyframes soft-pulse { 50% { opacity: .3; } }
  @keyframes base-pulse { 50% { opacity: .18; } }
  @keyframes blink { 50% { opacity: .08; } }
  @keyframes ripple { 0% { transform: scale(.05); opacity: .9; } 100% { transform: scale(1); opacity: 0; } }
  @keyframes flash { 0%, 100% { opacity: 0; } 50% { opacity: .28; } }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } .flash, .ripples { display: none; } }

/* ---------- dim when nothing has been touched: only the timer keeps its normal look ---------- */
h1, section, .controls, .hint.center, #tbx-chrome { transition: opacity .8s ease, background-color .8s ease, border-color .8s ease; }
body.dim { background: color-mix(in srgb, var(--bg) 55%, #000); }
body.dim h1, body.dim section:not(.stage), body.dim .controls, body.dim .hint.center, body.dim #tbx-chrome { opacity: .16; }
body.dim .stage { background: transparent; border-color: transparent; }
body.dim.focus { cursor: none; }

/* ---------- full screen: nothing but the timer ---------- */
body.focus #tbx-chrome { display: none !important; }
body.focus h1, body.focus main > section:not(.stage), body.focus #dialHint { display: none; }
body.focus main { max-width: none; min-height: 100vh; min-height: 100dvh; padding: 8px; display: flex; flex-direction: column; justify-content: center; }
body.focus .stage { margin: 0; padding: .25rem; background: transparent; border-color: transparent; }
body.focus .dial-wrap { width: min(100%, calc(100vh - 13rem)); width: min(100%, calc(100dvh - 13rem)); }
body.focus .time { font-size: clamp(3rem, 16vw, 6rem); }
@media (min-aspect-ratio: 6/5) {
  body.focus .stage { display: flex; align-items: center; justify-content: center; gap: clamp(1rem, 4vw, 4rem); }
  body.focus .dial-wrap { flex: none; margin: 0; width: min(calc(100vh - 24px), 62vw); width: min(calc(100dvh - 24px), 62vw); }
  body.focus .side { margin: 0; flex: 0 1 30rem; }
  body.focus .time { font-size: clamp(3rem, 9vw, 7.5rem); }
}

@media (max-width: 600px) {
  section { padding: .9rem .65rem; border-radius: 12px; }
  .stage { padding: .75rem .25rem 1rem; }
}
@media (max-height: 560px) and (orientation: landscape) {
  .dial-wrap { width: min(100%, 300px, 70vh); }
}
