:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f8;
  --border: #e3e6ee;
  --text: #161a26;
  --muted: #646b7d;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef0ff;
  --accent-text: #ffffff;
  --success: #0f9d58;
  --success-soft: #e6f6ee;
  --warn: #b26a00;
  --warn-soft: #fff5e0;
  --danger: #d93025;
  --danger-soft: #fdecea;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 4px 16px rgba(16, 24, 40, .06);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1117;
    --surface: #161b24;
    --surface-2: #1d2430;
    --border: #2a3242;
    --text: #e8ebf2;
    --muted: #98a1b3;
    --accent: #7c74ff;
    --accent-hover: #918aff;
    --accent-soft: #232650;
    --success: #3ccf86;
    --success-soft: #12301f;
    --warn: #f0b44c;
    --warn-soft: #33270f;
    --danger: #ff6b5e;
    --danger-soft: #3a1714;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
@media (min-width: 860px) { body { padding-bottom: 40px; } }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); word-break: break-all; }
.pre { white-space: pre-line; }

/* ---------- layout */
.container { max-width: 1080px; margin: 0 auto; padding: 16px; outline: none; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.two-col { display: grid; gap: 16px; }
@media (min-width: 860px) { .two-col { grid-template-columns: 1fr 1fr; align-items: start; } }

/* ---------- top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { max-width: 1080px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); font-size: 1.05rem; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw; }
.brand-logo { width: 32px; height: 32px; border-radius: 8px; flex: none; display: block; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.tabs-desktop { display: none; gap: 4px; }
@media (min-width: 860px) { .tabs-desktop { display: flex; } }
.tabs-desktop a { padding: 6px 12px; border-radius: 999px; color: var(--muted); font-weight: 500; }
.tabs-desktop a:hover { text-decoration: none; color: var(--text); background: var(--surface-2); }
.tabs-desktop a.active { color: var(--accent); background: var(--accent-soft); }

.tabs-mobile {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 860px) { .tabs-mobile { display: none; } }
.tabs-mobile a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 9px; color: var(--muted); font-size: .72rem; font-weight: 500; }
.tabs-mobile a:hover { text-decoration: none; }
.tabs-mobile a.active { color: var(--accent); }
.tabs-mobile svg { width: 22px; height: 22px; }

/* ---------- controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 10px 16px; border-radius: var(--radius-sm); font: inherit; font-weight: 600;
  cursor: pointer; transition: background .15s, border-color .15s, opacity .15s; text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: .88rem; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--accent); }
.btn-ghost:hover { background: var(--accent-soft); }
.icon-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  min-width: 36px; height: 36px; border-radius: 10px; font: inherit; font-weight: 600; font-size: .85rem;
  cursor: pointer; padding: 0 8px;
}
.icon-btn:hover { background: var(--surface-2); }
.chip {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  padding: 6px 12px; border-radius: 999px; font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.chip.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }

input, textarea, select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px;
}
input:focus, textarea:focus, select:focus, .btn:focus-visible, .chip:focus-visible, .icon-btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
textarea { min-height: 110px; resize: vertical; font-family: var(--mono); font-size: .9rem; }
label.field { display: block; }
label.field > span { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 4px; }
.checkbox { display: flex; gap: 8px; align-items: flex-start; font-size: .9rem; }
.checkbox input { width: auto; margin-top: 4px; }

.segmented { display: flex; background: var(--surface-2); border-radius: var(--radius-sm); padding: 3px; gap: 3px; flex-wrap: wrap; }
.segmented button {
  flex: 1; border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: .88rem;
  padding: 8px 10px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.stepper { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.stepper button { width: 40px; height: 40px; border: 0; background: var(--surface-2); color: var(--text); font-size: 1.2rem; cursor: pointer; }
.stepper input { width: 64px; border: 0; border-radius: 0; text-align: center; padding: 8px 4px; }

/* ---------- cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card-flat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.product {
  text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
  font: inherit; color: inherit; transition: border-color .15s, transform .15s;
}
.product:hover { border-color: var(--accent); transform: translateY(-1px); }
.product.soldout { opacity: .55; }
.product-name { font-weight: 600; line-height: 1.35; }
.product-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: end; gap: 8px; }
.price { font-weight: 700; font-size: 1.05rem; }
.price-sub { font-size: .8rem; color: var(--muted); }
.product > .badge { align-self: flex-start; }
.product img { width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 8px; background: var(--surface-2); }

.badge { display: inline-block; font-size: .74rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }

.section-title { margin: 20px 0 10px; display: flex; align-items: center; gap: 8px; }
.section-title h2 { margin: 0; }

.balance-card { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.balance-card .card-flat { padding: 14px; }
.balance-value { font-size: 1.4rem; font-weight: 700; }

.kv { display: grid; grid-template-columns: auto 1fr auto; gap: 8px 12px; align-items: center; }
.kv dt { color: var(--muted); font-size: .88rem; }
.kv dd { margin: 0; font-weight: 600; word-break: break-all; }

.notice { padding: 12px 14px; border-radius: var(--radius-sm); font-size: .9rem; background: var(--surface-2); }
.notice-warn { background: var(--warn-soft); color: var(--warn); }
.notice-success { background: var(--success-soft); color: var(--success); }
.notice-danger { background: var(--danger-soft); color: var(--danger); }
.notice-accent { background: var(--accent-soft); color: var(--accent); }

.qr { display: block; width: 220px; max-width: 100%; aspect-ratio: 1; margin: 0 auto; border-radius: 12px; background: #fff; padding: 8px; }

.items-box {
  background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px;
  font-family: var(--mono); font-size: .86rem; max-height: 260px; overflow: auto; white-space: pre-wrap; word-break: break-all;
}

.list { display: flex; flex-direction: column; gap: 10px; }
.order { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.order summary { list-style: none; cursor: pointer; padding: 14px 16px; display: flex; gap: 12px; justify-content: space-between; align-items: center; }
.order summary::-webkit-details-marker { display: none; }
.order[open] summary { border-bottom: 1px solid var(--border); }
.order .order-body { padding: 12px 16px 16px; }

.faq details { border-bottom: 1px solid var(--border); padding: 12px 0; }
.faq details:last-child { border-bottom: 0; }
.faq summary { cursor: pointer; font-weight: 600; }
.faq details p { margin: 8px 0 0; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; justify-content: center; padding: 48px 0; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); display: inline-block; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.hero { padding: 6px 0 4px; }
.hero h1 { font-size: 1.35rem; }
.search { position: relative; }
.search input { padding-left: 36px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--muted); }

/* ---------- sheet (modal / bottom sheet) */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 40; background: rgba(10, 12, 20, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 640px) { .sheet-backdrop { align-items: center; padding: 24px; } }
.sheet {
  position: relative; background: var(--surface); width: 100%; max-width: 520px;
  max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  animation: up .2s ease-out;
}
@media (min-width: 640px) { .sheet { border-radius: 18px; } }
@keyframes up { from { transform: translateY(24px); opacity: 0; } }
.sheet-close { position: absolute; right: 12px; top: 12px; }
.sheet h2 { padding-right: 40px; }

.total-row { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 0; border-top: 1px dashed var(--border); }
.total-row .price { font-size: 1.3rem; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 500; font-size: .9rem;
  max-width: calc(100% - 32px); box-shadow: var(--shadow);
}
@media (min-width: 860px) { .toast { bottom: 28px; } }

/* category banners */
.cat-thumb { width: 88px; aspect-ratio: 16/9; object-fit: cover; border-radius: 8px; flex: none; background: var(--surface-2); }
.sheet-banner { display: block; width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 12px; background: var(--surface-2); }
.sheet .sheet-banner + h2 { padding-right: 0; }
