@font-face {
  font-family: "Jost";
  src: url("fonts/jost.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --bg: #efece4;
  --panel: #f8f6f0;
  --ink: #1d1c1a;
  --muted: #6b675f;
  --line: rgb(29 28 26 / 0.16);
  --work: #b3261a;
  --short: #e2b714;
  --long: #1b4a9c;
  /* What sits on top of each colour. Yellow needs dark ink to stay legible. */
  --on-work: #fbf7ef;
  --on-short: #1d1c1a;
  --on-long: #fbf7ef;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141311;
    --panel: #1f1d1a;
    --ink: #ece8df;
    --muted: #958f84;
    --line: rgb(236 232 223 / 0.18);
    --work: #d2402f;
    --short: #ebc334;
    --long: #3b6fd0;
  }
}

:root[data-phase="work"] { --phase: var(--work); --on-phase: var(--on-work); }
:root[data-phase="short"] { --phase: var(--short); --on-phase: var(--on-short); }
:root[data-phase="long"] { --phase: var(--long); --on-phase: var(--on-long); }

*, *::before, *::after { box-sizing: border-box; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Jost", Futura, "Century Gothic", system-ui, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

p, h2, h3, ul, ol { margin: 0; padding: 0; }
ul, ol { list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-underline-offset: 0.18em; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.noscript { position: fixed; inset: auto 0 1rem; text-align: center; color: var(--muted); }

/* ---------- top bar ---------- */

/* Rows are named outright so that hiding the bar or the strip in a small
   window leaves the face in the middle row rather than sliding it up. */
.bar { grid-row: 1; }
main { grid-row: 2; }
footer { grid-row: 3; }

.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px max(12px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
}

.hint {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.95rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.hint::before {
  content: "";
  display: inline-block;
  width: 0.5em;
  height: 0.5em;
  margin-right: 0.55em;
  border-radius: 50%;
  background: var(--phase);
  vertical-align: 0.08em;
}

.tools {
  display: flex;
  gap: 2px;
  margin-left: auto;
}

.tool {
  position: relative;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

.tool:hover { color: var(--ink); background: var(--line); }

.tool svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#sound[aria-pressed="true"] { color: var(--ink); }
#sound[aria-pressed="true"] .slash { display: none; }

.dot {
  position: absolute;
  top: 8px;
  right: 7px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--work);
  box-shadow: 0 0 0 2px var(--bg);
}

/* ---------- the face ---------- */

main {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: clamp(8px, 2.5dvh, 28px);
  min-height: 0;
  padding: 0 16px;
}

.face svg {
  display: block;
  width: min(78vw, 54dvh, 540px);
  height: auto;
  overflow: visible;
}

#shape {
  fill: var(--phase);
  transition: fill 0.8s ease;
}

#number, #unit {
  fill: var(--on-phase);
  text-anchor: middle;
  transition: fill 0.8s ease;
  font-variant-numeric: tabular-nums;
}

#number {
  font-size: 118px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

#unit {
  font-size: 17px;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  opacity: 0.82;
}

.caption {
  text-align: center;
}

.caption .now {
  font-size: clamp(1.2rem, 1rem + 1.2vw, 1.6rem);
  line-height: 1.25;
}

.caption .now b { font-weight: 600; }

.caption .next {
  margin-top: 0.15em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 0.18em;
  cursor: pointer;
}

.link::before {
  content: "·";
  display: inline-block;
  margin: 0 0.45em;
  color: var(--muted);
  text-decoration: none;
}

/* ---------- the three hours ---------- */

footer {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 44px max(30px, env(safe-area-inset-right)) calc(46px + env(safe-area-inset-bottom)) max(30px, env(safe-area-inset-left));
  font-size: 0.82rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.strip {
  display: flex;
  gap: 3px;
}

/* --done runs 0 to 1 across a segment: spent time fades, what is left stays solid. */
.seg {
  position: relative;
  flex: var(--min) 1 0;
  height: 10px;
  border-radius: 2px;
  background: linear-gradient(
    to right,
    color-mix(in srgb, var(--c) 30%, transparent) calc(var(--done, 0) * 100%),
    var(--c) 0
  );
}

.seg--work { --c: var(--work); }
.seg--short { --c: var(--short); }
.seg--long { --c: var(--long); }

.needle {
  position: absolute;
  left: calc(var(--done, 0) * 100%);
  top: -7px;
  bottom: -7px;
  width: 2px;
  margin-left: -1px;
  border-radius: 1px;
  background: var(--ink);
}

.needle time {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.95rem;
  font-weight: 500;
  white-space: nowrap;
}

.tick {
  position: absolute;
  top: calc(100% + 11px);
  left: 0;
  transform: translateX(-50%);
  color: var(--muted);
  white-space: nowrap;
}

.tick--end {
  left: auto;
  right: 0;
  transform: translateX(50%);
}

/* A small window is still a clock: drop the extras before shrinking the face. */
@media (max-height: 430px) {
  footer { display: none; }
  main { padding-bottom: 12px; }
}

@media (max-height: 300px) {
  .bar { display: none; }
  .caption .next { display: none; }
  .face svg { width: min(78vw, 62dvh); }
}

/* ---------- panels ---------- */

dialog {
  width: min(31rem, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 28px 28px 24px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 24px 60px rgb(0 0 0 / 0.25);
  overflow: auto;
}

dialog::backdrop { background: rgb(0 0 0 / 0.38); }

dialog h2 {
  margin-right: 2rem;
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 1.2;
}

dialog h2 + p { margin-top: 0.5rem; }

dialog h3 {
  margin-top: 1.6rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--line);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}

.close:hover { color: var(--ink); background: var(--line); }

.legend {
  display: grid;
  gap: 0.5rem;
  margin-top: 1.1rem;
}

.legend li {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 0.75rem;
  align-items: center;
}

.legend svg { width: 22px; height: 22px; }
.legend b { font-weight: 600; }
.is-work { fill: var(--work); }
.is-short { fill: var(--short); }
.is-long { fill: var(--long); }

.rules {
  display: grid;
  gap: 0.4rem;
  margin-top: 1.1rem;
  padding-left: 1.1rem;
  list-style: disc;
}

.rules li::marker { color: var(--muted); }

.credit, .keys, .note {
  margin-top: 1.1rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.settings { margin-top: 0.4rem; }

.row {
  display: flex;
  flex-wrap: wrap; /* on a phone the control drops under its label */
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem 1rem;
  min-height: 46px;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--line);
}

.row input[type="checkbox"] {
  width: 1.2rem;
  height: 1.2rem;
  accent-color: var(--ink);
}

.row input[type="range"] {
  width: 9rem;
  accent-color: var(--ink);
}

.row select {
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  font-variant-numeric: tabular-nums;
}

kbd {
  display: inline-block;
  min-width: 1.5em;
  padding: 0 0.35em;
  border: 1px solid var(--line);
  border-radius: 4px;
  font: inherit;
  font-size: 0.85em;
  text-align: center;
}

.keys {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
}

.keys span { white-space: nowrap; }

/* Shortcuts are no use without a keyboard. */
@media (pointer: coarse) and (hover: none) {
  .keys { display: none; }
}

textarea {
  display: block;
  width: 100%;
  margin-top: 1rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  font-size: 1.05rem;
  line-height: 1.5;
  resize: vertical;
}

.actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.9rem;
}

.actions span {
  margin-right: auto;
  color: var(--muted);
  font-size: 0.95rem;
}

.btn {
  padding: 0.45rem 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: none;
  cursor: pointer;
}

.btn:hover { background: var(--line); }

.btn--main {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--bg);
}

.btn--main:hover { background: var(--ink); opacity: 0.88; }

@media (prefers-reduced-motion: reduce) {
  #shape, #number, #unit { transition: none; }
}
