/* Self-hosted fonts (SIL OFL; see fonts/LICENSE.txt): no requests to third parties */
@font-face {
  font-family: "Atkinson Hyperlegible";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/fonts/atkinson-400-latin-ext.woff2) format("woff2");
  unicode-range:
    U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
    U+A720-A7FF;
}
@font-face {
  font-family: "Atkinson Hyperlegible";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(/fonts/atkinson-400-latin.woff2) format("woff2");
  unicode-range:
    U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Atkinson Hyperlegible";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(/fonts/atkinson-700-latin-ext.woff2) format("woff2");
  unicode-range:
    U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F,
    U+A720-A7FF;
}
@font-face {
  font-family: "Atkinson Hyperlegible";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(/fonts/atkinson-700-latin.woff2) format("woff2");
  unicode-range:
    U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Bricolage Grotesque";
  font-style: normal;
  font-weight: 600 700;
  font-display: swap;
  src: url(/fonts/bricolage-latin.woff2) format("woff2");
  unicode-range:
    U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* Layout: single phone column, sticky tab bar; today's gauge first, log and history behind tabs */
:root {
  --bg: #f3f5f4;
  --surface: #ffffff;
  --fg: #1d2624;
  --muted: #5d6b67;
  --line: #dbe2df;
  --accent: #2f6f62;
  --accent-soft: #e1efea;
  --green: #2e8a57;
  --green-text: #26774a;
  --amber: #c78512;
  --amber-text: #855600;
  --shadow-ink: #1d2624;
  --red: #c2412f;
  --err: var(--red);
  --spent: #cfd8d4;
  --display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --body: "Atkinson Hyperlegible", system-ui, -apple-system, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141a19;
    --surface: #1d2523;
    --fg: #e6eeeb;
    --muted: #97a8a3;
    --line: #2f3a37;
    --accent: #6cc0ab;
    --accent-soft: #213531;
    --green: #58c487;
    --green-text: #58c487;
    --amber: #e8a93a;
    --amber-text: #e8a93a;
    --shadow-ink: #000;
    --red: #ef7461;
    --spent: #34403d;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141a19;
  --surface: #1d2523;
  --fg: #e6eeeb;
  --muted: #97a8a3;
  --line: #2f3a37;
  --accent: #6cc0ab;
  --accent-soft: #213531;
  --green: #58c487;
  --green-text: #58c487;
  --amber: #e8a93a;
  --amber-text: #e8a93a;
  --shadow-ink: #000;
  --red: #ef7461;
  --spent: #34403d;
  color-scheme: dark;
}
:root[data-theme="light"] {
  color-scheme: light;
}
* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
} /* section{display:grid} would otherwise outrank the browser's own [hidden] rule and show every tab at once */
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--body);
  font-size: var(--text-base);
  line-height: var(--leading-snug);
}
.wrap {
  max-width: 1120px;
  margin: 0 auto;
  padding-inline: var(--space-4);
  padding-block: max(var(--space-3), env(safe-area-inset-top, 0)) var(--space-12);
}
header {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
}
h1 {
  font-family: var(--display);
  font-size: var(--text-xl);
  margin: 0;
  text-wrap: balance;
}
h2 {
  font-family: var(--display);
  font-size: var(--text-md);
  margin: 0 0 var(--space-2-5);
}
.date {
  display: block;
  color: var(--muted);
  font-size: var(--text-sm);
}
nav {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 5;
  background: var(--bg);
  display: flex;
  gap: var(--space-1-5);
  padding-block: var(--space-2-5);
  margin-top: var(--space-1-5);
  overflow-x: auto;
  scrollbar-width: none;
}
nav button {
  flex: 1 0 auto;
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 700;
  padding: var(--space-2-5) var(--space-3);
  white-space: nowrap;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
}
nav button[aria-selected="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}
section {
  display: grid;
  gap: var(--space-4-5);
}
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  display: grid;
  gap: var(--space-3);
  align-content: start;
}
.label {
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}
.checkin {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
}
.checkin button {
  font: inherit;
  padding: var(--space-3) var(--space-1);
  border-radius: var(--radius-md);
  border: 2px solid var(--line);
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  display: grid;
  gap: var(--space-1-5);
  justify-items: center;
  align-content: start;
  text-align: center;
}
.checkin button b {
  font-size: var(--text-base);
  display: inline-flex;
  align-items: center;
  gap: var(--space-1-5);
}
.checkin button[data-s="green"][aria-pressed="true"] {
  border-color: var(--green);
  background: color-mix(in srgb, var(--green) 14%, transparent);
}
.checkin button[data-s="amber"][aria-pressed="true"] {
  border-color: var(--amber);
  background: color-mix(in srgb, var(--amber) 14%, transparent);
}
.checkin button[data-s="red"][aria-pressed="true"] {
  border-color: var(--red);
  background: color-mix(in srgb, var(--red) 14%, transparent);
}
.advice {
  margin: var(--space-2-5) 0 0;
  font-size: var(--text-base);
  color: var(--fg);
  min-height: 2.9em;
}
.gauge-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: var(--space-2);
}
.big {
  font-family: var(--display);
  font-size: 2.6rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.big small {
  font-size: var(--text-base);
  color: var(--muted);
  font-family: var(--body);
}
.cells {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: var(--space-1);
  margin-top: var(--space-3);
}
.cell {
  height: 26px;
  border-radius: var(--radius-xs);
  background: var(--accent);
}
.cell.spent {
  background: var(--spent);
}
.cell.lost {
  background: transparent;
  border: 1.5px dashed var(--line);
}
.cells.low .cell:not(.spent):not(.lost) {
  background: var(--amber);
}
.cells.out .cell:not(.spent):not(.lost) {
  background: var(--red);
}
/* A switch row: the whole row is the tap target; the real checkbox sits invisibly over it so it stays accessible */
.switch-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-top: var(--space-3);
  min-height: 60px;
  padding: var(--space-3) var(--space-3-5);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition:
    background-color var(--dur) var(--ease),
    border-color var(--dur) var(--ease);
}
.switch-text {
  display: grid;
  gap: var(--space-0-5);
  min-width: 0;
}
.switch-text b {
  font-size: var(--text-base);
}
.switch-text small {
  color: var(--muted);
  font-size: var(--text-sm);
}
.switch {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}
.switch-ui {
  flex: none;
  position: relative;
  width: 50px;
  height: 30px;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--muted) 45%, var(--surface));
  transition: background-color var(--dur) var(--ease);
}
.switch-ui::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  transition: transform var(--dur) var(--ease);
}
.switch:checked + .switch-ui {
  background: var(--accent);
}
.switch:checked + .switch-ui::after {
  transform: translateX(20px);
}
.switch:focus-visible + .switch-ui {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.switch-row:has(.switch:checked) {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.switch-row:has(.switch:checked) small {
  color: var(--fg);
}
@media (prefers-reduced-motion: reduce) {
  .switch-row,
  .switch-ui,
  .switch-ui::after {
    transition: none;
  }
}
@media (forced-colors: active) {
  .switch-ui {
    border: 2px solid ButtonText;
    background: Canvas;
  }
  .switch-ui::after {
    background: ButtonText;
    box-shadow: none;
  }
  .switch:checked + .switch-ui {
    background: Highlight;
  }
  .switch:checked + .switch-ui::after {
    background: HighlightText;
  }
}
.acts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: 1fr;
  gap: var(--space-2);
}
.act {
  font: inherit;
  text-align: left;
  padding: 11px var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-rows: minmax(3.6em, auto) 44px;
  gap: var(--space-2);
  align-items: center;
  min-width: 0;
}
.act span {
  min-width: 0;
  overflow-wrap: anywhere;
}
.act .c {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.act.rec .c {
  color: var(--green-text);
}
.act:active {
  transform: scale(0.98);
}
.act.on {
  cursor: default;
  border-color: var(--green);
  background: color-mix(in srgb, var(--green) 14%, transparent);
}
.act.on:active {
  transform: none;
}
.act.on .name {
  flex: 1;
  font-weight: 600;
}
.stepper {
  grid-column: 1/-1;
  grid-row: 2;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2-5);
  width: 100%;
}
.step {
  font: inherit;
  font-size: var(--text-lg);
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--radius-md);
  border: 1px solid var(--green);
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
}
.step:active {
  background: color-mix(in srgb, var(--green) 22%, var(--bg));
}
.count {
  font-variant-numeric: tabular-nums;
  min-width: 2.2ch;
  text-align: center;
}
.act-picked {
  display: grid;
  gap: var(--space-2);
}
ul.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-1-5);
}
ul.list li {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2-5);
  align-items: center;
  font-size: var(--text-sm);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--line);
}
ul.list li:last-child {
  border-bottom: 0;
}
.x {
  font: inherit;
  font-size: var(--text-sm);
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline;
}
.empty {
  color: var(--muted);
  font-size: var(--text-sm);
  margin: 0;
}
form {
  display: grid;
  gap: var(--space-3-5);
}
fieldset {
  border: 0;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-2);
}
legend {
  font-weight: 700;
  margin-bottom: var(--space-1-5);
}
/* The browser's default placeholder grey is under 3:1 on the dark theme; the muted text colour is chosen for both. */
::placeholder {
  color: var(--muted);
  opacity: 1;
}
/* One size for every question on the Episode form (the single-answer ones were 14px, the multi-answer ones 16px). */
#epform legend,
#epform label.legend {
  font: 700 var(--text-base) var(--body);
}
#epform legend .meta {
  font-weight: 400;
  font-size: var(--text-sm);
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1-5);
}
.chip {
  position: relative;
}
.chip input {
  position: absolute;
  opacity: 0;
  inset: 0;
}
.chip span {
  display: inline-block;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  font-size: var(--text-sm);
  cursor: pointer;
}
@media (max-width: 700px) {
  .chip span {
    display: inline-flex;
    align-items: center;
    min-height: 44px; /* a touch-sized target on a phone */
  }
}
.chip input:checked + span {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--fg);
  font-weight: 700;
}
.chip input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
input[type="datetime-local"],
select,
textarea {
  font: inherit;
  width: 100%;
  padding: var(--space-2-5);
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
}
textarea {
  min-height: 70px;
  resize: vertical;
}
.primary {
  font: inherit;
  font-weight: 700;
  padding: var(--space-3);
  border-radius: var(--radius-md);
  border: 0;
  background: var(--accent);
  color: var(--bg);
  cursor: pointer;
}
.warn {
  border-left: 4px solid var(--red);
  padding: var(--space-2-5) var(--space-3);
  background: color-mix(in srgb, var(--red) 9%, transparent);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
}
.toast {
  color: var(--green-text);
  font-weight: 700;
  min-height: 1.2em;
  margin: 0;
}
.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: var(--space-1-5);
  background: var(--spent);
}
.dot.green {
  background: var(--green);
}
.dot.amber {
  background: var(--amber);
}
.dot.red {
  background: var(--red);
}
.ep {
  display: grid;
  gap: var(--space-1);
  padding: var(--space-2-5) 0;
  border-bottom: 1px solid var(--line);
  font-size: var(--text-sm);
}
.ep:last-child {
  border-bottom: 0;
}
.ep b {
  font-variant-numeric: tabular-nums;
}
.meta {
  color: var(--muted);
  font-size: var(--text-sm);
}
.sync {
  color: var(--muted);
  transition: opacity var(--dur) var(--ease);
}
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
  .act:active {
    transform: none;
  }
}
/* Self-hosted additions */
.head-actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}
.ghost {
  font: inherit;
  font-size: var(--text-sm);
  padding: var(--space-1-5) var(--space-2-5);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-decoration: none;
}
.ghost:hover {
  color: var(--fg);
}
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: var(--space-3);
  padding-inline: var(--space-4);
}
.login .panel {
  width: 100%;
  max-width: 380px;
  display: grid;
  gap: var(--space-4);
}
.login label {
  display: grid;
  gap: var(--space-1-5);
  font-weight: 700;
}
.login input {
  font: inherit;
  width: 100%;
  padding: var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
}
.login input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
/* The shared error pattern: every failure message uses this colour and weight. */
.err {
  color: var(--err);
  font-weight: 700;
  margin: 0;
  min-height: 1.2em;
}
.tag {
  color: var(--muted);
  margin: 0;
  font-size: var(--text-base);
}
#checkin {
  margin-top: var(--space-2);
}
.login .brand {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-2-5);
}
.title {
  display: flex;
  gap: var(--space-2-5);
  align-items: center;
  min-height: 44px;
}
.title img {
  border-radius: var(--radius-sm);
}

/* Accounts, settings, admin and history extras */
nav::-webkit-scrollbar {
  display: none;
}
@media (max-width: 380px) {
  nav button {
    font-size: var(--text-sm);
    padding-inline: var(--space-2);
  }
}
button:disabled {
  opacity: 0.5;
  cursor: default;
}
input:not([type]),
input[type="email"],
input[type="url"],
input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="time"],
input[type="file"] {
  font: inherit;
  width: 100%;
  padding: var(--space-2-5);
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
}
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.who {
  color: var(--muted);
  font-size: var(--text-sm);
}
.banner {
  margin-top: var(--space-2-5);
  padding: var(--space-2-5) var(--space-3);
  border-radius: var(--radius-md);
  border-left: 4px solid var(--amber);
  background: color-mix(in srgb, var(--amber) 12%, transparent);
  font-size: var(--text-sm);
}
.notice {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--muted);
}
.daynav {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: var(--space-2);
  align-items: center;
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--line);
}
.daynav .mid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: var(--space-1) var(--space-2-5);
  min-width: 0;
}
.daynav b {
  font-family: var(--display);
}
.daynav input[type="date"] {
  width: auto;
  max-width: 100%;
  padding: var(--space-1-5) var(--space-2);
  font-size: var(--text-sm);
}
.daynav .ghost {
  font-size: var(--text-lg);
  padding: var(--space-1) var(--space-3);
  min-width: 44px;
  min-height: 44px;
}
.timerow {
  display: flex;
  align-items: center;
  gap: var(--space-2-5);
  margin-bottom: var(--space-2-5);
  font-size: var(--text-sm);
  color: var(--muted);
}
.timerow input {
  width: auto;
}
.field {
  display: grid;
  gap: var(--space-1-5);
  font-weight: 700;
  font-size: var(--text-base);
}
.field input,
.field select,
.field textarea {
  font-weight: 400;
}
.hint {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-sm);
}
.msg {
  margin: 0;
  min-height: 1.2em;
  font-weight: 700;
  color: var(--green-text);
}
.msg.err {
  color: var(--err);
}
.row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2-5);
  align-items: center;
}
.row select {
  flex: 1;
  min-width: 0;
  width: auto;
}
.row2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}
.radio {
  display: flex;
  gap: var(--space-2);
  align-items: center;
  font-size: var(--text-sm);
}
.radio input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}
.secondary,
.danger {
  font: inherit;
  font-weight: 700;
  padding: var(--space-2-5) var(--space-3-5);
  border-radius: var(--radius-md);
  background: transparent;
  cursor: pointer;
  text-decoration: none;
}
.secondary {
  border: 1px solid var(--accent);
  color: var(--accent);
}
.danger {
  border: 1px solid var(--red);
  color: var(--red);
}
a.btn {
  display: inline-block;
}
.small {
  font-size: var(--text-sm);
  padding: var(--space-1-5) var(--space-2-5);
}
.danger-zone {
  border-color: color-mix(in srgb, var(--red) 40%, var(--line));
}
.actrow {
  display: grid;
  grid-template-columns: 1fr 68px auto;
  gap: var(--space-1-5);
  align-items: center;
  margin-bottom: var(--space-1-5);
}
.actrow input {
  padding: var(--space-2);
}
ul.people li {
  display: grid;
  gap: var(--space-1-5);
  align-items: start;
  justify-content: stretch;
}
.people .top {
  display: flex;
  gap: var(--space-2);
  align-items: baseline;
  flex-wrap: wrap;
}
.badge {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 700;
  padding: var(--space-0-5) var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--fg);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge.off {
  background: color-mix(in srgb, var(--red) 16%, transparent);
}
.badge.wait {
  background: color-mix(in srgb, var(--amber) 22%, transparent);
}
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1-5);
}
ul.audit li {
  display: grid;
  gap: var(--space-0-5);
  justify-content: stretch;
  font-size: var(--text-sm);
}
.reveal {
  margin-top: var(--space-3-5);
  padding: var(--space-3);
  border: 1px dashed var(--accent);
  border-radius: var(--radius-md);
  display: grid;
  gap: var(--space-2);
}
.reveal code {
  font-size: var(--text-md);
  letter-spacing: 0.04em;
  word-break: break-all;
  user-select: all;
}
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
  text-align: center;
}
.stat b {
  display: block;
  font-family: var(--display);
  font-size: var(--text-xl);
  line-height: 1.1;
}
.stat span {
  font-size: var(--text-xs);
  color: var(--muted);
}
.stat.green b {
  color: var(--green-text);
}
.stat.amber b {
  color: var(--amber-text);
}
.stat.red b {
  color: var(--red);
}
.trend-notes {
  display: grid;
  gap: var(--space-1);
  margin-top: var(--space-2-5);
}
.trend-notes p {
  margin: 0;
}
.dayrow {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: var(--space-2-5);
  align-items: center;
  text-align: left;
  cursor: pointer;
}
.ep .actions {
  margin-top: var(--space-1);
}
.toastbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  max-width: min(92vw, 520px);
  background: var(--fg);
  color: var(--bg);
  padding: var(--space-2-5) var(--space-3-5);
  border-radius: var(--radius-md);
  display: flex;
  gap: var(--space-3);
  align-items: center;
  z-index: var(--z-toast);
  font-size: var(--text-sm);
  box-shadow: var(--shadow-pop);
}
.toastbar[hidden] {
  display: none;
}
.toastbar button {
  font: inherit;
  font-weight: 700;
  background: none;
  border: 0;
  color: var(--accent-soft);
  cursor: pointer;
  text-decoration: underline;
}
.fatal {
  margin: var(--space-10) 0;
  text-align: center;
}

/* The doctor's summary: hidden on screen, shown alone only while printing it */
#print-view {
  display: none;
}
@media print {
  body.printing {
    background: #fff;
    color: #000;
  }
  body.printing .wrap {
    max-width: none;
    padding: 0;
  }
  body.printing .wrap > :not(#print-view),
  body.printing .toastbar {
    display: none !important;
  }
  body.printing #print-view {
    display: block;
    font-family: system-ui, sans-serif;
    font-size: 11pt;
    line-height: var(--leading-snug);
  }
  #print-view h1 {
    font-size: 18pt;
    margin: 0 0 2pt;
  }
  #print-view h2 {
    font-size: 12pt;
    margin: 14pt 0 4pt;
  }
  #print-view p {
    margin: 2pt 0;
  }
  #print-view table {
    width: 100%;
    border-collapse: collapse;
    font-size: 10pt;
  }
  #print-view th,
  #print-view td {
    border-bottom: 1px solid #bbb;
    padding: 3pt 5pt;
    text-align: left;
    vertical-align: top;
  }
  #print-view tr {
    break-inside: avoid;
  }
  #print-view .small-print {
    font-size: 9pt;
    color: #444;
    margin-top: 14pt;
  }
}
.setup {
  margin: 0;
  font-size: var(--text-sm);
  padding: var(--space-2-5) var(--space-3);
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
}
.setup code {
  font-size: var(--text-sm);
  word-break: break-all;
}

/* Ordered settings: one stable row layout, generous touch handles, clear drag/drop feedback. */
.ordered-list {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.order-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: 0.45rem;
}
.order-row > input[type="text"] {
  min-width: 0;
  flex: 1;
  width: 0;
}
.order-row .order-cost {
  width: 4.5rem;
  flex: 0 0 4.5rem;
}
.drag-handle {
  min-width: 44px;
  min-height: 44px;
  padding: 0.25rem;
  cursor: grab;
  touch-action: none;
  font-size: var(--text-xl);
  color: var(--accent);
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
}
.drag-handle:active {
  cursor: grabbing;
}
.order-actions {
  display: flex;
  gap: 0.15rem;
}
.order-actions button {
  min-height: 44px;
  min-width: 40px;
  padding: 0.25rem;
  font-size: var(--text-base);
  text-decoration: none;
  border-radius: var(--radius-sm);
}
.order-actions button:hover:not(:disabled) {
  background: var(--accent-soft);
  color: var(--accent);
}
.drop-placeholder {
  outline: 2px dashed var(--accent);
  opacity: 0.45;
}
.drag-preview {
  position: fixed;
  z-index: var(--z-drag);
  pointer-events: none;
  box-shadow: var(--shadow-pop);
  transform: rotate(1deg);
  opacity: 0.96;
}
[aria-invalid="true"] {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.panel.recovery {
  border: 2px solid var(--red);
}
/* The status pill hangs below the header; with a refused change it has words in it, so leave room for them. */
#recovery:not([hidden]) {
  margin-top: var(--space-11);
}
.recovery-item {
  margin-top: 1rem;
  border-top: 1px solid var(--line);
  padding-top: 0.75rem;
  overflow-wrap: anywhere;
}
.filters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}
.filters .field {
  margin: 0;
}
input[type="search"] {
  font: inherit;
  width: 100%;
  padding: var(--space-2-5);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--fg);
}
#summary-preview {
  max-height: 26rem;
  overflow: auto;
  margin-top: 1rem;
  border: 1px solid var(--line);
  padding: 0.75rem;
}
#summary-preview table {
  border-collapse: collapse;
  font-size: var(--text-sm);
}
#summary-preview td,
#summary-preview th {
  border: 1px solid var(--line);
  padding: 0.35rem;
  text-align: left;
}
/* On a phone the preview is read as part of the page, with each row a small card, not a window onto a wide table. */
@media (max-width: 700px) {
  #summary-preview {
    max-height: none;
    overflow: visible;
  }
  #summary-preview table,
  #summary-preview tbody {
    display: block;
  }
  #summary-preview thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
  #summary-preview tr {
    display: block;
    margin-bottom: var(--space-2-5);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: var(--space-1-5) var(--space-2);
  }
  #summary-preview td {
    display: grid;
    grid-template-columns: minmax(6.5rem, 38%) 1fr;
    gap: var(--space-2);
    border: 0;
    padding: 3px 0;
    overflow-wrap: anywhere;
  }
  #summary-preview td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 700;
  }
  #summary-preview td:empty {
    display: none;
  }
}
#reveal-pw {
  display: block;
  margin: var(--space-3) 0;
  padding: var(--space-3);
  border: 1px dashed var(--accent);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  letter-spacing: 0.03em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: all;
}
@media (max-width: 480px) {
  .order-row {
    flex-wrap: wrap;
  }
  .order-row > input[type="text"] {
    flex-basis: calc(100% - 60px);
  }
  .order-row .order-cost {
    margin-left: var(--space-12);
  }
  .order-actions {
    margin-left: auto;
  }
  .filters {
    grid-template-columns: 1fr;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
  }
}

/* Contextual help uses the same quiet visual language as the log. */
.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.label-row h2 {
  margin-bottom: 0;
}
.help-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font: 700 var(--text-base) var(--body);
  cursor: help;
}
.help-tip:hover {
  border-color: var(--accent);
}
.help-tip {
  position: relative;
}
.help-tip::after {
  content: "";
  position: absolute;
  inset: -6px;
}
.help-link {
  white-space: nowrap;
  min-height: 44px;
}
.help-eyebrow,
.help-category {
  color: var(--accent);
  font-size: var(--text-sm);
  font-weight: 700;
}
.help-eyebrow {
  margin: 0 0 0.4rem;
}
.help-intro {
  background: linear-gradient(135deg, var(--surface), var(--accent-soft));
  padding: 1.3rem;
}
.help-intro h2 {
  font-size: var(--text-xl);
}
.help-intro p {
  margin-top: 0.4rem;
}
.help-topic {
  border-top: 1px solid var(--line);
  margin-top: 0.35rem;
}
.help-topic summary {
  cursor: pointer;
  padding: 1rem 1.6rem 1rem 0;
  position: relative;
  list-style: none;
  display: grid;
  gap: 0.25rem;
  font-weight: 700;
}
.help-topic summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}
.help-topic summary::-webkit-details-marker {
  display: none;
}
.help-topic summary::after {
  content: "+";
  position: absolute;
  right: 0.2rem;
  top: 1.2rem;
  color: var(--accent);
  font-size: var(--text-lg);
}
.help-topic[open] summary::after {
  content: "−";
}
.help-topic[open] summary {
  color: var(--accent);
}
.help-answer {
  padding: 0 0 1.1rem;
  font-size: var(--text-base);
  line-height: var(--leading-normal);
}
.help-answer p:first-child {
  margin-top: 0;
}
.help-answer .warn {
  margin-bottom: 1rem;
}
.tooltip {
  position: fixed;
  z-index: var(--z-tooltip);
  max-width: min(320px, calc(100vw - 24px));
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--fg);
  color: var(--surface);
  box-shadow: var(--shadow-pop);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  overflow-wrap: anywhere;
  animation: tip-appear 0.12s ease-out;
}
@keyframes tip-appear {
  from {
    opacity: 0;
    transform: translateY(3px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@media (prefers-reduced-motion: reduce) {
  .tooltip {
    animation: none;
  }
}
@media print {
  #jiggered-tooltip {
    display: none !important;
  }
}

/* Panels stack their children with one consistent gap, so adjacent buttons never touch. */
.panel > h2,
.panel > .label-row h2 {
  margin-bottom: 0;
}
.panel > .x,
.panel > .secondary,
.panel > .primary {
  justify-self: start;
}
.panel .switch-row,
.panel .advice,
.panel .cells,
.panel .hint {
  margin-top: 0;
}
.panel .hint summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  cursor: pointer;
  color: var(--accent);
  font-weight: 700;
}
.panel details.hint {
  display: grid;
  gap: var(--space-2);
}
.panel details.hint p {
  margin: var(--space-2) 0 0;
}
.gauge-head .big {
  margin-top: var(--space-1-5);
}
@media (max-width: 480px) {
  .panel > .secondary,
  .panel > .primary {
    justify-self: stretch;
  }
  .row > .secondary,
  .row > .primary {
    flex: 1 1 100%;
  }
  .checkin {
    gap: var(--space-1-5);
  }
  .checkin button b {
    font-size: var(--text-base);
  }
  .acts {
    gap: var(--space-3);
  }
  .act-groups {
    gap: var(--space-5);
  }
  .act-group,
  .act-fav {
    gap: var(--space-3);
  }
  .group-filter {
    gap: var(--space-3);
  }
  .chips {
    gap: var(--space-2-5) var(--space-2);
  }
  .chip span {
    padding: var(--space-2-5) var(--space-3-5);
  }
  .chip-search {
    margin-bottom: var(--space-2);
  }
  #setform .row {
    gap: var(--space-3);
    margin-top: var(--space-3-5);
  }
  #setform [data-gap] {
    margin-bottom: var(--space-1);
  }
}

/* Long lists: search, favourites, groups and paging. Short lists never show any of this. */
.act-search input {
  font-weight: 400;
}
.act-groups {
  display: grid;
  gap: var(--space-3-5);
}
.act-fav,
.act-group {
  display: grid;
  gap: var(--space-2);
}
.act-fav h3 {
  margin: 0;
}
.act-group > summary {
  cursor: pointer;
  font-weight: 700;
  list-style: none;
  padding: var(--space-1-5) 0;
  display: flex;
  gap: var(--space-2);
  align-items: baseline;
}
.act-group > summary::-webkit-details-marker {
  display: none;
}
.act-group > summary::before {
  content: "▸";
  color: var(--accent);
}
.act-group[open] > summary::before {
  content: "▾";
}
.act-group > .secondary {
  justify-self: start;
}
.chip.fav span {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
}
.chip-search {
  margin-bottom: var(--space-0-5);
}
.chips[data-empty="1"]::after {
  content: "Nothing matches. Clear the search to see them all.";
  color: var(--muted);
  font-size: var(--text-sm);
}
@media (max-width: 480px) {
  .order-row .order-group {
    flex: 1 1 100%;
    width: 100%;
    margin-left: var(--space-12);
    max-width: calc(100% - 48px);
  }
}
.order-row .order-group {
  flex: 0 1 8rem;
  min-width: 0;
}

/* Calm interaction: nothing below the header may move when a save starts or finishes. */
.sync[data-state="saved"] {
  opacity: 0;
}
.sync[data-state="attention"] {
  opacity: 1;
}
.sync.err {
  color: var(--err);
  font-weight: 700;
}
.checkin button,
.cell,
.act {
  transition:
    background-color var(--dur) var(--ease),
    border-color var(--dur) var(--ease),
    color var(--dur) var(--ease),
    transform var(--dur-fast) var(--ease);
}
.cell {
  transition:
    background-color var(--dur) var(--ease),
    border-color var(--dur) var(--ease);
}
@media (prefers-reduced-motion: reduce) {
  .sync,
  .checkin button,
  .cell,
  .act {
    transition: none !important;
  }
}

/* Group filter on Today, and the shared-defaults notice */
.group-filter {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2-5);
  margin: var(--space-1) 0 var(--space-4);
}
.group-filter[hidden] {
  display: none;
}
.pill {
  font: inherit;
  font-size: var(--text-sm);
  white-space: nowrap;
  flex: none;
  min-height: 44px;
  padding: var(--space-1-5) var(--space-3-5);
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  display: inline-flex;
  gap: var(--space-1-5);
  align-items: center;
}
.pill .meta {
  font-variant-numeric: tabular-nums;
}
.pill:hover {
  border-color: var(--accent);
}
.pill[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  font-weight: 700;
}
.pill:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.defaults-notice {
  border-left: 4px solid var(--accent);
}
.defaults-notice {
  padding-block: var(--space-3);
}
.defaults-notice p {
  margin: 0 0 var(--space-2-5);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
}
.defaults-notice p .meta {
  font-size: inherit;
  font-weight: 700;
}
.defaults-notice .row {
  flex-wrap: wrap;
  gap: var(--space-2);
}
.defaults-notice .small {
  min-height: 44px;
}

/* Symptom and trigger lists: status line above the chips */
.chip-status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  min-height: 32px;
  margin: var(--space-0-5) 0 var(--space-2-5);
  font-size: var(--text-sm);
  color: var(--muted);
}
.chip-status[hidden] {
  display: none;
}
.chip-status .x {
  min-height: 36px;
  padding: var(--space-1-5) var(--space-2);
  white-space: nowrap;
}
#ep-sym-more,
#ep-trig-more {
  width: 100%;
  min-height: 44px;
  margin-top: var(--space-3);
}

/* Morning check-in: status dot and name, a one-word feel, and what it costs as its own badge */
.checkin button b::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--dot);
  flex: none;
}
.checkin button[data-s="green"] {
  --dot: var(--green);
}
.checkin button[data-s="amber"] {
  --dot: var(--amber);
}
.checkin button[data-s="red"] {
  --dot: var(--red);
}
.checkin button .mood {
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: var(--leading-tight);
}
.checkin button .cost {
  font-size: var(--text-xs);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--fg) 8%, transparent);
  color: var(--fg);
}
.checkin button[aria-pressed="true"] b::before {
  content: "✓";
  width: auto;
  height: auto;
  background: none;
  color: var(--dot);
  font-weight: 800;
  line-height: 1;
}
.checkin button[aria-pressed="true"] .mood {
  color: var(--fg);
}
.checkin button[aria-pressed="true"] .cost {
  background: color-mix(in srgb, var(--dot) 28%, transparent);
}
@media (max-width: 360px) {
  .checkin {
    gap: 5px;
  }
  .checkin button .cost {
    padding: 3px 7px;
  }
}

/* History and profile: generous desktop canvas, the same calm phone experience. */
.history-intro,
.profile-hero {
  background: linear-gradient(130deg, var(--accent-soft), var(--surface) 75%);
  border-color: color-mix(in srgb, var(--accent) 30%, var(--line));
  padding: var(--space-6);
}
.history-intro h2,
.profile-hero h2 {
  font-size: var(--text-2xl);
  letter-spacing: -0.03em;
  margin: 0;
  overflow-wrap: anywhere;
}
.history-intro .meta {
  max-width: 70ch;
}
.history-filter-panel .filters {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.history-filter-panel .filters label:has(#hist-query) {
  grid-column: 1/-1;
}
.history-filter-panel .filters .toggle {
  align-self: end;
  min-height: 44px;
}
.history-filter-panel #history-count {
  margin-bottom: 0;
}
.history-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-3);
  margin-top: var(--space-4);
}
.metric {
  display: grid;
  gap: var(--space-2-5);
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--bg);
  min-width: 0;
  align-content: start;
}
.metric b {
  font-family: var(--display);
  font-size: var(--text-3xl);
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.metric b small {
  font: 400 var(--text-base) var(--body);
  color: var(--muted);
}
.metric .meta {
  font-size: var(--text-sm);
}
.checkin-summary {
  margin-top: var(--space-6);
}
.checkin-summary h3,
.chart-card h3,
.insight-card h3 {
  font-family: var(--display);
  font-size: var(--text-base);
  margin: var(--space-1-5) 0 var(--space-2-5);
}
.checkin-composition {
  display: block;
  width: 100%;
  height: 18px;
  overflow: hidden;
  border-radius: var(--radius-sm);
}
.composition-empty {
  fill: var(--spent);
}
.composition-green {
  fill: var(--green);
}
.composition-amber {
  fill: var(--amber);
}
.composition-red {
  fill: var(--red);
}
.chart-legend {
  display: flex;
  align-items: center;
  gap: var(--space-2-5) var(--space-4-5);
  flex-wrap: wrap;
  font-size: var(--text-sm);
  color: var(--muted);
  margin-block: var(--space-3);
}
.chart-legend span {
  display: flex;
  align-items: center;
  gap: var(--space-1-5);
}
.chart-legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--spent);
  flex: none;
}
.chart-legend .legend-used {
  background: var(--accent);
}
.chart-legend .legend-allowance {
  background: var(--muted);
  border-radius: 0;
  height: 3px;
  width: 15px;
}
.chart-legend .legend-green {
  background: var(--green);
}
.chart-legend .legend-amber {
  background: var(--amber);
}
.chart-legend .legend-red {
  background: var(--red);
}
.comparison-note {
  padding-top: var(--space-3-5);
  border-top: 1px solid var(--line);
  line-height: var(--leading-normal);
}
.history-visuals {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-6);
}
.chart-card {
  min-width: 0;
  display: grid;
  grid-template-rows: subgrid;
  grid-row: span 6;
  row-gap: 0;
}
.chart-combined {
  grid-column: 1/-1;
  display: block;
  grid-row: auto;
  border-top: 1px solid var(--line);
  padding-top: var(--space-6);
}
.chart-spent {
  stroke: var(--fg);
  stroke-width: 2;
  stroke-dasharray: 3 4;
  fill: none;
}
.chart-spent-point {
  fill: var(--fg);
}
.chart-sleep {
  fill: var(--amber);
}
.chart-legend .legend-spent {
  background: var(--fg);
  border-radius: 0;
  height: 3px;
  width: 15px;
}
.chart-legend .legend-sleep {
  background: var(--amber);
  border-radius: 0;
}
.energy-report {
  line-height: var(--leading-normal);
  font-variant-numeric: tabular-nums;
}
.history-chart {
  display: block;
  width: 100%;
  height: auto;
  margin-top: var(--space-3);
  overflow: visible;
}
.chart-grid {
  stroke: var(--line);
  stroke-width: 1;
}
.chart-zero {
  stroke: var(--muted);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}
.chart-axis {
  fill: var(--muted);
  font: var(--text-sm) var(--body);
}
.chart-used {
  stroke: var(--accent);
  stroke-width: 3;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.chart-allowance {
  stroke: var(--muted);
  stroke-width: 2;
  stroke-dasharray: 6 5;
  fill: none;
}
.chart-point,
.chart-episode {
  fill: var(--accent);
}
.chart-hit {
  fill: transparent;
  cursor: crosshair;
}
.chart-hit.is-inspected {
  fill: color-mix(in srgb, var(--accent) 10%, transparent);
}
.chart-inspector {
  border-radius: var(--radius-md);
  padding: var(--space-3-5);
  background: var(--bg);
  border: 1px solid var(--line);
  margin-top: var(--space-3);
}
.chart-inspector .field {
  font-size: var(--text-sm);
}
.chart-inspector .meta {
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  min-height: 6em;
  margin: var(--space-2-5) 0;
}
.chart-data {
  margin-top: var(--space-3);
  font-size: var(--text-sm);
}
.chart-data summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  cursor: pointer;
  color: var(--accent);
}
.table-scroll {
  overflow-x: auto;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  margin-top: var(--space-1-5);
}
.table-scroll table {
  border-collapse: collapse;
  width: 100%;
  font-size: var(--text-sm);
}
.table-scroll td,
.table-scroll th {
  padding: var(--space-2-5);
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.table-scroll th {
  font-weight: 700;
}
.table-scroll thead {
  background: var(--accent-soft);
}
.table-scroll tbody th {
  min-width: 170px;
  font-weight: 400;
}
.chart-empty {
  display: grid;
  align-content: center;
  text-align: center;
  min-height: 190px;
  margin-top: var(--space-3-5);
  padding: var(--space-6);
  border: 1px dashed var(--line);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--muted);
}
.chart-empty p {
  font-size: var(--text-sm);
  max-width: 38ch;
  margin: var(--space-3) auto;
}
.insights-note {
  margin-bottom: var(--space-4-5);
  max-width: 85ch;
  line-height: var(--leading-normal);
}
.patterns-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3-5);
}
.insight-card {
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  min-width: 0;
}
.insight-card .meta {
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
}
.insight-card .hint {
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
}
.pattern-ranking {
  list-style: none;
  margin: var(--space-2-5) 0;
  padding: 0;
  display: grid;
  gap: var(--space-2-5);
}
.pattern-ranking li {
  display: grid;
  gap: 5px;
  min-width: 0;
}
.pattern-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  font: inherit;
  font-size: var(--text-sm);
  width: 100%;
  min-height: 36px;
  padding: var(--space-1) 0;
  color: var(--fg);
  text-align: left;
  border: 0;
  background: none;
  cursor: pointer;
}
.pattern-link span {
  overflow-wrap: anywhere;
}
.pattern-link b {
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  flex: none;
}
.pattern-link:hover span {
  text-decoration: underline;
  text-underline-offset: 3px;
}
.pattern-ranking meter {
  display: block;
  width: 100%;
  height: 8px;
  border: 0;
  appearance: none;
  background: var(--accent-soft);
  border-radius: var(--radius-xs);
}
.pattern-ranking meter::-webkit-meter-bar {
  background: var(--accent-soft);
  border: 0;
  border-radius: var(--radius-xs);
}
.pattern-ranking meter::-webkit-meter-optimum-value {
  background: var(--accent);
  border-radius: var(--radius-xs);
}
.pattern-ranking meter::-moz-meter-bar {
  background: var(--accent);
  border-radius: var(--radius-xs);
}
.history-records {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4-5);
  align-items: start;
}
.history-records > div {
  min-width: 0;
}
.history-records .ep {
  min-width: 0;
  overflow-wrap: anywhere;
}
.history-records .dayrow {
  flex-wrap: wrap;
  padding-block: var(--space-1);
}
.history-records .dayrow .meta {
  font-size: var(--text-sm);
}
.profile-heading {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}
.profile-heading > div:last-child {
  min-width: 0;
}
.profile-avatar {
  width: 68px;
  height: 68px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: var(--radius-xl);
  background: var(--accent);
  color: var(--bg);
  font-family: var(--display);
  font-size: var(--text-xl);
  font-weight: 700;
  box-shadow: 0 4px 16px color-mix(in srgb, var(--accent) 16%, transparent);
}
.profile-focus {
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  max-width: 60ch;
  overflow-wrap: anywhere;
  margin: 0;
}
.profile-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3);
  border-top: 1px solid var(--line);
  padding-top: var(--space-4-5);
  margin-top: var(--space-4-5);
}
.profile-stats > div {
  display: grid;
  gap: var(--space-1);
  min-width: 0;
}
.profile-stats b {
  font: 700 var(--text-xl) var(--display);
  font-variant-numeric: tabular-nums;
}
.profile-stats span {
  font-size: var(--text-sm);
  color: var(--muted);
}
#account-panel > .panel,
#history-filters {
  scroll-margin-top: var(--space-20);
}
#profile-focus-count {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-size: var(--text-sm);
}
.account-privacy p {
  line-height: var(--leading-relaxed);
  margin-bottom: 0;
}
@media (max-width: 700px) {
  .history-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-2);
  }
  .history-visuals,
  .patterns-grid,
  .history-records {
    grid-template-columns: minmax(0, 1fr);
  }
  .history-visuals .chart-card + .chart-card {
    border-top: 1px solid var(--line);
    padding-top: var(--space-5);
  }
  .metric {
    padding: var(--space-3);
    gap: var(--space-2);
  }
  .metric b {
    font-size: var(--text-2xl);
  }
  .metric .label {
    font-size: var(--text-xs);
  }
  .history-intro,
  .profile-hero {
    padding: var(--space-4-5);
  }
  .profile-hero h2 {
    font-size: var(--text-xl);
  }
  .profile-avatar {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-lg);
    font-size: var(--text-lg);
  }
  .profile-heading {
    gap: var(--space-3);
  }
  .chart-inspector .meta {
    min-height: 0;
  }
}
@media (max-width: 380px) {
  .history-filter-panel .filters,
  .row2:has(#profile-theme) {
    grid-template-columns: minmax(0, 1fr);
  }
  .history-filter-panel .filters label:has(#hist-query) {
    grid-column: auto;
  }
  .profile-stats {
    gap: var(--space-2);
  }
  .profile-stats span {
    font-size: var(--text-xs);
  }
}
@media (forced-colors: active) {
  .chart-used,
  .chart-allowance {
    stroke: CanvasText;
  }
  .chart-point,
  .chart-episode,
  .composition-green,
  .composition-amber,
  .composition-red {
    fill: CanvasText;
  }
  .chart-hit.is-inspected {
    stroke: Highlight;
    fill: transparent;
  }
  .chart-grid {
    stroke: GrayText;
  }
  .profile-avatar {
    border: 1px solid CanvasText;
  }
}
.history-intro p {
  margin: 0;
}
/* Calm History: one period, the calendar and one day before optional detail. */
.history-period-bar {
  display: flex;
  gap: var(--space-3) var(--space-4);
  align-items: center;
  flex-wrap: wrap;
}
.history-period-bar > .field {
  display: flex;
  align-items: center;
  gap: var(--space-2-5);
  white-space: nowrap;
}
.history-period-bar > .field select {
  width: auto;
  min-width: 130px;
}
.history-period-bar > .meta {
  flex: 1 1 220px;
  max-width: none;
}
.history-period-bar > .primary {
  margin-left: auto;
}
/* Shown only after narrowing the period to one day: a button, not a bar the width of the page. */
#history-return-period {
  justify-self: start;
}
/* The calendar and the selected day are two cards of one height: the calendar fills its card whatever the period, and
   the day's buttons dock to the bottom edge of theirs. */
.history-overview {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: var(--space-4-5);
  align-items: stretch;
}
.history-overview > * {
  min-width: 0;
}
.matrix-overview {
  display: flex;
  flex-direction: column;
}
.matrix-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3) var(--space-5);
}
.matrix-title {
  flex: 1 1 240px;
  display: grid;
  gap: var(--space-1);
  min-width: 0;
}
.matrix-title h2 {
  margin: 0;
}
.matrix-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-3-5) var(--space-6);
  border-top: 1px solid var(--line);
  padding-top: var(--space-3-5);
}
.matrix-facts {
  flex: 1 1 240px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3);
}
.matrix-facts > div {
  display: grid;
  gap: var(--space-1-5);
}
.matrix-facts b {
  font: 700 var(--text-xl) var(--display);
}
.matrix-facts span {
  font-size: var(--text-sm);
  color: var(--muted);
}
.history-disclosure > summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 44px;
  cursor: pointer;
}
.history-disclosure > summary::-webkit-details-marker {
  display: none;
}
.history-disclosure > summary h2::before {
  content: "▸ ";
  color: var(--accent);
}
.history-disclosure[open] > summary h2::before {
  content: "▾ ";
}
.history-disclosure > summary .meta {
  text-align: right;
  overflow-wrap: anywhere;
}
/* The heading's bottom margin would push the title off the summary's centre. */
.history-disclosure > summary h2,
.history-filter-panel > summary h2 {
  margin: 0;
}
.history-section-body {
  display: grid;
  gap: var(--space-4-5);
  min-width: 0;
}
.history-section-body > * {
  min-width: 0;
}
.matrix-day-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
}
.matrix-day-heading > div:first-child {
  display: grid;
  gap: var(--space-1);
  min-width: 0;
}
.matrix-day-heading .row {
  flex: none;
  flex-wrap: nowrap;
  gap: var(--space-1-5);
}
.matrix-day-heading button {
  min-width: 44px;
  min-height: 44px;
}
.matrix-day-heading .row > button {
  flex: 0 0 44px;
  padding-inline: 0;
}
.matrix-balance {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: var(--space-1) var(--space-4);
  padding: var(--space-3-5) var(--space-4);
  background: var(--accent-soft);
  border-radius: var(--radius-md);
}
.matrix-balance > .label {
  grid-column: 1 / -1;
}
.matrix-balance > b {
  font: 700 2.5rem var(--display);
  line-height: 1;
}
.matrix-activities,
.matrix-episodes {
  list-style: none;
  padding: 0;
  margin: var(--space-2) 0 0;
}
.matrix-activities li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--line);
}
.matrix-activities li > span {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--space-0-5) var(--space-2-5);
  overflow-wrap: anywhere;
  min-width: 0;
}
.matrix-activities b {
  white-space: nowrap;
}
.matrix-activities .recovery {
  color: var(--accent);
}
.matrix-episodes button {
  width: 100%;
  justify-content: space-between;
  gap: var(--space-3);
  text-align: left;
}
.matrix-episodes button > span:first-child {
  display: grid;
  gap: var(--space-1);
  overflow-wrap: anywhere;
}
.matrix-reading h4 {
  margin: 0;
  font-size: var(--text-sm);
}
.matrix-reading .plan-history {
  display: grid;
  gap: var(--space-2);
  margin: 0;
  padding: var(--space-3-5) var(--space-4);
}
.matrix-reading .plan-history p {
  margin: 0;
}
.plan-history-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-3);
}
.matrix-mode {
  flex: 0 1 200px;
  min-width: 190px;
  font-size: var(--text-xs);
}
.matrix-mode select {
  padding: var(--space-2);
}
.matrix-period {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.matrix-period .meta {
  font-size: var(--text-sm);
}
.matrix-period .row:has(button:not([hidden])) {
  min-height: 36px;
}

/* The days. data-layout is set in history-matrix.js (see matrixLayout): a list of rows for a week or less, a calendar
   for a few weeks, a heatmap with a column per week for more. Each fills the width of its card. A day's colours are
   the --tone variables, so a list row can colour only its chip while a calendar square or heatmap cell is the colour. */
.matrix-body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--space-3-5);
  min-width: 0;
}
.matrix-calendar {
  display: grid;
  gap: var(--space-2) var(--space-1-5);
  min-width: 0;
}
.matrix-grid {
  display: grid;
  gap: var(--space-1);
  min-width: 0;
  align-self: start;
}
/* A dot in the corner of a day that has an episode, whatever the calendar is coloured by. */
.matrix-ep {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--fg);
  box-shadow: 0 0 0 2px var(--surface);
}
.matrix-ep-key {
  position: static;
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: var(--space-1-5);
  box-shadow: none;
}
.matrix-dense .matrix-cell .matrix-ep {
  display: none;
}
.matrix-cell {
  position: relative;
  --tone-bg: var(--spent);
  --tone-ink: var(--fg);
  min-width: 0;
  min-height: 0;
  width: 100%;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  background: var(--tone-bg);
  color: var(--tone-ink);
  font: 700 var(--text-xs) var(--body);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.matrix-cell.green,
.matrix-cell.recovery {
  --tone-bg: var(--green);
  --tone-ink: #fff;
}
.matrix-cell.amber {
  --tone-bg: var(--amber);
  --tone-ink: #1d2624;
}
.matrix-cell.red {
  --tone-bg: var(--red);
  --tone-ink: #fff;
}
.matrix-cell.level-1,
.matrix-key.level-1 {
  --tone-bg: color-mix(in srgb, var(--accent) 20%, var(--surface));
}
.matrix-cell.level-2,
.matrix-key.level-2 {
  --tone-bg: color-mix(in srgb, var(--accent) 40%, var(--surface));
}
.matrix-cell.level-3,
.matrix-key.level-3 {
  --tone-bg: color-mix(in srgb, var(--accent) 85%, var(--surface));
  --tone-ink: var(--bg);
}
.matrix-cell.level-4,
.matrix-key.level-4 {
  --tone-bg: var(--accent);
  --tone-ink: var(--bg);
}
.matrix-cell.empty {
  --tone-bg: var(--bg);
  --tone-ink: var(--muted);
  border: 1px dashed color-mix(in srgb, var(--muted) 40%, transparent);
}
.matrix-blank {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  background: var(--bg);
  opacity: 0.4;
}
.matrix-cell[aria-pressed="true"] {
  outline: 2px solid var(--fg);
  outline-offset: 1px;
}
.matrix-cell:hover {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.matrix-mark {
  line-height: 1;
}

/* List: a row per day, each with its chip and a line saying what was recorded. */
.matrix-calendar[data-layout="list"] .matrix-months,
.matrix-calendar[data-layout="list"] .matrix-weekdays {
  display: none;
}
.matrix-calendar[data-layout="list"] .matrix-grid {
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-2);
}
.matrix-calendar[data-layout="list"] .matrix-cell {
  grid-template-columns: 4.8rem 3.6rem minmax(0, 1fr);
  place-items: center start;
  column-gap: var(--space-3-5);
  min-height: 56px;
  padding: var(--space-1-5) var(--space-4) var(--space-1-5) var(--space-3-5);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--bg);
  color: var(--fg);
  font: 400 var(--text-sm) var(--body);
  text-align: left;
}
.matrix-calendar[data-layout="list"] .matrix-cell[aria-pressed="true"] {
  background: var(--accent-soft);
}
.matrix-calendar[data-layout="list"] .matrix-when {
  display: grid;
  gap: var(--space-0-5);
  line-height: var(--leading-tight);
}
.matrix-calendar[data-layout="list"] .matrix-when b {
  font-size: var(--text-base);
}
.matrix-calendar[data-layout="list"] .matrix-when span {
  font-size: var(--text-sm);
  color: var(--muted);
}
.matrix-calendar[data-layout="list"] .matrix-mark {
  justify-self: stretch;
  padding: var(--space-2) var(--space-1-5);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--tone-bg);
  color: var(--tone-ink);
  font: 700 var(--text-base) var(--display);
  text-align: center;
}
.matrix-calendar[data-layout="list"] .matrix-cell.empty .matrix-mark {
  border: 1px dashed color-mix(in srgb, var(--muted) 40%, transparent);
}
.matrix-calendar[data-layout="list"] .matrix-note {
  color: var(--muted);
  line-height: var(--leading-snug);
  overflow-wrap: anywhere;
}

/* Calendar: Monday to Sunday across, a row per week, the date in each square. */
.matrix-calendar[data-layout="calendar"] {
  grid-template-columns: minmax(0, 1fr);
}
.matrix-calendar[data-layout="calendar"] .matrix-months {
  display: none;
}
.matrix-calendar[data-layout="calendar"] .matrix-weekdays {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: var(--space-1-5);
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 700;
  text-align: center;
}
.matrix-calendar[data-layout="calendar"] .matrix-grid {
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-auto-rows: 58px;
  gap: var(--space-1-5);
}
.matrix-calendar[data-layout="calendar"] .matrix-cell {
  grid-template-rows: auto 1fr;
  place-items: stretch;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  text-align: left;
}
.matrix-calendar[data-layout="calendar"] .matrix-when {
  font-size: var(--text-xs);
  line-height: 1.1;
}
.matrix-calendar[data-layout="calendar"] .matrix-mark {
  align-self: end;
  justify-self: end;
  font: 700 var(--text-base) var(--display);
}
.matrix-calendar[data-layout="calendar"] .matrix-blank {
  border-radius: var(--radius-sm);
}

/* Heatmap: a column per week, weekday letters down the side. Cells share the width, so a longer period gets smaller
   cells rather than a smaller grid. */
.matrix-calendar[data-layout="heatmap"] {
  grid-template-columns: 18px minmax(0, 1fr);
}
.matrix-calendar[data-layout="heatmap"] .matrix-months {
  grid-column: 2;
  display: flex;
  justify-content: space-between;
  gap: var(--space-1-5);
  color: var(--muted);
  font-size: var(--text-xs);
  white-space: nowrap;
}
.matrix-calendar[data-layout="heatmap"] .matrix-weekdays {
  display: grid;
  grid-template-rows: repeat(7, minmax(0, 1fr));
  gap: var(--space-1);
  font-size: var(--text-xs);
  line-height: 1;
  color: var(--muted);
}
/* The letters add no height of their own, so they never stretch their column past the cells beside them; each is
   stretched to its row and centred in it, however small the cells are. */
.matrix-calendar[data-layout="heatmap"] .matrix-weekdays span {
  display: flex;
  align-items: center;
  contain: size;
}
.matrix-calendar[data-layout="heatmap"] .matrix-grid {
  grid-auto-flow: column;
  grid-template-rows: repeat(7, minmax(0, 1fr));
  grid-template-columns: repeat(var(--weeks), minmax(0, 1fr));
}
.matrix-calendar[data-layout="heatmap"] .matrix-cell,
.matrix-calendar[data-layout="heatmap"] .matrix-blank {
  aspect-ratio: 1;
  max-height: 48px;
}
.matrix-dense .matrix-calendar .matrix-mark {
  display: none;
}
.matrix-dense .matrix-calendar .matrix-grid,
.matrix-dense .matrix-calendar .matrix-weekdays {
  gap: 3px;
}
.matrix-dense .matrix-calendar .matrix-cell,
.matrix-dense .matrix-calendar .matrix-blank {
  border-radius: 2px;
}
.matrix-reading {
  display: flex;
  flex-direction: column;
  gap: var(--space-3-5);
  min-width: 0;
}
.matrix-reading h3 {
  font: 700 var(--text-lg)/1.2 var(--display);
  letter-spacing: -0.03em;
  margin: 0;
  overflow-wrap: anywhere;
}
.matrix-reading dl {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-3);
  margin: 0;
}
.matrix-reading dt {
  font-size: var(--text-xs);
  color: var(--muted);
}
.matrix-reading dd {
  font-size: var(--text-sm);
  margin: var(--space-1) 0 0;
  font-weight: 700;
  overflow-wrap: anywhere;
}
/* A day with nothing on it: the message fills the space the records would, and the button stays at the bottom. */
.matrix-reading > .empty {
  flex: 1 1 auto;
  display: grid;
  place-content: center;
  padding: var(--space-4);
  border: 1px dashed var(--line);
  border-radius: var(--radius-md);
  text-align: center;
}
.matrix-reading > .row:last-child {
  margin-top: auto;
}
.matrix-reading > .row > button {
  flex: 1 1 auto;
}
.matrix-day {
  flex: 0 1 220px;
  font-size: var(--text-sm);
}
.matrix-legend {
  margin-block: 0;
}
.matrix-legend .matrix-key {
  border-radius: 3px;
  width: 12px;
  height: 12px;
  background: var(--tone-bg);
}
@media (max-width: 700px) {
  #history-return-period {
    justify-self: stretch;
  }
  .history-overview {
    grid-template-columns: 1fr;
  }
  .history-period-bar {
    align-items: stretch;
    gap: var(--space-3);
  }
  .history-period-bar > .field {
    flex: 1 1 100%;
    justify-content: space-between;
  }
  .history-period-bar > .field select {
    flex: 1 1 auto;
  }
  .history-period-bar > .meta {
    flex-basis: 100%;
    min-width: 0;
  }
  .history-period-bar > .primary {
    width: 100%;
  }
  .history-disclosure > summary {
    flex-wrap: wrap;
  }
  .history-disclosure > summary .meta {
    text-align: left;
  }
  .matrix-day {
    flex-basis: 100%;
  }
  .matrix-mode {
    flex: 1 1 100%;
    min-width: 0;
  }
  .matrix-calendar[data-layout="list"] .matrix-cell {
    grid-template-columns: 4.2rem 3.2rem minmax(0, 1fr);
    column-gap: var(--space-2-5);
    padding-inline: var(--space-2-5);
  }
}
@media (max-width: 700px) {
  /* A month of days is six columns: let the grid use the panel's edge so each day is a touch-sized target. */
  .matrix-calendar[data-layout="heatmap"] {
    grid-template-columns: 14px minmax(0, 1fr);
    gap: var(--space-2) var(--space-1);
    width: calc(100% + 16px);
    margin-inline: -8px;
  }
  .matrix-calendar[data-layout="heatmap"] .matrix-grid {
    gap: 3px;
  }
  .matrix-calendar[data-layout="heatmap"] .matrix-weekdays {
    gap: 3px;
  }
  .matrix-dense .matrix-calendar .matrix-grid,
  .matrix-dense .matrix-calendar .matrix-weekdays {
    gap: var(--space-0-5);
  }
  .matrix-calendar[data-layout="heatmap"] .matrix-months {
    font-size: var(--text-xs);
  }
}
@media (forced-colors: active) {
  .matrix-cell {
    border: 1px solid CanvasText;
  }
  .matrix-cell[aria-pressed="true"] {
    outline-color: Highlight;
  }
  .matrix-dense .matrix-calendar .matrix-mark {
    display: inline;
  }
  .matrix-reading {
    border-color: CanvasText;
  }
}

/* The activity, symptom and trigger editors are sections that start closed, so the page is short until you open one. */
.list-section {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--bg);
}
.list-section > summary {
  cursor: pointer;
  font-weight: 700;
  list-style: none;
  display: flex;
  gap: var(--space-2);
  align-items: baseline;
  min-height: 44px;
  padding: var(--space-2-5) var(--space-3);
  box-sizing: border-box;
  align-items: center;
}
.list-section > summary::-webkit-details-marker {
  display: none;
}
.list-section > summary::before {
  content: "▸";
  color: var(--accent);
  transition: transform var(--dur-fast) var(--ease);
}
.list-section[open] > summary::before {
  transform: rotate(90deg);
}
.list-section[open] > summary {
  border-bottom: 1px solid var(--line);
}
.list-section > .list-body {
  display: grid;
  gap: var(--space-2-5);
  padding: var(--space-3);
}
.list-section > summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  .list-section > summary::before {
    transition: none;
  }
}

/* Section shortcuts scroll a panel to the top; leave room for the sticky tab bar. */
#trends-panel,
#history-records,
#history-share,
#profile-panel,
#settings-panel,
#pw-panel {
  scroll-margin-top: 84px;
}
#history-records h2:focus,
#history-share h2:focus {
  outline: none;
}
#history-records h2:focus-visible,
#history-share h2:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* Touch targets: text-style buttons are at least 44px tall, without changing how they read. */
.x {
  min-height: 44px;
  padding: 0 var(--space-1-5);
  display: inline-flex;
  align-items: center;
  text-underline-offset: 3px;
}
.panel > .x {
  margin-inline: -6px;
}

/* Today: the check-in shrinks to one line once chosen, so the activities rise up the screen. */
.checkin-done {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-1-5) var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--bg);
}
.checkin-done .dot {
  margin-right: var(--space-2);
}
.checkin-done b {
  font-family: var(--display);
}

/* First-run checklist */
.onboarding {
  border-left: 4px solid var(--accent);
}
.steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-2-5);
}
.steps li {
  display: flex;
  gap: var(--space-2-5);
  align-items: flex-start;
}
.steps .tick {
  flex: none;
  width: 22px;
  height: 22px;
  margin-top: 1px;
  border-radius: 50%;
  border: 2px solid var(--line);
  display: grid;
  place-items: center;
  font-size: var(--text-sm);
  font-weight: 800;
  color: var(--surface);
}
.steps li.done .tick {
  background: var(--accent);
  border-color: var(--accent);
}
.steps li.done .tick::before {
  content: "✓";
}
.steps li.done > span:last-child {
  color: var(--muted);
  text-decoration: line-through;
}
#step-wording .tick {
  visibility: hidden; /* a choice, not a step to finish */
}
.step-wording-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1-5) var(--space-3);
}
.step-wording {
  display: inline-flex;
  gap: var(--space-2);
}
.app-shell .step-wording button[aria-pressed="true"],
.app-shell .plan-daytype button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}
.plan-daytype {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: var(--space-1-5) 0 var(--space-3);
}
.step-budget {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}
.step-budget input {
  width: 5.5rem;
}

/* Help is a view opened from the header, not a tab: Back returns to where you were. */
#help-back {
  justify-self: start;
  margin-bottom: var(--space-1-5);
}

/* Episode form: one label style throughout, and Save stays in reach on a phone. */
.field-block {
  display: grid;
  gap: var(--space-1-5);
}
.legend {
  font-weight: 700;
}
.save-bar {
  display: grid;
  gap: var(--space-2-5);
}
@media (max-width: 700px) {
  .save-bar {
    position: sticky;
    bottom: 0;
    z-index: 4;
    background: var(--surface);
    margin-inline: -16px;
    padding: var(--space-3) var(--space-4) calc(var(--space-3) + env(safe-area-inset-bottom, 0));
    border-top: 1px solid var(--line);
  }
}
.banner.welcome {
  border-left-color: var(--accent);
  background: var(--accent-soft);
}

/* One frame width for every view, so the header and tabs never jump; each view sets its own content width. */
#today-panel,
#episode-panel {
  width: 100%;
  max-width: 560px;
  margin-inline: auto;
}
#account-panel,
#help-panel {
  width: 100%;
  max-width: 760px;
  margin-inline: auto;
}
.today-side {
  display: grid;
  gap: var(--space-4-5);
  align-content: start;
}
@media (min-width: 960px) {
  #today-panel {
    max-width: none;
    grid-template-columns: minmax(320px, 400px) minmax(0, 1fr);
    align-items: start;
  }
  #today-panel > * {
    grid-column: 2;
  }
  #today-panel > #onboarding,
  #today-panel > #today-ongoing,
  #today-panel > #day-notice {
    grid-column: 1/-1;
  }
  #today-panel > .today-side {
    grid-column: 1;
    grid-row: span 2;
    position: sticky;
    top: 76px;
    max-height: calc(100vh - 92px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
}

/* Header: one row. The save status floats under it and takes no space; the account menu holds sign-out. */
#sync {
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 6;
  margin: var(--space-0-5) 0 0;
  max-width: min(100%, 440px);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: var(--text-sm);
  text-align: right;
  min-height: 0;
  line-height: var(--leading-snug);
}
#sync[data-state="saved"] {
  pointer-events: none;
}
.menu {
  position: relative;
}
.menu > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  cursor: pointer;
  border-radius: var(--radius-pill);
  padding: var(--space-0-5) var(--space-2-5) var(--space-0-5) var(--space-0-5);
}
.menu > summary::-webkit-details-marker {
  display: none;
}
.menu > summary:hover .avatar {
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.menu > summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--bg);
  font: 700 var(--text-sm) var(--display);
}
.menu-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: var(--z-menu);
  min-width: 210px;
  display: grid;
  padding: var(--space-1-5);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-pop);
}
.menu-pop form {
  display: block;
}
.menu-item {
  font: inherit;
  width: 100%;
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  text-align: left;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--fg);
  cursor: pointer;
}
.menu-item:hover,
.menu-item:focus-visible {
  background: var(--accent-soft);
}

/* The day: the date reads in the person's own format and opens the native picker. */
.daynav .mid {
  position: relative;
  cursor: pointer;
}
.day-date {
  color: var(--muted);
  font-size: var(--text-sm);
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}
.day-pick {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  padding: 0;
  border: 0;
}

/* History: a starter panel for new accounts, and filters that fold away. */
.history-filter-panel > summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 44px;
  cursor: pointer;
}
.history-filter-panel > summary::-webkit-details-marker {
  display: none;
}
.history-filter-panel > summary h2::before {
  content: "▸ ";
  color: var(--accent);
}
.history-filter-panel[open] > summary h2::before {
  content: "▾ ";
}
.history-filter-panel > summary .meta {
  text-align: right;
  overflow-wrap: anywhere;
}

/* Phones: the tabs move to a bar along the bottom, within reach of a thumb and never clipped. */
@media (max-width: 600px) {
  nav {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0;
    padding: var(--space-1-5) var(--space-1-5)
      calc(var(--space-1-5) + env(safe-area-inset-bottom, 0));
    gap: var(--space-1);
    background: var(--surface);
    border-top: 1px solid var(--line);
    z-index: 15;
    overflow: visible;
  }
  nav button {
    flex: 1 1 0;
    min-width: 0;
    min-height: 48px;
    padding: var(--space-2) var(--space-0-5);
    font-size: var(--text-sm);
    border: 0;
    border-radius: var(--radius-md);
    background: none;
  }
  nav button[aria-selected="true"] {
    background: var(--accent-soft);
    color: var(--accent);
  }
  .wrap {
    padding-bottom: calc(92px + env(safe-area-inset-bottom, 0));
  }
  .toastbar {
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  }
  .save-bar {
    bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  }
  .date,
  .who {
    display: none;
  }
  header {
    min-height: 48px;
  }
}

/* Off-site protection and account security share the app's theme and accessible controls. */
.service-panel {
  gap: var(--space-5);
}
.service-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
}
.eyebrow {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin: 0 0 5px;
}
.service-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}
.service-stats > div {
  display: grid;
  gap: var(--space-1-5);
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--bg);
}
.service-stats b {
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}
.service-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3-5);
}
.service-grid input,
.service-grid select {
  width: 100%;
  min-width: 0;
}
.service-details {
  border-top: 1px solid var(--line);
  padding-block: var(--space-3);
}
.service-details > summary {
  cursor: pointer;
  min-height: 44px;
  font-weight: 700;
}
.service-details > summary .meta {
  display: block;
  font-weight: 400;
  margin-left: var(--space-4);
}
.service-details[open] > summary {
  margin-bottom: var(--space-3-5);
}
.service-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2-5);
}
.service-runs li {
  align-items: start;
}
.service-runs p {
  margin-block: 5px;
}
.service-panel form {
  gap: var(--space-3);
}
.service-panel .list li {
  overflow-wrap: anywhere;
}
.security-secret {
  overflow-wrap: anywhere;
  user-select: all;
  padding: var(--space-3-5);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--bg);
}
.security-qr {
  width: 220px;
  max-width: 100%;
  background: white;
  padding: var(--space-3);
  border-radius: var(--radius-md);
}
.security-codes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
}
.security-codes code {
  padding: var(--space-2);
  background: var(--bg);
  border-radius: var(--radius-sm);
  user-select: all;
}
.login .auth-links {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.login .auth-links button {
  font: inherit;
  color: var(--accent);
  border: 0;
  background: none;
  min-height: 44px;
  cursor: pointer;
}
.login form[hidden] {
  display: none;
}
.login .panel {
  width: 100%;
}
#admin-panel {
  width: 100%;
  max-width: 900px;
  margin-inline: auto;
}
@media (max-width: 600px) {
  .service-grid,
  .service-stats {
    grid-template-columns: 1fr;
  }
  .service-actions > * {
    flex: 1 1 160px;
  }
  .service-heading {
    align-items: start;
  }
}

.security-dialog {
  max-width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 40px);
  overflow: auto;
  color: var(--fg);
  background: var(--surface);
  padding: var(--space-6);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}
.security-dialog:not([open]) {
  display: none;
}
.security-dialog::backdrop {
  background: color-mix(in srgb, var(--fg) 40%, transparent);
  backdrop-filter: blur(3px);
}

#security-panel label:not(.radio),
.security-dialog label {
  display: grid;
  gap: var(--space-1-5);
  font-weight: 700;
}
.service-panel .field .meta {
  font-weight: 400;
}

.service-grid {
  align-items: start;
}
.service-grid .field {
  align-content: start;
}
.service-details .field {
  margin-bottom: var(--space-1-5);
}

/* Logged activity editor: clear metadata and stable, touch-friendly actions. */
#activity-log {
  margin-top: var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
}
#activity-log > summary {
  display: flex;
  align-items: center;
  gap: var(--space-2-5);
  list-style: none;
  cursor: pointer;
  padding: var(--space-3-5) var(--space-4);
  font-weight: 700;
  color: var(--accent);
  background: var(--bg);
}
#activity-log > summary::-webkit-details-marker {
  display: none;
}
#activity-log > summary::before {
  content: "›";
  font-size: 1.3em;
  line-height: 1;
  transform: rotate(0deg);
}
#activity-log[open] > summary::before {
  transform: rotate(90deg);
}
#activity-log > summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -3px;
}
#activity-log[open] > summary {
  border-bottom: 1px solid var(--line);
}
#entries {
  padding: 0 var(--space-4);
  gap: 0;
}
#entries > li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-4) 0;
}
.logged-activity {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--space-1) var(--space-3);
  min-width: 0;
}
.logged-time {
  grid-column: 1/-1;
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}
.logged-name {
  overflow-wrap: anywhere;
  line-height: var(--leading-snug);
}
.logged-cost {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  align-self: start;
  line-height: var(--leading-snug);
}
.logged-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
}
.logged-actions button {
  min-height: 44px;
  min-width: 76px;
  margin: 0;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  line-height: var(--leading-tight);
  border-radius: var(--radius-sm);
  text-decoration: none;
}
.logged-actions .logged-remove {
  color: var(--red);
  border-color: color-mix(in srgb, var(--red) 45%, var(--line));
}
@media (max-width: 600px) {
  #entries > li {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-3);
  }
  .logged-actions {
    width: 100%;
  }
  .logged-actions button {
    width: 100%;
  }
}

@media (max-width: 700px) {
  .history-visuals .chart-card {
    display: block;
    grid-row: auto;
  }
  .chart-combined {
    grid-column: auto;
  }
}
:root .app-loading .wrap > section[role="tabpanel"] {
  visibility: hidden;
}
.view-loading {
  display: none;
}
.app-loading .view-loading {
  display: block;
}
.profile-photo-picker {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}
.profile-photo-picker > div:last-child {
  flex: 1;
  min-width: 0;
}
.profile-photo-picker input {
  max-width: 100%;
}
.profile-avatar img,
.avatar img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
}

/* An editor opened from a timeline floats over the page, so the timeline and the scroll position stay where they were. */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  background: color-mix(in srgb, var(--fg) 45%, transparent);
}
form.is-sheet {
  position: fixed;
  z-index: var(--z-sheet);
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(540px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  margin: 0;
  padding: var(--space-4-5) var(--space-4-5) var(--space-3-5);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sheet);
}

/* On a phone the Save button stays in reach above the tab bar while a long form is on screen. */
@media (max-width: 700px) {
  .row.sticky-save > .primary {
    position: sticky;
    bottom: calc(78px + env(safe-area-inset-bottom, 0px));
    z-index: 4;
    box-shadow: 0 6px 18px #00000033;
  }
}
/* The activity and list editor on a phone: the name on top, points and group below it, the move buttons last. */
@media (max-width: 480px) {
  .order-row {
    display: grid;
    grid-template-columns: 44px 4.5rem minmax(0, 1fr);
    gap: var(--space-1-5) var(--space-2);
    align-items: center;
  }
  .order-row > .drag-handle {
    grid-column: 1;
    grid-row: 1 / span 3;
  }
  .order-row > input[type="text"]:not(.order-group) {
    grid-column: 2 / span 2;
    grid-row: 1;
    width: 100%;
  }
  .order-row > input.order-cost {
    grid-column: 2;
    grid-row: 2;
    margin: 0;
    width: 4.5rem;
  }
  .order-row > input.order-group {
    grid-column: 3;
    grid-row: 2;
    width: 100%;
    max-width: none;
    margin: 0;
  }
  .order-row:not(:has(.order-cost)) > input.order-group {
    grid-column: 2 / span 2;
  }
  .order-row > .order-actions {
    grid-column: 2 / span 2;
    grid-row: 3;
    margin: 0;
    justify-self: end;
  }
}
