/* Time Everything. One screen, a gym-clock scoreboard: plan readout on top, a 4x5 grid of numbers
   that fills the middle, and a fixed transport bar (work, rest, rounds, repeat, start) under the
   thumb. Dark by choice. Landscape phones put the grid and the transport side by side. */

@font-face { font-family: "Big Shoulders Display"; font-weight: 700; font-display: swap; src: url(fonts/big-shoulders-display-700.woff2) format("woff2"); }
@font-face { font-family: "Big Shoulders Display"; font-weight: 900; font-display: swap; src: url(fonts/big-shoulders-display-900.woff2) format("woff2"); }
@font-face { font-family: "Barlow Semi Condensed"; font-weight: 500; font-display: swap; src: url(fonts/barlow-semi-condensed-500.woff2) format("woff2"); }
@font-face { font-family: "Barlow Semi Condensed"; font-weight: 700; font-display: swap; src: url(fonts/barlow-semi-condensed-700.woff2) format("woff2"); }

:root {
  --rubber: #121211;      /* gym floor black, the ground */
  --slab: #1c1c1a;        /* number tiles */
  --seam: #2e2d29;        /* hairlines between tiles */
  --chalk: #f3f0e7;       /* digits and the armed state */
  --dust: #8d8a80;        /* secondary labels */
  --work: #ff5a26;        /* effort, the LED clock red */
  --rest: #3f8cff;        /* recovery */
  --ready: #ffb81c;       /* lead-in */
  --ink: #121211;         /* text on coloured fields */
  --f-num: "Big Shoulders Display", "Arial Narrow", "Roboto Condensed", Impact, sans-serif;
  --f-ui: "Barlow Semi Condensed", "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  height: 100dvh;
  background: var(--rubber); color: var(--chalk); font-family: var(--f-ui);
  -webkit-tap-highlight-color: transparent; overscroll-behavior: none; touch-action: manipulation;
  user-select: none; -webkit-user-select: none; -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--ready); outline-offset: -3px; }
[hidden] { display: none !important; }

/* Read by search engines and screen readers, kept off the scoreboard */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
.about a:focus { position: fixed; z-index: 30; left: 16px; top: 16px; width: auto; height: auto; padding: 12px 16px;
  margin: 0; clip: auto; clip-path: none; background: var(--chalk); color: var(--ink); font: 700 1rem/1 var(--f-ui); }
.noscript { position: fixed; inset: auto 16px 16px; z-index: 40; padding: 16px; background: var(--chalk); color: var(--ink);
  font: 500 1rem/1.4 var(--f-ui); }

.app {
  height: 100%; max-width: 560px; margin: 0 auto; display: flex; flex-direction: column;
  padding: calc(var(--safe-t) + 10px) calc(var(--safe-r) + 16px) calc(var(--safe-b) + 12px) calc(var(--safe-l) + 16px);
  gap: 10px;
}

/* Plan readout */
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.plan { min-width: 0; }
.brand { font: 700 0.72rem/1 var(--f-ui); letter-spacing: 0.22em; text-transform: uppercase; color: var(--dust); margin: 0; }
.readout { font: 900 clamp(2rem, 9.5vw, 3rem)/0.95 var(--f-num); letter-spacing: 0.01em; margin-top: 6px;
  font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.readout.long { font-size: clamp(1.7rem, 8vw, 3rem); }
.readout .x { color: var(--dust); font-weight: 700; }
.readout .r { color: var(--rest); }
.total { font: 500 0.85rem/1.2 var(--f-ui); color: var(--dust); margin-top: 4px; letter-spacing: 0.04em; }
.total b { color: var(--chalk); font-weight: 700; }

.tools { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; flex: none; }
.units { display: flex; border: 1px solid var(--seam); }
.units button { font: 700 0.8rem/1 var(--f-ui); letter-spacing: 0.16em; padding: 12px 12px; color: var(--dust); min-width: 52px; }
.units button[aria-pressed="true"] { background: var(--chalk); color: var(--ink); }
.units.off { visibility: hidden; }
.mute { width: 44px; height: 28px; margin-right: -10px; color: var(--dust); display: grid; place-items: center; }
.mute svg { width: 20px; height: 20px; }
.mute .wave { display: inline; }
.mute .cross { display: none; }
.mute[aria-pressed="true"] { color: var(--chalk); }
.mute[aria-pressed="true"] .wave { display: none; }
.mute[aria-pressed="true"] .cross { display: inline; }

/* Number grid */
.grid {
  flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(5, 1fr);
  gap: 1px; background: var(--seam); border: 1px solid var(--seam);
}
.cell {
  background: var(--slab); position: relative; display: grid; place-items: center; min-width: 0; min-height: 0; overflow: hidden;
  font: 900 min(15vw, 9.2vh, 5rem)/1 var(--f-num); font-variant-numeric: tabular-nums;
  transition: background-color 120ms ease, color 120ms ease;
}
.cell.w3 { font-size: min(11.5vw, 7.4vh, 3.9rem); }
.cell:active { background: #26251f; }
.cell[aria-pressed="true"] { background: var(--chalk); color: var(--ink); }
.cell .u { position: absolute; left: 8px; bottom: 6px; font: 700 0.62rem/1 var(--f-ui); letter-spacing: 0.18em; text-transform: uppercase; opacity: 0.75; }
.grid[data-field="rest"] .cell[aria-pressed="true"] { background: var(--rest); color: var(--ink); }
.cell .go { position: absolute; right: 8px; top: 7px; font: 700 0.62rem/1 var(--f-ui); letter-spacing: 0.16em; }

/* The line under the grid: a hint, or once a timer has run, the recent timers. Fixed height
   either way, so the grid never changes size. Recent chips borrow the gaps either side. */
.hint { font: 500 0.8rem/1.3 var(--f-ui); color: var(--dust); text-align: center; letter-spacing: 0.03em; height: 1.05rem;
  display: flex; align-items: center; justify-content: center; gap: 8px; }
.hint b { color: var(--chalk); font-weight: 700; }
.recent {
  height: 34px; margin-block: -8px; padding-inline: 12px; border: 1px solid var(--seam); min-width: 0;
  font: 700 1.05rem/1 var(--f-num); letter-spacing: 0.02em; color: var(--chalk); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.recent .x { color: var(--dust); }
.recent .r { color: var(--rest); }
.recent:active { background: var(--slab); }
.hint .lbl { font: 700 0.62rem/1 var(--f-ui); letter-spacing: 0.18em; text-transform: uppercase; }

/* Transport */
.fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--seam); border: 1px solid var(--seam); }
.field { background: var(--rubber); padding: 9px 10px 8px; text-align: left; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field .k { font: 700 0.68rem/1 var(--f-ui); letter-spacing: 0.2em; text-transform: uppercase; color: var(--dust); }
.field .v { font: 900 1.7rem/1 var(--f-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.field[aria-pressed="true"] { background: var(--chalk); color: var(--ink); }
.field[aria-pressed="true"] .k { color: var(--ink); }
.field.off .v { color: var(--dust); }
.field[aria-pressed="true"].off .v { color: #6b685f; }

.go-row { display: grid; grid-template-columns: 64px 1fr; gap: 10px; }
.repeat { border: 1px solid var(--seam); display: grid; place-items: center; color: var(--dust); position: relative; }
.repeat svg { width: 26px; height: 26px; }
.repeat[aria-pressed="true"] { color: var(--work); border-color: var(--work); }
.repeat[aria-pressed="true"]::after { content: ""; position: absolute; bottom: 9px; width: 5px; height: 5px; border-radius: 50%; background: var(--work); }
.start {
  background: var(--work); color: var(--ink); height: 64px; display: flex; align-items: center; justify-content: space-between;
  padding-inline: 20px; font: 900 1.9rem/1 var(--f-num); letter-spacing: 0.06em; text-transform: uppercase;
}
.start span:last-child { font-variant-numeric: tabular-nums; letter-spacing: 0.01em; }
.start:active { filter: brightness(0.9); }
.start:focus-visible { outline-color: var(--chalk); }

/* Running screen */
.run {
  position: fixed; inset: 0; z-index: 10; background: var(--work); color: var(--ink); display: flex; flex-direction: column;
  padding: calc(var(--safe-t) + 14px) calc(var(--safe-r) + 16px) calc(var(--safe-b) + 14px) calc(var(--safe-l) + 16px);
  transition: background-color 250ms ease;
}
.run[data-phase="rest"] { background: var(--rest); }
.run[data-phase="ready"] { background: var(--ready); }
.run[data-phase="done"] { background: var(--chalk); }
.run button:focus-visible { outline-color: var(--ink); outline-offset: 3px; }
.run-in { max-width: 560px; width: 100%; margin: 0 auto; flex: 1; display: flex; flex-direction: column; min-height: 0; }
.run-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.phase { font: 900 clamp(2.4rem, 13vw, 4rem)/0.9 var(--f-num); letter-spacing: 0.04em; text-transform: uppercase; margin: 0; }
.round { font: 700 1rem/1 var(--f-ui); letter-spacing: 0.16em; text-transform: uppercase; text-align: right; }
.round b { font: 900 1.9rem/1 var(--f-num); letter-spacing: 0.02em; display: block; margin-top: 4px; font-variant-numeric: tabular-nums; }
.clock { flex: 1; min-height: 0; width: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 6px; }
.clock > span { display: block; }
.time {
  font: 900 min(40vw, 34vh, 15rem)/0.82 var(--f-num); font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
  transition: opacity 150ms ease;
}
.run.paused .time { opacity: 0.35; }
.state { font: 700 1rem/1 var(--f-ui); letter-spacing: 0.24em; text-transform: uppercase; min-height: 1rem; }
.next { font: 500 1.05rem/1.3 var(--f-ui); letter-spacing: 0.04em; opacity: 0.8; min-height: 1.4rem; text-align: center; }
.bar { height: 10px; background: rgba(18, 18, 17, 0.18); margin-block: 14px 14px; flex: none; }
.bar i { display: block; height: 100%; background: var(--ink); transform-origin: left; transform: scaleX(0); }
.ctrls { display: grid; grid-template-columns: 1fr 1.6fr 1fr; gap: 10px; flex: none; }
.ctrls button { height: 64px; border: 2px solid var(--ink); font: 700 0.95rem/1 var(--f-ui); letter-spacing: 0.16em; text-transform: uppercase; }
.ctrls .main { background: var(--ink); color: var(--chalk); font: 900 1.7rem/1 var(--f-num); letter-spacing: 0.08em; }
.ctrls .armed { background: var(--ink); color: var(--chalk); }
.ctrls .gone { visibility: hidden; }

@media (min-height: 760px) { .field .v { font-size: 2rem; } }

/* Landscape phone: grid on the left, readout and transport on the right */
@media (orientation: landscape) and (max-height: 540px) {
  .app {
    max-width: 960px; display: grid; gap: 8px 16px;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
    grid-template-rows: auto 1fr auto auto;
    grid-template-areas: "grid top" "grid hint" "grid fields" "grid go";
  }
  .top { grid-area: top; }
  .grid { grid-area: grid; container-type: size; }
  .hint { grid-area: hint; align-self: center; height: auto; min-height: 1.05rem; flex-wrap: wrap; }
  .recent { margin-block: 0; }
  .fields { grid-area: fields; }
  .go-row { grid-area: go; }
  .cell { font-size: min(13cqw, 12.5cqh, 5rem); }
  .cell.w3 { font-size: min(10cqw, 10cqh, 3.9rem); }
  .readout { font-size: clamp(1.7rem, 5vw, 2.6rem); }
  .readout.long { font-size: clamp(1.5rem, 3.6vw, 2.2rem); }
  .start { height: 56px; }

  .run-in { max-width: 960px; }
  .time { font-size: min(30vw, 40vh, 15rem); }
  .phase { font-size: clamp(2rem, 9vh, 3rem); }
  .bar { margin-block: 8px; }
  .ctrls button { height: 52px; }
}

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