:root {
  --bg: #14161c; --panel: #1e2129; --panel2: #262a34; --text: #e8e6e1; --muted: #9aa0ab;
  --accent: #d4a24c; --good: #5fb87a; --warn: #e0a040; --bad: #d9624f; --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
header { padding: calc(env(safe-area-inset-top) + 10px) 16px 6px; }
.header-row { display: flex; justify-content: space-between; align-items: center; }
#account-button { font-size: 15px; }
h1 { margin: 0; font-size: 22px; color: var(--accent); letter-spacing: .5px; }
main { padding: 8px 12px calc(90px + env(safe-area-inset-bottom)); max-width: 900px; margin: 0 auto; }
.tab { display: none; } .tab.active { display: block; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 13px; }
.card-box { background: var(--panel); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.row { display: flex; gap: 8px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin: 8px 0; }
input, select, textarea, button { font: inherit; color: var(--text); background: var(--panel2);
  border: 1px solid #343946; border-radius: 10px; padding: 9px 11px; }
input, textarea { flex: 1; min-width: 0; }
.inline-input { width: 120px; padding: 5px 8px; }
button { cursor: pointer; } button:disabled { opacity: .5; }
button.primary { background: var(--accent); color: #1b1404; border: none; font-weight: 600; }
.link-button { background: none; border: none; color: var(--accent); padding: 4px; }
a { color: var(--accent); }
.big-button { display: block; text-align: center; background: var(--accent); color: #1b1404; font-weight: 700;
  border-radius: var(--radius); padding: 18px; margin: 10px 0; cursor: pointer; font-size: 18px; }
nav { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: #0f1115; border-top: 1px solid #2a2e38;
  padding-bottom: env(safe-area-inset-bottom); }
nav button { flex: 1; background: none; border: none; border-radius: 0; padding: 8px 0 10px; font-size: 22px;
  display: flex; flex-direction: column; align-items: center; color: var(--muted); }
nav button span { font-size: 11px; } nav button.active { color: var(--accent); }

/* Scan results */
.scan-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.scan-cell { background: var(--panel); border-radius: 10px; padding: 6px; position: relative; font-size: 12px;
  border: 2px solid transparent; }
.scan-cell.review { border-color: var(--warn); } .scan-cell.unmatched { border-color: var(--bad); }
.scan-cell.skip { opacity: .35; }
.scan-cell img { width: 100%; border-radius: 6px; display: block; aspect-ratio: 488/680; object-fit: cover; background: #000; }
.scan-cell .name { font-weight: 600; margin-top: 4px; line-height: 1.2; }
.scan-cell .controls { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.scan-cell .controls button, .scan-cell .controls select { padding: 3px 6px; font-size: 12px; border-radius: 6px; }
.badge { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--panel2); }
.badge.warn { background: var(--warn); color: #000; } .badge.bad { background: var(--bad); color: #fff; }
.price { color: var(--good); font-weight: 600; }

/* Collection */
.coll-item { display: flex; gap: 10px; background: var(--panel); border-radius: 10px; padding: 8px; margin-bottom: 6px; align-items: center; }
.coll-item img { width: 52px; border-radius: 4px; }
.coll-item .info { flex: 1; min-width: 0; }
.coll-item .info .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qty-controls { display: flex; align-items: center; gap: 4px; }
.qty-controls button { padding: 2px 9px; }
.stat-big { font-size: 26px; font-weight: 700; color: var(--accent); }
.top-list { margin: 6px 0 0; padding-left: 18px; font-size: 14px; }
.spark { width: 100%; height: 50px; }

/* Chat */
#chat-log { display: flex; flex-direction: column; gap: 10px; margin-bottom: 140px; }
.msg { background: var(--panel); border-radius: var(--radius); padding: 10px 14px; overflow-wrap: anywhere; }
.msg.user { background: #3a2f1a; align-self: flex-end; max-width: 88%; }
.msg.assistant { align-self: stretch; }
.msg img.attached { max-width: 160px; border-radius: 8px; display: block; margin-bottom: 6px; }
.msg h1, .msg h2, .msg h3 { font-size: 17px; margin: 10px 0 4px; color: var(--accent); }
.msg ul { padding-left: 20px; margin: 4px 0; } .msg p { margin: 6px 0; }
.msg code { background: var(--panel2); padding: 1px 4px; border-radius: 4px; }
.msg .events { font-size: 12px; color: var(--muted); border-left: 2px solid #3a3f4b; padding-left: 8px; margin-bottom: 6px; }
.msg .cost { font-size: 11px; color: var(--muted); margin-top: 6px; }
#chat-form { position: fixed; left: 0; right: 0; bottom: calc(58px + env(safe-area-inset-bottom)); background: var(--bg);
  padding: 6px 12px; border-top: 1px solid #2a2e38; }
#chat-form .row { flex-wrap: nowrap; margin: 0; }
#chat-form textarea { resize: none; }
.icon-button { font-size: 22px; cursor: pointer; padding: 4px; }

/* Decks */
.deck-row { background: var(--panel); border-radius: 10px; padding: 10px 12px; margin-bottom: 6px; cursor: pointer; }
.deck-card { display: flex; justify-content: space-between; font-size: 14px; padding: 2px 0; border-bottom: 1px solid #262a34; }
.deck-card.missing { color: var(--warn); }
.deck-card { align-items: center; gap: 6px; }
.deck-card .dc-name { flex: 1; cursor: pointer; }
.deck-card .dc-controls { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.deck-card .dc-controls button { padding: 1px 8px; font-size: 13px; border-radius: 6px; }
#deck-search-results { max-height: 50vh; overflow-y: auto; }

/* Suggestions & discussion */
.switch { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }
details summary { cursor: pointer; padding: 6px 0; }
.sugg-row { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid #262a34; }
.sugg-row img { width: 46px; border-radius: 4px; cursor: pointer; }
.sugg-row .info { flex: 1; min-width: 0; }
.sugg-row .info .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sugg-row button { padding: 6px 10px; }
.sugg-row .sugg-add { font-size: 18px; padding: 4px 14px; }
#discuss-log { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
#discuss-log .msg { font-size: 15px; }
#deck-search-results .coll-item button.primary { padding: 6px 14px; font-size: 18px; }
textarea.export { width: 100%; height: 160px; font-family: ui-monospace, monospace; font-size: 12px; }

/* Account */
.user-row { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid #262a34; flex-wrap: wrap; }
.user-row .info { flex: 1; min-width: 140px; }
.user-row input.cap { width: 80px; padding: 5px 8px; flex: none; }
.spend-bar { height: 8px; background: var(--panel2); border-radius: 4px; overflow: hidden; margin: 6px 0; }
.spend-bar div { height: 100%; background: var(--accent); }
.account-section { background: var(--panel); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.account-section input { width: 100%; margin-bottom: 8px; }

img.qr { display: block; width: 220px; height: 220px; margin: 10px auto; background: #fff; border-radius: 8px; }

/* Modal */
#modal { position: fixed; inset: 0; background: rgba(0,0,0,.75); z-index: 10; display: flex; align-items: flex-end; }
.modal-inner { background: var(--bg); width: 100%; max-height: 85vh; overflow-y: auto; border-radius: 16px 16px 0 0;
  padding: 14px 14px calc(14px + env(safe-area-inset-bottom)); }
.printing-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.printing { font-size: 11px; cursor: pointer; background: var(--panel); border-radius: 8px; padding: 4px; }
.printing img { width: 100%; border-radius: 5px; }
.printing.selected { outline: 2px solid var(--accent); }

.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--muted); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 1s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (min-width: 700px) { .printing-grid { grid-template-columns: repeat(3, 200px); } .scan-grid { max-width: 820px; } }
