:root {
  --bg: #fff;
  --fg: #000;
  --g1: #333;
  --g2: #6b6b6b;
  --g3: #a3a3a3;
  --g4: #c8c8c8;
  --rule: #e5e5e5;
  --tint: #f5f5f5;
  --accent: #ff4f00;
  --sans: 'Geist', ui-sans-serif, system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
  --mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --gutter: 16px;
  --max: 960px;
  --vh: 100vh;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}
@supports (height: 100dvh) { :root { --vh: 100dvh; } }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  min-height: var(--vh);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
.muted { color: var(--g2); }
.small { font-size: 13px; }

.wrap {
  max-width: var(--max);
  margin: 0 auto;
  padding-left: calc(var(--gutter) + var(--sal));
  padding-right: calc(var(--gutter) + var(--sar));
}

.label {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--g2);
}

/* ---------- header / tabs ---------- */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--fg);
  padding-top: var(--sat);
}
.top-inner { display: flex; align-items: stretch; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: baseline; gap: 10px; padding: 12px 0 4px; }
.brand-name { font-weight: 600; font-size: 18px; letter-spacing: -0.01em; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); width: 100%; }
.tab {
  min-height: 44px;
  padding: 0 4px;
  border: 0;
  background: none;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--g2);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
}
.tab:hover { color: var(--fg); }
.tab[aria-selected='true'] { color: var(--fg); border-bottom-color: var(--fg); }
@media (min-width: 720px) {
  .top-inner { flex-wrap: nowrap; }
  .brand { padding: 0; align-items: center; }
  .tabs { width: auto; grid-template-columns: repeat(4, auto); }
  .tab { padding: 0 16px; min-height: 52px; }
}

main { padding-bottom: calc(48px + var(--sab)); }
.panel { padding-top: 24px; }

/* ---------- controls ---------- */
.btn {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--fg);
  background: var(--bg);
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:hover { background: var(--tint); }
.btn:active { background: var(--rule); }
.btn-primary { background: var(--fg); color: var(--bg); }
.btn-primary:hover { background: var(--g1); }
.btn-quiet { border-color: var(--rule); color: var(--g2); }
.btn-small { min-height: 44px; padding: 0 12px; font-size: 12px; }
.btn:focus-visible, .tab:focus-visible, .input:focus-visible, textarea:focus-visible, .seg button:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

.input {
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: 0;
  background: var(--bg);
  font-size: 16px; /* >= 16px: no iOS zoom */
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
}
.input:focus { border-color: var(--fg); outline: none; }

.seg { display: inline-grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--fg); }
.seg button {
  min-height: 44px;
  min-width: 64px;
  border: 0;
  border-left: 1px solid var(--fg);
  background: var(--bg);
  font-family: var(--mono);
  font-size: 13px;
  cursor: pointer;
  border-radius: 0;
  touch-action: manipulation;
}
.seg button:first-child { border-left: 0; }
.seg button[aria-checked='true'] { background: var(--fg); color: var(--bg); }

/* ---------- build ---------- */
.summary {
  display: grid;
  grid-template-columns: 1fr;
  border-top: 1px solid var(--fg);
}
.summary-main { padding: 16px 0; border-bottom: 1px solid var(--rule); }
.big { font-size: 56px; line-height: 1; letter-spacing: -0.04em; font-weight: 500; margin-top: 6px; }
.big-of { color: var(--g3); }
.summary-side { display: grid; grid-template-columns: auto 1fr; gap: 16px; padding: 16px 0; border-bottom: 1px solid var(--rule); align-items: end; }
.field { display: grid; gap: 6px; }
#wpm { width: 100%; max-width: 110px; }
.summary-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 10px 0; border-bottom: 1px solid var(--fg); min-height: 64px; }
.summary-row .mono { font-size: 16px; }
@media (min-width: 720px) {
  .summary { grid-template-columns: 1fr auto; }
  .summary-main, .summary-side { border-bottom: 1px solid var(--rule); }
  .summary-side { padding-left: 24px; border-left: 1px solid var(--rule); }
  .summary-row { grid-column: 1 / -1; }
  .big { font-size: 80px; }
}

.over, .summary-row.over .mono, .summary-row.over .label { color: var(--accent) !important; }

.sections { list-style: none; margin: 0; padding: 0; }
.sec {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  padding: 20px 0;
  border-bottom: 1px solid var(--rule);
}
.sec-head { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.sec-num { font-family: var(--mono); font-size: 12px; color: var(--g3); }
.sec-title { font-weight: 600; font-size: 17px; margin: 0; }
.sec-target { display: flex; align-items: center; gap: 8px; }
.sec-target .input { width: 84px; text-align: center; font-family: var(--mono); }
.sec-target .input.invalid { border-color: var(--accent); }
.sec textarea {
  grid-column: 1 / -1;
  width: 100%;
  min-height: 112px;
  padding: 10px 12px;
  border: 1px solid var(--rule);
  border-radius: 0;
  font-size: 16px;
  line-height: 1.55;
  resize: vertical;
  background: var(--bg);
  -webkit-appearance: none;
}
.sec textarea:focus { border-color: var(--fg); outline: none; }
.sec-meta { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 16px; }
.sec-meta .label b { font-weight: 500; color: var(--fg); }
.sec-meta .over b { color: var(--accent); }
.sec-bar { grid-column: 1 / -1; height: 2px; background: var(--rule); position: relative; overflow: hidden; }
.sec-bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--fg); }
.sec-bar.over i { background: var(--accent); }

.foot-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; padding: 24px 0; }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; margin: 16px 0; font-size: 14px; }
.table th, .table td { text-align: left; padding: 10px 8px 10px 0; border-bottom: 1px solid var(--rule); vertical-align: baseline; }
.table th { font-family: var(--mono); font-size: 11px; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; color: var(--g2); border-bottom-color: var(--fg); }
.table td.num, .table th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; padding-right: 0; padding-left: 8px; white-space: nowrap; }
.table tfoot td { border-top: 1px solid var(--fg); border-bottom: 0; font-weight: 600; }

/* ---------- rehearse ---------- */
.rehearse-start, .result, .runs { border-top: 1px solid var(--fg); padding: 16px 0; }
.rehearse-start p { max-width: 56ch; }
.start-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 8px 0 16px; }
.start-row .btn-primary { min-width: 160px; min-height: 52px; font-size: 15px; }
.check-inline { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.check-inline input { width: 20px; height: 20px; accent-color: #000; }
.keys { display: flex; flex-wrap: wrap; gap: 8px 24px; margin: 0; padding-top: 12px; border-top: 1px solid var(--rule); }
.keys div { display: flex; gap: 8px; align-items: baseline; }
.keys dt { font-size: 12px; }
.keys dd { margin: 0; font-size: 13px; color: var(--g2); }
@media (hover: none) and (pointer: coarse) { .keys { display: none; } }
.result { margin-top: 8px; }
.runs-list { list-style: none; margin: 8px 0 0; padding: 0; }
.run { border-bottom: 1px solid var(--rule); }
.run summary {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  min-height: 48px;
  cursor: pointer;
  list-style: none;
}
.run summary::-webkit-details-marker { display: none; }
.run summary .when { font-size: 14px; }
.run summary .mono { font-size: 15px; }
.run .table { margin-top: 0; }
.empty { color: var(--g3); font-size: 14px; padding: 12px 0; }

/* ---------- checklist ---------- */
.checklist-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; border-top: 1px solid var(--fg); padding: 16px 0; border-bottom: 1px solid var(--fg); }
.checklist { list-style: none; margin: 0; padding: 0; }
.ci { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; gap: 4px; border-bottom: 1px solid var(--rule); min-height: 56px; }
.ci-box { display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; cursor: pointer; }
.ci-box input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.ci-box span { width: 22px; height: 22px; border: 1px solid var(--fg); display: block; position: relative; }
.ci-box input:checked + span { background: var(--fg); }
.ci-box input:checked + span::after {
  content: ''; position: absolute; left: 7px; top: 3px; width: 5px; height: 10px;
  border: solid var(--bg); border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.ci-box input:focus-visible + span { outline: 2px solid var(--fg); outline-offset: 2px; }
.ci-text { border: 1px solid transparent; padding: 8px; min-height: 44px; font-size: 16px; width: 100%; background: transparent; border-radius: 0; }
.ci-text:focus { border-color: var(--fg); outline: none; }
.ci.done .ci-text { color: var(--g3); text-decoration: line-through; }
.ci-del { width: 44px; height: 44px; border: 0; background: none; font-size: 22px; line-height: 1; color: var(--g2); cursor: pointer; }
.ci-del:hover { color: var(--fg); }
.add-item { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 16px 0; }

/* ---------- export ---------- */
.export-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--fg); padding: 12px 0; }
.export-actions { display: flex; align-items: center; gap: 12px; }
.md {
  margin: 0;
  padding: 16px;
  border: 1px solid var(--rule);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 60vh;
  overflow: auto;
  -webkit-user-select: text;
  user-select: text;
}

/* ---------- teleprompter overlay ---------- */
.prompter {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  height: 100vh;
  height: var(--vh);
  display: flex;
  flex-direction: column;
  padding: var(--sat) var(--sar) var(--sab) var(--sal);
  overscroll-behavior: contain;
}
.prompter:fullscreen { width: 100%; height: 100%; }
.pr-top {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: 'total stop' 'sec sec';
  gap: 4px 12px;
  padding: 12px var(--gutter) 10px;
  border-bottom: 1px solid var(--fg);
}
.pr-clock { grid-area: total; }
.pr-sec { grid-area: sec; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.pr-stop { grid-area: stop; align-self: start; }
.pr-total { font-size: 64px; line-height: 1; font-weight: 500; letter-spacing: -0.04em; }
.pr-sec-time { font-size: 28px; line-height: 1.1; font-weight: 500; }
.pr-total.over, .pr-sec-time.over { color: var(--accent); }
.pr-progress { height: 3px; background: var(--rule); }
.pr-bar { height: 100%; width: 0; background: var(--fg); }
.pr-bar.over { background: var(--accent); }
.pr-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px var(--gutter) 40vh;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.pr-section { padding: 16px 0 20px; border-bottom: 1px solid var(--rule); color: var(--g4); transition: color 0.2s; }
.pr-section .label { color: inherit; display: flex; justify-content: space-between; gap: 12px; }
.pr-section p { margin: 8px 0 0; font-size: 26px; line-height: 1.4; font-weight: 500; white-space: pre-wrap; word-break: break-word; }
.pr-section.current { color: var(--fg); }
.pr-section.current .label { color: var(--g2); }
.pr-section.done { color: var(--g4); }
.pr-section .placeholder { font-style: normal; color: var(--g3); }
.pr-bottom {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px var(--gutter);
  border-top: 1px solid var(--fg);
}
.pr-bottom .btn { min-width: 96px; min-height: 52px; }
.pr-hint { text-align: center; }
@media (hover: none) and (pointer: coarse) { .pr-hint { visibility: hidden; } }
.pr-countin {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg); font-size: 160px; font-weight: 500; letter-spacing: -0.04em;
}
@media (min-width: 720px) {
  .pr-top { grid-template-columns: 1fr 1fr auto; grid-template-areas: 'total sec stop'; align-items: end; padding: 20px 32px 16px; }
  .pr-sec { flex-direction: column; align-items: flex-start; gap: 6px; }
  .pr-total { font-size: 96px; }
  .pr-sec-time { font-size: 48px; }
  .pr-body { padding: 24px 32px 40vh; }
  .pr-body > * { max-width: 900px; margin-left: auto; margin-right: auto; }
  .pr-section p { font-size: 40px; line-height: 1.35; }
  .pr-bottom { padding: 12px 32px; }
}

body.prompting { overflow: hidden; }
