/* Ballers IQ v5 base (WP1): reset, type ramp, shared components, screen transition, reduced motion.
   Spec §4 (layout), §11 (contract: .t-* .btn .btn-pri .btn-sec .btn-ghost .card .chip .sheet .tabbar .bar), §13.
   Tokens only: no raw colours here. The pressed colour lands in the same frame as the touch (no colour
   transition on press-in); the press scale eases in over 100 ms; release eases out over 200 ms.
   iOS only applies :active when a touchstart listener exists (index.html has <body ontouchstart="">);
   JS can also add .is-pressed on pointerdown for the same look. */

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; background: var(--bg); font: 500 16px/22px var(--f-body); }
html, body { margin: 0; height: 100%; }
body {
  min-height: 100dvh; overflow: hidden; overscroll-behavior: none;
  background: var(--bg); color: var(--ink);
  font: 500 16px/22px var(--f-body); font-synthesis: none;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
h1, h2, h3, h4, p, ul, ol, figure, blockquote { margin: 0; }
ul, ol { padding: 0; list-style: none; }
img, svg, canvas, video { display: block; max-width: 100%; }
svg { overflow: visible; }
button, input, textarea, select { font: inherit; color: inherit; letter-spacing: inherit; }
button { margin: 0; padding: 0; border: 0; background: none; cursor: pointer; touch-action: manipulation; text-align: inherit; }
a { color: inherit; text-decoration: none; touch-action: manipulation; }
input, textarea { -webkit-user-select: text; user-select: text; }
[hidden] { display: none !important; }

/* focus: a clear ring for keyboards only */
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

/* ---------- app column ---------- */
#app {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  width: 100%; max-width: var(--maxw); margin: 0 auto;
  padding-left: var(--sal); padding-right: var(--sar);
  isolation: isolate; overflow: hidden;
}

/* a screen: fades and lifts 8 px in over 300 ms (150 ms fade with reduced motion) [G4, U10].
   fill-mode is backwards only, so no transform stays on the screen after it lands (fixed children stay fixed). */
.screen {
  flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative;
  animation: screen-in var(--d-screen) var(--e-emph) backwards;
}
.screen.is-leaving { animation: fade-out var(--d-small) var(--e-accel) forwards; pointer-events: none; }
@keyframes screen-in { from { opacity: 0; transform: translateY(var(--lift)); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }

/* ---------- type ramp (contract) [U4] ---------- */
.t-hero    { font: 900 64px/64px var(--f-head); letter-spacing: -.035em; font-variant-numeric: tabular-nums; }
.t-display { font: 900 34px/36px var(--f-head); letter-spacing: -.025em; }
.t-title   { font: 800 22px/26px var(--f-head); letter-spacing: -.012em; }
.t-head    { font: 700 17px/22px var(--f-body); letter-spacing: -.01em; }
.t-body    { font: 500 16px/22px var(--f-body); }
.t-cap     { font: 700 13px/16px var(--f-body); letter-spacing: .005em; }
.t-over    { font: 800 11.5px/12px var(--f-head); letter-spacing: .08em; text-transform: uppercase; }
/* icons from icons.js: 24 px grid, 2 px stroke */
.i { width: 24px; height: 24px; flex: none; }

/* ---------- buttons ---------- */
.btn {
  position: relative; display: flex; align-items: center; justify-content: center; gap: var(--s2);
  width: 100%; min-height: var(--cta); padding: var(--s2) var(--s5); border-radius: var(--r);
  font: 800 17px/22px var(--f-head); letter-spacing: .04em; text-transform: uppercase; text-align: center;
  color: var(--ink); background: var(--raised);
  box-shadow: inset 0 1px 0 var(--hi), inset 0 0 0 1px var(--line);
  -webkit-user-select: none; user-select: none; touch-action: manipulation;
  transition: transform var(--d-small) var(--e-decel), background-color var(--d-small) var(--e-decel), box-shadow var(--d-small) var(--e-decel), opacity var(--d-small);
}
.btn .i { width: 22px; height: 22px; margin: 0 -2px; }
.btn:active, .btn.is-pressed { transform: scale(.97); background-color: var(--pressed); transition: transform var(--d-tap) var(--e-emph); }
.btn:focus-visible { outline-offset: 4px; }
/* desktop pointer only: a quiet lift on hover (touch never sees it, so no sticky hover on phones) */
@media (hover: hover) and (pointer: fine) {
  .btn-sec:hover:not(:active), .card.is-tap:hover:not(:active), button.card:hover:not(:active) { background-color: var(--pressed); }
  .btn-pri:hover:not(:active) { box-shadow: inset 0 1px 0 var(--hi-2), inset 0 -2px 0 var(--lo), 0 12px 30px -10px var(--pri-glow); }
  .btn-ghost:hover:not(:active), .btn-icon:hover:not(:active) { color: var(--ink); }
}
.btn[disabled], .btn[aria-disabled="true"] { opacity: .4; pointer-events: none; }

/* primary: one per screen. Orange fill, lit top edge, soft glow; presses in to 0.94 */
.btn-pri {
  color: var(--on-pri); background: var(--pri);
  box-shadow: inset 0 1px 0 var(--hi-2), inset 0 -2px 0 var(--lo), 0 10px 26px -12px var(--pri-glow);
}
.btn-pri:active, .btn-pri.is-pressed { transform: scale(.94); background-color: var(--pri-press); box-shadow: inset 0 1px 0 var(--hi), inset 0 2px 6px var(--lo), 0 4px 12px -8px var(--pri-glow); }

.btn-sec { background: var(--raised); color: var(--ink); }

/* text-only: "Not now", "Leave". Still a 44 px target */
.btn-ghost {
  width: auto; min-height: var(--hit); padding: var(--s1) var(--s4); margin: 0 auto; border-radius: var(--r-sm);
  font: 700 17px/22px var(--f-body); letter-spacing: -.01em; text-transform: none; color: var(--ink2);   /* SCREENS §1.3 */
  background: transparent; box-shadow: none;
}
.btn-ghost:active, .btn-ghost.is-pressed { transform: scale(.96); background-color: var(--line); color: var(--ink); }

/* extensions: destructive confirm (reset progress) and a round 44 px icon button (X, back, settings) */
.btn-bad { color: var(--on-pri); background: var(--bad); box-shadow: inset 0 1px 0 var(--hi-2), inset 0 -2px 0 var(--lo); }
.btn-bad:active, .btn-bad.is-pressed { transform: scale(.94); background-color: var(--bad); opacity: .85; }
.btn-icon {
  display: inline-grid; place-items: center; flex: none; width: var(--hit); height: var(--hit); min-height: 0; padding: 0;
  border-radius: var(--r-pill); color: var(--ink2); background: transparent; box-shadow: none;
  transition: transform var(--d-small) var(--e-decel), background-color var(--d-small) var(--e-decel), color var(--d-small);
}
.btn-icon:active, .btn-icon.is-pressed { transform: scale(.9); background-color: var(--raised); color: var(--ink); transition: transform var(--d-tap) var(--e-emph); }
.btn-icon .i { width: 24px; height: 24px; margin: 0; }

/* ---------- card ---------- */
.card {
  position: relative; display: block; width: 100%; padding: var(--s4); border-radius: var(--r);
  background: var(--card); color: var(--ink); text-align: left;
  box-shadow: inset 0 1px 0 var(--hi), inset 0 0 0 1px var(--line);
}
/* tappable cards press like buttons */
button.card, a.card, .card.is-tap { transition: transform var(--d-small) var(--e-decel), background-color var(--d-small) var(--e-decel); }
button.card:active, a.card:active, .card.is-tap:active, .card.is-pressed { transform: scale(.98); background-color: var(--raised); transition: transform var(--d-tap) var(--e-emph); }
.card-raised { background: var(--raised); box-shadow: inset 0 1px 0 var(--hi), inset 0 0 0 1px var(--line), var(--shadow); }

/* ---------- chip ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 6px 12px; border-radius: var(--r-pill);
  font: 700 13px/16px var(--f-body); color: var(--ink); background: var(--raised); white-space: nowrap;
  box-shadow: inset 0 0 0 1px var(--line);
}
.chip .i { width: 16px; height: 16px; margin-left: -2px; }
.chip-pri  { color: var(--pri-ink); background: var(--pri-soft); box-shadow: none; }
.chip-good { color: var(--good);    background: var(--good-soft); box-shadow: none; }
.chip-bad  { color: var(--bad);     background: var(--bad-soft); box-shadow: none; }
.chip-gold { color: var(--gold);    background: var(--gold-soft); box-shadow: none; }
/* a button chip keeps a 44 px hit area without looking bigger */
button.chip { position: relative; transition: transform var(--d-small) var(--e-decel); }
button.chip::after { content: ''; position: absolute; left: 0; right: 0; top: 50%; height: var(--hit); transform: translateY(-50%); }
button.chip:active { transform: scale(.94); transition: transform var(--d-tap) var(--e-emph); }
/* spring in, 200 ms (approximates damping 0.8) */
.chip-pop { animation: chip-pop var(--d-small) var(--spring) backwards; }
@keyframes chip-pop { from { opacity: 0; transform: scale(var(--pop)); } }

/* ---------- progress bar: <div class="bar" style="--p:.4"></div>, 4 px ---------- */
.bar { position: relative; height: 4px; border-radius: var(--r-pill); background: var(--raised); overflow: hidden; }
.bar::after {
  content: ''; position: absolute; inset: 0; border-radius: inherit; background: var(--bar-fill, var(--pri));
  transform: translateX(calc((min(max(var(--p, 0), 0), 1) - 1) * 100%));
  transition: transform var(--d-reveal) var(--e-decel);
}
.bar-good { --bar-fill: var(--good); }
.bar-gold { --bar-fill: var(--gold); }

/* ---------- bottom sheet ----------
   <div class="scrim"></div><div class="sheet" role="dialog" aria-modal="true">…</div>
   Both are fixed, so they can sit anywhere (append to body). Close: add .is-closing to both, remove on animationend. */
.scrim {
  position: fixed; inset: 0; z-index: var(--z-sheet); background: var(--scrim);
  animation: fade-in var(--d-screen) var(--e-decel) backwards;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-sheet);
  width: 100%; max-width: var(--maxw); max-height: calc(100dvh - var(--sat) - var(--s5)); margin: 0 auto;
  display: flex; flex-direction: column; gap: var(--s3);
  padding: var(--s6) var(--margin) calc(var(--s4) + var(--sab));
  overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none;
  background: var(--raised); color: var(--ink); border-radius: var(--r) var(--r) 0 0;
  box-shadow: inset 0 1px 0 var(--hi), var(--shadow);
  animation: sheet-up var(--d-screen) var(--e-decel) backwards;
}
.sheet::-webkit-scrollbar { display: none; }
/* grabber */
.sheet::before { content: ''; position: absolute; top: var(--s2); left: 50%; width: 36px; height: 5px; margin-left: -18px; border-radius: var(--r-pill); background: var(--line-2); }
.sheet .btn-sec { background: var(--pressed); }
.sheet .btn-sec:active { background: var(--line-2); }
.sheet .card { background: var(--card); }
.scrim.is-closing { animation: fade-out var(--d-small) var(--e-accel) forwards; pointer-events: none; }
.sheet.is-closing { animation: sheet-down var(--d-small) var(--e-accel) forwards; pointer-events: none; }
@keyframes sheet-up { from { transform: translateY(100%); } }
@keyframes sheet-down { to { transform: translateY(100%); } }

/* ---------- tab bar: <nav class="tabbar"><a class="tab" aria-current="page"><svg class="i">…</svg><span>Home</span></a>…</nav> ---------- */
.tabbar {
  position: relative; z-index: var(--z-tab); flex: none; display: flex;
  padding: 0 var(--s2) var(--sab); background: var(--bg);
  box-shadow: inset 0 1px 0 var(--line);
}
.tab {
  position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: var(--tab); padding-top: 2px; color: var(--ink3);
  font: 700 12px/14px var(--f-body); letter-spacing: .01em;
  transition: color var(--d-small) var(--e-decel);
}
.tab.has-dot::after { content: ''; position: absolute; top: 6px; left: calc(50% + 10px); width: 8px; height: 8px; border-radius: 50%; background: var(--pri); z-index: 2; }
.tab .i { position: relative; z-index: 1; transition: transform var(--d-small) var(--e-decel); }
/* indicator lozenge behind the icon */
.tab::before {
  content: ''; position: absolute; top: 5px; left: 50%; width: 56px; height: 28px; margin-left: -28px; border-radius: var(--r-pill);
  background: var(--pri-soft); opacity: 0; transform: scaleX(.5);
  transition: transform var(--d-small) var(--spring), opacity var(--d-small) var(--e-decel);
}
.tab[aria-current="page"], .tab.is-on { color: var(--ink); }
.tab[aria-current="page"] .i, .tab.is-on .i { color: var(--pri-ink); }
.tab[aria-current="page"]::before, .tab.is-on::before { opacity: 1; transform: none; }
.tab:active .i, .tab.is-pressed .i { transform: scale(.88); transition: transform var(--d-tap) var(--e-emph); }
.tab:active::before, .tab.is-pressed::before { opacity: 1; background: var(--line); transform: none; }
.tab[aria-current="page"]:active::before, .tab.is-on:active::before { background: var(--pri-soft); }
.tab:focus-visible { outline-offset: -4px; border-radius: var(--r-sm); }

/* ---------- helpers (last, so they win over component defaults) ---------- */
.scroll { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.scroll::-webkit-scrollbar { display: none; }
.pad { padding-left: var(--margin); padding-right: var(--margin); }
.safe-top { padding-top: var(--sat); }
.safe-bottom { padding-bottom: var(--sab); }
.stack { display: flex; flex-direction: column; gap: var(--s3); }
.row { display: flex; align-items: center; gap: var(--s2); }
.grow { flex: 1; min-width: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.tnum { font-variant-numeric: tabular-nums; }

/* ink helpers */
.c-ink  { color: var(--ink); }
.c-ink2 { color: var(--ink2); }
.c-ink3 { color: var(--ink3); }
.c-pri  { color: var(--pri-ink); }
.c-good { color: var(--good); }
.c-bad  { color: var(--bad); }
.c-gold { color: var(--gold); }


/* ---------- reduced motion: movement becomes fades (tokens shrink durations and zero the lift) ---------- */
@media (prefers-reduced-motion: reduce) {
  .sheet { animation-name: fade-in; }
  .sheet.is-closing { animation-name: fade-out; }
  .tab::before { transform: none; }
}
:root[data-motion="reduce"] .sheet { animation-name: fade-in; }
:root[data-motion="reduce"] .sheet.is-closing { animation-name: fade-out; }
:root[data-motion="reduce"] .tab::before { transform: none; }
/* press scales stay: they run 100 ms, inside the 150 ms limit, and they are feedback, not decoration (QA 19). */
