:root {
    --bg: #e8dfce;
    --bg-2: #ddd3bf;
    --panel: #f4eee3;
    --ink: #1a1a1a;
    --muted: #7c7c7c;
    --line: rgba(26, 26, 26, 0.14);
    --mint: #8a6a28;
    --mint-2: #ceaf73;
    --ember: #ec673e;
    --gold: #ceaf73;
    --red: #c4472a;
    --blue: #00a3e4;
    --purple: #8f4aff;
    --header: #1a1a1a;
    --cream: #e8dfce;
    --shadow: 0 12px 32px rgba(26, 26, 26, 0.12);
    --radius: 12px;
    --mono: "Cascadia Mono", "Segoe UI Mono", ui-monospace, monospace;
    --sans: "M PLUS 1", "Hiragino Sans", Meiryo, system-ui, sans-serif;
    --display: Oxanium, "M PLUS 1", sans-serif;
    --touch: 44px;
    --tabbar-h: calc(58px + env(safe-area-inset-bottom, 0px));
    --header-h: calc(4.1rem + env(safe-area-inset-top, 0px));
    --pad: 1rem;
    --kb: 0px;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
html, body {
    margin: 0;
    min-height: 100%;
    min-height: 100dvh;
}
body {
    font-family: var(--sans);
    background:
        radial-gradient(900px 420px at 100% -10%, rgba(206, 175, 115, 0.28), transparent 55%),
        var(--bg);
    color: var(--ink);
    letter-spacing: 0.01em;
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    -webkit-tap-highlight-color: rgba(206, 175, 115, 0.25);
    text-size-adjust: 100%;
    overflow-x: hidden;
}
button, a, .tabbar a, .tabbar button { touch-action: manipulation; }
a { color: var(--mint); text-decoration: none; }
@media (hover: hover) {
    a:hover { color: #1a1a1a; }
}
code { font-family: var(--mono); font-size: 0.92em; color: #6b5424; }
figure { margin: 0; }
h1, h2, h3, .kicker, .desk-nav, .tabbar {
    font-family: var(--display);
}

.topbar, main, .chat-root { position: relative; z-index: 1; }

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.8rem;
    padding: 0.55rem var(--pad);
    padding-top: max(0.55rem, env(safe-area-inset-top, 0px));
    border-bottom: 1px solid #000;
    background: var(--header);
    position: sticky;
    top: 0;
    z-index: 20;
}
.brand {
    display: flex;
    align-items: center;
    min-width: 0;
    color: var(--gold);
}
.brand img {
    height: 38px;
    width: auto;
    max-width: min(42vw, 200px);
    object-fit: contain;
    display: block;
}
.desk-nav {
    display: flex;
    gap: 0.15rem;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
}
.desk-nav a, .desk-nav summary {
    padding: 0.4rem 0.7rem;
    color: var(--cream);
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    border-bottom: 2px solid transparent;
    cursor: pointer;
}
.desk-nav a.is-active, .desk-nav a:hover, .desk-nav summary:hover {
    color: var(--gold);
    border-bottom-color: var(--gold);
}
.nav-more { position: relative; }
.nav-more summary { list-style: none; }
.nav-more summary::-webkit-details-marker { display: none; }
.nav-more-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 0.4rem);
    min-width: 11.5rem;
    background: var(--header);
    border: 1px solid #333;
    padding: 0.35rem;
    z-index: 30;
    display: grid;
}
.nav-more-panel a { display: block; width: 100%; border-bottom: 0; }
.nav-more-panel a.is-active { background: rgba(206, 175, 115, 0.12); }

.tabbar {
    display: none;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 25;
    grid-template-columns: repeat(5, 1fr);
    background: var(--header);
    border-top: 1px solid #000;
    padding: 0.2rem 0.2rem calc(0.25rem + env(safe-area-inset-bottom, 0px));
    user-select: none;
}
body.no-chat .tabbar { grid-template-columns: repeat(4, 1fr); }
.tabbar a, .tabbar button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.12rem;
    min-height: 48px;
    background: none;
    border: 0;
    color: var(--cream);
    font-size: 0.68rem;
    font-weight: 650;
    padding: 0.25rem 0.15rem;
    border-radius: 12px;
    font-family: inherit;
}
.tabbar svg {
    width: 22px; height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linejoin: round;
    stroke-linecap: round;
}
.tabbar a.is-active,
.tabbar button.is-active,
html.chat-open .tabbar .tab-chat,
.tabbar .tab-more[aria-expanded="true"] {
    color: var(--gold);
    background: rgba(206, 175, 115, 0.12);
}

.more-sheet {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(26, 26, 26, 0.45);
    display: grid;
    align-items: end;
}
.more-sheet[hidden] { display: none; }
.more-sheet-card {
    background: var(--header);
    color: var(--cream);
    padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
    border-radius: 16px 16px 0 0;
}
.more-sheet-card header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.6rem;
    font-family: var(--display);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--gold);
}
.more-sheet-card nav { display: grid; gap: 0.2rem; }
.more-sheet-card a {
    color: var(--cream);
    padding: 0.75rem 0.4rem;
    border-bottom: 1px solid #333;
    font-family: var(--display);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.more-sheet-card a:hover { color: var(--gold); }
.more-sheet-card a:last-child { border-bottom: 0; }
body.more-open { overflow: hidden; }

main {
    width: min(1180px, calc(100% - 2 * var(--pad)));
    margin: 0 auto 5.5rem;
    padding-top: 1.25rem;
    padding-bottom: 1rem;
}

.hero {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 0.35rem;
}
.hero h1, .detail h1 { font-size: clamp(1.35rem, 3vw, 2.1rem); line-height: 1.18; margin: 0.15rem 0 0.35rem; }
.kicker { color: #6b5424; text-transform: uppercase; letter-spacing: 0.16em; font-size: 0.72rem; margin: 0; }
.lede { color: var(--muted); max-width: 46rem; margin: 0; }
.value-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    margin: 0.85rem 0 0;
    padding: 0.4rem 0.85rem 0.4rem 0.45rem;
    background: linear-gradient(180deg, #2a2314, #1a1710);
    border: 1px solid rgba(240, 199, 94, 0.45);
    border-radius: 999px;
    box-shadow: 0 0 18px rgba(240, 199, 94, 0.12);
}
.value-chip-icon {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
}
.value-chip small {
    display: block;
    color: var(--gold);
    font-size: 0.65rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}
.value-chip strong {
    display: block;
    color: #f6e7b2;
    font-size: 1.05rem;
    font-variant-numeric: tabular-nums;
}

.searchbar {
    margin-top: 0.6rem;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.5rem;
    background: var(--panel);
    padding: 0.4rem;
    border-radius: 8px;
    border: 1px solid var(--line);
    box-shadow: none;
}
input, textarea, select {
    width: 100%;
    background: #fff;
    color: var(--ink);
    border: 1px solid rgba(26, 26, 26, 0.2);
    border-radius: 12px;
    padding: 0.75rem 0.9rem;
    font: inherit;
    min-height: var(--touch);
    -webkit-appearance: none;
    appearance: none;
}
input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
    min-width: 1.25rem;
    min-height: 1.25rem;
    padding: 0;
    margin: 0;
    flex: none;
    display: inline-grid;
    place-content: center;
    border: 2px solid var(--ink);
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
}
input[type="checkbox"]::after {
    content: "";
    width: 0.72rem;
    height: 0.72rem;
    transform: scale(0);
    background: var(--gold);
    clip-path: polygon(14% 44%, 0 65%, 40% 100%, 100% 18%, 80% 0, 38% 62%);
}
input[type="checkbox"]:checked {
    background: var(--header);
    border-color: var(--header);
}
input[type="checkbox"]:checked::after {
    transform: scale(1);
}
input[type="checkbox"]:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}
.searchbar input { border: 0; background: transparent; border-radius: 999px; min-height: 42px; }
button, .ghost {
    font: inherit;
    border: 0;
    border-radius: 999px;
    background: var(--header);
    color: var(--gold);
    font-weight: 700;
    padding: 0.65rem 1.1rem;
    cursor: pointer;
    min-height: var(--touch);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    font-family: var(--display);
}
button.ghost, a.ghost {
    background: transparent;
    color: var(--ink);
    border: 1px solid var(--ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.row { display: flex; gap: 0.8rem; align-items: center; }
.row.wrap { flex-wrap: wrap; }
button:disabled { opacity: 0.55; cursor: wait; }

.filter-toggle {
    display: none;
    width: 100%;
    margin: 1rem 0 0;
    background: var(--panel);
    color: var(--ink);
    border: 1px solid var(--line);
}
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
    align-items: end;
    margin: 1.2rem 0;
}
.filters label { font-size: 0.78rem; color: var(--muted); display: grid; gap: 0.3rem; min-width: 140px; flex: 1 1 140px; }
.result-meta { margin: 0.75rem 0 1rem; color: var(--muted); }

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0.9rem;
}
.card-tile {
    display: block;
    background: var(--panel);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--line);
    color: var(--ink);
    transform: translateY(0);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}
@media (hover: hover) {
    .card-tile:hover {
        transform: translateY(-3px);
        box-shadow: 0 10px 22px rgba(26, 26, 26, 0.12), 0 0 0 1px var(--gold);
        color: var(--ink);
    }
}
.card-tile img, .detail-art img, .variant img, .compare-card img {
    width: 100%;
    aspect-ratio: 63 / 88;
    object-fit: contain;
    background: #1a1a1a;
    display: block;
}
.card-tile.landscape img,
.detail-art.landscape img,
.variant.landscape img,
.compare-card.landscape img,
.db-table img.landscape {
    aspect-ratio: 88 / 63;
    object-fit: contain;
}
.card-tile.landscape .missing,
.detail-art.landscape .missing-art,
.compare-card.landscape .missing-art {
    aspect-ratio: 88 / 63;
}
.db-table img.landscape {
    width: 50px;
    height: 36px;
}
.detail-layout:has(.landscape) {
    grid-template-columns: minmax(240px, 460px) 1fr;
}
.card-tile .meta { padding: 0.65rem 0.7rem 0.85rem; }
.card-tile .meta strong { display: block; font-size: 0.9rem; }
.card-tile .meta span { color: var(--muted); font-size: 0.72rem; font-family: var(--mono); }
.rarity-chip {
    display: inline-block;
    margin-top: 0.3rem;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 0.15rem 0.45rem;
    border-radius: 999px;
    background: #ddd3bf;
    font-family: var(--sans) !important;
    color: var(--ink) !important;
}
.rarity-c { background: #d9d3c4; }
.rarity-u { background: #c5dcc8; }
.rarity-r { background: #c9daf0; }
.rarity-rr { background: #e0cff0; }
.rarity-sr { background: linear-gradient(90deg, #b8860b, #f0c75e); color: #1a1200 !important; }
.rarity-sp, .rarity-osr, .rarity-ssp, .rarity-sss {
    background: linear-gradient(90deg, var(--ember), var(--gold), var(--mint));
    color: #1a1200 !important;
}

.pager { display: flex; gap: 0.5rem; justify-content: center; margin-top: 1.4rem; align-items: center; flex-wrap: wrap; }
.pager button { background: var(--panel); color: var(--ink); border: 1px solid var(--line); }

.detail-layout {
    display: grid;
    grid-template-columns: minmax(200px, 340px) 1fr;
    gap: 1.6rem;
    margin-top: 1rem;
}
.detail-art {
    border-radius: 22px;
    overflow: hidden;
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    cursor: zoom-in;
}
.have-chip, .have-line {
    margin: 0.2rem 0 0.55rem;
    color: var(--mint);
    font-weight: 650;
    font-size: 0.85rem;
}
.have-line { font-weight: 500; color: var(--ink); }
.card-loupe {
    position: fixed;
    z-index: 85;
    pointer-events: none;
    border-radius: 50%;
    border: 3px solid var(--gold);
    box-shadow: var(--shadow), inset 0 0 0 1px rgba(0, 0, 0, 0.45);
    background-color: #1a1a1a;
}
.card-loupe[hidden] { display: none; }
@media (hover: none) {
    .card-loupe { display: none !important; }
}
.card-tile { position: relative; cursor: pointer; }
.have-badge {
    position: absolute;
    top: 0.45rem;
    right: 0.45rem;
    z-index: 2;
    background: rgba(26, 26, 26, 0.86);
    color: var(--gold);
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 0.15rem 0.45rem;
}
.back { color: var(--muted); display: inline-flex; align-items: center; margin-bottom: 0.6rem; min-height: 40px; }
.card-code { font-family: var(--mono); color: var(--gold); }
.stat-pills { display: flex; flex-wrap: wrap; gap: 0.4rem; padding: 0; list-style: none; }
.stat-pills li {
    border: 1px solid var(--line);
    padding: 0.3rem 0.65rem;
    border-radius: 999px;
    font-size: 0.8rem;
}
.stat-pills .kw {
    color: inherit;
    text-decoration: none;
    cursor: help;
}
.stat-pills .apt, .stat-pills .apt .kw { color: var(--mint); }
.color-red { color: #ff8b7a; border-color: #ff6b6b; }
.color-blue { color: var(--blue); border-color: #4aa8e8; }
.color-green { color: var(--mint); border-color: var(--mint-2); }
.color-white { color: #5c5648; border-color: #c9c0aa; }
.color-purple { color: var(--purple); border-color: #a67ee8; }
.color-yellow { color: #8a6a28; border-color: #d4a83a; }
.color-black { color: #1a1a1a; }
.color-colorless { color: var(--muted); border-color: #c9c0aa; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 0.7rem; }
.stat-grid div { background: var(--panel); padding: 0.8rem; border-radius: 12px; }
.stat-grid dt { color: var(--muted); font-size: 0.75rem; }
.stat-grid dd { margin: 0.2rem 0 0; font-size: 1.2rem; font-weight: 700; }
.effect pre {
    white-space: pre-wrap;
    background: #efe8d8;
    padding: 1rem;
    border-radius: 14px;
    border: 1px solid var(--line);
    font-family: var(--sans);
    line-height: 1.45;
}
.text-icon {
    display: inline-block;
    height: 1.35em;
    width: auto;
    max-width: 7.5em;
    vertical-align: -0.28em;
    margin: 0 0.08em;
    padding: 0.04em 0.14em;
    object-fit: contain;
    background: #efe6d2;
    border-radius: 4px;
}
.qty-panel {
    margin-top: 1.2rem;
    padding: 1rem;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.qty-panel[data-collection] {
    margin-top: 0.9rem;
    padding: 0.55rem 0.7rem 0.5rem;
    border-radius: 12px;
}
.qty-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.35rem 0.8rem;
    margin-bottom: 0.4rem;
}
.qty-panel[data-collection] h2 {
    margin: 0;
    font-size: 0.82rem;
}
.qty-panel[data-collection] .have-line {
    margin: 0;
    font-size: 0.78rem;
}
.qty-panel[data-collection] .qty-row {
    gap: 0.4rem 0.5rem;
}
.qty-panel[data-collection] label {
    font-size: 0.72rem;
    gap: 0.12rem;
}
.qty-panel[data-collection] input[type=number],
.qty-panel[data-collection] input[type=text],
.qty-panel[data-collection] select {
    min-height: 34px;
    padding: 0.2rem 0.4rem;
    font-size: 0.85rem;
}
.qty-panel[data-collection] input[type=number] { width: 3.8rem; }
.qty-panel[data-collection] .ghost,
.qty-panel[data-collection] [data-save-qty] {
    min-height: 34px;
    padding: 0.2rem 0.55rem;
    font-size: 0.82rem;
}
.qty-panel[data-collection] [data-qty-status] {
    margin: 0.25rem 0 0;
    min-height: 1em;
    font-size: 0.75rem;
}
.variant-row { display: flex; gap: 0.8rem; overflow: auto; -webkit-overflow-scrolling: touch; padding-bottom: 0.3rem; scroll-snap-type: x proximity; }
.variant { width: 110px; flex: none; color: var(--muted); font-size: 0.75rem; scroll-snap-align: start; }
.missing-art, .missing {
    aspect-ratio: 63/88;
    display: grid;
    place-items: center;
    background: repeating-linear-gradient(45deg, #efe8d8, #efe8d8 10px, #ddd3bf 10px, #ddd3bf 20px);
    color: var(--muted);
}

.account .lede { margin-bottom: 0.6rem; }
.rights-list {
    margin: 0 0 1rem;
    padding-left: 1.2rem;
    color: var(--muted);
    font-size: 0.9rem;
}
.rights-list li { margin: 0.2rem 0; }
.account-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.1rem 1.2rem 1.3rem;
}
.span-2 { grid-column: span 2; }
.admin-head { display: flex; justify-content: space-between; gap: 0.8rem; align-items: center; }
.admin label, .admin-login label, .modal-card label, .account label, .panel label {
    display: grid;
    gap: 0.3rem;
    font-size: 0.8rem;
    color: var(--muted);
    margin: 0.55rem 0;
}
.admin-login { max-width: 420px; background: var(--panel); padding: 1.4rem; border-radius: var(--radius); }
.error { color: #b42318; }
.ok { color: var(--mint); }
.warn { color: var(--gold); }
.form-status { min-height: 1.2em; color: var(--muted); }
.import-log {
    background: #0a100e;
    color: #b8f5cc;
    padding: 0.8rem;
    border-radius: 10px;
    max-height: 240px;
    overflow: auto;
    font-size: 0.82rem;
}
.edition-list { list-style: none; padding: 0; }
.edition-list li { display: grid; grid-template-columns: 90px 1fr 50px auto; gap: 0.6rem; align-items: center; margin-bottom: 0.4rem; }
.tabs { display: flex; gap: 0.4rem; flex-wrap: nowrap; margin: 1rem 0; overflow: auto; -webkit-overflow-scrolling: touch; padding-bottom: 0.2rem; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { background: var(--panel); color: var(--ink); border: 1px solid var(--line); white-space: nowrap; }
.tabs button.is-active { background: var(--header); color: var(--gold); }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }
.table-wrap { overflow: auto; margin-top: 1rem; -webkit-overflow-scrolling: touch; }
.db-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.db-table th, .db-table td { text-align: left; padding: 0.5rem 0.5rem; border-bottom: 1px solid var(--line); }
.db-table img { width: 36px; height: 50px; object-fit: contain; border-radius: 4px; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 40; display: grid; place-items: center; padding: 1rem; }
.modal[hidden] { display: none; }
.modal-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 1rem 1.1rem 1.2rem;
    width: min(720px, 100%);
    max-height: 90vh;
    overflow: auto;
}
.card-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
.danger, .danger-btn { background: #5a1c1c; color: #ffd6d6; border: 1px solid #7a2a2a; }
.soft { border: 0; border-top: 1px solid var(--line); margin: 1.4rem 0; }
.muted { color: var(--muted); font-size: 0.85rem; }

.qty-row { display: flex; flex-wrap: wrap; gap: 0.8rem; align-items: end; }
.qty-row label { display: grid; gap: 0.25rem; font-size: 0.8rem; color: var(--muted); }
.qty-row .ghost { min-height: 40px; padding: 0.35rem 0.7rem; }
.compare-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}
.compare-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.8rem; }
.deck-list { list-style: none; padding: 0; }
.deck-list li {
    display: flex;
    justify-content: space-between;
    gap: 0.8rem;
    align-items: center;
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--line);
    min-height: var(--touch);
}
.deck-list a { color: var(--ink); flex: 1; min-width: 0; }
.deck-list a span { color: var(--muted); font-weight: 400; margin-left: 0.4rem; }
.deck-layout { display: grid; grid-template-columns: 1.4fr 0.8fr; gap: 1.2rem; }
.search-hits { display: grid; gap: 0.4rem; margin: 0.6rem 0 1rem; }
.search-hits button { text-align: left; background: var(--panel); color: var(--ink); border: 1px solid var(--line); }
.deck-cards { list-style: none; padding: 0; }
.deck-cards li { display: grid; grid-template-columns: 1fr auto auto auto; gap: 0.5rem; align-items: center; margin-bottom: 0.5rem; }
.curve { display: flex; gap: 0.35rem; align-items: end; height: 120px; }
.curve-bar { flex: 1; display: flex; flex-direction: column; justify-content: end; align-items: center; height: 100%; }
.curve-bar div { width: 100%; background: var(--mint-2); border-radius: 4px 4px 0 0; min-height: 2px; }
.curve-bar span { font-size: 0.7rem; color: var(--muted); }
.warn-list { color: var(--gold); padding-left: 1.1rem; }
.color-check { list-style: none; padding: 0; margin: 0.4rem 0 1rem; }
.color-check li { padding: 0.15rem 0; color: var(--muted); font-size: 0.9rem; }
#new-deck { width: min(100%, 28rem); }
#new-deck input { flex: 1; min-width: 10rem; }

.chat-fab {
    position: fixed;
    right: max(1rem, env(safe-area-inset-right));
    bottom: max(1rem, env(safe-area-inset-bottom));
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.55rem 0.9rem 0.55rem 0.55rem;
    box-shadow: var(--shadow);
}
.chat-fab-orb {
    width: 28px; height: 28px; border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #fff8e8, var(--gold) 42%, #8a6a28 80%);
    animation: pulse 2.8s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(206, 175, 115, 0.45); }
    50% { box-shadow: 0 0 0 10px rgba(206, 175, 115, 0); }
}
.chat-panel {
    position: fixed;
    right: max(1rem, env(safe-area-inset-right));
    bottom: 5.2rem;
    width: min(420px, calc(100vw - 1.6rem));
    height: min(620px, calc(100dvh - 7rem));
    background: var(--header);
    color: var(--cream);
    border: 1px solid #333;
    border-radius: 22px;
    box-shadow: var(--shadow);
    z-index: 31;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.chat-panel[hidden] { display: none; }
.chat-root.is-wide .chat-panel {
    width: min(820px, calc(100vw - 2rem));
    height: min(80dvh, calc(100dvh - 6rem));
}
.chat-head { display: flex; justify-content: space-between; padding: 0.9rem 1rem 0.4rem; border-bottom: 1px solid #333; gap: 0.6rem; color: var(--cream); }
.chat-head-actions { display: flex; gap: 0.35rem; }
.chat-kicker { margin: 0; font-size: 0.7rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold); }
.chat-head h2 { margin: 0.1rem 0 0; font-size: 1.1rem; color: var(--cream); }
.icon-btn {
    background: transparent;
    color: var(--ink);
    border: 1px solid var(--line);
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 10px;
    min-height: 40px;
}
.chat-panel .icon-btn,
.more-sheet-card .icon-btn {
    color: var(--cream);
    border-color: #444;
}
.chat-hint { margin: 0; padding: 0.6rem 1rem; color: #a89878; font-size: 0.8rem; }
.chat-log { flex: 1; overflow: auto; padding: 0.4rem 1rem 1rem; display: grid; gap: 0.7rem; align-content: start; overscroll-behavior: contain; }
.msg { padding: 0.7rem 0.8rem; border-radius: 14px; line-height: 1.45; }
.msg.user { background: #2a2418; color: var(--cream); justify-self: end; max-width: 90%; white-space: pre-wrap; }
.msg.bot { background: #242424; color: var(--cream); border: 1px solid #333; }
.msg.err { background: #3a1b1b; color: #ffd6d6; white-space: pre-wrap; }
.msg.bot.md { white-space: normal; }
.msg.bot.md h2, .msg.bot.md h3, .msg.bot.md h4 { font-size: 1rem; margin: 0.55em 0 0.3em; }
.msg.bot.md p { margin: 0.4em 0; }
.msg.bot.md ul, .msg.bot.md ol { margin: 0.4em 0; padding-left: 1.25em; }
.msg.bot.md li { margin: 0.15em 0; }
.msg.bot.md code { font-family: var(--mono); background: #111; color: var(--gold); padding: 0.12em 0.38em; border-radius: 5px; font-size: 0.88em; }
.msg.bot.md pre { background: #111; padding: 0.7rem; border-radius: 10px; overflow-x: auto; }
.msg.bot.md pre code { padding: 0; background: none; }
.msg.bot.md a { color: var(--gold); }
.msg.bot.md blockquote { margin: 0.4em 0; padding-left: 0.8em; border-left: 2px solid var(--line); color: var(--muted); }
.msg.bot.md strong { color: var(--cream); }
.chat-form { display: grid; grid-template-columns: 1fr auto; gap: 0.5rem; padding: 0.7rem; padding-bottom: calc(0.7rem + var(--kb)); border-top: 1px solid #333; align-items: end; }
.chat-form textarea { resize: none; min-height: 48px; }

.empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 3rem 1rem; }

@media (hover: hover) and (pointer: fine) {
    input, textarea, select { font-size: 0.95rem; }
}

/* —— Tablet + Phone chrome —— */
@media (max-width: 1100px) {
    .desk-nav { display: none; }
    .tabbar { display: grid; }
    main { margin-bottom: calc(var(--tabbar-h) + 1.2rem); }
    .chat-fab { display: none; }
    .card-grid { grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); }
    .detail-layout { grid-template-columns: minmax(220px, 280px) 1fr; gap: 1.2rem; }
    .deck-layout { grid-template-columns: 1fr 0.9fr; }
    .filters label { flex: 1 1 160px; }
    html.chat-open .tabbar { display: none; }
    html.chat-open #chat-expand { display: none; }
    html.chat-open .chat-panel {
        inset: 0;
        width: 100%;
        height: 100dvh;
        height: calc(100dvh - var(--kb));
        max-height: none;
        border-radius: 0;
        right: 0;
        bottom: 0;
        padding-top: env(safe-area-inset-top, 0px);
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    html.chat-open body { overflow: hidden; }
    .modal { place-items: end center; padding: 0; }
    .modal-card {
        width: 100%;
        max-height: min(92dvh, 920px);
        border-radius: 22px 22px 0 0;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    }
    input, textarea, select { font-size: 16px; }
}

@media (min-width: 721px) and (max-width: 1100px) {
    .hero:has(.row), .hero:has(#new-deck) {
        display: grid;
        grid-template-columns: 1fr auto;
        gap: 1.2rem;
        align-items: end;
    }
    .compare-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .card-grid { grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); }
}

@media (max-width: 900px) {
    .admin-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .detail-layout { grid-template-columns: 1fr 1fr; }
}

/* —— Phone —— */
@media (max-width: 720px) {
    :root { --pad: 0.85rem; }
    .brand img { height: 32px; }
    main { width: calc(100% - 2 * var(--pad)); padding-top: 0.9rem; }
    .hero h1, .detail h1 { font-size: 1.55rem; }
    .lede { font-size: 0.92rem; }
    .searchbar {
        grid-template-columns: 1fr;
        border-radius: 18px;
        padding: 0.55rem;
        margin-top: 0.9rem;
    }
    .searchbar button { width: 100%; }
    .sticky-search {
        position: sticky;
        top: var(--header-h);
        z-index: 15;
        background: var(--panel);
    }
    .filter-toggle { display: flex; justify-content: center; }
    .filters {
        display: none;
        grid-template-columns: 1fr 1fr;
        background: var(--panel);
        border: 1px solid var(--line);
        border-radius: 16px;
        padding: 0.85rem;
        margin-top: 0.7rem;
    }
    .filters.is-open { display: grid; }
    .filters label { min-width: 0; }
    .result-meta { grid-column: 1 / -1; margin: 0; }
    .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.7rem; }
    .card-tile .meta strong { font-size: 0.82rem; }
    .detail-layout { grid-template-columns: 1fr; }
    .detail-art { max-width: 320px; margin: 0 auto; }
    .account-grid { grid-template-columns: 1fr; }
    .deck-layout { grid-template-columns: 1fr; }
    .compare-grid {
        display: flex;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        gap: 0.75rem;
        padding-bottom: 0.4rem;
        -webkit-overflow-scrolling: touch;
    }
    .compare-card {
        min-width: min(78vw, 280px);
        scroll-snap-align: start;
        flex: none;
    }
    .card-form { grid-template-columns: 1fr; }
    .edition-list li { grid-template-columns: 1fr; }
    .qty-row { display: grid; grid-template-columns: 1fr 1fr; }
    .qty-row [data-save-qty] { grid-column: 1 / -1; }
    .qty-row input[type=number] { width: 100%; }
    .deck-list li { flex-wrap: wrap; }
    .deck-list a { flex: 1 1 12rem; }
    .deck-list a span { display: block; margin-left: 0; font-size: 0.82rem; }
    .deck-cards li { grid-template-columns: 1fr auto; }
    .deck-builder .row.wrap input { flex: 1 1 100%; }
    .admin-head { flex-direction: column; align-items: stretch; }
    .hero .row.wrap { display: grid; grid-template-columns: 1fr 1fr; }
    .hero .row.wrap .ghost { width: 100%; }
    #new-deck { width: 100%; display: grid; }
    #new-deck button { width: 100%; }
    .tabs {
        position: sticky;
        top: var(--header-h);
        z-index: 14;
        background: var(--bg);
        backdrop-filter: blur(12px);
        margin-top: 0.5rem;
        padding: 0.45rem 0;
    }
    .db-table thead { display: none; }
    .db-table, .db-table tbody, .db-table tr, .db-table td {
        display: block;
        width: 100%;
    }
    .db-table tr {
        background: var(--panel);
        border: 1px solid var(--line);
        border-radius: 16px;
        margin-bottom: 0.75rem;
        padding: 0.75rem 0.85rem;
    }
    .db-table td {
        border: 0;
        padding: 0.35rem 0;
        display: flex;
        justify-content: space-between;
        gap: 0.6rem;
        align-items: center;
    }
    .db-table td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 0.75rem;
        flex: none;
    }
    .db-table td:not([data-label])::before,
    .db-table td[data-label=""]::before { content: none; }
    .db-table td:first-child { justify-content: flex-start; }
    .db-table td[data-label=""]:last-child { display: block; }
    .db-table td[data-label=""]:last-child button { width: 100%; }
    .db-table td[data-label="Aktionen"] { display: block; }
    .db-table td[data-label="Aktionen"] .row-actions { justify-content: flex-end; margin-top: 0.25rem; }
    .db-table img { width: 48px; height: 68px; }
    .db-table input[type=number] { width: 5.5rem; min-height: var(--touch); }
}

@media (max-width: 380px) {
    .card-grid { gap: 0.5rem; }
    .filters { grid-template-columns: 1fr; }
    .tabbar a span, .tabbar button span { font-size: 0.62rem; }
}

@media (pointer: coarse) {
    .desk-nav a, .tabs button, .search-hits button { min-height: var(--touch); }
}

@media (display-mode: standalone) {
    .topbar { padding-top: max(0.85rem, env(safe-area-inset-top, 0px)); }
}

.badge-row, .card-tile .meta .badge { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.35rem; }
.badge {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 0.12rem 0.4rem;
    border-radius: 999px;
    letter-spacing: 0.04em;
}
.badge.ban { background: #f4d6d2; color: #8a2418; }
.badge.errata { background: #f3e6c8; color: #8a6a28; }
.badge.price { background: #efe4c8; color: #6b5424; }
.badge.foil { background: #1a1a1a; color: var(--gold); }
.deck-cards li.is-foil { outline: 1px solid rgba(240, 199, 94, 0.35); }
.deck-foil-add { margin: 0.4rem 0 0.6rem; }
.progress-list, .gap-list, .pull-list, .mini-cards { list-style: none; padding: 0; }
.progress-list li { display: grid; grid-template-columns: 5rem minmax(7.5rem, auto) 1fr; gap: 0.5rem; align-items: center; margin: 0.45rem 0; }
.progress-list .bar { height: 8px; background: #ddd3bf; border-radius: 99px; overflow: hidden; grid-column: 1 / -1; }
.progress-list .bar i { display: block; height: 100%; background: var(--mint-2); }
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 0.6rem; margin-top: 0.8rem; }
.pick-card { background: var(--panel); border: 1px solid var(--line); color: var(--ink); text-align: left; padding: 0.4rem; }
.pick-card img { width: 100%; aspect-ratio: 63/88; object-fit: contain; background: #1a1a1a; }
.deck-cards li.is-illegal { outline: 2px solid #c4472a; background: rgba(196, 71, 42, 0.1); }
.deck-cards li.is-missing a { color: var(--gold); }
.banner { min-height: 1.2em; color: var(--muted); }
.banner.ok { color: var(--mint); }
.banner.warn { color: var(--gold); }
.illegal-list { color: #b42318; }
.tag-row { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 0.6rem; }
.check { display: flex; align-items: center; gap: 0.35rem; color: var(--ink); }
.row-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; justify-content: flex-end; }
.row-actions button { min-height: 34px; padding: 0.2rem 0.7rem; font-size: 0.72rem; }
#users-temp-pw code {
    display: inline-block;
    margin-left: 0.25rem;
    padding: 0.15rem 0.4rem;
    background: #fff;
    border: 1px solid var(--line);
    user-select: all;
}
.trade-card h3 { margin: 0.8rem 0 0.3rem; font-size: 0.9rem; color: var(--muted); }
.booster-grid { margin-top: 1rem; }
.color-check li.warn, .color-check .warn { color: var(--gold); }
.card-hover {
    position: fixed;
    z-index: 80;
    pointer-events: none;
    width: min(240px, 42vw);
    filter: drop-shadow(0 16px 32px rgba(0, 0, 0, 0.55));
}
.card-hover[hidden] { display: none; }
.card-hover img {
    width: 100%;
    border-radius: 12px;
    display: block;
    background: #1a1a1a;
}
.kw {
    color: var(--gold);
    text-decoration: underline dotted rgba(206, 175, 115, 0.85);
    text-underline-offset: 0.18em;
    cursor: help;
    border-radius: 3px;
}
.kw:focus-visible {
    outline: 2px solid var(--mint);
    outline-offset: 2px;
}
.kw-icon {
    color: inherit;
    text-decoration: none;
}
.kw-tip {
    position: fixed;
    z-index: 90;
    max-width: min(320px, calc(100vw - 16px));
    padding: 0.7rem 0.85rem 0.85rem;
    background: var(--header);
    color: var(--cream);
    border: 1px solid var(--gold);
    border-radius: 12px;
    box-shadow: var(--shadow);
}
.kw-tip[hidden] { display: none; }
.kw-tip strong {
    display: block;
    color: var(--gold);
    font-size: 0.82rem;
    letter-spacing: 0.04em;
    margin: 0 0 0.35rem;
}
.kw-tip p {
    margin: 0;
    font-size: 0.88rem;
    line-height: 1.4;
    color: var(--cream);
}
.card-view-modal { z-index: 55; }
.card-view {
    width: min(920px, 100%);
    max-height: min(92dvh, 960px);
    overflow: auto;
}
.modal-card.card-view.landscape {
    width: min(1100px, 96vw);
    max-height: min(92dvh, 980px);
}
.card-view-layout {
    display: grid;
    grid-template-columns: minmax(140px, 280px) 1fr;
    gap: 1rem;
    padding: 0 0.2rem 0.4rem;
}
.card-view-layout.landscape {
    grid-template-columns: minmax(420px, 1.4fr) minmax(280px, 0.9fr);
    align-items: start;
}
.card-view .detail-art img {
    width: 100%;
    height: auto;
    max-height: min(58vh, 520px);
    aspect-ratio: auto;
    object-fit: contain;
    border-radius: 14px;
}
.card-view .detail-art.landscape img,
.card-view .detail-art.landscape .missing {
    aspect-ratio: 88 / 63;
}
.card-view h3 { margin: 0.8rem 0 0.3rem; font-size: 0.95rem; }
body.modal-open { overflow: hidden; }
.card-view > header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.55rem;
}
.card-view > header h2 { flex: 1; margin: 0; font-size: 1.05rem; }
.card-view > header .ghost { min-height: 36px; padding: 0.3rem 0.65rem; font-size: 0.8rem; }
.tile-actions {
    display: flex;
    gap: 0.3rem;
    padding: 0 0.5rem 0.5rem;
}
.tile-actions button {
    flex: 1;
    min-height: 32px;
    padding: 0.2rem 0.35rem;
    font-size: 0.72rem;
    background: #fff;
    color: var(--ink);
    border: 1px solid var(--line);
}
.card-tile:focus,
.card-tile:focus-visible {
    outline: 2px solid var(--mint);
    outline-offset: 2px;
}
.detail-art { touch-action: pinch-zoom; overflow: hidden; }
.detail-art img { transform-origin: center center; }
@media (hover: hover) and (pointer: fine) {
    .detail-art { touch-action: auto; }
}
.errata-excerpt {
    margin-top: 0.7rem;
    padding: 0.65rem 0.75rem;
    background: #f6ecd4;
    border: 1px solid rgba(206, 175, 115, 0.55);
    border-radius: 12px;
}
.errata-excerpt strong { color: #8a6a28; font-size: 0.78rem; letter-spacing: 0.04em; }
.errata-excerpt pre {
    margin: 0.35rem 0 0;
    white-space: pre-wrap;
    font-size: 0.82rem;
}
.price-line { color: var(--mint); font-size: 0.88rem; margin: 0.35rem 0 0.7rem; }
.price-line[data-price-cents], .badge.price[data-price-cents] { cursor: help; }
.price-chart {
    position: fixed;
    z-index: 88;
    pointer-events: none;
    background: var(--header);
    color: var(--cream);
    border: 1px solid var(--gold);
    border-radius: 12px;
    padding: 0.55rem 0.65rem 0.65rem;
    box-shadow: var(--shadow);
}
.price-chart p {
    margin: 0.15rem 0 0;
    font-size: 0.72rem;
    color: #c5b48a;
    max-width: 196px;
}
.activity-list {
    list-style: none;
    padding: 0;
    margin: 0.8rem 0 0;
}
.activity-list li {
    display: grid;
    grid-template-columns: 52px 1fr;
    gap: 0.7rem;
    align-items: center;
    padding: 0.55rem 0;
    border-bottom: 1px solid var(--line);
}
.activity-list p { margin: 0; }
.activity-list time { color: var(--muted); font-size: 0.78rem; font-family: var(--mono); }
.activity-thumb {
    width: 52px;
    height: 72px;
    display: block;
    overflow: hidden;
    border-radius: 6px;
    background: #1a1a1a;
}
.activity-thumb img { width: 100%; height: 100%; object-fit: contain; }
.activity-thumb.empty { background: #ddd3bf; }
.card-code-link {
    display: inline;
    padding: 0;
    margin: 0;
    border: 0;
    background: none;
    color: var(--gold);
    font: inherit;
    font-family: var(--mono);
    text-decoration: underline dotted;
    cursor: pointer;
}
.glossary-toc {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin: 0.4rem 0 1.2rem;
}
.glossary-toc a {
    border: 1px solid var(--ink);
    color: var(--ink);
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    font-family: var(--display);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.glossary-toc a:hover { color: var(--gold); background: var(--header); }
    margin: 1.6rem 0 0.4rem;
    font-size: 0.78rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #6b5424;
}
.glossary-list { list-style: none; padding: 0; max-width: 46rem; }
.glossary-item {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 0.9rem 1rem;
    margin: 0.7rem 0;
    scroll-margin-top: calc(var(--header-h) + 0.8rem);
}
.glossary-item:target {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}
.glossary-item h2 { margin: 0 0 0.35rem; font-size: 1rem; display: flex; align-items: center; gap: 0.45rem; }
.glossary-item .kw-img { width: 28px; height: 28px; object-fit: contain; }
.glossary-item p { margin: 0; color: var(--ink); }
.progress-list li { display: block; margin: 0.45rem 0; }
.progress-link {
    display: grid;
    grid-template-columns: 5rem minmax(7.5rem, auto) 1fr;
    gap: 0.5rem;
    align-items: center;
    color: var(--ink);
    border-radius: 10px;
    padding: 0.35rem 0.4rem;
}
.progress-link:hover { background: rgba(206, 175, 115, 0.16); }
.progress-link .bar { grid-column: 1 / -1; }
.gap-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 0.55rem;
    align-items: baseline;
    margin: 0.4rem 0;
}
.gap-have { color: var(--muted); font-size: 0.8rem; }
.gap-price { color: var(--gold); font-weight: 700; }
.coll-filters { margin: 0.6rem 0 0.9rem; }
.coll-filters label { font-size: 0.78rem; color: var(--muted); display: grid; gap: 0.3rem; min-width: 140px; }
.foil-toggle {
    min-height: 36px;
    padding: 0.2rem 0.55rem;
    font-size: 0.75rem;
    background: var(--panel);
    color: var(--muted);
    border: 1px solid var(--line);
}
.foil-toggle.is-on {
    color: var(--gold);
    border-color: rgba(240, 199, 94, 0.55);
}
.deck-cards { min-height: 2.5rem; }
.deck-cards.is-drop, .search-hits.is-drop {
    outline: 2px dashed var(--mint);
    outline-offset: 4px;
}
#wish-all { margin: 0.35rem 0 0.55rem; }
@media (max-width: 700px) {
    .tile-actions { flex-direction: column; }
    .gap-row { grid-template-columns: 1fr auto; }
    .gap-have { grid-column: 1 / -1; }
}
@media (max-width: 700px) {
    .card-view-layout,
    .card-view-layout.landscape { grid-template-columns: 1fr; }
    .modal-card.card-view.landscape { width: min(920px, 100%); }
    .card-hover { display: none; }
}
@media print {
    .topbar, .tabbar, .chat-fab, .no-print { display: none !important; }
}
