:root {
  --bg: #fdfcf9; --fg: #1d1d1b; --muted: #6b6a66; --line: #e6e3dc;
  --accent: #b4532a; --accent-soft: #f6e6dd; --tomato: #d9341f;
  /* The page colours itself by what's going on: the plain theme while nothing has
     started, yellow while paused, green for focus, a pale blue for a short break and
     a fuller blue for the long one. Each has a light and a dark version; the theme
     setting (system, light, dark) picks which, via data-theme on <html>. */
  --bg-paused: #fbe9b8; --bg-focus: #dcefd9; --bg-short: #e8f1fb; --bg-long: #d2e3f7;
  --font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161614; --fg: #ece9e2; --muted: #9b988f; --line: #2d2c28; --accent: #e8905f; --accent-soft: #3a261c; color-scheme: dark;
    --bg-paused: #3d3010; --bg-focus: #1b2e1c; --bg-short: #1b2431; --bg-long: #172a44;
  }
}
:root[data-theme="dark"] {
  --bg: #161614; --fg: #ece9e2; --muted: #9b988f; --line: #2d2c28; --accent: #e8905f; --accent-soft: #3a261c; color-scheme: dark;
  --bg-paused: #3d3010; --bg-focus: #1b2e1c; --bg-short: #1b2431; --bg-long: #172a44;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--fg);
  font: 16px/1.5 var(--font-ui);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  transition: background-color 600ms ease;
}
body[data-state="paused"] { background: var(--bg-paused); }
body[data-state="focus"] { background: var(--bg-focus); }
body[data-state="short"] { background: var(--bg-short); }
body[data-state="long"] { background: var(--bg-long); }
button { font: inherit; color: inherit; }
a { color: var(--accent); }

.app {
  max-width: 34rem; margin: 0 auto; padding: 32px 16px 48px;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
}

.top { text-align: center; }
h1 { margin: 0; font-size: 1.6rem; letter-spacing: 0.02em; }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 0.95rem; }

.phases { display: flex; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 999px; }
.phases button {
  border: 0; background: transparent; border-radius: 999px; padding: 6px 14px; cursor: pointer;
  font-size: 0.9rem; color: var(--muted);
}
.phases button:hover { color: var(--fg); }
.phases button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.phases button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.stage { position: relative; width: min(360px, 82vw); aspect-ratio: 1; }
#tomato { width: 100%; height: 100%; display: block; cursor: grab; position: relative; z-index: 1; }
#tomato.dragging { cursor: grabbing; }
.floor {
  position: absolute; left: 14%; right: 14%; bottom: 4%; height: 10%;
  border-radius: 50%; background: radial-gradient(ellipse at center, rgba(0,0,0,0.22), rgba(0,0,0,0) 70%);
}
@media (prefers-color-scheme: dark) { .floor { background: radial-gradient(ellipse at center, rgba(0,0,0,0.6), rgba(0,0,0,0) 70%); } }
.nogl { color: var(--muted); text-align: center; padding-top: 40%; }
.reorient {
  position: absolute; top: 6px; right: 6px; z-index: 2;
  width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  opacity: 0.7; transition: opacity 200ms;
}
.reorient:hover { opacity: 1; background: var(--accent-soft); color: var(--accent); }
.reorient:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; opacity: 1; }
.reorient svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.reorient[hidden] { display: none; }

.readout { text-align: center; }
.time { font: 600 3.6rem/1 var(--font-mono); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.app.running .time { color: var(--accent); }
/* The tally: the set as a list, one row per block or break, with when it started
   and finished, and a note under the ones that have happened. */
.tally { width: 100%; max-width: 22rem; margin: 16px auto 0; padding: 0; list-style: none; text-align: left; font-size: 0.85rem; color: var(--muted); }
.tally li { display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 10px; padding: 3px 0; border-top: 1px solid var(--line); }
.tally li:first-child { border-top: 0; }
.tally li.todo { opacity: 0.55; }
.tally .dot { width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--dot, var(--accent)); }
.tally li.done .dot, .tally li.now .dot { background: var(--dot, var(--accent)); }
.tally li.now .dot { animation: breathe 2.4s ease-in-out infinite; }
.tally li.focus { --dot: #3ca050; } .tally li.short { --dot: #7fb0ec; } .tally li.long { --dot: #3c78dc; }
/* The label is an input: click it and type a note in its place. */
.tally .name { min-width: 0; border: 0; border-bottom: 1px dashed transparent; border-radius: 0; background: transparent; font: inherit; color: inherit; padding: 2px 0; outline: 0; text-overflow: ellipsis; }
.tally .name:hover { border-bottom-color: var(--line); }
.tally .name:focus { border-bottom-color: var(--accent); color: var(--fg); text-decoration: none; }
.tally .name.noted { color: var(--fg); }
.tally li.done .name { text-decoration: line-through; }
.tally li.now .name { color: var(--fg); font-weight: 600; }
.tally .when { font-family: var(--font-mono); font-size: 0.75rem; font-variant-numeric: tabular-nums; }
@keyframes breathe { 50% { transform: scale(1.35); } }
.nudge { margin: 10px 0 0; font-size: 0.9rem; color: var(--accent); font-weight: 600; min-height: 1.4em; }
body:not([data-state="idle"]) .nudge { visibility: hidden; }

.controls { display: flex; gap: 10px; align-items: center; }
.controls button {
  border: 1px solid var(--line); background: transparent; border-radius: 12px;
  padding: 10px 18px; cursor: pointer; font-size: 0.95rem;
}
.controls button:hover { background: var(--accent-soft); }
.controls button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.controls .primary { background: var(--accent); color: #fff; border-color: transparent; padding: 12px 30px; font-weight: 600; min-width: 128px; }
.controls .primary:hover { filter: brightness(1.08); background: var(--accent); }
body[data-state="idle"] .controls .primary { animation: nudge 1.8s ease-in-out infinite; }
@keyframes nudge { 50% { transform: scale(1.05); box-shadow: 0 0 0 6px var(--accent-soft); } }
.controls .quiet { display: none; background: var(--fg); color: var(--bg); border-color: transparent; animation: shake 500ms ease-in-out infinite; }
.app.ringing .controls .quiet { display: inline-block; }
@keyframes shake { 25% { transform: rotate(-3deg); } 75% { transform: rotate(3deg); } }
.legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px; margin: 0; padding: 0; list-style: none; font-size: 0.8rem; color: var(--muted); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 3px; border: 1px solid rgba(127,127,127,0.35); }
.legend .idle { background: var(--bg); } .legend .paused { background: var(--bg-paused); } .legend .focus { background: var(--bg-focus); }
.legend .short { background: var(--bg-short); } .legend .long { background: var(--bg-long); }
.controls .pip { padding: 10px; display: inline-flex; }
.controls .pip svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; }
.controls .pip.on { background: var(--accent-soft); color: var(--accent); }

.settings { width: 100%; max-width: 24rem; border: 1px solid var(--line); border-radius: 12px; padding: 8px 14px; font-size: 0.9rem; }
.settings summary { cursor: pointer; color: var(--muted); }
.settings .grid { display: grid; gap: 10px; padding: 12px 0 6px; }
.settings label { display: flex; align-items: center; gap: 8px; }
.settings label span { flex: 1; }
.settings input[type="number"], .settings select { font: inherit; padding: 4px 6px; border: 1px solid var(--line); border-radius: 8px; background: transparent; color: inherit; }
.settings input[type="number"] { width: 4.2em; }
.settings .check { gap: 10px; }
.settings .vol { display: flex; align-items: center; gap: 8px; }
.settings .vol label { flex: 1; }
.settings .vol input[type="range"] { width: 7.5em; accent-color: var(--accent); margin: 0; }
.settings .sample { width: 28px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: transparent; cursor: pointer; font-size: 11px; color: var(--accent); }
.settings .sample:hover { background: var(--accent-soft); }
.settings .clear-set { justify-self: start; border: 1px solid var(--line); background: transparent; border-radius: 8px; padding: 5px 10px; cursor: pointer; }
.settings .clear-set:hover { background: var(--accent-soft); }

.about { color: var(--muted); font-size: 0.85rem; text-align: center; max-width: 28rem; }
.about p { margin: 6px 0; }

@media (prefers-reduced-motion: reduce) { .tally li.now, .controls .quiet, body[data-state="idle"] .controls .primary { animation: none; } body { transition: none; } }
