:root {
  --bg: #f6f3ec;
  --surface: #ffffff;
  --ink: #14213d;
  --muted: #4a5571;
  --line: #d9d4c7;
  --accent: #b86b00;      /* amber, AA on white */
  --accent-bg: #fff1d6;
  --blue: #1f64b8;
  --blue-bg: #e3eefc;
  --up: #b42318;
  --down: #087443;
  --focus: #1f64b8;
  --map-land: #e7e2d6;
  --map-edge: #c9c2b2;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1626; --surface: #172036; --ink: #edf1fa; --muted: #aeb8cf; --line: #2c3854;
    --accent: #f5b13d; --accent-bg: #3a2c12; --blue: #7fb2f5; --blue-bg: #1c2d4d;
    --up: #ff8a7a; --down: #5fd4a0; --focus: #7fb2f5; --map-land: #24304b; --map-edge: #34415f;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--blue); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sprite { display: none; }
.ico {
  width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.95em; }

/* header / footer */
.top {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  max-width: 1200px; margin: 0 auto; padding: 16px;
}
.mascot { width: 56px; height: 56px; }
.brand { flex: 1 1 200px; min-width: 200px; }
.actions { display: flex; gap: 8px; margin-left: auto; }
.brand h1 { margin: 0; font-size: 1.6rem; line-height: 1.1; letter-spacing: -0.02em; }
.brand p { margin: 0; color: var(--muted); font-size: 0.95rem; }
.foot {
  display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: center;
  padding: 24px 16px 40px; color: var(--muted); font-size: 0.95rem;
}

main { max-width: 1200px; margin: 0 auto; padding: 0 16px; display: grid; gap: 16px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  color: var(--ink); font: inherit; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.icon-only { width: 44px; justify-content: center; padding: 0; }
.linkish {
  min-height: 44px; border: 0; background: none; color: var(--blue); font: inherit;
  text-decoration: underline; cursor: pointer;
}

/* filters */
.controls { display: flex; flex-wrap: wrap; gap: 12px 24px; }
.seg { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0; padding: 0; border: 0; }
.seg legend {
  float: left; display: flex; align-items: center; gap: 6px; margin-right: 6px;
  color: var(--muted); font-size: 0.95rem;
}
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span {
  display: inline-flex; align-items: center; gap: 4px; min-height: 44px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
}
.seg b { font-weight: 500; color: var(--muted); font-size: 0.85em; }
.seg input:checked + span { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.seg input:checked + span b { color: inherit; opacity: 0.8; }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px;
}
.stat .n { font-size: 1.7rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 0.95rem; }

/* cards */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 16px; min-width: 0;
}
.card h2 { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 1.25rem; }
.hint { margin: 4px 0 12px; color: var(--muted); font-size: 0.95rem; }
.map { height: clamp(280px, 52vw, 520px); }

/* calendar table: real table; rows stack into cards on narrow screens */
.cal { width: 100%; border-collapse: collapse; }
.cal th, .cal td { text-align: left; vertical-align: top; padding: 10px 8px; border-top: 1px solid var(--line); }
.cal thead th {
  position: sticky; top: 0; z-index: 1; background: var(--surface);
  color: var(--muted); font-weight: 600; font-size: 0.9rem; border-top: 0;
}
.cal .date { white-space: nowrap; font-variant-numeric: tabular-nums; }
.cal .ev-name { font-weight: 600; }
.cal .sub { color: var(--muted); font-size: 0.92rem; }
.cal tr.exposed td:first-child { box-shadow: inset 4px 0 0 var(--accent); }
.cal tr.opex td { background: var(--blue-bg); color: var(--ink); font-size: 0.95rem; }
.cal tr.month th {
  background: var(--bg); font-size: 0.95rem; padding: 6px 8px; color: var(--muted);
}
.cal tr.flash td { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: var(--accent-bg); } }
@media (prefers-reduced-motion: reduce) { .cal tr.flash td { animation: none; background: var(--accent-bg); } }

.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.tag {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px;
  border: 1px solid var(--line); font-size: 0.85rem; white-space: nowrap;
}
.tag.watch { background: var(--accent-bg); border-color: var(--accent); }
.tag.rule, .tag.llm { border-style: dashed; color: var(--muted); }
.tag .dir-up { color: var(--up); }
.tag .dir-down { color: var(--down); }
.tag.tentative { border-style: dashed; }

@media (max-width: 720px) {
  .cal thead { display: none; }
  .cal, .cal tbody, .cal tr, .cal td, .cal th { display: block; width: 100%; }
  .cal tr { border-top: 1px solid var(--line); padding: 8px 0; }
  .cal td, .cal th { border: 0; padding: 2px 8px; }
  .cal td[data-label]::before {
    content: attr(data-label) " "; color: var(--muted); font-size: 0.85rem; font-weight: 600;
  }
  .cal tr.exposed { box-shadow: inset 4px 0 0 var(--accent); }
  .cal tr.exposed td:first-child { box-shadow: none; }
}

/* loading / empty / error */
.state { display: grid; justify-items: center; gap: 8px; padding: 32px 16px; text-align: center; color: var(--muted); }
.state[hidden] { display: none; }
.state.loading img { animation: bob 1.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-4deg); } }
@media (prefers-reduced-motion: reduce) { .state.loading img { animation: none; } }

/* dialog */
dialog {
  width: min(640px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0;
  border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--ink);
}
dialog::backdrop { background: rgb(10 15 30 / 0.55); }
dialog section { padding: 0 20px 20px; }
dialog h3 { display: flex; align-items: center; gap: 8px; margin: 18px 0 6px; font-size: 1.05rem; }
.dlg-head {
  display: flex; align-items: center; gap: 12px; padding: 12px 12px 0 20px;
}
.dlg-head h2 { flex: 1; margin: 0; font-size: 1.3rem; }
.fresh { margin: 0; padding-left: 20px; }
.fresh .bad { color: var(--up); font-weight: 600; }
html:has(dialog[open]) { overflow: hidden; }

/* settings dialog */
.settings { display: grid; gap: 8px; padding: 0 20px 20px; }
.settings label { font-weight: 600; font-size: 0.95rem; margin-top: 6px; }
.settings select, .settings input {
  min-height: 44px; width: 100%; padding: 0 10px; font: inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
.settings code { font-size: 0.9em; }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); justify-self: start; }
.meter { height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; background: var(--accent); }
#set-status.bad { color: var(--up); font-weight: 600; }
#set-status.good { color: var(--down); font-weight: 600; }

/* map card header + reserves */
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.res .val { font-variant-numeric: tabular-nums; font-weight: 600; }
.res .chg-down { color: var(--up); }   /* a falling buffer is the risk signal */
.res .chg-up { color: var(--down); }
.res .na { color: var(--muted); font-weight: 400; }
.res-sources { margin: 10px 0 0; font-size: 0.9rem; color: var(--muted); }
