:root {
  --accent: #ff5000;
  --accent-weak: #fff1ea;
  --accent-ink: #c43c00;
  --good: #11833f;
  --good-weak: #e8f6ee;
  --bg: #f5f5f7;
  --card: #ffffff;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --line: #e3e3e8;
  --field: #f7f7f9;
  --danger: #d70015;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --accent: #ff6a1f;
    --accent-weak: #3a2216;
    --accent-ink: #ff9a63;
    --good: #4cd17d;
    --good-weak: #183324;
    --bg: #111113;
    --card: #1c1c1f;
    --ink: #f2f2f5;
    --muted: #9a9aa1;
    --line: #2e2e33;
    --field: #26262a;
    --danger: #ff5a5f;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --accent: #ff6a1f;
  --accent-weak: #3a2216;
  --accent-ink: #ff9a63;
  --good: #4cd17d;
  --good-weak: #183324;
  --bg: #111113;
  --card: #1c1c1f;
  --ink: #f2f2f5;
  --muted: #9a9aa1;
  --line: #2e2e33;
  --field: #26262a;
  --danger: #ff5a5f;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
}
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.boot { padding: 40vh 16px 0; text-align: center; color: var(--muted); }

/* 按钮与输入 */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 10px; padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 4px;
}
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-outline { border-color: var(--accent); color: var(--accent-ink); background: transparent; }
.btn-small { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; }
.icon-btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  width: 36px; height: 36px; border-radius: 10px; font-size: 18px; cursor: pointer; flex: none;
}
input, select {
  font: inherit; color: var(--ink); background: var(--field); border: 1px solid transparent;
  border-radius: 8px; padding: 7px 9px; width: 100%; min-width: 0;
}
input:focus, select:focus { outline: none; border-color: var(--accent); background: var(--card); }
input[type='number'] { -moz-appearance: textfield; }
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* 激活页 */
.gate { min-height: 100vh; display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px 32px; }
.gate-card {
  width: 100%; max-width: 400px; background: var(--card); border-radius: 18px; padding: 28px 22px;
  box-shadow: var(--shadow); text-align: center;
}
.gate-logo {
  width: 56px; height: 56px; margin: 0 auto 12px; border-radius: 16px; background: var(--accent); color: #fff;
  font-size: 28px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.gate-card h1 { font-size: 22px; }
.gate-card > .muted { margin: 6px 0 20px; font-size: 14px; }
.code-input {
  text-align: center; font-size: 19px; letter-spacing: 1px; padding: 12px; margin-bottom: 12px;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; text-transform: uppercase;
}
.gate-msg { min-height: 22px; margin-top: 12px; font-size: 14px; }
.gate-msg.error { color: var(--danger); }
.gate-msg.ok { color: var(--good); }
.rebind-box { background: var(--accent-weak); border-radius: 12px; padding: 12px; margin-top: 8px; text-align: left; font-size: 14px; }
.rebind-box p { margin: 0 0 10px; }
.gate-tips { text-align: left; color: var(--muted); font-size: 13px; padding-left: 18px; margin: 20px 0 0; }
.gate-tips li { margin: 3px 0; }
.device-line { font-size: 12px; margin: 14px 0 0; }

/* 顶栏 */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--card); border-bottom: 1px solid var(--line); }
.topbar-inner { display: flex; align-items: center; gap: 10px; padding: 10px 16px; max-width: 1180px; margin: 0 auto; }
.brand { font-size: 17px; color: var(--accent-ink); white-space: nowrap; }
.plan-bar { display: flex; gap: 6px; flex: 1; min-width: 0; justify-content: flex-end; }
.plan-select { max-width: 220px; font-weight: 600; }
.plan-menu {
  position: absolute; right: 16px; top: 54px; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12); padding: 6px; display: flex; flex-direction: column; min-width: 140px;
}
.plan-menu button { appearance: none; border: 0; background: none; color: var(--ink); font: inherit; text-align: left; padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.plan-menu button:hover { background: var(--field); }
.plan-menu .danger { color: var(--danger); }

/* 布局 */
.layout { max-width: 1180px; margin: 0 auto; padding: 12px 16px 96px; display: grid; gap: 12px; }
@media (min-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); align-items: start; padding-bottom: 40px; }
  .col-result { position: sticky; top: 70px; max-height: calc(100vh - 80px); overflow: auto; }
  .sticky-bar { display: none !important; }
}
.col-input { display: grid; gap: 12px; min-width: 0; }
.panel { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.panel-head h2 { font-size: 16px; }
.count { color: var(--muted); font-weight: 400; font-size: 14px; }

/* 商品卡片 */
.item { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; }
.item-head { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.item-no {
  flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--accent-weak); color: var(--accent-ink);
  font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.item-head input { font-weight: 600; }
.del-btn { appearance: none; border: 0; background: none; color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer; padding: 4px 6px; flex: none; }
.del-btn:hover { color: var(--danger); }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
@media (min-width: 520px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field > span { font-size: 12px; color: var(--muted); }
.field.wide { grid-column: span 2; }
.pair { display: flex; gap: 4px; align-items: center; }
.pair > em { font-style: normal; font-size: 12px; color: var(--muted); flex: none; }
.switches { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 8px; }
.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; user-select: none; }
.switch input { appearance: none; width: 36px; height: 22px; border-radius: 11px; background: var(--line); position: relative; padding: 0; border: 0; cursor: pointer; flex: none; transition: background 0.15s; }
.switch input::after { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform 0.15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(14px); }
.chain { margin-top: 8px; font-size: 12px; color: var(--muted); line-height: 1.7; word-break: break-all; }
.chain b { color: var(--accent-ink); font-size: 13px; }
.more-toggle { appearance: none; border: 0; background: none; color: var(--accent-ink); font: inherit; font-size: 12px; cursor: pointer; padding: 0; margin-top: 8px; }

/* 共享券 */
.coupon-group { border-top: 1px dashed var(--line); padding-top: 10px; margin-top: 10px; }
.coupon-group:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.coupon-group h3 { font-size: 14px; display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.coupon-group h3 small { font-weight: 400; color: var(--muted); font-size: 12px; }
.coupon-row { background: var(--field); border-radius: 10px; padding: 8px; margin-bottom: 8px; }
.coupon-row input, .coupon-row select { background: var(--card); }
.coupon-row .item-head { margin-bottom: 6px; }
.hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }

/* 结果 */
.summary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.stat { background: var(--field); border-radius: 10px; padding: 10px; }
.stat .label { font-size: 12px; color: var(--muted); }
.stat .value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat.best { background: var(--accent-weak); }
.stat.best .value { color: var(--accent-ink); }
.stat.save .value { color: var(--good); }
.verdict { padding: 10px 12px; border-radius: 10px; background: var(--good-weak); color: var(--good); font-weight: 600; margin-bottom: 12px; font-size: 14px; }
.verdict.neutral { background: var(--field); color: var(--ink); }
.order { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; }
.order-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.order-head h3 { font-size: 15px; }
.order-total { font-weight: 700; color: var(--accent-ink); font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.chip { font-size: 12px; border-radius: 6px; padding: 2px 7px; background: var(--accent-weak); color: var(--accent-ink); }
.chip.gray { background: var(--field); color: var(--muted); }
.rows { width: 100%; border-collapse: collapse; font-size: 13px; }
.rows td { padding: 6px 0; border-top: 1px solid var(--line); vertical-align: top; }
.rows td:last-child { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; padding-left: 8px; }
.rows .name { font-weight: 600; }
.rows .steps { color: var(--muted); font-size: 12px; line-height: 1.6; }
.rows .unit { color: var(--muted); font-size: 12px; }
.section-title { font-size: 14px; margin: 16px 0 8px; }
.suggest { border-radius: 10px; padding: 10px; background: var(--field); margin-bottom: 8px; font-size: 13px; }
.suggest.rec { background: var(--good-weak); }
.suggest .tag { display: inline-block; font-size: 12px; font-weight: 700; border-radius: 6px; padding: 1px 7px; margin-right: 6px; background: var(--good); color: #fff; }
.suggest .tag.no { background: var(--muted); }
.suggest .nums { margin-top: 4px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; font-size: 14px; }
.notice { font-size: 12px; color: var(--muted); background: var(--field); border-radius: 8px; padding: 8px 10px; margin-bottom: 10px; }

.footer { text-align: center; padding: 0 16px 100px; }
@media (min-width: 960px) { .footer { padding-bottom: 24px; } }

.sticky-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; background: var(--card); border-top: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}
.sticky-total { font-size: 18px; font-weight: 700; color: var(--accent-ink); font-variant-numeric: tabular-nums; }
.sticky-save { color: var(--good); }

/* 水印：角落显示卡密尾号，不挡操作 */
.watermark {
  position: fixed; right: 10px; bottom: 76px; z-index: 20; pointer-events: none; user-select: none;
  font-size: 11px; color: var(--muted); opacity: 0.55; background: var(--card); border: 1px solid var(--line);
  border-radius: 6px; padding: 2px 6px; font-family: ui-monospace, 'SF Mono', Menlo, monospace;
}
@media (min-width: 960px) { .watermark { bottom: 12px; } }

.toast {
  position: fixed; left: 50%; top: 70px; transform: translateX(-50%); z-index: 30; max-width: calc(100% - 32px);
  background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 14px; font-size: 13px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

/* v2：选档建议、规则口径、校准 */
.chip.green { background: var(--good-weak); color: var(--good); }
.tier { font-size: 13px; padding: 8px 10px; border-radius: 10px; background: var(--field); margin-bottom: 8px; color: var(--muted); }
.tier.used { background: var(--accent-weak); color: var(--accent-ink); }
.verdict.warn { background: var(--accent-weak); color: var(--accent-ink); font-weight: 500; }
.rule-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.hint.first { margin: 0 0 10px; }
.calib-msg { font-size: 13px; margin-top: 8px; border-radius: 10px; }
.calib-msg:not(:empty) { padding: 8px 10px; background: var(--field); }
.calib-msg.good { background: var(--good-weak); color: var(--good); }
.calib-msg.bad { background: var(--accent-weak); color: var(--accent-ink); }
.pair .btn { flex: none; }
.steps.presale { color: var(--accent-ink); }
#rules .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field.row-end { justify-content: flex-end; align-items: flex-end; }
#vip > .grid { margin-bottom: 4px; }

.fatal {
  position: fixed; left: 12px; right: 12px; top: 12px; z-index: 50; background: var(--card); color: var(--ink);
  border: 1px solid var(--danger); border-radius: 12px; padding: 12px 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  display: flex; flex-direction: column; gap: 6px; align-items: flex-start; font-size: 14px;
}
.fatal-title { color: var(--danger); font-weight: 600; word-break: break-all; }
.fatal-hint { color: var(--muted); font-size: 12px; }

.gate-tag { display: inline-block; font-size: 12px; font-weight: 700; border-radius: 6px; padding: 1px 7px; margin-right: 6px; background: var(--danger); color: #fff; vertical-align: 1px; }

/* v3：参与凑单、更多优惠、汇总分项、页面内对话框 */
.item.off { opacity: 0.55; }
.item.off .chain { text-decoration: line-through; }
.join { display: inline-flex; align-items: center; flex: none; cursor: pointer; }
.join input { width: 18px; height: 18px; accent-color: var(--accent); padding: 0; }
.subsidy-row { margin-top: 8px; }
.chip-btn { appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--accent-ink); border-radius: 6px; font-size: 12px; padding: 4px 6px; cursor: pointer; flex: none; white-space: nowrap; }
details.more { margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 6px; }
details.more summary { cursor: pointer; font-size: 13px; color: var(--accent-ink); padding: 4px 0; }
details.more .grid { margin-top: 6px; }
.switches.wide { grid-column: 1 / -1; }
.breakdown { background: var(--field); border-radius: 10px; padding: 6px 10px; margin-bottom: 4px; }
.bd-row { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; padding: 4px 0; border-bottom: 1px solid var(--line); }
.bd-row:last-child { border-bottom: 0; }
.bd-row small { font-size: 11px; margin-left: 4px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.order-sub { margin: -2px 0 6px; }
.stat .sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.steps.extreme { color: var(--good); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.dialog { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.35); display: flex; align-items: center; justify-content: center; padding: 16px; }
.dialog-card { background: var(--card); border-radius: 14px; padding: 18px; width: 100%; max-width: 360px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25); }
.dialog-card h3 { font-size: 16px; margin-bottom: 10px; }
.dialog-card p { margin: 0 0 10px; font-size: 14px; }
.dialog-input { margin-bottom: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* 顶部授权徽标 + 退出：宽屏一行；窄屏时品牌和徽标在第一行，方案选择换到第二行 */
.license-bar { position: relative; display: flex; align-items: center; gap: 4px; flex: none; }
.license-badge {
  appearance: none; border: 1px solid var(--line); background: var(--good-weak); color: var(--good); border-radius: 999px;
  padding: 5px 10px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
.license-badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.license-badge.soon { background: var(--accent-weak); color: var(--accent-ink); }
.bar-sep { color: var(--line); }
.logout-btn { appearance: none; border: 0; background: none; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer; padding: 5px 4px; white-space: nowrap; }
.logout-btn:hover { color: var(--danger); }
.license-pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 200px; background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12); padding: 10px 12px; font-size: 13px; line-height: 1.7; white-space: nowrap;
}
.license-pop b { font-variant-numeric: tabular-nums; }
.plan-bar { position: relative; }
.plan-menu { right: 0; top: calc(100% + 6px); z-index: 20; }
@media (max-width: 719px) {
  .topbar-inner { flex-wrap: wrap; row-gap: 8px; }
  .brand { order: 1; }
  .license-bar { order: 2; margin-left: auto; }
  .plan-bar { order: 3; flex: 1 0 100%; justify-content: stretch; }
  .plan-select { max-width: none; flex: 1; }
  .license-badge { padding: 4px 9px; font-size: 12px; }
}
