/* Layout: header with the week total, a wrapping grid of day cards (the score is
   the hero), settings below; tapping a day opens its points ledger in a dialog. */
:root {
  color-scheme: light;
  --bg: #f1f4f8;
  --surface: #ffffff;
  --text: #17202c;
  --muted: #5b6676;
  --line: #d9dfe8;
  --chip: #e8edf4;
  --accent: #2b60d6;
  --good: #1b7d46;
  --ok: #985d0b;
  --low: #bf3a2c;
  --font-body: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-num: "Barlow Semi Condensed", "Arial Narrow", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e1218;
    --surface: #19202a;
    --text: #e8edf4;
    --muted: #9ba6b6;
    --line: #2c3543;
    --chip: #242c38;
    --accent: #85aaff;
    --good: #4ade80;
    --ok: #fbbf24;
    --low: #f87171;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1218;
  --surface: #19202a;
  --text: #e8edf4;
  --muted: #9ba6b6;
  --line: #2c3543;
  --chip: #242c38;
  --accent: #85aaff;
  --good: #4ade80;
  --ok: #fbbf24;
  --low: #f87171;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0 auto;
  max-width: 960px;
  padding-block: 16px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--font-body);
}

button, input { font: inherit; color: inherit; }

button {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}

button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input:not([type=checkbox]):not([type=radio]) {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  min-width: 0;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
}

h1, h2, h3 { text-wrap: balance; }
h1 { margin: 0; font: 700 1.6rem/1.15 var(--font-num); letter-spacing: 0.01em; }
.sub { margin: 2px 0 0; color: var(--muted); }

.week-total { text-align: right; }
.week-total span { display: block; font: 700 2rem/1 var(--font-num); font-variant-numeric: tabular-nums; }
.week-total small { color: var(--muted); white-space: nowrap; font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; }

.week-switch {
  display: inline-flex;
  margin-bottom: 16px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}
.week-switch button {
  padding: 5px 14px;
  border: none;
  border-radius: 999px;
  background: none;
  color: var(--muted);
}
.week-switch button[aria-pressed="true"] { background: var(--chip); color: var(--text); font-weight: 600; }

.banner {
  margin-bottom: 16px;
  padding: 10px 12px;
  border: 1px solid var(--low);
  border-radius: 10px;
  background: var(--surface);
  color: var(--low);
}
.banner button { margin-left: 4px; }

.days {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.day {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding: 14px;
  border-radius: 12px;
  color: var(--text);
  text-align: left;
}

.day.today { border: 2px solid var(--accent); padding: 13px; }
.day-head { display: flex; flex-wrap: wrap; justify-content: space-between; column-gap: 8px; }
.day-date { white-space: nowrap; }
.day-name { font-weight: 600; }
.day-date, .day-weather { color: var(--muted); font-size: 0.9rem; }
.day-score { font: 700 2.75rem/1 var(--font-num); font-variant-numeric: tabular-nums; }
.day-meta { display: flex; flex-wrap: wrap; gap: 6px; min-height: 1.5em; }

.good { color: var(--good); }
.ok { color: var(--ok); }
.low { color: var(--low); }
.day.good, .day.ok, .day.low { color: var(--text); }
.day.good .day-score { color: var(--good); }
.day.ok .day-score { color: var(--ok); }
.day.low .day-score { color: var(--low); }

.tag {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--chip);
  font-size: 0.8rem;
}
.tag.pref-preferred { color: var(--good); }
.tag.pref-hated { color: var(--low); }
.tag.temp-unusual { color: var(--ok); }

.panel {
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.panel summary { cursor: pointer; font-weight: 600; }
.panel > :not(summary) { margin-top: 12px; }
.rules { padding-left: 20px; max-width: 65ch; }

.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.row input:not([type=checkbox]) { flex: 1 1 8rem; }
.row input[type=time] { flex: 0 0 auto; }
/* iOS collapses an empty time input to the height of its (empty) value. */
input[type=time]::-webkit-date-and-time-value { min-height: 1.45em; text-align: left; }
.error { color: var(--low); }

.setting { display: grid; gap: 4px; max-width: 28rem; }
.setting input[type=range] { width: 100%; accent-color: var(--accent); }
.setting small { color: var(--muted); }
.setting output { font-weight: 600; font-variant-numeric: tabular-nums; }
.sync { gap: 8px; }
/* Full size: iOS zooms into inputs smaller than 16px when they're focused. */
.sync input { flex: 1 1 12rem; min-width: 0; font-family: ui-monospace, Menlo, monospace; }
.sync-confirm { display: grid; gap: 8px; padding: 10px; border: 1px solid var(--low); border-radius: 8px; }
button.danger { color: var(--low); border-color: var(--low); font-weight: 600; }

dialog {
  width: min(440px, calc(100% - 32px));
  padding: 16px;
  border: none;
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }

.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.dialog-head h2 { margin: 0; font: 700 1.3rem/1.2 var(--font-num); }
.icon { padding: 2px 8px; border: none; background: none; color: var(--muted); }

.dlg-score { margin: 8px 0; font-size: 1.1rem; }
.dlg-score span { font: 700 2.25rem/1 var(--font-num); }

.breakdown, .appointments { margin: 0; padding: 0; list-style: none; }
.breakdown li, .appointments li {
  display: flex;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.breakdown li { justify-content: space-between; }
.breakdown .pts { font-variant-numeric: tabular-nums; font-weight: 600; }
.appointments .time { color: var(--muted); min-width: 3.5rem; font-variant-numeric: tabular-nums; }
.appointments .label { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.appointments .empty { color: var(--muted); }

.choice {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0 0;
  padding: 0;
  border: none;
}
.choice legend { padding: 0; margin-bottom: 8px; color: var(--muted); }
.choice label {
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice label:has(input:checked) { border-color: var(--accent); background: var(--chip); font-weight: 600; }
.choice label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

h3 { margin: 16px 0 4px; font-size: 1rem; }
#add-form { margin-top: 10px; }
