/* ============================================================
   BINDER — design tokens + core components
   Mobile-first. Dark-first. Zero external requests.
   Every page: <link rel="stylesheet" href="shared/tokens.css">
   (from root pages; adjust relative path if nested)
   ============================================================ */

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
img, svg { display: block; max-width: 100%; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }

/* ---------- tokens ---------- */
:root {
  color-scheme: dark;

  /* surfaces (match validated dataviz dark surfaces) */
  --page:        #0d0d0d;
  --surface-1:   #1a1a19;   /* cards, chart surface */
  --surface-2:   #242423;   /* raised: sheets, tabbar */
  --surface-3:   #2e2e2c;   /* pressed / inset */

  /* ink */
  --ink:         #ffffff;
  --ink-2:       #c3c2b7;
  --ink-3:       #898781;
  --hairline:    rgba(255,255,255,0.10);
  --grid:        #2c2c2a;

  /* brand — holo foil. Brand moments ONLY, never chart series. */
  --holo-a:      #9085e9;   /* violet */
  --holo-b:      #3987e5;   /* blue   */
  --holo-c:      #19c2a0;   /* aqua   */
  --holo: linear-gradient(100deg, var(--holo-a), var(--holo-b) 45%, var(--holo-c));

  /* chart series (validated dark-mode categorical slots — fixed order) */
  --series-1:    #3987e5;
  --series-2:    #d95926;
  --series-3:    #199e70;

  /* status / deltas */
  --good:        #0ca30c;
  --warning:     #fab219;
  --serious:     #ec835a;
  --critical:    #d03b3b;

  /* rarity tiers (achievements) */
  --tier-common:    #898781;
  --tier-uncommon:  #199e70;
  --tier-rare:      #3987e5;
  --tier-epic:      #9085e9;
  --tier-legendary: #eda100;

  /* type — system sans everywhere, no webfonts */
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --fs-hero:  clamp(2rem, 8vw, 3.4rem);
  --fs-h1:    clamp(1.5rem, 6vw, 2.2rem);
  --fs-h2:    1.25rem;
  --fs-body:  1rem;
  --fs-small: 0.875rem;
  --fs-micro: 0.75rem;

  --r-card: 16px;
  --r-chip: 999px;
  --gap:    16px;
  --pad:    20px;
  --maxw:   1080px;
  --tabbar-h: 64px;
}

body {
  font-family: var(--font);
  font-size: var(--fs-body);
  line-height: 1.5;
  background: var(--page);
  color: var(--ink);
  min-height: 100vh;
}

/* ---------- layout ---------- */
.wrap { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 var(--pad); }
.app-main { padding: 12px var(--pad) calc(var(--tabbar-h) + 32px); max-width: var(--maxw); margin: 0 auto; }
.stack { display: flex; flex-direction: column; gap: var(--gap); }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- type helpers ---------- */
h1 { font-size: var(--fs-h1); font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; }
h2 { font-size: var(--fs-h2); font-weight: 700; letter-spacing: -0.01em; }
.small { font-size: var(--fs-small); color: var(--ink-2); }
.micro { font-size: var(--fs-micro); color: var(--ink-3); }
.num { font-variant-numeric: tabular-nums; }
.holo-text {
  background: var(--holo);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}

/* ---------- components ---------- */
.card {
  background: var(--surface-1);
  border: 1px solid var(--hairline);
  border-radius: var(--r-card);
  padding: var(--pad);
}
.card.holo-edge { position: relative; background:
  linear-gradient(var(--surface-1), var(--surface-1)) padding-box,
  var(--holo) border-box;
  border: 1px solid transparent;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 22px;
  border-radius: 12px; font-weight: 700; font-size: var(--fs-body);
  transition: transform .06s ease, opacity .15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--holo); color: #0d0d0d; }
.btn-ghost { border: 1px solid var(--hairline); color: var(--ink); background: var(--surface-2); }
.btn-block { width: 100%; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: var(--r-chip);
  background: var(--surface-2); border: 1px solid var(--hairline);
  font-size: var(--fs-small); font-weight: 600; color: var(--ink-2);
}
.chip.active { background: var(--ink); color: var(--page); border-color: var(--ink); }

.delta-up   { color: var(--good);     font-weight: 700; }
.delta-down { color: var(--critical); font-weight: 700; }

/* rarity badge — achievements */
.badge {
  width: 64px; height: 64px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); border: 2px solid var(--tier, var(--tier-common));
  font-size: 26px; position: relative;
}
.badge.locked { filter: grayscale(1) brightness(0.55); border-style: dashed; }
.badge.t-common    { --tier: var(--tier-common); }
.badge.t-uncommon  { --tier: var(--tier-uncommon); }
.badge.t-rare      { --tier: var(--tier-rare); }
.badge.t-epic      { --tier: var(--tier-epic); }
.badge.t-legendary { --tier: var(--tier-legendary);
  box-shadow: 0 0 18px rgba(237,161,0,0.35); }

.progress { height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 4px; background: var(--holo); }

/* stat tile */
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .v { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.02em; }
.stat .l { font-size: var(--fs-micro); color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.06em; }

/* pro lock */
.pro-tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: var(--fs-micro); font-weight: 800; letter-spacing: 0.08em;
  padding: 3px 8px; border-radius: 6px;
  background: var(--holo); color: #0d0d0d; text-transform: uppercase;
}

/* ---------- app chrome ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px var(--pad);
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--hairline);
}
.topbar .logo { font-weight: 900; font-size: 1.15rem; letter-spacing: -0.02em; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; align-items: stretch;
  background: color-mix(in srgb, var(--surface-2) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--hairline);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; font-size: var(--fs-micro); font-weight: 600; color: var(--ink-3);
}
.tabbar a.active { color: var(--ink); }
.tabbar a svg { width: 24px; height: 24px; }
.tabbar .scan-fab {
  flex: 0 0 72px; align-self: center; margin-top: -26px;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--holo); color: #0d0d0d;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 20px rgba(57,135,229,0.4);
}

/* ---------- charts ---------- */
.viz { background: var(--surface-1); border-radius: 12px; }
.viz text { font-family: var(--font); fill: var(--ink-3); font-size: 11px; }
.viz .axis line, .viz .grid-line { stroke: var(--grid); stroke-width: 1; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: var(--fs-small); color: var(--ink-2); }
.legend .key { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.demo-note { font-size: var(--fs-micro); color: var(--ink-3); font-style: italic; }

/* ---------- desktop enhancement ---------- */
@media (min-width: 768px) {
  :root { --pad: 28px; }
  .grid-2 { grid-template-columns: repeat(2, 1fr); gap: var(--gap); }
  .grid-4-desk { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--gap); }
  .tabbar { max-width: 480px; left: 50%; transform: translateX(-50%);
    border-radius: 20px 20px 0 0; border: 1px solid var(--hairline); border-bottom: none; }
}

/* ============================================================
   P1 SYSTEM LAYER — appended, additive only, no :root redefines
   ============================================================ */

/* ---------- native-feel layer ---------- */
html { -webkit-tap-highlight-color: transparent; }
body { overscroll-behavior-y: none; touch-action: manipulation; }
.topbar, .tabbar { user-select: none; -webkit-user-select: none; }

/* ---------- shared primitives ---------- */
.icon { width: 24px; height: 24px; display: block; }

.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: 0 0 auto;
  background: var(--holo); color: #0d0d0d; border: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 12.5px; font-weight: 800;
}

.icon-btn {
  width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
  flex: 0 0 auto; border-radius: 50%;
}
.icon-btn:active { background: var(--surface-2); }

/* ---------- tap-target fix (interactive chips only) ---------- */
button.chip, label.chip { min-height: 44px; padding: 0 16px; }

/* ---------- :has()-filter plumbing ---------- */
.vh { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; }
input.vh:focus-visible + label.chip { outline: 2px solid var(--holo-b); outline-offset: 2px; }

/* ---------- data-product utilities ---------- */
.eyebrow-src {
  display: block; font-size: var(--fs-micro); color: var(--ink-3);
  text-transform: uppercase; letter-spacing: 0.08em; font-weight: 800; margin-bottom: 4px;
}

.era-chip {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: var(--r-chip);
  font-size: var(--fs-micro); font-weight: 700; color: var(--ink-2);
  background: transparent; border: 1px solid var(--hairline); white-space: nowrap;
}
.era-chip.recent { border-color: var(--series-1); }
.era-chip.old    { border-color: var(--series-2); }

.verdict-pill {
  display: inline-flex; align-items: center; padding: 2px 9px; border-radius: var(--r-chip);
  font-size: var(--fs-micro); font-weight: 700; color: var(--ink-2);
}
.verdict-pill.warn { background: color-mix(in srgb, var(--warning) 14%, transparent); }
.verdict-pill.flat { background: color-mix(in srgb, var(--ink-3) 14%, transparent); }
.verdict-pill.good { background: color-mix(in srgb, var(--good) 14%, transparent); }

.card > h2 { margin-bottom: 12px; }

/* ---------- motion layer ---------- */
@view-transition { navigation: auto; }

@keyframes page-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
.app-main { animation: page-in .22s cubic-bezier(.2,.8,.2,1) both; }

/* tab bar */
.tabbar a { position: relative; transition: color .15s ease, transform .08s ease; }
.tabbar a:active { transform: scale(.92); }
.tabbar a.active::before {
  content: ""; position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
  width: 22px; height: 3px; border-radius: 2px; background: var(--holo);
}

/* scan FAB */
.scan-fab:active { transform: scale(.90); }
@keyframes fab-glow {
  0%, 100% { box-shadow: 0 6px 20px rgba(57,135,229,.40); }
  50%      { box-shadow: 0 6px 28px rgba(144,133,233,.55); }
}
.scan-fab { animation: fab-glow 4s ease-in-out infinite; }

/* streak flame */
@keyframes flame-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.08); }
}
@keyframes flame-halo {
  0%, 100% { box-shadow: 0 0 0 0 rgba(250,178,25,0); }
  50%      { box-shadow: 0 0 18px 3px rgba(250,178,25,.35); }
}
.flame-circle { animation: flame-halo 2.2s ease-in-out infinite; }
.flame-circle svg { animation: flame-pulse 2.2s ease-in-out infinite; }
.streak-chip svg { animation: flame-pulse 2.2s ease-in-out infinite; }

/* progress bars fill on load */
.progress > i { transform-origin: left; animation: bar-fill .6s .1s cubic-bezier(.2,.8,.2,1) both; }
@keyframes bar-fill {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}

/* badge unlock moment */
@keyframes unlock-pop {
  0%   { transform: scale(.6); opacity: 0; }
  60%  { transform: scale(1.12); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
.just-unlocked .badge { animation: unlock-pop 900ms cubic-bezier(.2,.8,.2,1) both; }
.just-unlocked { position: relative; }
.just-unlocked::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%;
  border: 2px solid transparent; border-top-color: var(--tier-rare);
  animation: ring-sweep 1.1s linear 2;
}
@keyframes ring-sweep { to { transform: rotate(360deg); } }
.just-unlocked::before {
  content: "NEW"; position: absolute; top: -4px; right: -8px; z-index: 2;
  background: var(--tier-rare); color: #0d0d0d; font-size: 9px; font-weight: 800;
  letter-spacing: .04em; padding: 2px 5px; border-radius: 5px;
}

/* streak "today pending" dot */
.day-dot.today {
  background: transparent; border: 2px solid var(--holo-b);
  animation: flame-pulse 1.8s ease-in-out infinite;
}

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