/* Riftbound Holdings.
 *
 * Palette, surfaces and ink are the validated reference instance. Data marks
 * use ONE sequential hue, so there is no categorical palette to mis-read
 * under colour-vision deficiency. Text always wears ink tokens.
 *
 * Both themes are written out explicitly; dark is its own set of steps chosen
 * against the dark surface, not an automatic inversion.
 *
 * Mobile first: layout starts single-column with a bottom nav, and widens.
 */

:root {
  color-scheme: light;
  --page:      #f9f9f7;
  --surface:   #fcfcfb;
  --raised:    #ffffff;
  --ink:       #0b0b0b;
  --ink-2:     #52514e;
  --muted:     #898781;
  --grid:      #e1e0d9;
  --baseline:  #c3c2b7;
  --border:    rgba(11, 11, 11, 0.10);
  --accent:    #2a78d6;
  --accent-in: #ffffff;
  --accent-dim:#cde2fb;
  --bar:       #2a78d6;
  --good:      #006300;
  --good-bg:   #e6f4e6;
  --warn:      #fab219;
  --crit:      #d03b3b;
  --crit-bg:   #fbe9e9;
  --shadow-1:  0 1px 2px rgba(11,11,11,.06);
  --shadow-2:  0 1px 2px rgba(11,11,11,.06), 0 6px 18px rgba(11,11,11,.07);
  --r:         12px;
  --r-sm:      8px;
  --tap:       44px;         /* minimum touch target */
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page:      #0d0d0d;
  --surface:   #1a1a19;
  --raised:    #212120;
  --ink:       #ffffff;
  --ink-2:     #c3c2b7;
  --muted:     #898781;
  --grid:      #2c2c2a;
  --baseline:  #383835;
  --border:    rgba(255, 255, 255, 0.10);
  --accent:    #3987e5;
  --accent-in: #0b0b0b;
  --accent-dim:#184f95;
  --bar:       #3987e5;
  --good:      #0ca30c;
  --good-bg:   #10240f;
  --warn:      #fab219;
  --crit:      #e66767;
  --crit-bg:   #2a1414;
  --shadow-1:  0 1px 2px rgba(0,0,0,.5);
  --shadow-2:  0 1px 2px rgba(0,0,0,.5), 0 6px 20px rgba(0,0,0,.4);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --raised: #212120;
    --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --baseline: #383835;
    --border: rgba(255,255,255,0.10);
    --accent: #3987e5; --accent-in: #0b0b0b; --accent-dim: #184f95;
    --bar: #3987e5; --good: #0ca30c; --good-bg: #10240f;
    --crit: #e66767; --crit-bg: #2a1414;
    --shadow-1: 0 1px 2px rgba(0,0,0,.5);
    --shadow-2: 0 1px 2px rgba(0,0,0,.5), 0 6px 20px rgba(0,0,0,.4);
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }   /* author display rules outrank the UA rule */

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--accent); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.wrap { max-width: 1500px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 700px) { .wrap { padding: 0 24px; } }

/* Visible focus everywhere, never removed. */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* --------------------------------------------------------------- app bar -- */

.appbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.appbar-in {
  max-width: 1500px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 14px;
}
.logo {
  display: flex; align-items: center; gap: 9px;
  font-weight: 650; font-size: 16px; color: inherit; text-decoration: none;
  letter-spacing: -.01em;
}
.logo-mark {
  width: 26px; height: 26px; border-radius: 7px; flex: none;
  background: linear-gradient(140deg, var(--accent), var(--accent-dim));
  display: grid; place-items: center; color: var(--accent-in);
  font-size: 13px; font-weight: 700;
}
.appbar nav { display: none; gap: 2px; margin-left: 8px; }
@media (min-width: 760px) { .appbar nav { display: flex; } }
.navlink {
  padding: 8px 12px; border-radius: var(--r-sm); text-decoration: none;
  color: var(--ink-2); font-size: 14.5px; font-weight: 500;
  min-height: var(--tap); display: inline-flex; align-items: center;
}
.navlink:hover { background: var(--page); color: var(--ink); }
.navlink[aria-current="page"] { background: var(--accent); color: var(--accent-in); }
.appbar .right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* The fetch date belongs on every page: a price without its date invites
 * trusting a number that may be a week old. */
.freshness {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 12.5px; color: var(--ink-2);
  background: var(--page); border-bottom: 1px solid var(--border);
  padding: 6px 16px;
}
.freshness .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--good);
  flex: none;
}
.freshness.stale { background: var(--crit-bg); color: var(--ink); }
.freshness.stale .dot { background: var(--crit); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }

/* ------------------------------------------------------------ bottom nav -- */

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 45;
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 760px) { .tabbar { display: none; } }
.tabbar a {
  flex: 1; min-height: 56px; display: grid; place-items: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: 11px; padding: 6px 0;
}
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a[aria-current="page"] { color: var(--accent); }
body.has-tabbar { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
@media (min-width: 760px) { body.has-tabbar { padding-bottom: 0; } }

/* ------------------------------------------------------------------ hero -- */

.hero {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; padding: 18px 0 12px;
}
.hero-figure { line-height: 1.05; }
.hero-label {
  font-size: 11px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--muted); display: block; margin-bottom: 3px;
}
.hero-value {
  font-size: clamp(34px, 9vw, 46px); font-weight: 660; letter-spacing: -.025em;
  font-variant-numeric: tabular-nums; display: block;
}
.hero-sub { font-size: 13px; color: var(--ink-2); }

/* ------------------------------------------------------------------ kpis -- */

.kpis {
  display: grid; gap: 10px; margin: 0 0 16px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 11px 13px;
}
.kpi-label {
  font-size: 10.5px; letter-spacing: .07em; text-transform: uppercase;
  color: var(--muted); display: block;
}
.kpi-value {
  font-size: 21px; font-weight: 620; font-variant-numeric: tabular-nums;
  display: block; margin-top: 1px;
}
.kpi-note {
  font-size: 12px; color: var(--ink-2); display: block;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ------------------------------------------------------------------ bars -- */

.bars { display: grid; gap: 8px; }
.bar-row {
  display: grid; grid-template-columns: 96px 1fr auto; gap: 10px;
  align-items: center; font-size: 13.5px;
}
.bar-name { color: var(--ink-2); white-space: nowrap; overflow: hidden;
            text-overflow: ellipsis; }
.bar-track { background: var(--grid); border-radius: 5px; height: 11px;
             overflow: hidden; }
.bar-fill {
  height: 100%; background: var(--bar); border-radius: 0 5px 5px 0;
  transition: width .5s cubic-bezier(.22,.61,.36,1);
}
.bar-val { font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- controls -- */

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 14px; margin-bottom: 16px;
}
.filters { display: grid; gap: 10px; }
@media (min-width: 700px) {
  .filters { grid-template-columns: 2fr repeat(4, 1fr) auto; align-items: end; }
}
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 11.5px; color: var(--muted); font-weight: 500; }
.field.row { flex-direction: row; align-items: center; gap: 6px; }

input, select, textarea, .btn {
  font: inherit; color: var(--ink); background: var(--raised);
  border: 1px solid var(--baseline); border-radius: var(--r-sm);
  padding: 9px 11px; min-height: var(--tap); width: 100%;
}
textarea { min-height: 160px; font-family: ui-monospace, monospace; font-size: 14px; }
.btn {
  cursor: pointer; width: auto; display: inline-flex; align-items: center;
  justify-content: center; gap: 7px; font-weight: 550;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--accent); color: var(--accent-in); border-color: var(--accent);
}
.btn-primary:hover { filter: brightness(1.07); }
.btn-danger { color: var(--crit); border-color: var(--crit); }
.btn-sm { min-height: 36px; padding: 6px 10px; font-size: 13.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.check { display: flex; align-items: center; gap: 8px; min-height: var(--tap);
         font-size: 14.5px; color: var(--ink-2); }
.check input { width: 20px; height: 20px; min-height: 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: var(--page);
  border-radius: 999px; padding: 4px 10px; font-size: 12.5px;
  color: var(--ink-2); text-decoration: none;
}
.chip.on { background: var(--accent); color: var(--accent-in);
           border-color: var(--accent); }

/* ------------------------------------------------------------ card grid -- */

.grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
@media (min-width: 700px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(178px, 1fr)); gap: 14px; }
}
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); overflow: hidden; display: flex;
  flex-direction: column; box-shadow: var(--shadow-1);
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
@media (hover: hover) {
  .card:hover { box-shadow: var(--shadow-2); transform: translateY(-2px); }
}
.card.owned { border-color: var(--accent); }
.card-art { position: relative; aspect-ratio: .72; background: var(--grid);
            display: block; }
.card-art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-badge {
  position: absolute; inset-inline-end: 6px; inset-block-end: 6px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  border: 1px solid var(--border); border-radius: 7px;
  padding: 2px 7px; font-size: 13px; font-weight: 660;
  font-variant-numeric: tabular-nums; backdrop-filter: blur(4px);
}
.card-qtybadge {
  position: absolute; inset-inline-start: 6px; inset-block-start: 6px;
  background: var(--accent); color: var(--accent-in);
  border-radius: 7px; padding: 2px 7px; font-size: 12.5px; font-weight: 660;
}
.card-body { padding: 9px 10px 10px; display: grid; gap: 7px; }
.card-name {
  font-size: 13.5px; font-weight: 550; line-height: 1.3; min-height: 2.6em;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-name a { color: inherit; text-decoration: none; }
.card-name a:hover { text-decoration: underline; }
.card-meta {
  font-size: 11.5px; color: var(--muted); display: flex; gap: 6px;
  flex-wrap: wrap; min-height: 1.6em;
}
.tag { border: 1px solid var(--border); border-radius: 5px; padding: 0 5px;
       color: var(--ink-2); }
.card-line { font-size: 12.5px; }
.card-line strong { font-variant-numeric: tabular-nums; }

/* A price that just changed should announce itself, then settle. */
@keyframes flash-up {
  0%   { background: var(--good-bg); }
  100% { background: transparent; }
}
@keyframes flash-down {
  0%   { background: var(--crit-bg); }
  100% { background: transparent; }
}
.flash-up   { animation: flash-up 2.2s ease-out; }
.flash-down { animation: flash-down 2.2s ease-out; }
.delta { font-size: 11.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--good); }
.delta.down { color: var(--crit); }

/* --------------------------------------------------------------- stepper -- */

.qty { display: flex; align-items: stretch; }
.qty button {
  width: var(--tap); min-height: 38px; padding: 0; cursor: pointer;
  background: var(--raised); color: var(--ink); font: inherit;
  border: 1px solid var(--baseline); font-size: 19px; line-height: 1;
}
.qty button:first-of-type { border-radius: var(--r-sm) 0 0 var(--r-sm); }
.qty button:last-of-type { border-radius: 0 var(--r-sm) var(--r-sm) 0;
                           margin-inline-start: -1px; }
.qty button:disabled { opacity: .4; cursor: default; }
.qty input {
  width: 100%; min-width: 48px; min-height: 38px; padding: 0 4px;
  text-align: center; border-radius: 0; margin-inline: -1px;
  font-variant-numeric: tabular-nums; appearance: textfield;
}
.qty input::-webkit-outer-spin-button,
.qty input::-webkit-inner-spin-button { appearance: none; margin: 0; }
.qty.on input { border-color: var(--accent); font-weight: 660; }

/* ----------------------------------------------------------------- table -- */

.tablewrap {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); overflow-x: auto; -webkit-overflow-scrolling: touch;
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  position: sticky; top: 0; z-index: 3; background: var(--surface);
  text-align: left; font-size: 11.5px; letter-spacing: .05em;
  text-transform: uppercase; color: var(--muted); font-weight: 650;
  padding: 10px; white-space: nowrap; border-bottom: 1px solid var(--baseline);
}
thead th.num, td.num { text-align: right; }
thead th a { color: inherit; text-decoration: none; }
thead th a:hover { color: var(--ink); }
th[aria-sort] { color: var(--ink); }
tbody td {
  padding: 8px 10px; border-bottom: 1px solid var(--grid);
  border-right: 1px solid var(--grid);
}
tbody td:last-child { border-right: 0; }
tbody tr:nth-child(even) { background: color-mix(in srgb, var(--page) 55%, transparent); }
tbody tr.owned > td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
td img.thumb {
  width: 34px; height: 47px; object-fit: cover; border-radius: 4px;
  background: var(--grid); display: block;
}

/* ------------------------------------------------------------- progress -- */

.progress-shell {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 16px; box-shadow: var(--shadow-1);
}
.progress-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 10px;
}
.progress-count {
  font-size: clamp(26px, 7vw, 34px); font-weight: 660;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em;
}
.progress-count small { font-size: .5em; font-weight: 500; color: var(--muted); }
.progress-track {
  height: 14px; border-radius: 7px; background: var(--grid);
  overflow: hidden; position: relative;
}
.progress-fill {
  height: 100%; width: 0; border-radius: 0 7px 7px 0; background: var(--bar);
  transition: width .45s cubic-bezier(.22,.61,.36,1);
  position: relative; overflow: hidden;
}
/* A moving sheen says "still working" without implying extra progress. */
.progress-fill::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 20%,
    color-mix(in srgb, #fff 34%, transparent) 50%, transparent 80%);
  transform: translateX(-100%);
  animation: sheen 1.5s linear infinite;
}
.progress-shell[data-idle="1"] .progress-fill::after { animation: none; }
@keyframes sheen { to { transform: translateX(100%); } }
.progress-stats {
  display: grid; gap: 8px; margin-top: 12px;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
}
.stat { background: var(--page); border: 1px solid var(--border);
        border-radius: var(--r-sm); padding: 8px 10px; }
.stat b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--muted); text-transform: uppercase;
             letter-spacing: .06em; }

.feed {
  margin-top: 14px; max-height: 340px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--page);
}
.feed ol { list-style: none; margin: 0; padding: 0; }
.feed li {
  display: grid; grid-template-columns: 1fr auto auto; gap: 10px;
  align-items: center; padding: 7px 11px;
  border-bottom: 1px solid var(--grid); font-size: 13.5px;
}
.feed li:last-child { border-bottom: 0; }
.feed li.enter { animation: slidein .28s ease-out; }
@keyframes slidein {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: none; }
}
.feed .fname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.feed .fprice { font-variant-numeric: tabular-nums; font-weight: 600; }

/* -------------------------------------------------------------- messages -- */

.messages { display: grid; gap: 8px; margin: 12px 0; }
.msg {
  border: 1px solid var(--border); border-left: 4px solid var(--accent);
  background: var(--surface); border-radius: var(--r-sm);
  padding: 10px 12px; font-size: 14px;
}
.msg.error, .msg.warning { border-left-color: var(--crit); }
.msg.success { border-left-color: var(--good); }

.empty { text-align: center; color: var(--ink-2); padding: 56px 16px; }
.empty h2 { margin: 0 0 6px; font-size: 18px; }

.pager { display: flex; gap: 8px; justify-content: center; align-items: center;
         padding: 22px 0 8px; flex-wrap: wrap; }
.pager .current { font-variant-numeric: tabular-nums; color: var(--ink-2);
                  font-size: 14px; }

.foot { padding: 26px 0 40px; font-size: 12.5px; color: var(--ink-2);
        display: grid; gap: 4px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(12px);
  bottom: calc(74px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--page); padding: 10px 16px;
  border-radius: 999px; font-size: 13.5px; z-index: 60; box-shadow: var(--shadow-2);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (min-width: 760px) { .toast { bottom: 24px; } }

/* Login is the only page without the app shell. */
.loginpage { min-height: 100svh; display: grid; place-items: center; padding: 20px; }
.loginbox {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r);
  padding: 26px 22px; box-shadow: var(--shadow-2);
}
.loginbox h1 { margin: 0 0 4px; font-size: 21px; }
.loginbox p.sub { margin: 0 0 20px; color: var(--ink-2); font-size: 14px; }
.loginbox .field { margin-bottom: 14px; }
.loginbox .btn { width: 100%; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
