:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1c2333;
  --muted: #6b7485;
  --line: #e5e8ef;
  --brand: #4f46e5;
  --brand-2: #7c3aed;
  --brand-soft: #eef0ff;
  --ok: #16a34a;
  --ok-soft: #e8f7ee;
  --warn: #d97706;
  --warn-soft: #fff5e5;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* header */
.topbar { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar .wrap { display: flex; align-items: center; height: 60px; gap: 20px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; color: var(--text); }
.logo-mark { width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(135deg, var(--brand), var(--brand-2)); display: grid; place-items: center; color: #fff; font-size: 16px; }
.nav { display: flex; gap: 4px; margin-left: auto; }
.nav a { padding: 7px 14px; border-radius: 9px; color: var(--muted); font-weight: 500; }
.nav a.active, .nav a:hover { background: var(--brand-soft); color: var(--brand); }

.hero { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; padding: 34px 0 60px; }
.hero h1 { margin: 0 0 6px; font-size: 28px; }
.hero p { margin: 0; opacity: .85; }
.notice { margin-top: -38px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 18px; display: flex; gap: 12px; align-items: flex-start; white-space: pre-wrap; }
.notice-icon { flex: none; width: 26px; height: 26px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); display: grid; place-items: center; font-size: 14px; }

/* tabs */
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: 24px 0 16px; }
.tab { border: 1px solid var(--line); background: var(--card); padding: 6px 16px; border-radius: 999px; cursor: pointer; color: var(--muted); }
.tab.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* product grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; padding-bottom: 40px; }
.pcard { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; cursor: pointer; display: flex; flex-direction: column; transition: transform .15s, box-shadow .15s; border: 1px solid transparent; }
.pcard:hover { transform: translateY(-2px); box-shadow: 0 8px 28px rgba(79, 70, 229, .14); border-color: #dcdcff; }
.pcard.soldout { opacity: .6; }
.pimg { aspect-ratio: 16/9; background: linear-gradient(135deg, #eef0ff, #f6efff); display: grid; place-items: center; color: var(--brand); font-size: 34px; font-weight: 700; overflow: hidden; }
.pimg img { width: 100%; height: 100%; object-fit: cover; }
.pbody { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.pname { font-weight: 600; font-size: 16px; line-height: 1.4; }
.pmeta { display: flex; justify-content: space-between; align-items: flex-end; margin-top: auto; }
.price { color: #e11d48; font-weight: 700; font-size: 22px; }
.price small { font-size: 13px; }
.oprice { color: var(--muted); text-decoration: line-through; font-size: 13px; margin-left: 6px; font-weight: 400; }
.tag { display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 6px; font-size: 12px; font-weight: 500; background: var(--brand-soft); color: var(--brand); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.tag.gray { background: #f0f1f5; color: var(--muted); }

/* panels & forms */
.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.panel h2 { margin: 0 0 16px; font-size: 19px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label { font-size: 13px; color: var(--muted); font-weight: 500; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 10px 12px; outline: none; transition: border-color .15s, box-shadow .15s; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79, 70, 229, .12); }
textarea.input { resize: vertical; min-height: 90px; font-family: var(--mono); font-size: 13px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--card); padding: 9px 16px; border-radius: 10px; cursor: pointer; font-weight: 500; white-space: nowrap; transition: background .15s, opacity .15s; }
.btn:hover { background: #f6f7fb; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, var(--brand), var(--brand-2)); border-color: transparent; color: #fff; }
.btn.primary:hover { opacity: .92; }
.btn.danger { color: var(--danger); border-color: #f5c6c6; }
.btn.block { width: 100%; padding: 12px; font-size: 16px; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.pw-wrap { position: relative; display: block; width: 100%; }
.pw-wrap .input { padding-right: 64px; }
.pw-eye { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: #f0f1f5; color: var(--muted); border-radius: 7px; padding: 3px 9px; font-size: 12px; cursor: pointer; }
.pw-eye:hover { color: var(--brand); background: var(--brand-soft); }
.qty { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.qty button { border: 0; background: #f6f7fb; width: 38px; cursor: pointer; font-size: 18px; }
.qty input { width: 70px; border: 0; text-align: center; outline: none; padding: 9px 0; }

/* modal */
.mask { position: fixed; inset: 0; background: rgba(15, 18, 30, .5); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade .15s; }
.modal { background: var(--card); border-radius: 18px; width: 100%; max-width: 560px; max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 24px 64px rgba(0, 0, 0, .25); animation: pop .18s; }
.modal.wide { max-width: 820px; }
.modal-head { display: flex; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); z-index: 1; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-close { margin-left: auto; border: 0; background: none; font-size: 22px; color: var(--muted); cursor: pointer; line-height: 1; }
.modal-body { padding: 20px 22px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.96); opacity: 0; } }

.desc { white-space: pre-wrap; word-break: break-word; background: #f8f9fc; border-radius: 10px; padding: 12px 14px; font-size: 14px; color: #3b4357; margin-bottom: 16px; max-height: 220px; overflow: auto; }
.summary { background: #f8f9fc; border-radius: 12px; padding: 12px 16px; margin: 6px 0 16px; }
.summary .line { display: flex; justify-content: space-between; padding: 3px 0; font-size: 14px; }
.summary .total { font-weight: 700; font-size: 16px; border-top: 1px dashed var(--line); margin-top: 6px; padding-top: 8px; }
.summary .total span:last-child { color: #e11d48; font-size: 20px; }
.tiers { display: flex; gap: 6px; flex-wrap: wrap; margin: -4px 0 14px; }

/* pay */
.pay-box { text-align: center; }
.pay-amount { font-size: 34px; font-weight: 800; color: #e11d48; margin: 4px 0; }
.qr { width: 220px; height: 220px; margin: 12px auto; border: 1px solid var(--line); border-radius: 12px; padding: 8px; background: #fff; }
.qr img { width: 100%; height: 100%; }
.countdown { font-family: var(--mono); color: var(--warn); font-weight: 600; }
.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; animation: spin .8s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* order */
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 8px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.cards-list { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-top: 10px; }
.card-item { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); font-family: var(--mono); font-size: 14px; word-break: break-all; }
.card-item:last-child { border-bottom: 0; }
.card-item .idx { color: var(--muted); flex: none; width: 24px; }
.card-item .ct { flex: 1; white-space: pre-wrap; }
.status-hero { text-align: center; padding: 10px 0 18px; }
.status-hero .icon { width: 56px; height: 56px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 28px; margin-bottom: 8px; }
.status-hero.ok .icon { background: var(--ok-soft); color: var(--ok); }
.status-hero.wait .icon { background: var(--warn-soft); color: var(--warn); }
.status-hero.bad .icon { background: var(--danger-soft); color: var(--danger); }
.status-hero h2 { margin: 0; font-size: 20px; }

.page { padding: 28px 0 48px; }
.narrow { max-width: 640px; margin: 0 auto; }
.empty { text-align: center; color: var(--muted); padding: 50px 0; }
.history-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.history-item:last-child { border-bottom: 0; }

.footer { text-align: center; color: var(--muted); font-size: 13px; padding: 24px 0 36px; white-space: pre-wrap; }

#toast { position: fixed; left: 50%; top: 24px; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: rgba(20, 24, 36, .92); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); animation: pop .18s; }
.toast.err { background: var(--danger); }

@media (max-width: 640px) {
  .topbar .wrap { gap: 10px; }
  .nav a { padding: 6px 10px; }
  .logo span.name { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .hero { padding: 24px 0 52px; }
  .hero h1 { font-size: 22px; }
  .grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .pbody { padding: 10px 12px 12px; }
  .pname { font-size: 14px; }
  .price { font-size: 18px; }
  .modal { border-radius: 16px; }
}
@media (max-width: 380px) { .grid { grid-template-columns: 1fr; } }
