:root {
  --bg: #f2f3f5; --card: #fff; --ink: #161b26; --muted: #6b7280; --line: #e6e8eb; --bar: #1d2330;
  --ex: #0e8a46; --good: #2563eb; --ok: #6b7280; --keep: #0e8a46; --del: #c0362c; --warn: #b54708;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0e1116; --card: #171b22; --ink: #e7e9ee; --muted: #9aa1ad; --line: #262b34; --bar: #0b0e13; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
button, select, input, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }

/* ---- top bar (sticky) */
.bar { position: sticky; top: 0; z-index: 5; background: var(--bar); color: #fff; padding: 6px 10px calc(6px) ;
  padding-top: max(6px, env(safe-area-inset-top)); }
.bar-top { display: flex; align-items: center; gap: 8px; min-height: 30px; }
.bar h1 { font-size: 16px; margin: 0; letter-spacing: .2px; }
.count { flex: 1; font-size: 12px; opacity: .7; }
.ghost { background: none; border: 0; color: inherit; padding: 6px; opacity: .8; cursor: pointer; text-decoration: underline; }
.controls { display: flex; gap: 6px; margin-top: 6px; }
.controls select, .chip { height: 32px; border-radius: 8px; border: 1px solid #3a4152; background: #262d3b; color: #fff; padding: 0 8px; }
.controls select { flex: 1; min-width: 0; }
.chip { flex: 0 0 auto; cursor: pointer; }
.chip[aria-pressed=true] { background: #fff; color: var(--bar); border-color: #fff; }

main { max-width: 760px; margin: 0 auto; padding: 8px 0 calc(24px + env(safe-area-inset-bottom)); }

/* ---- login */
.login { margin: 24px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
.login label { display: block; font-weight: 600; margin: 4px 0; }
.login input { width: 100%; height: 44px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); font-size: 16px; }
.primary { width: 100%; height: 44px; margin-top: 10px; border: 0; border-radius: 8px; background: var(--bar); color: #fff; font-weight: 600; cursor: pointer; }
@media (prefers-color-scheme: dark) { .primary { background: var(--good); } }
.login .ghost { color: var(--muted); margin-top: 6px; }
.err { color: var(--del); min-height: 1em; margin: 8px 0 0; }

/* ---- deal list: one compact row each */
.deals { list-style: none; margin: 0; padding: 0; background: var(--card); border-top: 1px solid var(--line); }
@media (min-width: 761px) { .deals { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; } }
.deal { display: grid; grid-template-columns: 56px 1fr auto; grid-template-areas: "thumb main price" "thumb acts acts" "more more more";
  column-gap: 10px; row-gap: 6px; padding: 10px 10px 8px; border-bottom: 1px solid var(--line); }
.deal:last-child { border-bottom: 0; }

.thumb { grid-area: thumb; width: 56px; height: 56px; border-radius: 8px; overflow: hidden; background: var(--line); display: grid; place-items: center; text-decoration: none; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb img:not([src]) { display: none; }
.ph { font-size: 11px; font-weight: 700; color: #fff; }
.thumb.excellent { background: var(--ex); } .thumb.good { background: var(--good); } .thumb.ok { background: var(--ok); }
.thumb.has-img { background: var(--line); } .thumb.has-img .ph { display: none; }

.main { grid-area: main; min-width: 0; text-align: left; background: none; border: 0; padding: 0; cursor: pointer; display: flex; flex-direction: column; gap: 1px; }
.line1 { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.grade, .state, .sample { font-size: 10.5px; font-weight: 700; line-height: 16px; padding: 0 6px; border-radius: 999px; color: #fff; text-transform: uppercase; letter-spacing: .3px; }
.grade.excellent { background: var(--ex); } .grade.good { background: var(--good); } .grade.ok { background: var(--ok); }
.state { background: var(--del); } .state:empty { display: none; }
.sample { background: var(--warn); display: none; } .deal.is-sample .sample { display: inline; }
.head { font-weight: 600; font-size: 15px; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.spec { font-size: 12.5px; }
.meta { font-size: 12px; color: var(--muted); }
.note-peek { font-size: 12px; color: var(--warn); font-style: italic; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-peek:empty { display: none; }

.price { grid-area: price; text-align: right; display: flex; flex-direction: column; align-items: flex-end; }
.eff { font-size: 17px; white-space: nowrap; }
.off { font-size: 12px; font-weight: 700; color: var(--ex); white-space: nowrap; }

.acts { grid-area: acts; display: flex; gap: 6px; }
.act { flex: 1; height: 32px; min-width: 0; border-radius: 8px; border: 1px solid var(--line); background: var(--card); cursor: pointer;
  display: grid; place-items: center; font-size: 13px; text-decoration: none; color: inherit; white-space: nowrap; padding: 0 4px; }
.act.keep[aria-pressed=true] { background: var(--keep); border-color: var(--keep); color: #fff; }
.act.delete[aria-pressed=true] { background: var(--del); border-color: var(--del); color: #fff; }
.act.note-btn.has-note { border-color: var(--warn); color: var(--warn); }

.more { grid-area: more; font-size: 12.5px; }
.note { width: 100%; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); resize: vertical; font-size: 16px; }
.saved { display: block; min-height: 14px; font-size: 11px; color: var(--muted); }
.breakdown { margin: 2px 0; }
.detail { white-space: pre-wrap; font: inherit; margin: 4px 0; color: var(--muted); }
.orig { margin: 2px 0; color: var(--muted); }

/* sold / ended / gone: crossed off */
.deal.ended .head, .deal.ended .eff { text-decoration: line-through; color: var(--muted); }
.deal.ended .off { color: var(--muted); }
.deal.ended .thumb { opacity: .5; filter: grayscale(1); }
.deal.deleted > :not(.acts):not(.more) { opacity: .45; }

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

@media (min-width: 560px) {
  .deal { grid-template-columns: 64px 1fr auto auto; grid-template-areas: "thumb main price acts" "more more more more"; align-items: center; }
  .thumb { width: 64px; height: 64px; }
  .acts { width: 290px; }
}
.bar-top, .controls { max-width: 760px; margin-left: auto; margin-right: auto; }
@media (min-width: 761px) { .controls select { flex: 0 1 200px; } }
