:root {
  /* Palette: D4D6CF light shade · 9FB4CF light accent · 285AA4 brand · 8A6B1E dark accent · 272618 dark shade.
     Surface/line/muted/warn values are tints of those five. */
  --light-shade: #D4D6CF;
  --light-accent: #9FB4CF;
  --brand: #285AA4;
  --dark-accent: #8A6B1E;
  --dark-shade: #272618;

  /* Light theme */
  --bg: var(--light-shade);
  --surface: #E1E2DD;
  --surface-2: #CACBC4;
  --line: #BABCB4;
  --text: var(--dark-shade);
  --muted: #525246;
  --accent: var(--brand);
  --start: var(--brand);
  --start-ink: #F1F2EE;
  --stop: var(--dark-accent);
  --stop-ink: #F1F2EE;
  --warn: #67531C;
  --ok: var(--brand);
  --err: #67531C;
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--dark-shade);
    --surface: #31311F;
    --surface-2: #3C3B2E;
    --line: #464639;
    --text: var(--light-shade);
    --muted: #A0A198;
    --accent: var(--light-accent);
    --start: var(--brand);
    --start-ink: var(--light-shade);
    --stop: var(--dark-accent);
    --stop-ink: var(--light-shade);
    --warn: #C2AB6E;
    --ok: var(--light-accent);
    --err: #C2AB6E;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}

.screen {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 24px);
}

button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; }

/* ---------- Login ---------- */
#login { display: grid; place-items: center; min-height: 100dvh; }
.login-card {
  width: 100%; max-width: 340px;
  display: flex; flex-direction: column; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px 22px;
}
.login-icon { align-self: center; border-radius: 18px; }
.login-card h1 { margin: 4px 0 8px; text-align: center; font-size: 22px; font-weight: 600; }
.login-card label { color: var(--muted); font-size: 14px; }

input[type=password], input[type=time], input[type=datetime-local], select {
  width: 100%; min-height: 48px; padding: 10px 12px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  font-size: 17px; /* >=16px avoids iOS zoom */
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Top bar ---------- */
.topbar { display: flex; align-items: center; gap: 6px; padding: 0 2px 8px; min-height: 44px; }
.topbar .live { margin-left: auto; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; margin-left: -10px;
  background: none; border: 0; border-radius: 12px; color: var(--muted);
}
.icon-btn:active { background: var(--surface); }
.icon-btn .slash { display: inline; }
.icon-btn.on { color: var(--accent); }
.icon-btn.on .slash { display: none; }
.icon-btn.on .bell { fill: currentColor; fill-opacity: .2; }
.title { font-weight: 600; letter-spacing: .02em; color: var(--muted); }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.on .dot { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.live.off .dot { background: var(--warn); }

/* ---------- Clock ---------- */
.clock { text-align: center; padding: 28px 0 18px; }
.elapsed {
  font-size: clamp(64px, 21vw, 150px);
  font-weight: 300; line-height: 1;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em;
  color: var(--muted);
}
.running .elapsed { color: var(--text); }

.linkish {
  background: none; border: 0; padding: 8px 10px; margin-top: 8px;
  color: var(--muted); font-size: 16px; text-decoration: underline dotted; text-underline-offset: 4px;
}
.started { margin-top: 12px; color: var(--muted); font-size: 16px; }
.target-row { margin: 12px auto 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; max-width: 400px; }
.target-row .chip { border-radius: 14px; white-space: pre-line; line-height: 1.3; }
.chip {
  min-height: 40px; padding: 8px 16px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
  font-variant-numeric: tabular-nums;
}
.chip.over { border-color: var(--warn); color: var(--warn); }
.chip.soon { border-color: var(--accent); color: var(--accent); }

.progress { margin: 16px auto 0; height: 6px; max-width: 320px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .3s linear; }
.progress.over > div { background: var(--warn); }

/* ---------- Toggle ---------- */
.toggle {
  display: block; width: 100%; min-height: 96px; margin: 8px 0 4px;
  border: 0; border-radius: 24px;
  font-size: 30px; font-weight: 600; letter-spacing: .02em;
  transition: transform .08s ease, filter .15s ease;
}
.toggle:active { transform: scale(.98); }
.toggle:disabled { filter: saturate(.4) brightness(.8); }
.toggle.start { background: var(--start); color: var(--start-ink); }
.toggle.stop { background: var(--stop); color: var(--stop-ink); }

.msg { min-height: 1.4em; margin: 6px 0 0; color: var(--err); font-size: 15px; text-align: center; }
.msg.ok { color: var(--ok); }
.muted { color: var(--muted); }

/* ---------- History ---------- */
.history h2 { font-size: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 20px 2px 8px; }
#historyList { list-style: none; margin: 0; padding: 0; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
#historyList:empty { display: none; }
#historyList li + li { border-top: 1px solid var(--line); }
.hrow {
  width: 100%; display: grid; grid-template-columns: 1fr auto auto; gap: 2px 12px; align-items: center;
  padding: 12px 14px; background: var(--surface); border: 0; text-align: left;
}
.hrow:active { background: var(--surface-2); }
.hrow .when { font-size: 16px; }
.hrow .day { font-size: 13px; color: var(--muted); }
.hrow .dur { grid-row: 1 / span 2; grid-column: 2; font-variant-numeric: tabular-nums; font-size: 17px; }
.hrow .edit-ico { grid-row: 1 / span 2; grid-column: 3; color: var(--muted); }

/* ---------- Footer tools ---------- */
.tools { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }
.tools .msg { flex-basis: 100%; text-align: left; }
.btn {
  min-height: 44px; padding: 10px 16px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
}
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--start-ink); font-weight: 600; }
.btn.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 45%, transparent); }
.hint { flex-basis: 100%; margin: 0; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; color: var(--muted); font-size: 15px; }
.hint .linkish { margin: 0; padding: 0 0 0 6px; font-size: 15px; }

/* ---------- Dialogs ---------- */
dialog {
  width: min(440px, calc(100vw - 24px)); padding: 0;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
}
dialog::backdrop { background: rgb(20 20 12 / .6); }
dialog form { display: flex; flex-direction: column; gap: 8px; padding: 20px; }
dialog h3 { margin: 0 0 6px; font-size: 18px; }
dialog label { color: var(--muted); font-size: 14px; }
dialog .msg { text-align: left; }
.dlg-actions { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.spacer { flex: 1; }

.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; }
.seg span { display: block; text-align: center; padding: 10px; border-radius: 9px; color: var(--muted); font-size: 16px; }
.seg input:checked + span { background: var(--surface-2); color: var(--text); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
.trow { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 6px; }
.trow label { display: flex; flex-direction: column; gap: 4px; }
#tClock { grid-template-columns: 1fr; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
