@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@500;600;700;800&family=Noto+Sans+HK:wght@400;500;700;900&display=swap');

:root{
  --bg:#f7f7f4;
  --card:#ffffff;
  --ink:#1d2023;
  --muted:#6b7178;
  --line:#e6e5e0;
  --accent:#c8372a;
  --accent-soft:#fbeae7;
  --green:#2b8a63;
  --green-soft:#e4f3ea;
  --red:#c8372a;
  --red-soft:#fbeae7;
  --pill-bg:#f1f0eb;
  --gold:#8a6b12;
  --gold-bg:#f3ead7;
  --shadow:0 1px 2px rgba(20,20,15,0.04), 0 6px 16px rgba(20,20,15,0.05);
}

[data-theme="dark"]{
  --bg:#121416;
  --card:#1b1e21;
  --ink:#f1f0ec;
  --muted:#9199a1;
  --line:#2b2f33;
  --accent:#e6584a;
  --accent-soft:#3a2320;
  --green:#4bc98a;
  --green-soft:#1c3229;
  --red:#e6584a;
  --red-soft:#3a2320;
  --pill-bg:#24282c;
  --gold:#e0b654;
  --gold-bg:#3a2f14;
  --shadow:0 1px 2px rgba(0,0,0,0.3), 0 8px 20px rgba(0,0,0,0.35);
}

*{ box-sizing:border-box; margin:0; padding:0; -webkit-tap-highlight-color:transparent; }

html{ background:var(--bg); }

body{
  background:var(--bg);
  color:var(--ink);
  font-family:'Manrope','Noto Sans HK',sans-serif;
  min-height:100vh;
  padding-bottom:calc(40px + env(safe-area-inset-bottom));
  transition:background .2s ease, color .2s ease;
}

input, button{ font-family:inherit; }

/* ---------- Sticky header ---------- */
header{
  position:sticky;
  top:0;
  z-index:10;
  background:var(--bg);
  padding:calc(16px + env(safe-area-inset-top)) 16px 12px;
  border-bottom:1px solid var(--line);
}

.header-top{
  display:flex;
  justify-content:space-between;
  align-items:flex-start;
  gap:10px;
}
.title-block{ min-width:0; }
.eyebrow{
  font-size:11px;
  letter-spacing:0.1em;
  text-transform:uppercase;
  color:var(--accent);
  font-weight:700;
  margin-bottom:4px;
}
h1{
  font-weight:800;
  font-size:20px;
  line-height:1.25;
  color:var(--ink);
}
h1 .en{
  display:block;
  font-weight:500;
  font-size:12.5px;
  color:var(--muted);
  margin-top:4px;
  line-height:1.4;
}

.theme-toggle{
  flex-shrink:0;
  background:var(--card);
  border:1px solid var(--line);
  color:var(--ink);
  width:40px;
  height:40px;
  border-radius:50%;
  font-size:17px;
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  box-shadow:var(--shadow);
}

.header-btn-group{
  display:flex;
  align-items:center;
  gap:8px;
  flex-shrink:0;
}
.lang-toggle{
  flex-shrink:0;
  background:var(--card);
  border:1px solid var(--line);
  color:var(--ink);
  height:40px;
  min-width:40px;
  padding:0 12px;
  border-radius:20px;
  font-size:13px;
  font-weight:800;
  letter-spacing:0.02em;
  cursor:pointer;
  box-shadow:var(--shadow);
}
.lang-toggle:active{ transform:scale(0.95); }

/* refresh progress bar */
.refresh-bar-track{
  height:2px;
  background:var(--line);
  border-radius:2px;
  margin-top:14px;
  overflow:hidden;
}
.refresh-bar-fill{
  height:100%;
  background:var(--accent);
  width:0%;
  transition:width 1s linear;
}

.search-row{
  margin-top:14px;
  display:flex;
  gap:8px;
}
.search-box{ flex:1; position:relative; }
.search-box input{
  width:100%;
  background:var(--card);
  border:1px solid var(--line);
  color:var(--ink);
  font-size:16px;
  padding:12px 14px 12px 38px;
  border-radius:12px;
  outline:none;
}
.search-box input::placeholder{ color:var(--muted); }
.search-box input:focus{ border-color:var(--accent); }
.search-box .icon{
  position:absolute; left:13px; top:50%; transform:translateY(-50%);
  color:var(--muted); font-size:14px; pointer-events:none;
}
.reload-btn{
  background:var(--card);
  border:1px solid var(--line);
  color:var(--muted);
  font-size:13px;
  font-weight:700;
  padding:0 16px;
  border-radius:12px;
  cursor:pointer;
  white-space:nowrap;
}
.reload-btn:active{ transform:scale(0.97); }

.region-scroll{
  margin-top:10px;
  display:flex;
  gap:8px;
  overflow-x:auto;
  padding-bottom:2px;
  -webkit-overflow-scrolling:touch;
  scrollbar-width:none;
}
.region-scroll::-webkit-scrollbar{ display:none; }
.region-pill{
  background:var(--pill-bg);
  border:1px solid transparent;
  color:var(--muted);
  font-size:13px;
  font-weight:700;
  padding:8px 14px;
  border-radius:20px;
  cursor:pointer;
  white-space:nowrap;
  flex-shrink:0;
}
.region-pill.active{
  background:var(--accent);
  color:#fff;
}

.meta-row{
  margin-top:10px;
  font-size:11.5px;
  color:var(--muted);
}

/* ---------- Store list ---------- */
main{
  padding:12px 16px 0;
  display:flex;
  flex-direction:column;
  gap:10px;
}

.loading-note, .empty-note{
  text-align:center;
  color:var(--muted);
  font-size:14px;
  padding:50px 20px;
}

.store-card{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:16px;
  overflow:hidden;
  box-shadow:var(--shadow);
}

.store-summary{
  padding:14px 16px;
  display:flex;
  align-items:center;
  gap:12px;
  cursor:pointer;
}
.store-info{ flex:1; min-width:0; }
.store-name-cn{ font-size:15.5px; font-weight:700; color:var(--ink); }
.store-name-en{ font-size:12px; color:var(--muted); margin-top:1px; }
.badge-row{ display:flex; gap:6px; margin-top:7px; flex-wrap:wrap; }
.badge{
  font-size:10.5px; font-weight:700; padding:3px 9px; border-radius:20px;
}
.badge.open{ background:var(--green-soft); color:var(--green); }
.badge.closed{ background:var(--red-soft); color:var(--red); }
.badge.issuing{ background:var(--green-soft); color:var(--green); }
.badge.stopped{ background:var(--accent-soft); color:var(--accent); }

.wait-figure{
  text-align:center;
  flex-shrink:0;
  min-width:56px;
}
.wait-num{
  font-size:22px;
  font-weight:800;
  color:var(--accent);
  line-height:1;
  transition:opacity .15s ease;
}
.wait-label{
  font-size:9.5px;
  color:var(--muted);
  margin-top:3px;
  line-height:1.25;
}
.chevron{
  color:var(--muted);
  font-size:13px;
  transition:transform .15s ease;
  flex-shrink:0;
}
.store-card.expanded .chevron{ transform:rotate(180deg); }

.store-detail{
  display:none;
  border-top:1px solid var(--line);
  padding:16px;
}
.store-card.expanded .store-detail{ display:block; }

.detail-header-row{
  display:flex;
  justify-content:space-between;
  align-items:center;
  margin-bottom:6px;
}
.detail-label{
  font-size:11.5px;
  letter-spacing:0.04em;
  text-transform:uppercase;
  color:var(--ink);
  font-weight:800;
}
.detail-label.secondary{ color:var(--muted); font-weight:700; }
.detail-sub{
  font-size:11.5px;
  color:var(--muted);
  margin-bottom:10px;
  line-height:1.4;
}
.live-indicator{
  display:flex; align-items:center; gap:5px;
  font-size:11px; color:var(--green); font-weight:700;
}
.live-dot{
  width:6px; height:6px; border-radius:50%; background:var(--green);
  animation:pulse 1.6s ease-in-out infinite;
}
@keyframes pulse{ 0%,100%{ opacity:1; } 50%{ opacity:0.3; } }

.pill-track{
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  margin-bottom:16px;
}
.pill-track:last-of-type{ margin-bottom:0; }
.number-pill{
  background:var(--pill-bg);
  color:var(--ink);
  font-weight:800;
  font-size:15px;
  padding:8px 14px;
  border-radius:10px;
}
.number-pill.highlight{
  background:var(--accent);
  color:#fff;
}
.queue-empty-msg{
  font-size:12.5px;
  color:var(--muted);
  padding:6px 0;
}

.detail-footer{
  display:flex;
  justify-content:space-between;
  align-items:center;
  margin-top:4px;
  flex-wrap:wrap;
  gap:8px;
}
.updated-text{
  font-size:11.5px;
  color:var(--muted);
}
.updated-text .time{ font-weight:800; color:var(--ink); }
.refresh-btn{
  background:var(--accent);
  color:#fff;
  border:none;
  font-weight:700;
  font-size:13px;
  padding:10px 16px;
  border-radius:10px;
  cursor:pointer;
}
.refresh-btn:active{ transform:scale(0.97); }
.refresh-btn:disabled{ opacity:0.5; cursor:default; }

.address-line{
  font-size:12px;
  color:var(--muted);
  margin-top:14px;
  padding-top:14px;
  border-top:1px solid var(--line);
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:8px;
  flex-wrap:wrap;
}
.map-link{
  color:var(--accent);
  font-weight:700;
  text-decoration:none;
  white-space:nowrap;
}

.detail-error{
  font-size:12px;
  color:var(--accent);
  background:var(--red-soft);
  padding:8px 12px;
  border-radius:8px;
  margin-top:10px;
}

.global-error{ padding:0 16px 12px; }
.global-error .box{
  background:var(--red-soft);
  color:var(--accent);
  font-size:13px;
  padding:12px 16px;
  border-radius:12px;
}

footer.attribution{
  padding:24px 16px 0;
  font-size:11.5px;
  color:var(--muted);
  line-height:1.6;
}

/* ---------- Header controls (hamburger / back link) ---------- */
.header-top{ position:relative; }
.title-block{ flex:1; text-align:center; }
.hamburger-btn{
  flex-shrink:0;
  background:var(--card);
  border:1px solid var(--line);
  color:var(--ink);
  width:40px;
  height:40px;
  border-radius:12px;
  font-size:18px;
  cursor:pointer;
  box-shadow:var(--shadow);
}
.back-link{
  display:none;
  background:none;
  border:none;
  color:var(--accent);
  font-size:11.5px;
  font-weight:700;
  padding:0;
  margin-bottom:4px;
  cursor:pointer;
}

/* ---------- Hamburger drawer ---------- */
.drawer-overlay{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,0.4);
  z-index:20;
  opacity:0;
  pointer-events:none;
  transition:opacity .2s ease;
}
.drawer-overlay.open{ opacity:1; pointer-events:auto; }

.drawer-panel{
  position:fixed;
  top:0; left:0; bottom:0;
  width:78%;
  max-width:300px;
  background:var(--card);
  z-index:21;
  transform:translateX(-100%);
  transition:transform .25s cubic-bezier(0.16,1,0.3,1);
  padding:calc(20px + env(safe-area-inset-top)) 16px 20px;
  display:flex;
  flex-direction:column;
  gap:6px;
  box-shadow:4px 0 24px rgba(0,0,0,0.15);
}
.drawer-panel.open{ transform:translateX(0); }

.drawer-header{ margin-bottom:14px; }
.drawer-brand{ font-size:17px; font-weight:800; color:var(--ink); }
.drawer-brand-en{ font-size:11.5px; color:var(--muted); margin-top:2px; }

.drawer-link{
  display:flex;
  align-items:center;
  gap:10px;
  background:transparent;
  border:none;
  text-align:left;
  color:var(--ink);
  font-size:14px;
  font-weight:700;
  padding:12px 10px;
  border-radius:12px;
  cursor:pointer;
}
.drawer-link small{ font-weight:600; color:var(--muted); font-size:10.5px; }
.drawer-link.active{ background:var(--accent-soft); color:var(--accent); }
.drawer-link.active small{ color:var(--accent); opacity:0.8; }

.drawer-footer{
  margin-top:auto;
  font-size:10.5px;
  color:var(--muted);
  line-height:1.6;
  padding:10px;
}

/* ---------- Page panels ---------- */
.page-panel{ display:none; }
.page-panel.active{ display:block; }

.sticky-sub-bar{
  position:sticky;
  top:var(--header-h, 0px);
  z-index:9;
  background:var(--bg);
  padding:12px 16px 10px;
}

/* ---------- Home / landing page ---------- */
.home-main{
  padding:20px 16px 8px;
  display:flex;
  flex-direction:column;
  gap:14px;
}
.home-hero{
  text-align:center;
  padding:10px 10px 20px;
}
.home-hero-emoji{ font-size:44px; margin-bottom:10px; }
.home-hero-title{
  font-size:21px;
  font-weight:800;
  color:var(--ink);
  line-height:1.35;
}
.home-hero-sub{
  font-size:12.5px;
  color:var(--muted);
  margin-top:8px;
  line-height:1.5;
}

.home-tool-grid{
  display:flex;
  flex-direction:column;
  gap:14px;
}

.tool-card{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:16px;
  padding:16px;
  display:flex;
  align-items:center;
  gap:14px;
  box-shadow:var(--shadow);
  cursor:pointer;
}
.tool-card:active{ transform:scale(0.98); }
.tool-card-icon{
  font-size:30px;
  width:52px; height:52px;
  border-radius:14px;
  background:var(--pill-bg);
  display:flex; align-items:center; justify-content:center;
  flex-shrink:0;
}
.tool-card-body{ flex:1; min-width:0; }
.tool-card-title{ font-size:15.5px; font-weight:800; color:var(--ink); }
.tool-card-title .en{ font-size:11.5px; font-weight:600; color:var(--muted); margin-left:4px; }
.tool-card-desc{ font-size:11.5px; color:var(--muted); margin-top:6px; line-height:1.5; }
.tool-card-arrow{ font-size:24px; color:var(--muted); flex-shrink:0; }

.home-footer{ padding:20px 16px 0; }

/* ---------- Calculator: summary bar ---------- */
.calc-summary-bar{
  border-bottom:1px solid var(--line);
  padding-bottom:12px;
}
.calc-summary-top{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
}
.calc-total-block{
  display:flex;
  align-items:baseline;
  gap:2px;
  color:var(--accent);
}
.calc-total-currency{ font-size:16px; font-weight:700; }
.calc-total-num{ font-size:34px; font-weight:800; line-height:1; }

.calc-people-block{
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:4px;
}
.people-stepper{
  display:flex;
  align-items:center;
  gap:8px;
  background:var(--card);
  border:1px solid var(--line);
  border-radius:20px;
  padding:4px 6px;
}
.people-step-btn{
  width:22px; height:22px;
  border-radius:50%;
  border:none;
  background:var(--pill-bg);
  color:var(--ink);
  font-weight:800;
  font-size:14px;
  cursor:pointer;
  display:flex; align-items:center; justify-content:center;
}
.people-step-btn:active{ transform:scale(0.9); }
.people-count-value{ font-size:12.5px; font-weight:700; color:var(--ink); }
.calc-per-person{ font-size:11px; color:var(--muted); font-weight:700; }

.calc-items-badge{
  background:var(--accent);
  color:#fff;
  border-radius:12px;
  min-width:52px;
  padding:6px 10px;
  text-align:center;
  flex-shrink:0;
}
.items-num{ display:block; font-size:20px; font-weight:800; line-height:1; }
.items-label{ font-size:8.5px; font-weight:700; letter-spacing:0.06em; opacity:0.85; }

.calc-summary-sub{
  font-size:11px;
  color:var(--muted);
  margin-top:8px;
  font-weight:600;
}

/* ---------- Calculator: main content ---------- */
.calc-main{
  padding:14px 16px 8px;
  display:flex;
  flex-direction:column;
  gap:2px;
}

.calc-toolbar{
  display:flex;
  gap:8px;
  margin-bottom:14px;
}
.calc-toolbar-btn{
  flex:1;
  border:none;
  border-radius:12px;
  padding:10px;
  font-size:12.5px;
  font-weight:700;
  cursor:pointer;
}
.calc-toolbar-btn.undo{ background:var(--pill-bg); color:var(--ink); }
.calc-toolbar-btn.undo:disabled{ opacity:0.4; cursor:default; }
.calc-toolbar-btn.reset{ background:var(--accent-soft); color:var(--accent); }
.calc-toolbar-btn.reset.confirming{ background:var(--accent); color:#fff; }

.section-label{
  font-size:11px;
  letter-spacing:0.08em;
  text-transform:uppercase;
  color:var(--muted);
  font-weight:700;
  margin-bottom:8px;
}

.plate-grid{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:10px;
}
.plate-card{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:14px;
  padding:10px;
  display:flex;
  align-items:center;
  gap:10px;
  box-shadow:var(--shadow);
}
.plate-img{
  width:48px; height:48px;
  object-fit:contain;
  flex-shrink:0;
}
.plate-info{ flex:1; min-width:0; }
.plate-top-row{
  display:flex;
  justify-content:space-between;
  align-items:baseline;
  margin-bottom:6px;
}
.plate-label{ font-size:15px; font-weight:800; color:var(--ink); }
.plate-price{ font-size:12px; font-weight:700; color:var(--muted); background:var(--pill-bg); padding:2px 7px; border-radius:6px; }
.plate-stepper{
  display:flex;
  align-items:center;
  justify-content:flex-end;
  gap:8px;
}
.stepper-btn{
  width:28px; height:26px;
  border-radius:8px;
  border:1px solid var(--line);
  background:var(--card);
  color:var(--ink);
  font-weight:800;
  font-size:16px;
  cursor:pointer;
  display:flex; align-items:center; justify-content:center;
}
.stepper-btn.plus{ background:var(--accent); color:#fff; border-color:var(--accent); }
.stepper-btn:active{ transform:scale(0.92); }
.stepper-count{ font-size:16px; font-weight:800; color:var(--ink); min-width:18px; text-align:center; }

.extra-quick-grid{
  display:grid;
  grid-template-columns:repeat(5, 1fr);
  gap:8px;
  margin-bottom:12px;
}
.extra-quick-btn{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:10px;
  padding:10px 4px;
  font-size:12.5px;
  font-weight:800;
  color:var(--ink);
  cursor:pointer;
}
.extra-quick-btn:active{ transform:scale(0.95); background:var(--accent-soft); }

.custom-price-row{
  display:flex;
  align-items:center;
  gap:8px;
  background:var(--card);
  border:1px solid var(--line);
  border-radius:12px;
  padding:6px 6px 6px 14px;
}
.custom-price-label{ font-size:12px; color:var(--muted); font-weight:700; white-space:nowrap; }
.custom-price-input{
  flex:1;
  border:none;
  background:transparent;
  color:var(--ink);
  font-size:16px;
  font-weight:700;
  outline:none;
  min-width:0;
}
.custom-price-add-btn{
  background:var(--ink);
  color:var(--bg);
  border:none;
  font-size:12.5px;
  font-weight:700;
  padding:10px 14px;
  border-radius:8px;
  cursor:pointer;
  white-space:nowrap;
}

.extra-items-list{
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:8px;
  margin-top:10px;
}
.extra-item-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:6px;
  background:var(--card);
  border:1px solid var(--line);
  border-radius:10px;
  padding:6px 8px;
}
.extra-item-price{ font-size:14px; font-weight:800; color:var(--accent); }
.extra-item-stepper{
  display:flex; align-items:center; gap:6px;
  background:var(--pill-bg);
  border-radius:8px;
  padding:3px 6px;
}
.extra-step-btn{
  width:18px; height:18px;
  border:none;
  border-radius:5px;
  background:transparent;
  color:var(--muted);
  font-weight:800;
  cursor:pointer;
}
.extra-step-count{ font-size:12px; font-weight:800; color:var(--ink); min-width:14px; text-align:center; }
.extra-remove-btn{
  border:none;
  background:transparent;
  color:var(--muted);
  cursor:pointer;
  font-size:13px;
  padding:2px 4px;
}

/* ---------- Timer ---------- */
.timer-card{ margin-top:2px; }
.timer-start-btn{
  width:100%;
  background:var(--card);
  border:1px solid var(--accent);
  color:var(--accent);
  font-weight:800;
  font-size:14px;
  padding:14px;
  border-radius:14px;
  cursor:pointer;
  box-shadow:var(--shadow);
}
.timer-start-btn:active{ transform:scale(0.98); }

.timer-active-row{
  background:var(--card);
  border:1px solid var(--line);
  border-radius:14px;
  padding:14px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  box-shadow:var(--shadow);
  flex-wrap:wrap;
}
.timer-stats{
  display:flex;
  align-items:center;
  gap:14px;
  flex-wrap:wrap;
}
.timer-stat{ display:flex; flex-direction:column; gap:2px; }
.timer-stat-label{ font-size:9.5px; color:var(--muted); font-weight:700; text-transform:uppercase; }
.timer-stat-value{ font-size:19px; font-weight:800; color:var(--ink); }
.timer-stat-value.remaining{ color:var(--green); font-size:24px; }
.timer-stat-value.remaining.urgent{ color:var(--accent); animation:pulse 1s ease-in-out infinite; }
.timer-stat-value.small{ font-size:12px; font-weight:700; color:var(--muted); }

.timer-controls{ display:flex; gap:8px; }
.timer-ctrl-btn{
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:2px;
  border:none;
  border-radius:10px;
  width:44px;
  height:40px;
  font-size:13px;
  cursor:pointer;
}
.timer-ctrl-btn span{ font-size:8px; font-weight:800; }
.timer-ctrl-btn.pause{ background:var(--gold-bg); color:var(--gold); }
.timer-ctrl-btn.resume{ background:var(--green-soft); color:var(--green); }
.timer-ctrl-btn.reset{ background:var(--pill-bg); color:var(--muted); }
.timer-ctrl-btn:active{ transform:scale(0.94); }

/* Slightly roomier on larger screens, but design stays mobile-first */
/* ---------- Tablet: a bit more breathing room, still single column ---------- */
@media (min-width:600px) and (max-width:899px){
  header, .page-panel, footer.attribution{
    max-width:640px;
    margin:0 auto;
  }
  .sticky-sub-bar{ max-width:640px; margin:0 auto; }
}

/* ---------- Desktop: wide shell + multi-column layouts ---------- */
@media (min-width:900px){
  header, .page-panel, footer.attribution{
    max-width:1040px;
    margin:0 auto;
  }
  .sticky-sub-bar{ max-width:1040px; margin:0 auto; }

  /* Store list becomes a real grid instead of one thin stacked column */
  #storeList{
    display:grid;
    grid-template-columns:repeat(auto-fill, minmax(340px, 1fr));
    gap:12px;
    align-items:start;
  }
  .loading-note, .empty-note{ grid-column:1 / -1; }

  /* Plates get a full row instead of a cramped 2-up grid */
  .plate-grid{ grid-template-columns:repeat(4, 1fr); }

  /* Extra quick-price buttons get more room to breathe */
  .extra-quick-grid{ grid-template-columns:repeat(8, 1fr); }
  .extra-items-list{ grid-template-columns:repeat(3, 1fr); }

  /* Home page: hero stays centered, tool cards sit side by side */
  .home-hero{ max-width:640px; margin:0 auto; }
  .home-main{
    display:grid;
    grid-template-columns:1fr;
    gap:16px;
    max-width:900px;
    margin:0 auto;
    padding-left:16px;
    padding-right:16px;
  }
  .home-tool-grid{
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:16px;
  }
}
