:root {
  --bg: #120c0a;
  --surface: #1d1512;
  --surface-2: #281d18;
  --line: #3a2a22;
  --text: #f7ece6;
  --muted: #b59d90;
  --accent: #ff6a1a;
  --accent-2: #ffb020;
  --good: #3ccf7a;
  --bad: #ff4d4d;
  --radius: 14px;
  --tabs-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 0 calc(var(--tabs-h) + env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* Header */
.top { padding: 14px 16px 6px; }
.top h1 { margin: 0; font-size: 22px; letter-spacing: .2px; display: flex; align-items: center; gap: 8px; }
.flame {
  width: 22px; height: 22px; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  background: radial-gradient(circle at 50% 75%, var(--accent-2), var(--accent) 55%, #c0261a);
}
.top .sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
main { padding: 0 16px 16px; }

/* Controls */
.toolbar { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 8px 0; display: grid; gap: 8px; }
input, select, textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 16px; /* 16px stops iOS zoom on focus */
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.chips { display: flex; gap: 6px; overflow-x: auto; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: 6px 14px; font-size: 14px; white-space: nowrap;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #1a0d06; font-weight: 600; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 12px;
  padding: 12px 16px; font-weight: 600; width: 100%; margin: 6px 0; cursor: pointer;
}
.btn.primary { background: linear-gradient(135deg, var(--accent-2), var(--accent)); border: 0; color: #1a0d06; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.btn.small { width: auto; padding: 6px 12px; margin: 0; font-size: 14px; }
.btn.file { position: relative; overflow: hidden; }
.btn.file input { position: absolute; inset: 0; opacity: 0; }
.btn.on { border-color: var(--accent); color: var(--accent); }

.summary { color: var(--muted); font-size: 13px; margin: 4px 0 8px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0; }
.center { text-align: center; }
.section-h { font-size: 16px; margin: 22px 0 6px; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.item {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center;
  padding: 12px; margin: 0 0 8px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); cursor: pointer;
}
.item.hot { border-color: #6b3417; box-shadow: inset 3px 0 0 var(--accent); }
.item .nm { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .val { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.item .val small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.compact .item { padding: 10px 12px; }
.badge {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--line); margin-right: 4px; vertical-align: 1px;
}
.badge.g { background: #2a1a0f; border-color: #7a3c12; color: var(--accent-2); }
.badge.jp { color: #ff8fa3; }
.badge.qty { color: var(--muted); }
.x { background: none; border: 0; color: var(--muted); font-size: 18px; padding: 4px 8px; }

.empty { text-align: center; color: var(--muted); padding: 40px 12px; }

/* Show stats */
.cards3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.stat span { display: block; color: var(--muted); font-size: 12px; }
.stat b { font-size: 18px; font-variant-numeric: tabular-nums; }

/* Trade */
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 3px; margin: 8px 0; }
.seg button { border: 0; background: none; padding: 8px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface-2); color: var(--text); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin: 10px 0; }
.panel h2 { font-size: 16px; margin: 0 0 8px; }
.panel .item { background: var(--surface-2); }
.panel-h { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.panel-h h2 { margin: 0; }
.addget { display: grid; grid-template-columns: 1fr 96px auto; gap: 6px; margin-top: 6px; }
.cash, .field { display: grid; grid-template-columns: 1fr 120px; align-items: center; gap: 8px; margin-top: 8px; color: var(--muted); font-size: 14px; }
.verdict { border-radius: var(--radius); padding: 14px; margin: 10px 0; background: var(--surface); border: 1px solid var(--line); }
.verdict.ok { border-color: var(--good); }
.verdict.low { border-color: var(--bad); }
.verdict h3 { margin: 0 0 6px; font-size: 18px; }
.verdict .ok-t { color: var(--good); }
.verdict .low-t { color: var(--bad); }
.verdict dl { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin: 8px 0 0; font-size: 14px; }
.verdict dt { color: var(--muted); }
.verdict dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.actions { display: grid; grid-template-columns: 2fr 1fr; gap: 8px; }

/* Bottom tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: rgba(18, 12, 10, .94); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabs button { border: 0; background: none; color: var(--muted); font-size: 11px; display: grid; place-items: center; align-content: center; gap: 2px; }
.tabs .i { font-size: 20px; line-height: 1; }
.tabs button.on { color: var(--accent); }

/* Dialogs */
/* Phones: full-screen sheet sized to the visible area (dvh), so browser toolbars never hide the Back bar. */
dialog {
  border: 0; padding: 0; margin: 0; width: 100%; max-width: 100%;
  height: 100vh; height: 100dvh; max-height: 100vh; max-height: 100dvh;
  background: var(--surface); color: var(--text); overflow-y: auto; overscroll-behavior: contain;
}
@media (min-width: 680px) {
  dialog { margin: auto; max-width: 640px; height: auto; max-height: 90vh; max-height: 90dvh; border-radius: 18px; }
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
.sheet { padding: 0 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet h2 { margin: 0 0 4px; font-size: 20px; line-height: 1.25; }
.sheet-bar {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 10px;
  margin: 0 -16px 12px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.back {
  border: 0; background: var(--surface-2); color: var(--accent); font-weight: 700; font-size: 16px;
  padding: 8px 16px 8px 12px; border-radius: 999px; min-height: 40px;
}
.sheet-bar .title { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; margin: 10px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.bigval { font-size: 30px; font-weight: 800; margin: 8px 0 0; font-variant-numeric: tabular-nums; }
.age { color: var(--muted); font-size: 13px; }
.age.stale { color: var(--accent-2); }
.floors { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.links { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.links a {
  display: block; text-align: center; padding: 10px; border-radius: 10px; background: var(--surface-2);
  border: 1px solid var(--line); color: var(--text); text-decoration: none; font-weight: 600; font-size: 14px;
}
.toggle { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 14px; margin: 8px 0; }
.toggle input { width: auto; }
.lbl { display: block; color: var(--muted); font-size: 13px; margin: 12px 0 4px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 600; z-index: 10;
  max-width: calc(100% - 32px);
}

/* eBay sales list */
.sales { list-style: none; margin: 6px 0 4px; padding: 0; }
.sales a {
  display: grid; grid-template-columns: auto 1fr auto; gap: 0 10px; align-items: baseline;
  padding: 8px 0; border-bottom: 1px solid var(--line); color: var(--text); text-decoration: none; font-size: 14px;
}
.sales .sd { color: var(--muted); font-variant-numeric: tabular-nums; }
.sales b { font-variant-numeric: tabular-nums; }
.sales .badge { grid-column: 3; }
.sales .st { grid-column: 1 / -1; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Crack check */
.badge.crack { color: var(--accent-2); border-color: #7a5a12; }
.crackbox { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.crackbox small { color: var(--muted); }
.crackbox.crack { border-color: var(--accent-2); }
.crackbox.maybe { border-color: #7a5a12; }
.crackbox.keep { border-color: var(--good); }

/* Import report and export help */
.report { margin: 8px 0; padding: 10px 12px 10px 28px; background: var(--surface-2); border-radius: 10px; font-size: 13px; }
.report li { margin: 2px 0; }
.report .flag-h { list-style: none; margin: 8px 0 2px -16px; color: var(--muted); font-weight: 600; }
.report .flag { color: var(--accent-2); }
.howto { margin-top: 8px; font-size: 14px; }
.howto summary { color: var(--accent); font-weight: 600; cursor: pointer; padding: 6px 0; }
.howto p { color: var(--muted); margin: 8px 0; }
.howto b { color: var(--text); }
