:root {
  --bg: #121417;
  --panel: #1b1e23;
  --panel-2: #23272d;
  --line: #2e333a;
  --text: #eef0f2;
  --muted: #9aa3ad;
  --amber: #ffb020;
  --green: #3ddc84;
  --red: #ff6b5e;
  --blue: #5aa9ff;
  --e10: #2fb36b;
  --e5: #c9a227;
  --b7: #8b939c;
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding-top: calc(56px + var(--safe-t));
  padding-bottom: calc(76px + var(--safe-b));
  -webkit-font-smoothing: antialiased;
}
h2 { font-size: 17px; margin: 0 0 10px; letter-spacing: -0.01em; }
a { color: var(--blue); }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* header */
.top {
  position: fixed; inset: 0 0 auto 0; z-index: 20;
  padding: calc(8px + var(--safe-t)) 16px 8px;
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(18, 20, 23, 0.92); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: -0.02em; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 8px 14px; border-radius: 999px; font: inherit; font-size: 14px; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.chip::after { content: "▾"; color: var(--muted); font-size: 11px; }

main { padding: 14px 16px 0; max-width: 640px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }

/* big instant button */
.bigbtn {
  width: 100%; border: 0; border-radius: var(--radius); padding: 18px 16px;
  background: linear-gradient(180deg, #ffbd3d, #f29a00); color: #1a1205;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font: inherit; cursor: pointer; box-shadow: 0 6px 24px rgba(255, 166, 0, 0.18);
}
.bigbtn:active { transform: scale(0.985); }
.bigbtn-label { font-size: 20px; font-weight: 800; letter-spacing: -0.01em; }
.bigbtn-sub { font-size: 13px; opacity: 0.75; }
.bigbtn.busy { opacity: 0.7; pointer-events: none; }
.bigbtn.busy .bigbtn-label::after { content: "…"; }

.status { font-size: 13px; color: var(--muted); margin: 10px 2px; min-height: 18px; }
.status.err { color: var(--red); }

/* ring cards */
.rings { display: grid; gap: 12px; }
.ring {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.ring-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 14px; padding: 14px 16px; width: 100%; background: none; border: 0; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.ring-radius {
  width: 54px; height: 54px; border-radius: 50%; border: 2px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1;
}
.ring-radius b { font-size: 19px; }
.ring-radius small { font-size: 10px; color: var(--muted); margin-top: 2px; }
.ring-main .where { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ring-main .meta { font-size: 13px; color: var(--muted); }
.price-board {
  background: #0b0c0e; border: 1px solid #2a2d31; border-radius: 10px; padding: 6px 10px; text-align: right;
  font-variant-numeric: tabular-nums; min-width: 92px;
}
.price-board b { font-size: 23px; white-space: nowrap; color: var(--green); letter-spacing: 0.02em; font-weight: 700; }
.price-board b small { font-size: 14px; margin-left: 1px; }
.price-board span { display: block; font-size: 11px; color: var(--muted); }
.ring-body { border-top: 1px solid var(--line); display: none; }
.ring.open .ring-body { display: block; }
.ring-empty { padding: 14px 16px; color: var(--muted); font-size: 14px; }

.st { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; align-items: center; padding: 11px 16px; border-bottom: 1px solid var(--line); }
.st:last-child { border-bottom: 0; }
.st .nm { font-weight: 600; font-size: 15px; }
.st .ad { font-size: 12px; color: var(--muted); }
.st .pp { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 17px; text-align: right; }
.st .pp small { display: block; font-size: 11px; color: var(--muted); font-weight: 500; }
.go {
  border: 0; background: var(--panel-2); color: var(--blue); border-radius: 10px; padding: 9px 12px;
  font: inherit; font-size: 14px; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.tag { display: inline-block; font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: var(--panel-2); color: var(--muted); margin-left: 4px; vertical-align: 1px; text-transform: uppercase; letter-spacing: 0.04em; }
.tag.best { background: rgba(61, 220, 132, 0.15); color: var(--green); }
.cheap { color: var(--green); }
.dear { color: var(--red); }

/* cards & forms */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 14px 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; }
.field { display: block; margin: 10px 0; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input[type=text], input[type=password], input[type=number], input[type=time], select {
  width: 100%; font: inherit; font-size: 16px; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; -webkit-appearance: none; appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
input:focus, select:focus { outline: 2px solid var(--amber); outline-offset: 0; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row .small { flex: 1 1 120px; margin: 10px 0 0; }
.btn {
  font: inherit; font-size: 15px; font-weight: 600; border-radius: 12px; padding: 12px 16px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text); cursor: pointer;
}
.btn.primary { background: var(--amber); color: #1a1205; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; }
.btn:active { transform: scale(0.98); }
.row .btn { flex: 1 1 150px; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 0 12px; }
.toggle { display: flex; gap: 10px; align-items: center; font-size: 15px; margin: 4px 0; }
.toggle input { width: 22px; height: 22px; accent-color: var(--amber); }
.segment { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.segment button { font: inherit; font-size: 14px; font-weight: 600; padding: 12px 6px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); }
.segment button.on { border-color: var(--amber); background: rgba(255, 176, 32, 0.12); color: var(--amber); }
.about p { font-size: 12px; margin: 4px 0; }

/* daily */
.daily-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 4px; }
.daily-grid div { background: var(--panel-2); border-radius: 12px; padding: 10px; text-align: center; }
.daily-grid b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; color: var(--green); }
.daily-grid small { color: var(--muted); font-size: 11px; }
.daily-grid em { display: block; font-style: normal; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trend { width: 100%; height: 60px; margin-top: 10px; }
.trend:empty { display: none; }
.trend path.l { fill: none; stroke: var(--amber); stroke-width: 2; vector-effect: non-scaling-stroke; }
.trend path.a { fill: rgba(255, 176, 32, 0.1); }

/* route */
.map { height: 300px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); margin: 14px 0; }
.leaflet-container { background: #1b1e23; font: inherit; }
.pin { background: #0b0c0e; color: var(--green); border: 1.5px solid var(--green); border-radius: 8px; font: 700 12px/1 -apple-system, sans-serif; padding: 4px 5px; white-space: nowrap; font-variant-numeric: tabular-nums; box-shadow: 0 2px 6px rgba(0,0,0,.5); }
.pin.mid { color: var(--amber); border-color: var(--amber); }
.pin.hi { color: var(--muted); border-color: var(--line); }
.pin.best { background: var(--green); color: #04120a; }
.best-card { border-color: rgba(61, 220, 132, 0.5); }
.best-card .big { font-size: 30px; font-weight: 800; color: var(--green); font-variant-numeric: tabular-nums; }
.navbtn { display: block; text-align: center; text-decoration: none; margin-top: 12px; }
.sum-line { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); }

/* live map */
#tab-map.active { margin: -14px -16px 0; }
.livemap-wrap { position: relative; height: calc(100dvh - 56px - 76px - var(--safe-t) - var(--safe-b)); }
.livemap { position: absolute; inset: 0; }
.map-stats {
  position: absolute; top: 10px; left: 10px; right: 64px; z-index: 500;
  background: rgba(18, 20, 23, 0.9); border: 1px solid var(--line); border-radius: 12px;
  padding: 8px 12px; font-size: 13px; color: var(--text); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.map-stats b { color: var(--green); font-variant-numeric: tabular-nums; }
.map-legend { position: absolute; bottom: 12px; left: 10px; z-index: 500; display: flex; gap: 6px; }
.lg { font-size: 11px; font-weight: 700; padding: 4px 8px; border-radius: 8px; background: #0b0c0e; border: 1.5px solid; }
.lg.cheap { color: var(--green); border-color: var(--green); }
.lg.mid { color: var(--amber); border-color: var(--amber); }
.lg.hi { color: var(--muted); border-color: var(--line); }
.map-btns { position: absolute; top: 10px; right: 10px; z-index: 500; display: flex; flex-direction: column; gap: 8px; }
.mapbtn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: rgba(18, 20, 23, 0.92); color: var(--text); display: flex; align-items: center; justify-content: center; }
.mapbtn svg { width: 22px; height: 22px; fill: currentColor; }
.mapbtn.spin svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.me-dot { width: 16px; height: 16px; border-radius: 50%; background: var(--blue); border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(90, 169, 255, 0.25); }
.pin.cheap { background: var(--green); color: #04120a; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); border: 1px solid var(--line); }
.leaflet-popup-content { margin: 12px 14px; font-size: 14px; min-width: 190px; }
.pop h3 { margin: 0 0 2px; font-size: 15px; }
.pop .ad { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.pop table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.pop td { padding: 3px 0; }
.pop td:last-child { text-align: right; font-weight: 700; }
.pop tr.sel td { color: var(--green); }
.pop .upd { color: var(--muted); font-size: 11px; margin-top: 6px; }
.pop .go { display: block; text-align: center; margin-top: 10px; }

/* bottom tabs */
.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 20; display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 8px calc(6px + var(--safe-b)); background: rgba(18, 20, 23, 0.94);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-top: 1px solid var(--line);
}
.tabs button { background: none; border: 0; color: var(--muted); font: inherit; font-size: 11px; font-weight: 600; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; }
.tabs svg { width: 24px; height: 24px; fill: currentColor; }
.tabs button.active { color: var(--amber); }

/* sheet */
.sheet { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.6); display: flex; align-items: flex-end; }
.sheet-panel { width: 100%; max-width: 640px; margin: 0 auto; background: var(--panel); border-radius: 22px 22px 0 0; padding: 22px 18px calc(22px + var(--safe-b)); border-top: 1px solid var(--line); }
.sheet-panel h2 { font-size: 22px; }
.fuel-options { display: grid; gap: 10px; margin-top: 14px; }
.fuel-options button {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 14px; align-items: center; text-align: left;
  padding: 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); font: inherit;
}
.fuel-options button.on { border-color: var(--amber); }
.fuel-options .dot { grid-row: span 2; width: 34px; height: 34px; border-radius: 50%; }
.fuel-options b { font-size: 17px; }
.fuel-options small { color: var(--muted); font-size: 13px; }
.dot.e10 { background: var(--e10); }
.dot.e5 { background: var(--e5); }
.dot.b7 { background: var(--b7); border: 3px solid #111; outline: 1px solid var(--line); }
.dot.b7p { background: #111; border: 3px solid var(--e5); }
.dot.ev { background: var(--blue); display: flex; align-items: center; justify-content: center; }
.dot.ev svg { width: 20px; height: 20px; fill: #fff; }
.fuel-options { max-height: 62dvh; overflow-y: auto; }
.fuel-options button { padding: 13px 16px; }
.segment { grid-template-columns: repeat(2, 1fr); }
.segment button:last-child:nth-child(odd) { grid-column: span 2; }
#sheetPass input { margin: 12px 0; }
