:root {
  --bg: #070709;
  --panel: #14161c;
  --panel-2: #1b1e26;
  --bezel: #2a2d34;
  --bezel-hi: #4a4e58;
  --bezel-lo: #121317;
  --recess: #050506;
  --led-red: #ff2d18;
  --led-red-dim: #3a0a08;
  --led-amber: #ffb000;
  --led-amber-dim: #3a2800;
  --urban: #c4121a;
  --nt: #1a8a3a;
  --lantau: #1a4f9c;
  --text: #e8e4d8;
  --muted: #9a9484;
  --label: #b7b19f;
  --danger: #e23a2b;
  --ok: #3dcf6a;
  --wait: #f0b429;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  --font-ui: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Heiti TC",
    "Segoe UI", sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --accent: var(--urban);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}
button, input { font-family: inherit; }

.app {
  min-height: 100vh;
  min-height: 100dvh;
  padding: calc(10px + var(--safe-t)) calc(12px + var(--safe-r)) calc(10px + var(--safe-b)) calc(12px + var(--safe-l));
  display: flex;
  flex-direction: column;
  gap: 10px;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(196, 18, 26, 0.18), transparent 55%),
    linear-gradient(180deg, #101115, #070709 40%);
}
.app[data-tariff="nt"] {
  --accent: var(--nt);
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(26, 138, 58, 0.16), transparent 55%),
    linear-gradient(180deg, #101115, #070709 40%);
}
.app[data-tariff="lantau"] {
  --accent: var(--lantau);
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(26, 79, 156, 0.2), transparent 55%),
    linear-gradient(180deg, #101115, #070709 40%);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.roof-lamp {
  width: 22px;
  height: 22px;
  border-radius: 4px 4px 3px 3px;
  background: #2a2a2a;
  box-shadow: inset 0 0 0 2px #111, 0 0 0 1px #555;
  position: relative;
  flex-shrink: 0;
}
.roof-lamp::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 2px;
  background: #3a3a3a;
}
.roof-lamp.on-vacant::after {
  background: #e11d2a;
  box-shadow: 0 0 12px #e11d2a;
}
.roof-lamp.on-hired::after {
  background: #111;
}
.roof-lamp.on-stopped::after {
  background: var(--wait);
  box-shadow: 0 0 12px var(--wait);
}
.titles h1 {
  margin: 0;
  font-size: clamp(15px, 2vw, 22px);
  letter-spacing: 0.04em;
  font-weight: 800;
}
.titles p {
  margin: 0;
  color: var(--muted);
  font-size: clamp(11px, 1.4vw, 13px);
}
.disclaimer-pill {
  color: #f0d27a;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.08em;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #33363f;
  background: #121318;
  color: var(--label);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
}
.chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #555;
}
.chip.ok .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.chip.warn .dot { background: var(--wait); box-shadow: 0 0 8px var(--wait); }
.chip.bad .dot { background: var(--danger); box-shadow: 0 0 8px var(--danger); }
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid #3a3d46;
  background: linear-gradient(#2a2d34, #16181d);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}
.icon-btn[aria-pressed="true"] { color: var(--wait); }

.meter {
  flex: 1;
  background:
    linear-gradient(180deg, #3a3d45, #1c1e24 18%, #15171c 82%, #0e0f12);
  border-radius: 22px;
  padding: 14px 14px 16px;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,0.18);
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}
.plate {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  color: #d8c48a;
  font-weight: 800;
  letter-spacing: 0.16em;
  font-size: 11px;
  text-transform: uppercase;
  padding: 0 6px;
}
.plate span { letter-spacing: 0.22em; }

.lamps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.lamp {
  text-align: center;
  border-radius: 8px;
  padding: 7px 4px;
  background: #0b0c0f;
  border: 1px solid #2a2c32;
  color: #4a4a4a;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
}
.lamp small { display: block; font-weight: 600; font-size: 10px; opacity: 0.85; }
.lamp.on-vacant { color: #7dff9a; background: #102016; box-shadow: inset 0 0 12px rgba(61,207,106,0.25); }
.lamp.on-hired { color: #ff6b5c; background: #2a0c0a; box-shadow: inset 0 0 12px rgba(255,45,24,0.3); }
.lamp.on-stopped { color: #ffd36a; background: #2a1d00; box-shadow: inset 0 0 12px rgba(240,178,41,0.3); }

.window {
  background: radial-gradient(120% 80% at 50% 0%, #1a0a08, var(--recess));
  border-radius: 14px;
  padding: 10px 12px 12px;
  box-shadow:
    inset 0 0 0 2px #000,
    inset 0 8px 18px rgba(0,0,0,0.65),
    0 0 0 1px #3d3230;
  position: relative;
  overflow: hidden;
}
.window::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.06), transparent 35%, rgba(0,0,0,0.2));
  pointer-events: none;
}
.window-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  color: #c9a089;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  position: relative;
  z-index: 1;
}
.currency {
  color: var(--led-red);
  text-shadow: 0 0 10px rgba(255,45,24,0.7);
  font-size: 18px;
  letter-spacing: 0.08em;
}
.fare-led {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: flex-end;
  align-items: flex-end;
  gap: 6px;
  min-height: clamp(88px, 18vw, 168px);
  padding: 4px 2px 0;
}

.aux {
  display: grid;
  grid-template-columns: 1.2fr 1fr 0.8fr;
  gap: 8px;
}
.aux-cell {
  background: var(--recess);
  border-radius: 12px;
  padding: 8px 10px 10px;
  box-shadow: inset 0 0 0 1px #000, 0 0 0 1px #2c2a24;
  min-width: 0;
}
.aux-cell .window-label { color: #c9b27a; font-size: 11px; }
.aux-led {
  display: flex;
  justify-content: flex-end;
  align-items: flex-end;
  gap: 3px;
  min-height: clamp(36px, 7vw, 56px);
  margin-top: 4px;
  overflow: hidden;
}
.aux-led .digit {
  --w: clamp(12px, 3.2vw, 28px);
  --h: clamp(22px, 5.6vw, 48px);
  --t: clamp(3px, 0.65vw, 5px);
}

/* 7-segment digits */
.digit {
  --on: var(--led-red);
  --off: var(--led-red-dim);
  --w: clamp(22px, 5.2vw, 52px);
  --h: clamp(40px, 9.4vw, 92px);
  --t: clamp(4px, 0.9vw, 8px);
  position: relative;
  width: var(--w);
  height: var(--h);
  flex: 0 0 auto;
}
.digit.amber { --on: var(--led-amber); --off: var(--led-amber-dim); }
.digit .seg {
  position: absolute;
  background: var(--off);
  border-radius: 2px;
}
.digit .seg.on {
  background: var(--on);
  box-shadow: 0 0 8px color-mix(in srgb, var(--on) 70%, transparent);
}
.digit .a, .digit .d, .digit .g {
  height: var(--t);
  left: calc(var(--t) * 1.1);
  right: calc(var(--t) * 1.1);
}
.digit .a { top: 0; }
.digit .g { top: calc(50% - var(--t) / 2); }
.digit .d { bottom: 0; }
.digit .b, .digit .c, .digit .e, .digit .f {
  width: var(--t);
}
.digit .b, .digit .f {
  top: calc(var(--t) * 0.7);
  height: calc(50% - var(--t) * 1.1);
}
.digit .c, .digit .e {
  bottom: calc(var(--t) * 0.7);
  height: calc(50% - var(--t) * 1.1);
}
.digit .b, .digit .c { right: 0; }
.digit .e, .digit .f { left: 0; }
.colon, .dot {
  width: clamp(8px, 1.6vw, 14px);
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  align-items: center;
  align-self: stretch;
}
.colon i, .dot i {
  display: block;
  width: clamp(6px, 1.2vw, 11px);
  height: clamp(6px, 1.2vw, 11px);
  border-radius: 50%;
  background: var(--led-amber);
  box-shadow: 0 0 8px rgba(255,176,0,0.7);
}
.dot { justify-content: flex-end; padding-bottom: 2px; }
.dot i { background: var(--led-red); box-shadow: 0 0 8px rgba(255,45,24,0.7); }
.dot.amber i { background: var(--led-amber); box-shadow: 0 0 8px rgba(255,176,0,0.7); }

.tariffs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.tariff {
  appearance: none;
  border: 0;
  cursor: pointer;
  border-radius: 12px;
  min-height: 64px;
  color: #f3f3f3;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.02em;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.25), 0 3px 0 #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.15;
}
.tariff small { font-weight: 600; opacity: 0.9; font-size: 11px; }
.tariff[data-id="urban"] { background: linear-gradient(#e2232c, #9c1016); }
.tariff[data-id="nt"] { background: linear-gradient(#2cb353, #146b2c); }
.tariff[data-id="lantau"] { background: linear-gradient(#3b73d6, #163a7c); }
.tariff { filter: grayscale(0.35) brightness(0.72); }
.tariff[aria-pressed="true"] {
  filter: none;
  outline: 3px solid #ffe08a;
  outline-offset: 1px;
}
.tariff:disabled { cursor: not-allowed; opacity: 0.72; }

.controls {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1.2fr;
  gap: 8px;
}
.extras-row {
  display: grid;
  grid-template-columns: 1fr 1.4fr 1fr 1fr;
  gap: 8px;
}
.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  min-height: 72px;
  border-radius: 14px;
  color: #fff;
  font-weight: 800;
  font-size: clamp(15px, 2vw, 20px);
  line-height: 1.15;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.28), 0 4px 0 #000;
  padding: 8px 8px;
}
.btn small { display: block; font-size: 12px; font-weight: 650; opacity: 0.92; }
.btn:active { transform: translateY(2px); box-shadow: inset 0 1px 0 rgba(255,255,255,0.15), 0 1px 0 #000; }
.btn:disabled { filter: grayscale(0.55) brightness(0.45); opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-start { background: linear-gradient(#3fce6c, #1b8a3e); }
.btn-wait { background: linear-gradient(#f0c14a, #b67a10); color: #1a1406; }
.btn-wait[aria-pressed="true"] { box-shadow: inset 0 0 0 3px #fff3, 0 4px 0 #000; }
.btn-stop { background: linear-gradient(#ee4336, #9b1a12); }
.btn-reset { background: linear-gradient(#5b6070, #2e323c); }
.btn-extra { background: linear-gradient(#3a3d48, #1d2027); min-height: 64px; font-size: 15px; }
.btn-extra[aria-pressed="true"] { outline: 2px solid var(--led-amber); }

.demo-bar {
  display: none;
  align-items: center;
  gap: 12px;
  background: #16130a;
  border: 1px solid #5a4a18;
  color: #f0d27a;
  border-radius: 12px;
  padding: 8px 12px;
  font-weight: 700;
}
.demo-bar.visible { display: flex; flex-wrap: wrap; }
.demo-bar input[type="range"] { flex: 1; min-width: 140px; accent-color: var(--wait); }
.demo-bar label { font-size: 13px; }

.footer {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
  text-align: center;
  padding: 2px 8px 6px;
}
.footer a { color: #d8c48a; }

/* Receipt overlay */
.receipt-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.62);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
}
.receipt-backdrop.open { display: flex; }
.receipt {
  width: min(420px, 100%);
  max-height: calc(100dvh - 40px);
  overflow: auto;
  background: #f4ecd8;
  color: #1a1a1a;
  padding: 22px 22px 16px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  font-family: "Courier New", "Noto Sans TC", ui-monospace, monospace;
  position: relative;
}
.receipt::before, .receipt::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  height: 10px;
  background: repeating-linear-gradient(90deg, #f4ecd8 0 10px, transparent 10px 16px);
}
.receipt::before { top: -10px; }
.receipt::after { bottom: -10px; transform: rotate(180deg); }
.receipt h2 {
  margin: 0 0 4px;
  text-align: center;
  font-size: 18px;
  letter-spacing: 0.08em;
}
.receipt .sub {
  text-align: center;
  margin: 0 0 12px;
  font-size: 12px;
}
.receipt hr {
  border: 0;
  border-top: 1px dashed #333;
  margin: 10px 0;
}
.receipt .row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  margin: 3px 0;
}
.receipt .total {
  font-size: 22px;
  font-weight: 800;
}
.receipt .fun {
  text-align: center;
  font-weight: 800;
  margin-top: 8px;
  font-size: 13px;
}
.receipt-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}
.receipt-actions .btn { flex: 1; min-height: 52px; font-size: 16px; color: #fff; }

@media (max-width: 820px) and (orientation: portrait) {
  .aux { grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
  .aux-cell { padding: 8px 6px 8px; }
  .aux-led .digit {
    --w: clamp(10px, 6.2vw, 16px);
    --h: clamp(20px, 11vw, 30px);
    --t: 3px;
  }
  .controls, .extras-row, .tariffs { grid-template-columns: 1fr 1fr; }
  .controls { grid-template-columns: 1fr 1fr; }
  .btn-stop { grid-column: 1 / -1; }
  .fare-led { min-height: 96px; }
  .btn { min-height: 64px; }
}
@media (min-width: 1100px) and (orientation: landscape) {
  .app { padding: 14px 18px; gap: 12px; }
  .meter { padding: 16px 20px 18px; }
  .btn, .tariff { min-height: 80px; }
}
@media (prefers-reduced-motion: reduce) {
  .btn:active { transform: none; }
}
