:root {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #f0f1f6;
  --text: #171923;
  --muted: #646a7d;
  --line: #e2e4ec;
  --accent: #4338ca;
  --accent-soft: #e8e7fb;
  --good: #15803d;
  --bad: #c2410c;
  --warn: #b45309;
  --urgent: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 24, 40, .06), 0 4px 16px rgba(20, 24, 40, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117;
    --surface: #181b24;
    --surface-2: #20242f;
    --text: #eceef4;
    --muted: #9aa0b2;
    --line: #2b2f3c;
    --accent: #8b85ff;
    --accent-soft: #2a2850;
    --good: #4ade80;
    --bad: #fb923c;
    --warn: #fbbf24;
    --urgent: #f87171;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.6rem; margin: .2em 0 .6em; letter-spacing: -.01em; }
h2 { font-size: 1.08rem; margin: 1.4em 0 .6em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
main { max-width: 980px; margin: 0 auto; padding: 16px 16px 40px; outline: none; }

/* header + nav */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); font-size: 1.05rem; white-space: nowrap; }
.topnav { display: flex; gap: 4px; flex: 1; }
.topnav a, .bottomnav a { color: var(--muted); border-radius: 10px; padding: 6px 10px; font-weight: 500; }
.topnav a.active { color: var(--accent); background: var(--accent-soft); }
.topnav .ni { margin-right: 4px; }
.sync { margin-left: auto; border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 99px; padding: 5px 12px; font: inherit; font-size: .8rem; cursor: pointer; white-space: nowrap; }
.sync.synced { color: var(--good); }
.sync.error { color: var(--bad); border-color: var(--bad); }
.bottomnav { display: none; }
@media (max-width: 720px) {
  .topnav { display: none; }
  .bottomnav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
    background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px);
    border-top: 1px solid var(--line); padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  .bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; font-size: .7rem; padding: 4px 0; }
  .bottomnav .ni { font-size: 1.25rem; line-height: 1.3; filter: grayscale(1); opacity: .7; }
  .bottomnav a.active { color: var(--accent); }
  .bottomnav a.active .ni { filter: none; opacity: 1; }
}
@media (min-width: 721px) { body { padding-bottom: 0; } }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: 8px 14px; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; margin-right: auto; }
.btn.sm { padding: 5px 10px; font-size: .82rem; border-radius: 8px; }
.btn.icon { padding: 5px 8px; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

.h-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.h-row h1, .h-row h2 { margin-bottom: .6em; }

/* stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); color: var(--text); display: flex; flex-direction: column; }
.stat span { font-size: .8rem; color: var(--muted); }
.stat b { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.stat small { color: var(--muted); font-size: .78rem; }
.stats.big .stat b { font-size: 1.7rem; }

.banner { background: var(--accent-soft); border-radius: var(--radius); padding: 10px 14px; margin: 12px 0; font-size: .9rem; display: grid; gap: 4px; }

/* todo list */
.count { background: var(--surface-2); color: var(--muted); border-radius: 99px; padding: 1px 8px; font-size: .78rem; font-weight: 600; vertical-align: 2px; }
.todos, .bens, .perks, .extras, .rank { list-style: none; margin: 0; padding: 0; }
.todos { display: grid; gap: 8px; }
.todo {
  display: flex; gap: 12px; justify-content: space-between; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--c);
  border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow);
}
.todo-main { min-width: 0; flex: 1; }
.todo-title { font-weight: 650; }
.todo-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: .82rem; margin: 2px 0 6px; }
.todo-amt { font-size: .85rem; color: var(--muted); }
.todo-side { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; text-align: right; }
.todo-actions { display: inline-flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 560px) {
  .todo { flex-direction: column; align-items: stretch; }
  .todo-side { flex-direction: row; justify-content: space-between; align-items: center; }
}
.due { font-size: .82rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.due.soon { color: var(--warn); }
.due.urgent, .due.late { color: var(--urgent); }
.bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 4px 0; max-width: 360px; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }

.chip { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-weight: 500; }
.swatch { display: inline-block; width: 18px; height: 12px; border-radius: 3px; flex: none; }
.swatch.big { width: 38px; height: 24px; border-radius: 5px; }
.tag { font-size: .75rem; font-weight: 600; background: var(--surface-2); color: var(--muted); border-radius: 6px; padding: 2px 7px; }
.tag.good { color: var(--good); }

.empty { text-align: center; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 32px 16px; }

/* card tiles */
.cgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.ccard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); color: var(--text); }
.ccard:hover { border-color: var(--accent); }
.ccard-art, .hero-art {
  aspect-ratio: 1.586; padding: 14px; color: #fff; display: flex; flex-direction: column; justify-content: space-between;
  background: linear-gradient(135deg, var(--c), color-mix(in srgb, var(--c) 55%, #000));
}
.ccard-art { aspect-ratio: auto; height: 110px; }
.ccard-name { font-weight: 700; font-size: 1.02rem; text-shadow: 0 1px 2px rgba(0,0,0,.3); }
.ccard-net { align-self: flex-end; font-size: .8rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; opacity: .9; }
.ccard-info { display: flex; justify-content: space-between; padding: 10px 14px; font-size: .85rem; gap: 8px; }
.ccard-info div { display: flex; flex-direction: column; }

/* add-card picker */
.picks { display: grid; gap: 6px; max-height: 60vh; overflow: auto; margin-top: 10px; }
.pick { display: flex; gap: 12px; align-items: center; text-align: left; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px; cursor: pointer; }
.pick:hover { border-color: var(--accent); }
.pick small { display: block; color: var(--muted); }

/* card detail */
.back { display: inline-block; margin-bottom: 10px; font-size: .9rem; }
.hero { display: flex; gap: 18px; align-items: center; margin-bottom: 14px; }
.hero-art { width: 210px; flex: none; border-radius: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.18); }
.hero-info h1 { margin: 0 0 4px; }
.hero-info p { margin: 0 0 10px; }
@media (max-width: 560px) { .hero { flex-direction: column; align-items: stretch; } .hero-art { width: 100%; max-width: 320px; } }

.bens { display: grid; gap: 10px; }
.ben { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.ben.is-done { opacity: .78; }
.ben-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.ben-name { font-weight: 650; }
.ben p { margin: 6px 0; }
.ben-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.hist { display: flex; gap: 4px; margin-top: 10px; flex-wrap: wrap; }
.h { width: 28px; height: 26px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); font: inherit; font-size: .72rem; font-weight: 700; cursor: pointer; padding: 0; }
.h.full { background: var(--good); color: #fff; border-color: transparent; }
.h.part { background: color-mix(in srgb, var(--good) 35%, var(--surface)); color: var(--text); }
.h.miss { background: color-mix(in srgb, var(--bad) 18%, var(--surface)); color: var(--bad); }
.h.open { border-color: var(--accent); color: var(--accent); }
.h.skip { text-decoration: line-through; }
.h.pre { opacity: .55; }
.h.future, .h.na { opacity: .4; cursor: default; }

.extras li { display: grid; grid-template-columns: 110px 1fr auto auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.perks { display: grid; gap: 6px; }
.perks li { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; font-size: .92rem; }

.tbl { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); font-size: .92rem; }
.tbl th, .tbl td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); }
.tbl td:not(:first-child), .tbl th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl tfoot td { font-weight: 700; border-bottom: 0; }
.table-wrap { overflow-x: auto; }
.mini { position: relative; height: 6px; margin-top: 6px; max-width: 220px; }
.mini i { position: absolute; left: 0; top: 0; height: 6px; border-radius: 99px; }
.mini .f { background: var(--surface-2); outline: 1px solid var(--line); }
.mini .u { background: var(--good); }
@media (max-width: 560px) { .hide-sm { display: none; } .tbl th, .tbl td { padding: 8px; } }

.meter { display: flex; height: 16px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin: 14px 0 6px; border: 1px solid var(--line); }
.meter i { display: block; height: 100%; background: var(--good); }
.meter i.pot { background: repeating-linear-gradient(45deg, color-mix(in srgb, var(--good) 40%, transparent) 0 6px, transparent 6px 10px); }
.legend { display: flex; gap: 14px; }
.lg { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.lg.used { background: var(--good); }
.lg.pot { background: color-mix(in srgb, var(--good) 40%, transparent); }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg a { padding: 5px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.seg a.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* best card */
.best { display: grid; gap: 8px; }
.cat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.cat summary { display: flex; gap: 12px; align-items: center; padding: 12px 14px; cursor: pointer; list-style: none; }
.cat summary::-webkit-details-marker { display: none; }
.cat summary::after { content: '›'; margin-left: auto; color: var(--muted); font-size: 1.3rem; transition: transform .15s; }
.cat[open] summary::after { transform: rotate(90deg); }
.cat-ic { font-size: 1.4rem; width: 32px; text-align: center; }
.cat-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cat-top { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: .9rem; }
.cat > p { margin: 0 14px 8px 58px; }
.rank { padding: 0 14px 12px 58px; counter-reset: r; }
.rank li { padding: 7px 0; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 10px; counter-increment: r; }
.rank li::before { content: counter(r); color: var(--muted); font-size: .8rem; width: 16px; }
.rank li .chip { flex: 1; }
.rank li > div { flex-basis: 100%; padding-left: 16px; }
.rank li.excluded { opacity: .5; }
.r-val { font-variant-numeric: tabular-nums; font-weight: 600; }
@media (max-width: 560px) { .rank, .cat > p { padding-left: 14px; margin-left: 14px; } }

/* settings */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 16px 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.cpp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.cpp-grid label { display: flex; flex-direction: column; gap: 4px; font-size: .88rem; font-weight: 600; }
.rot { border: 1px solid var(--line); border-radius: 10px; margin: 0 0 10px; display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 4px 12px; }
.rot legend { font-weight: 700; padding: 0 4px; }

/* forms + dialog */
dialog {
  border: 0; border-radius: 18px; padding: 20px; width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 40px);
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(10, 12, 20, .45); }
dialog h2 { margin: 0 32px 4px 0; font-size: 1.2rem; }
.dlg-x { position: absolute; top: 12px; right: 12px; border: 0; background: var(--surface-2); color: var(--muted); width: 30px; height: 30px; border-radius: 99px; cursor: pointer; font-size: .9rem; }
.form { display: grid; gap: 12px; margin-top: 12px; }
.form label, fieldset { display: grid; gap: 4px; font-size: .88rem; font-weight: 600; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { padding: 0; margin-bottom: 4px; }
legend small, label small { font-weight: 400; color: var(--muted); }
input, select {
  font: inherit; font-weight: 400; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; width: 100%; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=search] { margin-top: 8px; }
.check { display: flex !important; align-items: center; gap: 8px; font-weight: 500 !important; }
.check input { width: auto; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.money-in { display: flex; align-items: center; gap: 6px; }
.money-in span { color: var(--muted); font-weight: 600; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 6px; }
details summary { cursor: pointer; color: var(--accent); }
.earn-grid { display: grid; gap: 6px; max-height: 55vh; overflow: auto; }
.earn-row { display: grid !important; grid-template-columns: 1fr 90px; align-items: center; font-weight: 500 !important; }
.cat summary { color: var(--text); }
.swatch { box-shadow: inset 0 0 0 1px rgba(128, 128, 140, .35); }
