@font-face {
  font-family: "Familjen Grotesk";
  src: url("/fonts/familjen-grotesk-latin-wght-normal.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
}
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("/fonts/atkinson-hyperlegible-next-latin-wght-normal.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
}

:root {
  --paper: #f1f4f7;
  --grid: #e2e8ee;
  --surface: #ffffff;
  --ink: #16233a;
  --ink-soft: #4b5a72;
  --rule: #c5cfdb;
  --pen: #2447c8;
  --pen-ink: #ffffff;
  --marker: #ffe14d;
  --marker-ink: #16233a;
  --red: #c8312b;
  --green: #1f7a4d;
  --display: "Familjen Grotesk", "Segoe UI", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible Next", "Segoe UI", system-ui, sans-serif;
}
:root[data-theme="dark"] { color-scheme: dark; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0f1724; --grid: #172234; --surface: #16212f; --ink: #e8eef6; --ink-soft: #a5b3c7;
    --rule: #2c3a4e; --pen: #8fa8ff; --pen-ink: #0f1724; --marker: #7a6700; --marker-ink: #fff6c2;
    --red: #ff8a80; --green: #6fd3a0;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--body);
  font-size: 1.0625rem;
  line-height: 1.5;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  min-height: 100vh;
}
main {
  max-width: 34rem;
  margin: 0 auto;
  padding: 1.25rem 1rem calc(6.5rem + env(safe-area-inset-bottom));
  outline: none;
}

h1, h2, h3 { font-family: var(--display); line-height: 1.15; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 650; margin-top: 2rem; }
p { margin: 0.5rem 0 0; max-width: 62ch; }
.soft { color: var(--ink-soft); }
.small { font-size: 0.9375rem; }

:focus-visible { outline: 3px solid var(--pen); outline-offset: 2px; border-radius: 4px; }
/* Screen headings are focused by script after navigation so screen readers announce them; no ring needed. */
[tabindex="-1"]:focus { outline: none; }
.skip { position: absolute; left: -999px; top: 0; background: var(--ink); color: var(--paper); padding: 0.5rem 1rem; z-index: 10; }
.skip:focus { left: 0; }

/* ---------- the day ruler ---------- */
.countdown { display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; }
.countdown .num { font-family: var(--display); font-weight: 700; font-size: 4.5rem; line-height: 0.95; letter-spacing: -0.03em; }
.countdown .label { font-family: var(--display); font-size: 1.25rem; font-weight: 500; }
.ruler { display: block; width: 100%; height: auto; margin-top: 0.9rem; overflow: visible; }
.ruler .past { stroke: var(--ink); }
.ruler .future { stroke: var(--ink-soft); opacity: 0.55; }
.ruler .buffer { stroke: var(--ink-soft); opacity: 0.35; }
.ruler .today { stroke: var(--red); }
.ruler .pointer { fill: var(--red); }
.phases { display: flex; font-size: 0.875rem; color: var(--ink-soft); margin-top: 0.15rem; }
.phases span { white-space: nowrap; overflow: hidden; text-overflow: clip; padding-right: 0.25rem; }

/* ---------- ruled rows (no cards) ---------- */
.rows { list-style: none; margin: 0.5rem 0 0; padding: 0; border-top: 2px solid var(--ink); }
.rows > li {
  display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
  padding: 0.8rem 0; border-bottom: 1px solid var(--rule);
}
.rows .what { min-width: 0; }
.rows .subject { font-family: var(--display); font-weight: 650; font-size: 1.125rem; }
.rows .detail { display: block; color: var(--ink-soft); font-size: 0.9375rem; }

/* ---------- buttons and inputs ---------- */
.btn {
  font: inherit; font-family: var(--display); font-weight: 650; font-size: 1.0625rem;
  min-height: 2.75rem; padding: 0.5rem 1.15rem; border-radius: 999px; cursor: pointer;
  border: 2px solid var(--ink); background: transparent; color: var(--ink);
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; white-space: nowrap;
}
.btn.primary { background: var(--pen); border-color: var(--pen); color: var(--pen-ink); }
.btn.stop { background: var(--red); border-color: var(--red); color: #fff; }
.btn.small { min-height: 2.5rem; padding: 0.35rem 0.9rem; font-size: 0.9375rem; }
.btn[disabled] { opacity: 0.55; cursor: progress; }

label, legend { font-weight: 600; font-size: 0.9375rem; }
fieldset { border: 0; padding: 0; margin: 1.25rem 0 0; min-width: 0; }
legend { padding: 0; margin-bottom: 0.5rem; }
select, input[type="text"], input[type="password"], input[type="date"], input[type="time"], input[type="number"] {
  font: inherit; width: 100%; min-height: 2.75rem; padding: 0.4rem 0.7rem;
  border: 2px solid var(--ink); border-radius: 6px; background: var(--surface); color: var(--ink);
}
.field { margin-top: 1rem; }
.field label { display: block; margin-bottom: 0.3rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

.chips { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.chips input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chips label {
  display: inline-flex; align-items: center; min-height: 2.75rem; padding: 0.3rem 1rem; border-radius: 999px;
  border: 2px solid var(--ink); cursor: pointer; font-weight: 600; background: transparent;
}
.chips input:checked + label { background: var(--ink); color: var(--paper); }
.chips input:focus-visible + label { outline: 3px solid var(--pen); outline-offset: 2px; }

label.check { display: flex; align-items: center; gap: 0.6rem; min-height: 2.75rem; cursor: pointer; }
label.check input { width: 1.4rem; height: 1.4rem; accent-color: var(--pen); }

details { margin-top: 2rem; border-top: 2px solid var(--ink); padding-top: 0.75rem; }
summary { font-family: var(--display); font-weight: 650; font-size: 1.125rem; cursor: pointer; min-height: 2.5rem; display: flex; align-items: center; }

/* ---------- timer ---------- */
.clock { font-family: var(--display); font-weight: 700; font-size: 4rem; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1; margin-top: 0.75rem; }
.running-line { margin-top: 0.4rem; font-size: 1.125rem; }

/* ---------- progress ---------- */
.mark { padding: 0 0.15em; margin: 0 -0.15em; color: var(--ink); }
.mark.behind { background: linear-gradient(transparent 38%, var(--marker) 38%, var(--marker) 90%, transparent 90%); color: var(--marker-ink); }
.mark.weak { background: linear-gradient(transparent 38%, var(--marker) 38%, var(--marker) 90%, transparent 90%); color: var(--marker-ink); text-decoration: underline wavy var(--red) 2px; text-underline-offset: 4px; }
.bar { position: relative; height: 0.85rem; margin-top: 0.45rem; border: 2px solid var(--ink); border-radius: 3px; background: var(--surface); }
.bar > i { position: absolute; inset: 0 auto 0 0; background: var(--green); }
.bar.behind > i { background: var(--marker); }
.bar.weak > i { background: var(--red); }
.progress-row { display: block; width: 100%; }
.progress-row .top { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; }
.status { font-weight: 700; font-size: 0.9375rem; }
.status.weak { color: var(--red); }
.status.on_track { color: var(--green); }

.notice { margin-top: 1.25rem; padding: 0.75rem 0.9rem; border-left: 5px solid var(--pen); background: var(--surface); }
.notice.error { border-left-color: var(--red); }

.signed-out .tabs { display: none; }
.login { margin-top: 12vh; }
.form-error { color: var(--red); font-weight: 600; min-height: 1.5rem; margin: 0.75rem 0 0; }
.account { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.account p { margin: 0; }

.tabs {
  position: fixed; inset: auto 0 0 0; display: flex; justify-content: center;
  background: var(--surface); border-top: 2px solid var(--ink);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; max-width: 11rem; min-height: 3.5rem; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.1rem; text-decoration: none; color: var(--ink-soft); font-size: 0.875rem; font-weight: 600;
}
.tabs svg { width: 1.5rem; height: 1.5rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a[aria-current="page"] { color: var(--ink); box-shadow: inset 0 3px 0 var(--red); }

.toast {
  position: fixed; left: 50%; bottom: calc(4.75rem + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 2rem); background: var(--ink); color: var(--paper); padding: 0.7rem 1rem; border-radius: 8px;
  font-weight: 600; display: none;
}
.toast.show { display: block; }

@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }
@media (min-width: 40rem) { .countdown .num { font-size: 5.5rem; } }
