:root {
  --bg: #ffffff; --bg2: #f5f5f5; --bg3: #e5e5ea; --text: #1d1d1f; --text2: #6e6e73;
  --border: rgba(60, 60, 67, .18); --danger: #d70015; --go: #248a3d; --go-bg: rgba(52, 199, 89, .18); --stop-bg: rgba(255, 59, 48, .16);
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --control: 48px; --r-card: 28px; --r-group: 20px; --r-pill: 999px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #000; --bg2: #1c1c1e; --bg3: #2c2c2e; --text: #f5f5f7; --text2: #98989d; --border: rgba(84, 84, 88, .6); --danger: #ff453a; --go: #30d158; --go-bg: rgba(48, 209, 88, .2); --stop-bg: rgba(255, 69, 58, .2); }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); -webkit-font-smoothing: antialiased; }
main { max-width: 560px; margin: 0 auto; padding: var(--s5) var(--s4) calc(var(--control) + var(--s7) + env(safe-area-inset-bottom)); }
header { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); min-height: var(--control); margin: 0 0 var(--s4); }
header .tools { display: flex; align-items: center; gap: var(--s2); }
button.tool { min-width: 0; width: 44px; height: 44px; padding: 0; border-radius: 50%; display: grid; place-items: center; background: var(--bg2); color: var(--text); }
button.tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
h1 { font-family: var(--display); font-size: 34px; line-height: 41px; letter-spacing: -.022em; margin: 0; }
h2 { font-size: 13px; line-height: 18px; font-weight: 400; text-transform: uppercase; color: var(--text2); margin: var(--s5) var(--s4) var(--s2); }
section[hidden], [hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.big { font-family: var(--display); font-size: clamp(40px, 14vw, 64px); white-space: nowrap; line-height: 1; font-weight: 300; letter-spacing: -.02em; text-align: center; margin: var(--s5) 0; }
.sub { color: var(--text2); font-size: 15px; line-height: 20px; text-align: center; margin: var(--s2) 0; }
svg.face { display: block; width: min(320px, 80vw); height: auto; margin: 0 auto; }
.face .rim { fill: var(--bg2); }
.face .tick { stroke: var(--text2); stroke-linecap: round; }
.face .hand { stroke: var(--text); stroke-linecap: round; }
.face .sec { stroke: var(--accent); stroke-linecap: round; }
.face .hub { fill: var(--accent); }
.face text { fill: var(--text); font: 300 14px var(--font); text-anchor: middle; dominant-baseline: central; }
.group { background: var(--bg2); border-radius: var(--r-group); margin: var(--s2) 0 var(--s4); overflow: hidden; }
.row { display: flex; align-items: center; gap: var(--s3); min-height: var(--s7); padding: var(--s3) var(--s4); }
.row + .row { border-top: .5px solid var(--border); }
button.rowbtn { display: block; height: auto; min-width: 0; padding: 0; border-radius: 12px; background: none; color: inherit; text-align: start; font-size: inherit; }
.row .grow { flex: 1; min-width: 0; }
.row .label { font-size: 17px; line-height: 22px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .meta { font-size: 13px; line-height: 18px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .time { font-size: 28px; font-weight: 300; white-space: nowrap; }
.row .time.xl { font-size: 48px; font-weight: 200; line-height: 1.05; }
.row.off .time, .row.off .meta { color: var(--text2); }
.row.best .label, .row.best .num { color: var(--go); }
.row.worst .label, .row.worst .num { color: var(--danger); }
.controls { display: flex; gap: var(--s3); justify-content: space-between; margin: var(--s4) 0; }
.controls.center { justify-content: center; flex-wrap: wrap; }
button, input, select { font: inherit; font-size: 17px; height: var(--control); border-radius: var(--r-pill); border: 0; }
button { padding: 0 var(--s5); background: var(--bg2); color: var(--text); cursor: pointer; min-width: 120px; }
button.primary { background: var(--accent); color: #fff; }
button.go { background: var(--go-bg); color: var(--go); }
button.stop { background: var(--stop-bg); color: var(--danger); }
button.danger { color: var(--danger); }
/* iOS round controls: a tinted circle with a thin ring of the same tint around a gap */
#stopwatch .controls button, #tmStart { width: 84px; height: 84px; min-width: 0; padding: 0; border-radius: 50%; box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--bg2); }
#stopwatch .controls .go, #tmStart { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--go-bg); }
#stopwatch .controls .stop { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--stop-bg); }
#langPick, #timer .row input:not(.switch), #timer .row select { flex: 0 1 55%; height: auto; padding: 0; background: none; color: var(--text2); text-align: right; text-align-last: right; }
button.link { background: none; color: var(--accent); min-width: 0; padding: 0 var(--s2); }
button.icon { min-width: 0; padding: 0 var(--s4); height: 32px; font-size: 15px; }
button:disabled { opacity: .4; cursor: default; }
input, select { padding: 0 var(--s4); background: var(--bg2); color: var(--text); min-width: 0; width: 100%; }
button:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.form { display: flex; gap: var(--s2); flex-wrap: wrap; margin-bottom: var(--s2); }
.form > * { flex: 1 1 120px; }
/* iOS switch */
input.switch { appearance: none; -webkit-appearance: none; flex: none; width: 51px; height: 31px; padding: 0; border-radius: 31px; background: var(--bg3); position: relative; cursor: pointer; transition: background .2s; }
input.switch::before { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.25); transition: transform .2s; }
input.switch:checked { background: #34c759; }
input.switch:checked::before { transform: translateX(20px); }
[dir=rtl] input.switch:checked::before { transform: translateX(-20px); }
[dir=rtl] input.switch::before { left: auto; right: 2px; }
/* day chips */
.days { display: flex; gap: var(--s1); justify-content: space-between; margin: var(--s2) 0 var(--s4); }
.days button { min-width: 0; flex: 1; height: 40px; padding: 0; font-size: 15px; }
.days button[aria-pressed="true"] { background: var(--accent); color: #fff; }
/* sheets */
dialog { border: 0; padding: var(--s5) var(--s4) calc(var(--s5) + env(safe-area-inset-bottom)); width: 100%; max-width: 560px; margin: auto auto 0; border-radius: var(--r-card) var(--r-card) 0 0; background: var(--bg); color: var(--text); }
@media (min-width: 600px) { dialog { margin: auto; border-radius: var(--r-card); } }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog header { margin-bottom: var(--s4); }
#world header { flex-wrap: wrap-reverse; row-gap: var(--s2); }   /* narrow: buttons sit above the title, like iOS */
#world header > .tools { margin-inline-start: auto; }
dialog header > span { width: 60px; }
dialog .row a { color: var(--accent); text-decoration: none; }
dialog h1 { font-size: 17px; line-height: 22px; font-weight: 600; }
dialog label { display: block; font-size: 13px; color: var(--text2); margin: var(--s3) var(--s4) var(--s1); }
dialog .row label { margin: 0; font-size: 17px; color: var(--text); }
input[type="time"].wheel { font-size: 48px; font-weight: 200; height: 72px; text-align: center; background: var(--bg2); }
/* full screen views */
.full { position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s4); padding: var(--s5); background: var(--bg); text-align: center; }
.full .when { font-size: min(24vw, 120px); font-weight: 200; line-height: 1; }
.full .what { font-size: 22px; line-height: 28px; color: var(--text2); }
.full .controls { width: min(100%, 360px); flex-direction: column; }
.full .controls button { width: 100%; }
#stand { background: #000; color: #fff; cursor: pointer; user-select: none; }
#stand .when { font-size: min(30vw, 50vh); font-weight: 200; }
#stand .what { color: #98989d; font-size: 17px; white-space: nowrap; }
#stand.night { color: #ff3b30; }
#standFace { display: flex; flex-direction: column; align-items: center; gap: var(--s4); transition: transform 2s, opacity .2s; }
.standsvg { width: min(70vw, 60vh); height: auto; }
.standsvg line, .standsvg .arc { stroke: currentColor; stroke-linecap: round; fill: none; }
.standsvg .tick { stroke: currentColor; opacity: .6; }
.standsvg circle { fill: currentColor; }
.standsvg .arc { stroke-width: 2; stroke-dasharray: 2 6; opacity: .5; } .standsvg .horizon { stroke-width: 1; opacity: .35; }
#standDot.moon { fill: #000; stroke: currentColor; stroke-width: 3; }
#stand[data-face="analog"] .when { display: none; }
#stand[data-face="sun"] .when { font-size: min(14vw, 18vh); }
.standbar { position: absolute; bottom: calc(var(--s5) + env(safe-area-inset-bottom)); display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: var(--s4); opacity: .4; transition: opacity .2s; }
.standbar:hover, .standbar:focus-within { opacity: 1; }
.standbar .seg { display: flex; gap: 2px; padding: 2px; border-radius: var(--r-pill); background: #1c1c1e; }
.standbar .seg button { min-width: 0; height: 36px; padding: 0 var(--s4); font-size: 15px; background: none; color: #98989d; }
.standbar .seg button[aria-checked="true"] { background: #3a3a3c; color: #fff; }
.standbar input { width: 140px; height: 36px; accent-color: #98989d; background: none; }
#stand.night .what { color: #8a1f1a; }
/* timers */
.ring { flex: none; width: 56px; height: 56px; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 5; }
.ring .track { stroke: var(--bg3); }
.ring .bar { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset .3s linear; }
.stack { display: flex; flex-direction: column; gap: var(--s1); }
.stack button { height: 32px; min-width: 80px; font-size: 13px; padding: 0 var(--s3); }
.group button.icon:not(.go) { background: var(--bg3); }
#world .form { margin-top: var(--s5); }
h2.sleep-h { display: flex; align-items: center; gap: var(--s2); }
h2.sleep-h .bed { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
button.pill { min-width: 0; height: 32px; padding: 0 var(--s4); font-size: 15px; font-weight: 600; background: var(--bg3); color: var(--accent); flex: none; }
select.inline { width: auto; height: 32px; font-size: 15px; background: var(--bg3); }
kbd { font: 600 13px var(--font); min-width: 28px; height: 28px; padding: 0 var(--s2); display: inline-grid; place-items: center; border-radius: 8px; background: var(--bg3); color: var(--text); }
.keys .row { gap: var(--s1); }
.keys .label { white-space: normal; }
small.ap { font-size: .5em; font-weight: 400; margin-inline-start: .12em; letter-spacing: 0; }
.big small.ap { font-size: .42em; }
small.ap:first-child { margin-inline: 0 .12em; }
button.zone { display: flex; align-items: center; gap: var(--s3); }
button.zone .grow { display: block; min-width: 0; }
button.zone .meta, button.zone .label { display: block; }
svg.mini { display: none; }
/* Day faces are white and night faces black in both themes, like macOS Clock */
.mini .rim { fill: #fff; stroke: rgba(0, 0, 0, .08); } .mini .tick { stroke: #6e6e73; stroke-linecap: round; } .mini .hand { stroke: #1d1d1f; stroke-linecap: round; } .mini .hub { fill: var(--accent); }
.mini.night .rim { fill: #000; stroke: rgba(255, 255, 255, .14); } .mini.night .hand { stroke: #f5f5f7; } .mini.night .tick { stroke: #98989d; }
/* Wide windows: a grid of faces, like macOS Clock. Edit mode keeps the list. */
@media (min-width: 900px) {
  main:has(#world:not([hidden])) { max-width: 960px; }
  #zones:has(button.zone) { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: var(--s4); background: none; }
  #zones:has(button.zone) .row { padding: 0; border: 0; }
  #zones button.zone { flex-direction: column; gap: var(--s2); width: 100%; padding: var(--s4); background: var(--bg2); border-radius: var(--r-group); text-align: center; }
  #zones button.zone .grow { display: flex; flex-direction: column-reverse; }
  #zones button.zone .dn, #zones button.zone .time { display: none; }
  #zones svg.mini { display: block; width: 128px; height: 128px; }
}
.dn { flex: none; width: 20px; height: 20px; fill: none; stroke: var(--text2); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.scrub { margin: var(--s2) 0 var(--s4); padding: 0 var(--s4); }
.scrub-head { display: flex; align-items: center; gap: var(--s2); min-height: var(--s6); }
.scrub-head label { flex: 1; font-size: 13px; color: var(--text2); text-transform: uppercase; }
.scrub-head span { font-size: 15px; }
.scrub-head button.link { height: var(--s6); font-size: 15px; }
input[type="range"] { height: var(--s6); padding: 0; background: none; accent-color: var(--accent); }
.pick { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr) auto); gap: var(--s2); align-items: center; }
.pick select { text-align: center; font-size: 22px; height: 56px; }
.pick span { color: var(--text2); font-size: 15px; }
.toast { position: fixed; left: 50%; top: calc(var(--s4) + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 20; background: var(--text); color: var(--bg); padding: var(--s3) var(--s5); border-radius: var(--r-pill); font-size: 15px; white-space: nowrap; }
nav {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--s4) + env(safe-area-inset-bottom));
  display: flex; gap: 2px; padding: var(--s1); border-radius: var(--r-pill); width: min(calc(100% - 2 * var(--s4)), 528px);
  background: color-mix(in srgb, var(--bg2) 80%, transparent); backdrop-filter: blur(30px) saturate(190%);
  -webkit-backdrop-filter: blur(30px) saturate(190%); border: .5px solid var(--border);
}
nav button { flex: 1 1 0; min-width: 0; height: 52px; padding: 0 2px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; background: transparent; color: var(--text2); font-size: clamp(10px, 3vw, 11px); font-weight: 500; letter-spacing: -.02em; }
nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
nav span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
nav button[aria-current="page"] { background: var(--bg); color: var(--accent); }
.empty { color: var(--text2); text-align: center; padding: var(--s5); }
/* demo mode on the landing: no tab bar, no pointer, the app just plays */
.demo nav, .demo .toast { display: none !important; }
.demo main { padding-bottom: var(--s5); }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
