:root {
  color-scheme: light;
  --page: #f6f6f4;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --low: #2a78d6;
  --mid: #a8a69e;
  --high: #e34948;
  --sel: rgba(42, 120, 214, 0.14);
  --error: #c62f2f;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --low: #3987e5;
    --mid: #6b6a64;
    --high: #e66767;
    --sel: rgba(57, 135, 229, 0.22);
    --error: #ff7b7b;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  padding: env(safe-area-inset-top) 0 calc(env(safe-area-inset-bottom) + 88px);
  -webkit-tap-highlight-color: transparent;
}
main { max-width: 720px; margin: 0 auto; padding: 0 16px; }
button, select, input { font: inherit; color: inherit; }
a { color: var(--accent); }
h2 { font-size: 17px; margin: 0 0 8px; }
h3 { font-size: 15px; margin: 20px 0 8px; color: var(--ink-2); }
.muted { color: var(--ink-2); }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
  max-width: 720px; margin: 0 auto; padding: 10px 16px;
  background: var(--page);
}
.icon-btn {
  border: 0; background: none; padding: 8px; border-radius: 10px; cursor: pointer;
  color: var(--ink-2); line-height: 0; min-width: 40px; min-height: 40px;
}

.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 2px; }
.seg button {
  border: 0; background: none; padding: 6px 12px; border-radius: 8px; cursor: pointer;
  color: var(--ink-2); font-weight: 500; min-height: 36px;
}
.seg button[aria-selected="true"] { background: var(--ink); color: var(--page); }
.seg.small button { padding: 4px 10px; min-height: 32px; font-size: 14px; }

.now { padding: 8px 0 16px; }
.now-label { color: var(--ink-2); font-size: 14px; }
.hero { font-size: 48px; font-weight: 700; line-height: 1.1; letter-spacing: -0.02em; }
.hero-unit { font-size: 18px; font-weight: 500; color: var(--ink-2); letter-spacing: 0; }
.now-sub { color: var(--ink-2); font-size: 14px; margin-top: 4px; }
.now-mode { color: var(--muted); font-size: 12px; margin-top: 2px; }

.row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.legend { display: flex; gap: 10px; font-size: 12px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw.low { background: var(--low); } .sw.mid { background: var(--mid); } .sw.high { background: var(--high); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 12px; }
.chart-card { padding: 8px 4px 8px 0; }
.chart-wrap { position: relative; }
#chart { display: block; width: 100%; height: 220px; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
#chart .grid { stroke: var(--grid); stroke-width: 1; }
#chart .base { stroke: var(--axis); stroke-width: 1; }
#chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
#chart .daylabel { fill: var(--ink-2); font-size: 11px; font-weight: 600; }
#chart .dayline { stroke: var(--axis); stroke-dasharray: 3 3; }
#chart .nowline { stroke: var(--ink); stroke-width: 1.5; }
#chart .bar.low { fill: var(--low); } #chart .bar.mid { fill: var(--mid); } #chart .bar.high { fill: var(--high); }
#chart .bar.past { opacity: 0.35; }
#chart .bar.hover { opacity: 1; filter: brightness(1.15); }
#chart .selband { fill: var(--sel); }
.chart-note { font-size: 12px; color: var(--muted); padding: 2px 12px 0; }
.tip {
  position: absolute; top: 4px; pointer-events: none;
  background: var(--ink); color: var(--page); border-radius: 8px; padding: 4px 8px;
  font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums;
}

.cheapest { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 14px; }
.cheapest select { padding: 2px 4px; border-radius: 6px; border: 1px solid var(--border); background: var(--page); }
.link { border: 0; background: none; padding: 4px 0; color: var(--accent); font-weight: 600; cursor: pointer; text-align: left; }
.link:disabled { color: var(--muted); cursor: default; font-weight: 400; }

.list .day { margin: 20px 0 6px; font-size: 15px; font-weight: 700; display: flex; justify-content: space-between; align-items: baseline; }
.list .day small { font-weight: 400; color: var(--ink-2); font-size: 13px; }
.list .empty { color: var(--ink-2); font-size: 14px; padding: 12px; }
.slots { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.slot {
  display: grid; grid-template-columns: 96px 1fr auto; align-items: center; gap: 10px;
  width: 100%; border: 0; border-top: 1px solid var(--border); background: none;
  padding: 9px 12px; text-align: left; cursor: pointer; font-variant-numeric: tabular-nums;
}
.slot:first-child { border-top: 0; }
.slot .t { color: var(--ink-2); font-size: 14px; }
.slot .barbg { height: 6px; border-radius: 3px; background: var(--grid); overflow: hidden; position: relative; }
.slot .barbg i { position: absolute; top: 0; bottom: 0; left: 0; border-radius: 3px; }
.slot .barbg i.low { background: var(--low); } .slot .barbg i.mid { background: var(--mid); } .slot .barbg i.high { background: var(--high); }
.slot .p { font-weight: 600; min-width: 64px; text-align: right; }
.slot.past { opacity: 0.45; }
.slot.current { background: var(--sel); }
.slot.current .t { color: var(--ink); font-weight: 600; }
.slot.selected { box-shadow: inset 4px 0 0 var(--accent); background: var(--sel); }
.show-past { width: 100%; border: 0; background: none; color: var(--accent); padding: 10px 12px; text-align: left; cursor: pointer; font-size: 14px; }

.rem-list { list-style: none; margin: 0; padding: 0; }
.rem-list li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--border); font-size: 14px; }
.rem-list li:first-child { border-top: 0; }
.rem-list .grow { flex: 1; }
.rem-list small { color: var(--ink-2); display: block; }

.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; gap: 10px; align-items: center;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
}
.actionbar[hidden] { display: none; }
.ab-text { flex: 1; min-width: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.ab-sub { font-weight: 400; font-size: 13px; color: var(--ink-2); }

.primary, .secondary, .btnlike {
  border-radius: 10px; padding: 10px 16px; font-weight: 600; cursor: pointer; min-height: 44px;
  text-decoration: none; display: inline-flex; align-items: center;
}
.primary { background: var(--accent); color: #fff; border: 0; }
.secondary, .btnlike { background: none; color: var(--ink); border: 1px solid var(--border); }
.primary:disabled { opacity: 0.5; }

dialog {
  border: 0; padding: 0; background: var(--surface); color: var(--ink);
  width: min(560px, 100vw); max-width: 100vw; max-height: 92vh;
  border-radius: 18px 18px 0 0; margin: auto auto 0;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.sheet { padding: 20px 16px calc(16px + env(safe-area-inset-bottom)); }
.btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.btns.left { justify-content: flex-start; margin-top: 8px; }
.field { display: block; margin: 10px 0; font-size: 14px; color: var(--ink-2); }
.field small { color: var(--muted); }
.field select, .field input {
  display: block; width: 100%; margin-top: 4px; padding: 10px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--page); color: var(--ink); font-size: 16px;
}
.check { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.check input { width: 20px; height: 20px; }
.fees[aria-disabled="true"] { opacity: 0.45; }
.fees h4 { margin: 16px 0 0; font-size: 14px; }
.muted.small { font-size: 13px; }
.pair { display: flex; gap: 12px; }
.pair .field { flex: 1; }
.offsets { border: 0; padding: 0; margin: 8px 0; }
.offsets label { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--border); }
.offsets label:first-child { border-top: 0; }
.offsets input[type="radio"] { width: 20px; height: 20px; }
.offsets .custom input[type="number"] { width: 64px; padding: 6px; border-radius: 8px; border: 1px solid var(--border); background: var(--page); }
.offsets .custom select { padding: 6px; border-radius: 8px; border: 1px solid var(--border); background: var(--page); }
.error { color: var(--error); font-size: 14px; }
.footer { color: var(--muted); font-size: 12px; text-align: center; margin: 24px 0; }
.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 12px); transform: translateX(-50%);
  background: var(--ink); color: var(--page); padding: 10px 14px; border-radius: 10px; z-index: 20;
  font-size: 14px; max-width: calc(100vw - 32px);
}
