:root {
  --bg: #f4f6fb; --card: #ffffff; --ink: #0f172a; --muted: #64748b; --line: #e2e8f0;
  --brand: #2563eb; --brand-ink: #fff; --accent: #f59e0b;
  --ok: #16a34a; --warn: #d97706; --bad: #dc2626; --info: #2563eb; --ofd: #7c3aed;
  --radius: 16px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1120; --card: #131c31; --ink: #e5e9f2; --muted: #94a3b8; --line: #1f2a44; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif; -webkit-tap-highlight-color: transparent; }
body { padding-bottom: calc(96px + var(--safe-b)); max-width: 720px; margin: 0 auto; }
button { font: inherit; cursor: pointer; }
input { font: inherit; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; padding: calc(10px + var(--safe-t)) 16px 10px; background: #0f172a; color: #fff; }
.brand { display: flex; gap: 10px; align-items: center; }
.brand img { border-radius: 9px; }
.title { font-weight: 800; letter-spacing: .2px; }
.sub { font-size: 12px; color: #a5b4fc; }
.icon-btn { background: rgba(255,255,255,.1); color: #fff; border: 0; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; }

.banner { margin: 12px 16px 0; padding: 10px 12px; border-radius: 12px; background: #fef3c7; color: #78350f; font-size: 13px; border: 1px solid #fcd34d; }
@media (prefers-color-scheme: dark) { .banner { background: #3a2a07; color: #fde68a; border-color: #78560f; } }

.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 14px 16px 4px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 12px; color: var(--muted); }

.tabs { display: flex; gap: 6px; margin: 12px 16px 6px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.tab { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 8px; border-radius: 9px; font-weight: 600; }
.tab.active { background: var(--brand); color: #fff; }

.ledger { margin: 6px 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.ledger-head { display: grid; grid-template-columns: 56px 1fr auto; gap: 10px; padding: 8px 14px; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); border-bottom: 1px solid var(--line); }
.row { display: grid; grid-template-columns: 56px 1fr auto; gap: 10px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); width: 100%; text-align: left; background: transparent; border-left: 0; border-right: 0; border-top: 0; color: inherit; }
.row:last-child { border-bottom: 0; }
.row:active { background: rgba(37,99,235,.07); }
.date { text-align: center; line-height: 1.1; }
.date .mo { font-size: 11px; color: var(--muted); text-transform: uppercase; font-weight: 700; }
.date .dy { font-size: 20px; font-weight: 800; }
.mid { min-width: 0; }
.nick { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); margin-top: 2px; min-width: 0; }
.meta .num { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { display: inline-block; padding: 2px 7px; border-radius: 6px; font-size: 11px; font-weight: 800; color: #fff; white-space: nowrap; }
.demo-tag { background: #fde68a; color: #78350f; padding: 1px 5px; border-radius: 5px; font-size: 10px; font-weight: 800; }
.right { text-align: right; }
.pill { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.when { font-size: 11px; color: var(--muted); margin-top: 3px; }
.s-delivered { background: #dcfce7; color: #166534; }
.s-out_for_delivery { background: #ede9fe; color: #5b21b6; }
.s-in_transit, .s-info_received { background: #dbeafe; color: #1e40af; }
.s-pending { background: #f1f5f9; color: #475569; }
.s-available_for_pickup { background: #cffafe; color: #155e75; }
.s-failed_attempt, .s-expired { background: #ffedd5; color: #9a3412; }
.s-exception { background: #fee2e2; color: #991b1b; }
@media (prefers-color-scheme: dark) {
  .s-delivered { background: #14532d; color: #bbf7d0; } .s-out_for_delivery { background: #3b0764; color: #e9d5ff; }
  .s-in_transit, .s-info_received { background: #1e3a8a; color: #bfdbfe; } .s-pending { background: #1e293b; color: #cbd5e1; }
  .s-available_for_pickup { background: #164e63; color: #a5f3fc; } .s-failed_attempt, .s-expired { background: #7c2d12; color: #fed7aa; }
  .s-exception { background: #7f1d1d; color: #fecaca; }
}
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }

.fab { position: fixed; right: max(16px, calc(50% - 344px)); bottom: calc(20px + var(--safe-b)); z-index: 6; display: flex; align-items: center; gap: 6px; padding: 14px 20px 14px 16px; border: 0; border-radius: 999px; background: var(--brand); color: #fff; font-weight: 800; box-shadow: 0 10px 25px rgba(37,99,235,.35); }

.scrim { position: fixed; inset: 0; background: rgba(2,6,23,.5); z-index: 9; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; max-width: 720px; margin: 0 auto; max-height: 90vh; overflow: auto; background: var(--card); border-radius: 22px 22px 0 0; padding: 8px 18px calc(22px + var(--safe-b)); box-shadow: 0 -10px 30px rgba(0,0,0,.2); animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: .5; } to { transform: none; opacity: 1; } }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 10px; }
.sheet h2 { margin: 4px 0 12px; font-size: 20px; }
label { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin: 10px 0; }
label input { display: block; width: 100%; margin-top: 6px; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font-size: 17px; font-weight: 500; }
#numInput { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .5px; }
.detect { min-height: 30px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
.cand { border: 2px solid transparent; border-radius: 8px; padding: 4px 10px; font-weight: 800; color: #fff; font-size: 13px; opacity: .55; }
.cand.sel { opacity: 1; border-color: var(--ink); }
.primary, .secondary, .ghost, .danger { width: 100%; padding: 14px; border-radius: 14px; border: 0; font-weight: 800; margin-top: 8px; }
.primary { background: var(--brand); color: #fff; }
.primary:disabled { opacity: .5; }
.secondary { background: var(--ink); color: var(--bg); }
.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.danger { background: transparent; color: var(--bad); border: 1px solid var(--line); }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--bad); font-weight: 600; font-size: 14px; }

.plans { display: grid; gap: 12px; }
@media (min-width: 560px) { .plans { grid-template-columns: 1fr 1fr; } }
.plan { border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.plan.featured { border: 2px solid var(--brand); }
.plan-name { font-weight: 800; }
.price { font-size: 28px; font-weight: 900; margin: 4px 0; }
.price span { font-size: 13px; color: var(--muted); font-weight: 600; }
.plan ul { padding-left: 18px; margin: 6px 0 4px; color: var(--muted); font-size: 14px; }
.redeem { margin-top: 12px; font-size: 14px; }
.redeem form { display: flex; gap: 8px; margin-top: 8px; }
.redeem input { flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.redeem button { width: auto; margin: 0; padding: 10px 16px; }

.d-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.d-nick { font-size: 22px; font-weight: 800; margin: 0; }
.d-num { font-family: ui-monospace, Menlo, monospace; font-size: 14px; color: var(--muted); word-break: break-all; margin-top: 4px; }
.d-status { margin: 14px 0; padding: 14px; border-radius: 14px; background: var(--bg); }
.d-status .big { font-size: 18px; font-weight: 800; }
.timeline { list-style: none; padding: 0; margin: 8px 0; }
.timeline li { position: relative; padding: 0 0 14px 22px; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--line); }
.timeline li:first-child::before { background: var(--brand); }
.timeline .t { font-size: 12px; color: var(--muted); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 14px; margin: 10px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.keybox { font-family: ui-monospace, Menlo, monospace; font-size: 15px; background: var(--bg); padding: 12px; border-radius: 12px; border: 1px dashed var(--line); word-break: break-all; user-select: all; }
.section { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 12px; }
.section h3 { margin: 0 0 6px; font-size: 15px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); top: calc(64px + var(--safe-t)); z-index: 20; background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.3); max-width: 90vw; }
