/* 馬多多 — Fama digital market. Paper + emerald + cinnabar seal. */
:root {
    --paper: #f6f1e5;
    --card: #fffdf7;
    --ink: #1c2420;
    --ink-2: #4b5a52;
    --ink-3: #7d8a83;
    --line: #e3dccb;
    --brand: #0f5f48;
    --brand-2: #13866a;
    --on-brand: #fbf6ea;
    --seal: #d2452b;
    --gold: #b7862a;
    --ok: #15803d;
    --danger: #b42318;
    --shadow: 0 1px 2px rgb(28 36 32 / 6%), 0 6px 18px rgb(28 36 32 / 7%);
    --radius: 14px;
    --tabs-h: 0px;
    --font: "PingFang HK", "PingFang TC", "Noto Sans HK", "Microsoft JhengHei", system-ui, sans-serif;
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --paper: #121815;
        --card: #1a221e;
        --ink: #ecefe9;
        --ink-2: #b4c0b9;
        --ink-3: #85938b;
        --line: #2b3631;
        --brand: #2fae86;
        --brand-2: #45c79d;
        --on-brand: #08130f;
        --seal: #ef6a4c;
        --gold: #e0b558;
        --ok: #4ade80;
        --danger: #f87171;
        --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 22px rgb(0 0 0 / 28%);
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --paper: #121815;
    --card: #1a221e;
    --ink: #ecefe9;
    --ink-2: #b4c0b9;
    --ink-3: #85938b;
    --line: #2b3631;
    --brand: #2fae86;
    --brand-2: #45c79d;
    --on-brand: #08130f;
    --seal: #ef6a4c;
    --gold: #e0b558;
    --ok: #4ade80;
    --danger: #f87171;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 22px rgb(0 0 0 / 28%);
    color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
    background: var(--paper);
    color: var(--ink);
    font: 15px/1.5 var(--font);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg { flex: none; }

.app { min-height: 100%; display: flex; flex-direction: column; }

/* ---------- header ---------- */
.top {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
    background: color-mix(in srgb, var(--paper) 88%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 34px; height: 34px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { font-size: 18px; letter-spacing: 0.08em; }
.brand-text small { font-size: 11px; color: var(--ink-3); letter-spacing: 0.2em; }
.top-right { display: flex; align-items: center; gap: 8px; }
.points-chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px 4px 4px; border-radius: 999px;
    background: var(--card); border: 1px solid var(--line);
    font-variant-numeric: tabular-nums;
}
.points-coin {
    display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
    background: var(--gold); color: #fff; font-size: 11px; font-weight: 700;
}
.user-btn {
    width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line);
    background: var(--brand); color: var(--on-brand); font-weight: 700; cursor: pointer;
}

/* ---------- tabs ---------- */
.tabs {
    display: flex; gap: 4px; padding: 8px 16px 0;
    position: sticky; top: calc(55px + env(safe-area-inset-top)); z-index: 19;
    background: var(--paper);
}
.tabs a {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px; border-radius: 999px; color: var(--ink-2); font-weight: 600;
}
.tabs a svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a.active { background: var(--brand); color: var(--on-brand); }
@media (max-width: 640px) {
    :root { --tabs-h: calc(58px + env(safe-area-inset-bottom)); }
    .tabs {
        position: fixed; top: auto; bottom: 0; left: 0; right: 0;
        justify-content: space-around; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
        background: var(--card); border-top: 1px solid var(--line);
    }
    .tabs a { flex-direction: column; gap: 2px; padding: 4px 10px; font-size: 11px; border-radius: 10px; }
    .tabs a svg { width: 22px; height: 22px; }
    .tabs a.active { background: none; color: var(--brand); }
}

.view {
    flex: 1; width: 100%; max-width: 1120px; margin: 0 auto;
    padding: 16px 16px calc(32px + var(--tabs-h));
    outline: none;
}

/* ---------- common ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 40px; padding: 0 16px; border-radius: 11px;
    border: 1px solid var(--line); background: var(--card); color: var(--ink);
    font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-brand { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn-seal { background: var(--seal); border-color: var(--seal); color: #fff; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); }
.btn-small { min-height: 32px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn-block { width: 100%; min-height: 46px; font-size: 16px; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.panel {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 16px;
}
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 22px 0 10px; }
.section-title h2 { margin: 0; font-size: 17px; }
.section-title span { color: var(--ink-3); font-size: 13px; }
.muted { color: var(--ink-3); }
.empty {
    text-align: center; padding: 48px 16px; color: var(--ink-3);
    border: 1.5px dashed var(--line); border-radius: var(--radius);
}
.empty strong { display: block; color: var(--ink-2); font-size: 16px; margin-bottom: 4px; }
.empty .btn { margin-top: 14px; }
.spinner {
    width: 26px; height: 26px; margin: 48px auto; border-radius: 50%;
    border: 3px solid var(--line); border-top-color: var(--brand); animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.price { font-weight: 800; color: var(--seal); font-variant-numeric: tabular-nums; }
.price small { font-size: 0.72em; font-weight: 700; margin-left: 2px; }
.price.free { color: var(--ok); }
.tag {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
    background: color-mix(in srgb, var(--brand) 12%, transparent); color: var(--brand);
}
.tag-seal { background: color-mix(in srgb, var(--seal) 12%, transparent); color: var(--seal); }
.tag-muted { background: color-mix(in srgb, var(--ink-3) 15%, transparent); color: var(--ink-2); }

/* ---------- hero + filters ---------- */
.hero {
    position: relative; overflow: hidden;
    padding: 20px; border-radius: 18px; margin-bottom: 16px;
    background:
        radial-gradient(120% 140% at 100% 0%, color-mix(in srgb, var(--brand-2) 55%, transparent), transparent 60%),
        var(--brand);
    color: var(--on-brand);
}
.hero h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: 0.04em; }
.hero p { margin: 0; opacity: 0.85; font-size: 14px; max-width: 32em; }
.hero .hero-seal {
    position: absolute; right: 18px; bottom: -14px; font-size: 92px; font-weight: 900;
    color: color-mix(in srgb, var(--on-brand) 12%, transparent); letter-spacing: -0.05em; pointer-events: none;
}
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.search {
    flex: 1 1 240px; display: flex; align-items: center; gap: 8px;
    padding: 0 12px; height: 42px; border-radius: 12px;
    background: var(--card); border: 1px solid var(--line);
}
.search svg { width: 18px; height: 18px; fill: none; stroke: var(--ink-3); stroke-width: 2; stroke-linecap: round; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; }
.seg { display: inline-flex; padding: 3px; border-radius: 11px; background: var(--card); border: 1px solid var(--line); }
.seg button {
    border: 0; background: none; padding: 6px 12px; border-radius: 8px; cursor: pointer;
    color: var(--ink-2); font-weight: 600; font-size: 13px;
}
.seg button.on { background: var(--brand); color: var(--on-brand); }
.select {
    height: 42px; padding: 0 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
}

/* ---------- product grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 14px; }
@media (max-width: 420px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } }
.card {
    display: flex; flex-direction: column; overflow: hidden; min-width: 0;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow); transition: transform 0.15s ease;
}
.card:hover { transform: translateY(-2px); }
.cover {
    position: relative; aspect-ratio: 4 / 3; overflow: hidden;
    display: grid; place-items: center; background: var(--line);
}
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover-art { width: 100%; height: 100%; display: grid; place-items: center; }
.cover-art span { font-size: 44px; font-weight: 900; color: rgb(255 255 255 / 92%); text-shadow: 0 2px 10px rgb(0 0 0 / 18%); }
.cover .badge {
    position: absolute; left: 8px; top: 8px; padding: 2px 8px; border-radius: 999px;
    background: rgb(0 0 0 / 55%); color: #fff; font-size: 11px; font-weight: 600;
    display: inline-flex; align-items: center; gap: 4px; backdrop-filter: blur(4px);
}
.cover .badge svg { width: 12px; height: 12px; fill: currentColor; }
.cover .owned {
    position: absolute; right: 8px; top: 8px; padding: 2px 8px; border-radius: 999px;
    background: var(--ok); color: #fff; font-size: 11px; font-weight: 700;
}
.card-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.card-title {
    font-weight: 700; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2;
    -webkit-box-orient: vertical; overflow: hidden; min-height: 2.7em;
}
.card-meta { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-3); }
.card-meta .seller { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-foot { display: flex; justify-content: space-between; align-items: baseline; margin-top: auto; padding-top: 4px; }
.more-row { display: flex; justify-content: center; margin-top: 18px; }

/* ---------- detail ---------- */
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-2); margin-bottom: 12px; font-weight: 600; }
.back svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.detail { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 22px; align-items: start; }
@media (max-width: 760px) { .detail { grid-template-columns: 1fr; gap: 14px; } }
.detail .cover { border-radius: var(--radius); box-shadow: var(--shadow); }
.detail h1 { margin: 0 0 6px; font-size: 22px; line-height: 1.3; }
.detail .by { color: var(--ink-3); font-size: 14px; margin-bottom: 12px; }
.detail .by strong { color: var(--ink-2); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; margin: 14px 0; }
.facts dt { color: var(--ink-3); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.buybox { display: flex; flex-direction: column; gap: 10px; padding: 16px; margin-top: 6px; }
.buybox .row { display: flex; justify-content: space-between; align-items: baseline; }
.buybox .big-price { font-size: 28px; }
.desc { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.7; color: var(--ink-2); margin-top: 16px; }
.access-row { display: flex; gap: 8px; flex-wrap: wrap; }
.access-row .btn { flex: 1 1 140px; }

/* ---------- forms ---------- */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field > span { font-weight: 600; font-size: 14px; }
.field small { color: var(--ink-3); font-size: 12px; }
.input, .textarea {
    width: 100%; padding: 10px 12px; border-radius: 11px; border: 1px solid var(--line);
    background: var(--paper); outline: none;
}
.input:focus, .textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.textarea { min-height: 110px; resize: vertical; }
.kind-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kind-pick label {
    display: flex; gap: 10px; align-items: flex-start; padding: 12px; border-radius: 12px;
    border: 1.5px solid var(--line); cursor: pointer; background: var(--paper);
}
.kind-pick input { margin-top: 3px; accent-color: var(--brand); }
.kind-pick label:has(input:checked) { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 7%, var(--card)); }
.kind-pick strong { display: block; }
.kind-pick small { color: var(--ink-3); }
.drop {
    display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center;
    padding: 20px 12px; border: 1.5px dashed var(--line); border-radius: 12px; cursor: pointer; background: var(--paper);
}
.drop.has { border-style: solid; border-color: var(--brand); }
.drop input { display: none; }
.drop strong { overflow-wrap: anywhere; }
.price-input { display: flex; align-items: center; gap: 8px; }
.price-input .input { max-width: 160px; font-variant-numeric: tabular-nums; }
.form-error { color: var(--danger); font-size: 14px; min-height: 1.2em; }
.progress { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: var(--brand); transition: width 0.2s; }

/* ---------- seller dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 640px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat { padding: 12px 14px; }
.stat small { color: var(--ink-3); font-size: 12px; display: block; }
.stat strong { font-size: 20px; font-variant-numeric: tabular-nums; }
.quota { margin-top: 10px; padding: 12px 14px; }
.quota .row { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; color: var(--ink-2); }
.quota.warn .progress > i { background: var(--seal); }
.list { display: grid; gap: 8px; }
.item {
    display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 12px; align-items: center;
    padding: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
}
.item .thumb { width: 56px; height: 56px; border-radius: 10px; overflow: hidden; }
.item .thumb .cover { aspect-ratio: 1; height: 100%; }
.item .thumb .cover-art span { font-size: 22px; }
.item-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-sub { font-size: 12px; color: var(--ink-3); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.item-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 520px) {
    .item { grid-template-columns: 48px minmax(0, 1fr); }
    .item .thumb { width: 48px; height: 48px; }
    .item-actions { grid-column: 1 / -1; justify-content: flex-start; }
}

/* ---------- ledger ---------- */
.balance-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px; }
.balance-card strong { font-size: 32px; font-variant-numeric: tabular-nums; }
.ledger { display: grid; }
.ledger-row {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px;
    padding: 12px 2px; border-bottom: 1px solid var(--line);
}
.ledger-row .amt { font-weight: 800; font-variant-numeric: tabular-nums; text-align: right; }
.ledger-row .amt.plus { color: var(--ok); }
.ledger-row .amt.minus { color: var(--seal); }
.ledger-row small { color: var(--ink-3); font-size: 12px; }

/* ---------- sheets / dialogs ---------- */
.sheet-backdrop {
    position: fixed; inset: 0; z-index: 50; background: rgb(10 16 13 / 55%);
    display: flex; align-items: center; justify-content: center; padding: 16px;
    animation: fade 0.15s ease;
}
.sheet {
    width: min(460px, 100%); max-height: calc(100% - 32px); overflow: auto;
    background: var(--card); border-radius: 18px; padding: 18px; box-shadow: 0 20px 60px rgb(0 0 0 / 35%);
}
.sheet h3 { margin: 0 0 10px; font-size: 18px; }
.sheet .sheet-actions { display: flex; gap: 8px; margin-top: 16px; }
.sheet .sheet-actions .btn { flex: 1; }
.sheet-wide { width: min(960px, 100%); padding: 0; background: #000; overflow: hidden; }
.player-head {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 8px 8px 8px 14px; background: #0c0f0e; color: #e8ece9;
}
.player-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.player-head .btn { background: #1f2623; border-color: #2c3531; color: #e8ece9; }
.player-stage { position: relative; background: #000; aspect-ratio: 16 / 9; max-height: calc(100vh - 120px); }
.player-stage.doc { aspect-ratio: auto; height: min(80vh, 900px); }
.player-stage.audio { aspect-ratio: auto; padding: 36px 16px; }
.player-stage video, .player-stage iframe, .player-stage audio { width: 100%; height: 100%; border: 0; display: block; }
.player-stage audio { height: 54px; }
.confirm-lines { display: grid; gap: 6px; font-size: 15px; }
.confirm-lines div { display: flex; justify-content: space-between; }
.confirm-lines .total { border-top: 1px solid var(--line); padding-top: 8px; font-weight: 700; }
@keyframes fade { from { opacity: 0; } }

.toast {
    position: fixed; left: 50%; bottom: calc(24px + var(--tabs-h)); transform: translateX(-50%); z-index: 60;
    max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px;
    background: var(--ink); color: var(--paper); font-weight: 600; box-shadow: var(--shadow);
    animation: fade 0.15s ease;
}
.toast.error { background: var(--danger); color: #fff; }

.login-card { max-width: 400px; margin: 20px auto; }
.login-card h2 { margin: 0 0 4px; }
.login-card p { margin: 0 0 16px; color: var(--ink-3); font-size: 14px; }

.embed .top { padding-top: 10px; }
.embed .brand-text { display: none; }
