/* Fifty Hours app. Same tokens as the landing page (public/style.css):
   navy for night, yellow for day, Overpass / Public Sans / Overpass Mono. */
:root {
  --paper: #f3f4f7;
  --surface: #ffffff;
  --ink: #141a2b;
  --muted: #525b6f;
  --rule: #d5d9e2;
  --soft: #e7eaf1;
  --sign: #1d2e55;
  --on-sign: #ffffff;
  --link: #2446a0;
  --day: #f3c22f;
  --on-day: #141a2b;
  --night: #1d2e55;
  --on-night: #ffffff;
  --danger: #a3261b;
  --display: "Overpass", "Arial Narrow", system-ui, sans-serif;
  --body: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Overpass Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --radius: 14px;
  --tabs-h: 64px;
  color-scheme: light dark;
  accent-color: var(--sign);
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0e111a; --surface: #151a26; --ink: #e6e9f0; --muted: #9ca3b5; --rule: #283044; --soft: #161c2a;
    --sign: #26407e; --link: #f0c53a; --day: #e5b522; --night: #4a63a8; --danger: #ff8a7a;
    accent-color: var(--day);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100dvh; font-size-adjust: from-font; -webkit-tap-highlight-color: transparent; background: var(--paper); color: var(--ink);
  font: 400 1.0625rem/1.55 var(--body);
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom, 0px) + 16px);
}
a { color: var(--link); text-underline-offset: 0.18em; }
:focus-visible { outline: 3px solid var(--day); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3 { font-family: var(--display); margin: 0; text-wrap: balance; }
h2 { font-size: 1.5rem; font-weight: 800; line-height: 1.15; }
.h-sm { font-size: 1.05rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
p { margin: 0; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.fine { color: var(--muted); font-size: 0.9rem; }
.warn { color: var(--ink); background: color-mix(in srgb, var(--day) 25%, transparent); padding: 8px 10px; border-radius: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.wrap {
  max-width: 640px; margin-inline: auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
main.wrap { display: grid; gap: 16px; padding-top: 16px; }

.top { position: sticky; top: 0; z-index: 5; background: var(--paper); padding-top: env(safe-area-inset-top, 0px); border-bottom: 1px solid var(--rule); }
.top .wrap { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; }
.logo { display: flex; align-items: center; gap: 10px; font: 800 1.1rem/1 var(--display); color: var(--ink); text-decoration: none; }
.who { color: var(--muted); font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 6; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--rule);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tabs a {
  display: grid; place-items: center; min-height: var(--tabs-h); color: var(--muted); text-decoration: none;
  font: 800 0.9rem/1 var(--display); letter-spacing: 0.04em; text-transform: uppercase;
}
.tabs a { position: relative; }
.tabs a[aria-current="page"] { color: var(--ink); }
.tabs .ink { position: absolute; inset: 0 22% auto; height: 3px; border-radius: 0 0 3px 3px; background: var(--day); }

.banner {
  display: flex; align-items: center; gap: 10px; justify-content: center; padding: 10px 16px;
  background: var(--sign); color: var(--on-sign); text-decoration: none; font-weight: 600;
}
.banner-go { margin-left: 8px; background: var(--day); color: var(--on-day); border-radius: 6px; padding: 2px 10px; font: 800 0.85rem/1.6 var(--display); text-transform: uppercase; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #e5484d; display: inline-block; }
@media (prefers-reduced-motion: no-preference) { .dot { animation: pulse 1.6s ease-in-out 3; } }
@keyframes pulse { 50% { opacity: 0.35; } }

.card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 20px; display: grid; gap: 12px; }
.card.flush { padding: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 22px;
  border-radius: 10px; border: 2px solid var(--sign); background: var(--sign); color: var(--on-sign);
  font: 800 1rem/1 var(--display); letter-spacing: 0.01em; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn-day { background: var(--day); border-color: var(--day); color: var(--on-day); }
.btn-quiet { background: transparent; color: var(--ink); border-color: var(--ink); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); margin-left: auto; }
.btn-sm { min-height: 40px; padding: 0 16px; font-size: 0.95rem; }
.btn-big { min-height: 72px; font-size: 1.5rem; width: 100%; border-radius: 16px; text-transform: uppercase; letter-spacing: 0.04em; }
.btn-stop { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.file { position: relative; }

.timer { text-align: center; justify-items: center; padding: 24px 20px; }
.timer.is-on { background: var(--sign); color: var(--on-sign); border-color: var(--sign); }
.timer.is-on .muted, .timer.is-on .fine { color: color-mix(in srgb, var(--on-sign) 78%, transparent); }
.timer.is-on .btn-stop { background: var(--day); border-color: var(--day); color: var(--on-day); }
.eyebrow { display: flex; align-items: center; gap: 8px; font: 800 0.85rem/1 var(--display); text-transform: uppercase; letter-spacing: 0.1em; }
.clock { font-size: clamp(3rem, 15vw, 4.5rem); font-weight: 600; line-height: 1; letter-spacing: -0.02em; }

.progress-head { display: flex; align-items: baseline; justify-content: space-between; }
.progress-head h2 { font-size: 2.25rem; font-weight: 900; }
.progress-head h2 span { font-size: 1rem; font-weight: 600; color: var(--muted); }
.hours { display: grid; grid-template-columns: repeat(var(--cols, 10), minmax(0, 1fr)); gap: 4px; }
.hours i { aspect-ratio: 1; border-radius: 3px; }
.hours .d { background: var(--day); }
.hours .n { background: var(--night); }
.hours .o { box-shadow: inset 0 0 0 1.5px var(--rule); }
.tally { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); font-size: 0.95rem; }
.tally span { display: inline-flex; align-items: center; gap: 6px; }
.key { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.key.d { background: var(--day); } .key.n { background: var(--night); }
.done { font-weight: 600; }

.drives { list-style: none; margin: 0; padding: 0; }
.drives li + li { border-top: 1px solid var(--rule); }
.drives a { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 12px 0; color: inherit; text-decoration: none; }
.card.flush .drives a { padding: 12px 20px; }
.d-date { font-weight: 600; }
.d-time { color: var(--muted); font-size: 0.9rem; grid-column: 1; white-space: nowrap; }
.d-split { grid-column: 2; grid-row: 1 / span 2; display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; align-self: center; }
.pill { font: 600 0.85rem/1 var(--mono); padding: 5px 8px 4px; border-radius: 6px; background: var(--soft); white-space: nowrap; }
.pill.nite { background: var(--night); color: var(--on-night); }
.pill.day { background: var(--day); color: var(--on-day); }
.log-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.empty-state p { color: var(--muted); }

.form label { display: grid; gap: 6px; font-weight: 600; }
.form label.check, .check { display: flex; align-items: center; gap: 10px; font-weight: 400; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--paper); border: 1.5px solid var(--rule); border-radius: 10px;
  padding: 12px; min-height: 48px; width: 100%;
}
input[type="checkbox"], input[type="radio"] { width: 22px; height: 22px; min-height: 0; }
fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 10px; }
legend { font: 800 1.5rem/1.15 var(--display); margin-bottom: 8px; }
.preview { display: flex; gap: 6px; flex-wrap: wrap; min-height: 26px; }

.setup { padding-top: max(32px, env(safe-area-inset-top, 0px)); }
.setup-brand { display: flex; align-items: center; gap: 12px; font: 900 1.6rem/1 var(--display); }
.setup h1 { font-size: clamp(2rem, 8vw, 2.75rem); font-weight: 900; line-height: 1.05; letter-spacing: -0.02em; }
.lead { color: var(--muted); font-size: 1.15rem; }


/* The printable sheet: shown on screen as a preview, and the only thing printed. */
.sheet {
  background: #fff; color: #111; border: 1px solid var(--rule); border-radius: var(--radius); padding: 20px;
  overflow-x: auto; display: grid; gap: 12px; font-size: 0.85rem;
}
.sheet a { color: #1d2e55; }
.sheet h1 { font-size: 1.5rem; font-weight: 900; }
.sheet h2 { font-size: 1.1rem; }
.sheet-kicker { font: 800 0.72rem/1.3 var(--display); text-transform: uppercase; letter-spacing: 0.08em; color: #444; }
.sheet-sub { color: #333; }
.sheet-meta { display: flex; flex-wrap: wrap; gap: 4px 24px; margin: 8px 0 0; }
.sheet-meta dt { font: 700 0.7rem/1.2 var(--display); text-transform: uppercase; letter-spacing: 0.06em; color: #555; }
.sheet-meta dd { margin: 0; font-weight: 600; }
.sheet-table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.sheet-table th, .sheet-table td { border: 1px solid #999; padding: 5px 6px; text-align: left; vertical-align: top; }
.sheet-table thead th { background: #eef0f5; font: 700 0.7rem/1.2 var(--display); text-transform: uppercase; letter-spacing: 0.04em; }
.sheet-table tfoot th, .sheet-table tfoot td { font-weight: 700; background: #f6f7fa; }
.sheet-table .n { text-align: right; font-family: var(--mono); }
.sheet-table .sig { min-width: 60px; }
.sheet-table .empty { text-align: center; color: #666; padding: 16px; }
.sheet-note { color: #333; }
.sign { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; margin-top: 28px; }
.sign div { border-top: 1px solid #111; padding-top: 4px; font-size: 0.75rem; color: #444; }

@media print {
  @page { size: letter; margin: 0.5in; }
  body { background: #fff; padding: 0; }
  .top, .tabs, .banner, .no-print, #toast { display: none !important; }
  main.wrap { max-width: none; padding: 0; display: block; }
  .sheet { border: 0; padding: 0; border-radius: 0; overflow: visible; font-size: 9.5pt; }
  .sheet-table thead { display: table-header-group; }
  .sheet-table tfoot { display: table-row-group; } /* grand totals once, at the end */
  .sheet-table tr { break-inside: avoid; }
  .sheet a { color: #111; }
  .sheet a::after { content: " (" attr(href) ")"; font-size: 0.85em; word-break: break-all; }
}

/* The export page gets the width of a letter page on bigger screens. */
main.wrap:has(.sheet) { max-width: 880px; }
.sheet-table td:first-child, .sheet-table .mono { white-space: nowrap; }


/* ---------- Motion and feel ----------
   Screens slide in the direction you're going, the timer card morphs between
   ready and driving, earned hour squares pop in, and every control answers a
   press. All movement is opt-in under prefers-reduced-motion: no-preference. */

/* Press feedback: colour changes for everyone, scale only with motion allowed. */
.btn { transition: filter 150ms ease-out, background-color 150ms ease-out, box-shadow 150ms ease-out, scale 150ms ease-out; }
.btn:active { filter: brightness(0.92); }
.tabs a, .drives a { transition: background-color 120ms ease-out; }
.tabs a:active, .drives a:active { background: var(--soft); }
@media (hover: hover) { .drives a:hover { background: var(--soft); } }
@media (prefers-reduced-motion: no-preference) {
  .btn:active { scale: 0.97; }
  .btn-big:active { scale: 0.95; }
}

/* Hour squares: newly earned ones pop in, one after another. */
@media (prefers-reduced-motion: no-preference) {
  .hours i.pop {
    animation: pop 450ms ease-out both;
    animation: pop 450ms linear(0, 0.45 15%, 1.12 35%, 0.96 55%, 1.02 75%, 1) both;
    animation-delay: calc(min(var(--i), 40) * 22ms);
  }
}
@keyframes pop { from { scale: 0; } }

/* The driving card: a lane stripe rolls by for a few seconds when a drive starts. */
.timer { position: relative; overflow: hidden; }
.lane {
  position: absolute; inset: auto 0 0; height: 4px;
  background: repeating-linear-gradient(90deg, var(--day) 0 28px, transparent 28px 52px);
}
@media (prefers-reduced-motion: no-preference) {
  .lane { animation: lane 0.9s linear 5; }
}
@keyframes lane { to { translate: -52px 0; } }
.lane { inset-inline-end: -52px; }

/* View transitions between screens (progressive enhancement). */
.top { view-transition-name: top; }
.tabs { view-transition-name: tabs; }
.tabs .ink { view-transition-name: tab-ink; }
.banner { view-transition-name: banner; }
::view-transition-group(root) { animation-duration: 240ms; animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1); }
::view-transition-group(tab-ink) { animation-duration: 320ms; animation-timing-function: cubic-bezier(0.3, 1.3, 0.5, 1); }
@media (prefers-reduced-motion: no-preference) {
  html:active-view-transition-type(forward)::view-transition-old(root) { animation: 160ms ease-in both vt-out-left; }
  html:active-view-transition-type(forward)::view-transition-new(root) { animation: 240ms cubic-bezier(0.2, 0.8, 0.2, 1) both vt-in-right; }
  html:active-view-transition-type(backward)::view-transition-old(root) { animation: 160ms ease-in both vt-out-right; }
  html:active-view-transition-type(backward)::view-transition-new(root) { animation: 240ms cubic-bezier(0.2, 0.8, 0.2, 1) both vt-in-left; }
}
@keyframes vt-out-left { to { opacity: 0; translate: -28px 0; } }
@keyframes vt-in-right { from { opacity: 0; translate: 28px 0; } }
@keyframes vt-out-right { to { opacity: 0; translate: 28px 0; } }
@keyframes vt-in-left { from { opacity: 0; translate: -28px 0; } }

/* Start and Stop: the timer card morphs, and the cards below glide to their new place. */
html:active-view-transition-type(morph) .timer { view-transition-name: timer; }
html:active-view-transition-type(morph) .progress { view-transition-name: progress; }
html:active-view-transition-type(morph) .recent { view-transition-name: recent; }
::view-transition-group(timer), ::view-transition-group(progress), ::view-transition-group(recent) {
  animation-duration: 380ms; animation-timing-function: cubic-bezier(0.2, 0.9, 0.25, 1.05);
}
::view-transition-old(timer), ::view-transition-new(timer) { height: 100%; object-fit: cover; }

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}

/* Confirm dialog (native modal) with an entry and exit transition. */
dialog {
  width: min(400px, calc(100vw - 32px)); padding: 22px; border: 0; border-radius: 18px;
  background: var(--surface); color: var(--ink);
  box-shadow: 0 24px 60px -20px rgb(0 0 0 / 0.45);
  opacity: 0;
  transition-property: opacity, scale, display, overlay;
  transition-duration: 200ms;
  transition-timing-function: ease-out;
  transition-behavior: allow-discrete;
  @media (prefers-reduced-motion: no-preference) { scale: 0.94; }
  @media (prefers-reduced-motion: reduce) { transition-duration: 100ms; }
}
dialog[open] {
  opacity: 1;
  @starting-style { opacity: 0; }
  @media (prefers-reduced-motion: no-preference) {
    scale: 1;
    @starting-style { scale: 0.94; }
  }
}
dialog:modal { overscroll-behavior: contain; }
dialog::backdrop {
  overflow: hidden; overscroll-behavior: contain;
  background-color: rgb(14 17 26 / 0);
  transition-property: background-color, display, overlay;
  transition-duration: 200ms;
  transition-behavior: allow-discrete;
}
dialog[open]::backdrop {
  background-color: rgb(14 17 26 / 0.5);
  @starting-style { background-color: rgb(14 17 26 / 0); }
}
dialog h1 { font-size: 1.4rem; font-weight: 900; margin-bottom: 6px; }
dialog p { color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.btn-danger-fill { background: var(--danger); border-color: var(--danger); color: #fff; }
@media (prefers-color-scheme: dark) { .btn-danger-fill { color: #1a0d0b; } }

/* Toast: a manual popover, so it also shows above an open dialog. */
#toast {
  position: fixed; inset: auto 0 calc(var(--tabs-h) + env(safe-area-inset-bottom, 0px) + 12px);
  margin: 0 auto; width: fit-content; max-width: calc(100vw - 32px);
  border: 0; background: var(--ink); color: var(--paper); padding: 12px 18px; border-radius: 12px; font-weight: 600;
  box-shadow: 0 12px 30px -12px rgb(0 0 0 / 0.5);
  opacity: 0;
  transition-property: opacity, translate, display, overlay;
  transition-duration: 220ms;
  transition-timing-function: ease-out;
  transition-behavior: allow-discrete;
  @media (prefers-reduced-motion: no-preference) { translate: 0 16px; }
}
#toast:is(:popover-open, .show) {
  opacity: 1;
  @starting-style { opacity: 0; }
  @media (prefers-reduced-motion: no-preference) {
    translate: 0 0;
    @starting-style { translate: 0 16px; }
  }
}
/* Without popover support the toast is a plain fixed element. */
@supports not selector(:popover-open) { #toast:not(.show) { display: none; } }
@media print { dialog, #toast { display: none !important; } }

/* Button labels: trim the font's built-in leading so the capitals sit exactly
   centred (Overpass otherwise rides ~2px high). Progressive enhancement. */
.btn > .label { text-box: trim-both cap alphabetic; }

/* Setup and settings fields with their own label and hint. */
.form .field { display: grid; gap: 6px; }
.form .field > label { font-weight: 600; }
#state-hint:empty { display: none; }
input[aria-invalid="true"], input:user-invalid { border-color: var(--danger); }
#state[aria-invalid="true"] + datalist + #state-hint { color: var(--danger); }

/* Export preview on a phone: the sheet stays screen-width and only the wide
   log table scrolls sideways inside it. */
.sheet { grid-template-columns: minmax(0, 1fr); overflow-x: visible; }
.sheet-scroll { overflow-x: auto; }
.sheet-head h1 { overflow-wrap: anywhere; }
@media print { .sheet-scroll { overflow: visible; } }

/* Carried-over hours: a labelled line on the log and the sheets. */
.sheet-table tr.carry td { background: #fff8dd; font-style: italic; }
.proof { break-before: page; display: grid; gap: 10px; }
.proof img { max-width: 100%; max-height: 8.5in; object-fit: contain; border: 1px solid #999; }
.carry-list .pill.src { background: var(--day); color: var(--on-day); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form fieldset.sources { gap: 6px; }
.form fieldset.sources legend { font: 600 1.0625rem/1.55 var(--body); margin-bottom: 2px; }
.proof-thumb { max-width: 160px; max-height: 160px; border-radius: 8px; border: 1px solid var(--rule); }
.switching { display: grid; gap: 8px; }
