:root {
  --bg: #f5f6f3;
  --card: #ffffff;
  --ink: #1a1f1c;
  --muted: #5d6862;
  --line: #e2e6e2;
  --go: #15803d;
  --go-bg: #e7f4eb;
  --wait: #1d4ed8;
  --wait-bg: #e9effc;
  --none: #6b7280;
  --cheap: #3fa463;
  --normal: #c4ccc6;
  --pricey: #eea23b;
  --spike: #d64545;
  --past: 0.35;
  --focus: #2563eb;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 2px 10px rgb(0 0 0 / 0.04);
  --heat-0: #ffe45c;
  --heat-1: #ff9f2e;
  --heat-2: #ee3b2b;
  --heat-line: #c2410c;
  --grid: #e7ebe8;
  --night: rgb(60 90 160 / 0.08);
  --peak: rgb(214 69 69 / 0.09);
  /* price ramp, pale yellow → deep red; validated (dataviz validate_palette.js): CVD adjacent ΔE ≥ 8, steps spread in lightness */
  --h0: #fff59d; --h1: #ffca28; --h2: #ff9800; --h3: #f4511e; --h4: #c62828; --h5: #6d1b2b;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111513;
    --card: #1a201d;
    --ink: #e9eeea;
    --muted: #9aa69f;
    --line: #2a332e;
    --go: #4ade80;
    --go-bg: #15291d;
    --wait: #8fb0ff;
    --wait-bg: #18213a;
    --cheap: #3c9a5c;
    --normal: #4a544e;
    --pricey: #d18f33;
    --spike: #e05a5a;
    --past: 0.3;
    --shadow: none;
    --heat-0: #c9a92a;
    --heat-1: #d9792a;
    --heat-2: #d23f31;
    --heat-line: #fdba74;
    --grid: #27302b;
    --night: rgb(150 175 235 / 0.07);
    --peak: rgb(240 110 110 / 0.10);
    --h0: #f5e27a; --h1: #f2b51c; --h2: #ee8410; --h3: #e1521f; --h4: #c0352f; --h5: #8f2a3a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 560px; margin: 0 auto; padding: calc(10px + env(safe-area-inset-top)) 16px 4px;
}
.brand { display: flex; align-items: center; gap: 8px; color: inherit; text-decoration: none; font-weight: 650; font-size: 18px; }
.brand img { border-radius: 7px; }
.lang {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 4px 12px; font-size: 14px; font-weight: 600; cursor: pointer;
}

main { max-width: 560px; margin: 0 auto; padding: 4px 16px 24px; }
h2, h3 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* now */
.now { padding: 10px 2px 18px; }
.now-label { color: var(--muted); font-size: 14px; }
.now-price { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.now-price .big { font-size: 46px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.05; font-variant-numeric: tabular-nums; }
.now-price .unit { color: var(--muted); font-size: 17px; }
.word { font-weight: 650; font-size: 17px; padding-left: 4px; }
.word.cheap { color: var(--cheap); }
.word.normal { color: var(--muted); }
.word.pricey { color: var(--pricey); }
.word.spike { color: var(--spike); }
.now-sub { margin-top: 6px; font-size: 15px; }
.banner { background: var(--wait-bg); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin: 0 0 12px; }

/* machine cards */
.cards { display: grid; gap: 12px; }
.card {
  background: var(--card); border-radius: 16px; padding: 14px 16px 12px;
  box-shadow: var(--shadow); border: 1px solid var(--line);
  border-left: 5px solid var(--line);
}
.card.go { border-left-color: var(--go); }
.card.wait { border-left-color: var(--wait); }
.card-head { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 15px; }
.card-head svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.card-head h2 { font-size: 15px; font-weight: 600; color: var(--muted); flex: 1; min-width: 0; }
.btn.small-btn { min-height: 36px; padding: 4px 10px; font-size: 14px; color: var(--muted); border-radius: 999px; }
.headline { margin: 6px 0 2px; font-size: 21px; font-weight: 680; line-height: 1.25; }
.card.go .headline { color: var(--go); }
.card.wait .headline { color: var(--wait); }
.detail { margin: 0; color: var(--ink); font-size: 15px; }
.hint { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.btn {
  border: 1px solid var(--line); background: transparent; border-radius: 10px;
  padding: 8px 12px; min-height: 40px; cursor: pointer; font-size: 15px; font-weight: 550;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
}
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: var(--go); border-color: var(--go); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0b1a10; } }
.btn.danger { color: var(--spike); }
.rem {
  display: inline-flex; align-items: center; gap: 4px; background: var(--wait-bg); color: var(--wait);
  border-radius: 10px; padding: 4px 4px 4px 10px; font-size: 14px; font-weight: 550;
}
.rem button { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 18px; line-height: 1; padding: 4px 8px; min-height: 32px; }

/* price charts (electrify-style area) */
.days { margin-top: 6px; }
.days + .cards { margin-top: 20px; }
.day { margin-bottom: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 10px 6px 4px; box-shadow: var(--shadow); }
.day h3 { font-size: 15px; font-weight: 600; margin: 0 8px 2px; display: flex; gap: 8px; align-items: baseline; }
.day h3 .small { font-weight: 400; font-size: 13px; }
svg.chart { display: block; width: 100%; height: auto; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
svg.chart:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 8px; }
svg.chart .night { fill: var(--night); }
svg.chart .peak, svg.cols .peak { fill: var(--peak); }
svg.chart .grid { stroke: var(--grid); stroke-width: 1; }
svg.chart .axis { stroke: var(--muted); stroke-width: 1; opacity: .5; }
svg.chart .ylab, svg.chart .xlab { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
svg.chart .ylab { text-anchor: end; }
svg.chart .xlab { text-anchor: middle; }
svg.chart .pline { fill: none; stroke: var(--heat-line); stroke-width: 1.5; stroke-linejoin: round; }
svg.chart .past { fill: var(--card); opacity: .55; }
@media (prefers-color-scheme: dark) { svg.chart .past { opacity: .45; } }
svg.chart .nowline { stroke: var(--ink); stroke-width: 1.2; }
svg.chart .nowdot { fill: var(--ink); stroke: var(--card); stroke-width: 2; }
svg.chart .mm { fill: var(--ink); }
svg.chart .mmlab { fill: var(--ink); font-size: 10px; font-weight: 650; text-anchor: middle; font-variant-numeric: tabular-nums; paint-order: stroke; stroke: var(--card); stroke-width: 3px; }
svg.chart .xh { stroke: var(--ink); stroke-width: 1; }
svg.chart .xd { fill: var(--card); stroke: var(--ink); stroke-width: 2; }
svg.chart .hit { fill: transparent; cursor: crosshair; }
/* view switch */
.seg { display: flex; align-items: center; gap: 6px; margin: 0 2px 10px; flex-wrap: wrap; }
.seg .small { margin-right: 4px; }
.seg button { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 14px; min-height: 36px; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }

/* 15-minute columns on wide screens (sideways scroll) */
.colscroll { overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; padding-bottom: 2px; }
svg.cols { display: block; }
svg.cols .night { fill: var(--night); }
svg.cols .grid { stroke: var(--grid); stroke-width: 1; }
svg.cols .axis { stroke: var(--muted); stroke-width: 1; opacity: .5; }
svg.cols .hlab { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
svg.cols .blab { fill: var(--ink); font-size: 10px; font-variant-numeric: tabular-nums; }
svg.cols .bhit { fill: transparent; cursor: pointer; }
svg.cols .bar.h0 { fill: var(--h0); } svg.cols .bar.h1 { fill: var(--h1); } svg.cols .bar.h2 { fill: var(--h2); }
svg.cols .bar.h3 { fill: var(--h3); } svg.cols .bar.h4 { fill: var(--h4); } svg.cols .bar.h5 { fill: var(--h5); }
svg.cols .b.past .bar, svg.cols .b.past .blab { opacity: .38; }
svg.cols .b.now .bar { stroke: var(--ink); stroke-width: 2; }
svg.cols .b.now .blab, svg.cols .b.sel .blab { font-weight: 750; }
svg.cols .b.sel .bar { stroke: var(--focus); stroke-width: 2; }

/* 15-minute rows (electrify on a phone: time down the page, bars to the right) */
.qrows { display: grid; gap: 2px; padding: 4px 2px 6px; }
.qrow { display: grid; grid-template-columns: 46px 1fr 54px; align-items: center; column-gap: 8px; height: 22px; padding: 0 6px; border-radius: 5px; }
.qrow.hour { margin-top: 5px; }
.qrow.hour:first-child { margin-top: 0; }
.qrow.night { background: var(--night); }
.qrow.peak { background: var(--peak); }
.qrow .qt { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.qrow.hour .qt { color: var(--ink); font-weight: 650; }
.qrow .qb { position: relative; height: 13px; }
.qrow .qb i { position: absolute; top: 0; bottom: 0; border-radius: 0 4px 4px 0; }
.qrow .qb i.neg { border-radius: 4px 0 0 4px; }
.qrow .qb i.h0 { background: var(--h0); } .qrow .qb i.h1 { background: var(--h1); } .qrow .qb i.h2 { background: var(--h2); }
.qrow .qb i.h3 { background: var(--h3); } .qrow .qb i.h4 { background: var(--h4); } .qrow .qb i.h5 { background: var(--h5); }
.qrow .qv { text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; }
.qrow.past { opacity: .45; }
.qrow.now { box-shadow: inset 0 0 0 2px var(--ink); }
.qrow.now .qt, .qrow.now .qv { color: var(--ink); font-weight: 750; }
.past-toggle { margin: 4px 0 6px 6px; }

.bands { display: flex; flex-wrap: wrap; gap: 4px 12px; list-style: none; margin: 2px 2px 8px; padding: 0; font-size: 13px; font-variant-numeric: tabular-nums; }
.bands li { display: inline-flex; align-items: center; gap: 5px; }
.bands .sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.bands .sw.h0 { background: var(--h0); } .bands .sw.h1 { background: var(--h1); } .bands .sw.h2 { background: var(--h2); }
.bands .sw.h3 { background: var(--h3); } .bands .sw.h4 { background: var(--h4); } .bands .sw.h5 { background: var(--h5); }
.note-line { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--muted); margin: 2px 2px 0; }
.swatch-peak { flex: none; width: 14px; height: 14px; border-radius: 3px; margin-top: 2px; background: var(--peak); border: 1px solid var(--line); }
.swatch-night { flex: none; width: 14px; height: 14px; border-radius: 3px; margin-top: 2px; background: var(--night); border: 1px solid var(--line); }
.tbl { margin-top: 10px; font-size: 14px; }
.tbl summary { cursor: pointer; color: var(--muted); padding: 6px 0; }
.tbl .tables { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.tbl table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.tbl caption { text-align: left; font-weight: 600; padding-bottom: 4px; }
.tbl td { padding: 2px 6px; border-top: 1px solid var(--line); }
.tbl td:last-child { text-align: right; }
.readout { min-height: 22px; margin: 8px 0 0; font-size: 15px; font-variant-numeric: tabular-nums; }
.foot { margin-top: 28px; font-size: 13px; color: var(--muted); display: grid; gap: 4px; }

/* settings */
.set { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 4px 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.set > h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 650; padding: 12px 0 4px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.set > h2 + .row, .set > h2 + p + .row { border-top: 0; }
.row .lbl { flex: 1; min-width: 0; }
.row .lbl small { display: block; color: var(--muted); font-size: 13px; line-height: 1.35; margin-top: 2px; }
.row input[type=time], .row input[type=number], .row input[type=text], .row select {
  border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 6px 8px; min-height: 40px; max-width: 150px;
}
.row input[type=number] { width: 88px; }
.row input[type=text] { width: 160px; }
.row.stack { flex-wrap: wrap; row-gap: 8px; }
.row.stack .lbl { flex-basis: 100%; }
.row.stack .pair { justify-content: flex-start; }
.row.stack > select, .row.stack > input[type=text] { max-width: none; width: 100%; }
.pair { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; background: var(--normal); border-radius: 999px; transition: background .15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch input:checked + span { background: var(--go); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
details.machine { border-top: 1px solid var(--line); }
details.machine summary { list-style: none; cursor: pointer; padding: 12px 0; display: flex; align-items: center; gap: 8px; font-weight: 600; }
details.machine summary::-webkit-details-marker { display: none; }
details.machine summary svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; color: var(--muted); }
details.machine summary .sum { margin-left: auto; color: var(--muted); font-weight: 400; font-size: 14px; }
details.machine .row:first-of-type { border-top: 0; }
details.machine .body { padding-bottom: 8px; }
.set .note { color: var(--muted); font-size: 13px; margin: 0 0 10px; }
.set .actions { padding: 12px 0; display: flex; gap: 8px; flex-wrap: wrap; }
.about { color: var(--muted); font-size: 14px; padding-bottom: 12px; margin: 0; }

/* bottom tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; gap: 0;
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 5;
}
.tabs a {
  flex: 0 1 200px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 10px;
  color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 600;
}
.tabs a svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a.on { color: var(--go); }

/* bottom sheet + toast */
.sheet { position: fixed; inset: 0; z-index: 10; background: rgb(0 0 0 / 0.35); display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet .panel {
  background: var(--card); width: 100%; max-width: 560px; border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); display: grid; gap: 10px;
}
.sheet .panel h2 { font-size: 18px; }
.sheet .panel .btn { justify-content: center; width: 100%; }
.sheet .panel .other { display: flex; gap: 8px; }
.sheet .panel .other input { flex: 1; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 8px; min-height: 44px; }
.sheet .panel .other .btn { width: auto; }
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 15px; z-index: 20;
  width: max-content; max-width: calc(100vw - 32px); text-align: center;
}
.toast[hidden] { display: none; }
.empty { padding: 40px 0; text-align: center; color: var(--muted); }
