/*
 * GhostCart base styles (Phantom): reset, typography, atmosphere (aurora +
 * grain), layout primitives, utilities, motion (apparition, keyframes) and the
 * reduced-motion kill switch. Component styling lives in components.css;
 * page-specific styling in styles/pages/<page>.css namespaced under .page-<name>.
 */

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
  background: var(--bg);
}
body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
#app { position: relative; z-index: 1; }
img, svg, video, canvas { display: block; max-width: 100%; }
svg { flex-shrink: 0; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: not-allowed; }
a { color: inherit; text-decoration: none; }
p { margin: 0; }
h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 600; letter-spacing: -0.01em; line-height: 1.2; }
ul, ol { margin: 0; padding: 0; list-style: none; }
table { border-collapse: collapse; border-spacing: 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--s-4) 0; }
::selection { background: color-mix(in srgb, var(--ecto) 32%, transparent); color: var(--text); }
[hidden] { display: none !important; }

/* ---------- Atmosphere: aurora washes + stepped noise grain ----------
   Static markup in index.html (<div class="aurora"><i/><i/><i/></div><div class="grain"/>).
   Both are transform-only animations on their own layers; paused while the tab is hidden
   (html.is-hidden, set by app.js) and removed under reduced motion. */
.aurora { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; contain: strict; }
.aurora i {
  position: absolute; border-radius: 50%; filter: blur(70px); will-change: transform;
  animation: aurora-drift 26s ease-in-out infinite alternate;
}
.aurora i:nth-child(1) { width: 640px; height: 420px; left: 12%; top: -220px; background: var(--wash-1); }
.aurora i:nth-child(2) { width: 520px; height: 520px; right: -160px; top: 20%; background: var(--wash-2); animation-duration: 34s; }
.aurora i:nth-child(3) { width: 420px; height: 300px; left: 40%; bottom: -200px; background: var(--wash-1); animation-duration: 30s; }
@keyframes aurora-drift { to { transform: translate3d(60px, 40px, 0) scale(1.12); } }
.grain {
  position: fixed; inset: -50%; pointer-events: none; z-index: var(--z-grain); opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 1.1 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  will-change: transform;
  animation: grain 1.2s steps(6) infinite;
}
[data-theme="light"] .grain { filter: invert(1); }
@keyframes grain {
  0% { transform: translate(0, 0); } 20% { transform: translate(-3%, 2%); } 40% { transform: translate(2%, -3%); }
  60% { transform: translate(-2%, -1%); } 80% { transform: translate(3%, 3%); } 100% { transform: translate(0, 0); }
}
.is-hidden .aurora i, .is-hidden .grain { animation-play-state: paused; }
@media print { .aurora, .grain { display: none; } }

/* ---------- Typography ---------- */
.h1 { font: 600 var(--fs-display)/1.1 var(--font-display); letter-spacing: -0.01em; }
.h2 { font: 600 var(--fs-2xl)/1.15 var(--font-display); }
.h3 { font-size: var(--fs-xl); font-weight: 600; }
.h4 { font-size: var(--fs-lg); font-weight: 600; }
.text-xs { font-size: var(--fs-xs); }
.text-sm { font-size: var(--fs-sm); }
.text-md { font-size: var(--fs-md); }
.text-lg { font-size: var(--fs-lg); }
/* Mono uppercase micro-label: the Phantom eyebrow. <b> inside glows ectoplasm. */
.eyebrow {
  font: 600 10.5px/1.2 var(--font-mono);
  letter-spacing: var(--eyebrow-track);
  text-transform: uppercase;
  color: var(--text-3);
}
.eyebrow b { color: var(--ecto-text); font-weight: 600; }
.display { font-family: var(--font-display); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.muted { color: var(--text-3); }
.subtle { color: var(--text-2); }
.faint { color: var(--text-4); }
.strong { font-weight: 600; color: var(--text); }
.mono { font-family: var(--font-mono); font-size: 0.9em; letter-spacing: -0.01em; }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.money { font-family: var(--font-display); font-weight: 600; font-variant-numeric: tabular-nums; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.tone-success { color: var(--success); }
.tone-danger { color: var(--danger); }
.tone-warning { color: var(--warning); }
.tone-info { color: var(--info); }
.tone-accent { color: var(--ecto-text); }
.gradient-text {
  background: var(--ecto-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ---------- Scrollbars ---------- */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 10px;
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background-color: color-mix(in srgb, var(--ecto) 45%, transparent); }
::-webkit-scrollbar-corner { background: transparent; }

/* ---------- Focus: 2px mint, 2px offset ---------- */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

/* ---------- Layout utilities ---------- */
.row { display: flex; align-items: center; gap: var(--s-2); min-width: 0; }
.row.wrap { flex-wrap: wrap; }
.row.top { align-items: flex-start; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.stack { display: flex; flex-direction: column; gap: var(--s-3); min-width: 0; }
.stack.tight { gap: var(--s-1); }
.stack.loose { gap: var(--s-5); }
.grow { flex: 1 1 auto; min-width: 0; }
.shrink-0 { flex-shrink: 0; }
.gap-1 { gap: var(--s-1); } .gap-2 { gap: var(--s-2); } .gap-3 { gap: var(--s-3); }
.gap-4 { gap: var(--s-4); } .gap-5 { gap: var(--s-5); } .gap-6 { gap: var(--s-6); }
.mt-1 { margin-top: var(--s-1); } .mt-2 { margin-top: var(--s-2); } .mt-3 { margin-top: var(--s-3); }
.mt-4 { margin-top: var(--s-4); } .mt-6 { margin-top: var(--s-6); }
.mb-2 { margin-bottom: var(--s-2); } .mb-4 { margin-bottom: var(--s-4); }
.ml-auto { margin-left: auto; }
.w-full { width: 100%; }

.grid { display: grid; gap: 18px; }
.grid-2 { display: grid; gap: 18px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { display: grid; gap: 18px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { display: grid; gap: 18px; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-auto { display: grid; gap: 18px; grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)); }
.grid-auto-sm { display: grid; gap: var(--s-3); grid-template-columns: repeat(auto-fill, minmax(min(170px, 100%), 1fr)); }
/* 12-column Phantom grid (dashboard-style layouts): .grid-12 > .col-8 / .col-4 … */
.grid-12 { display: grid; gap: 18px; grid-template-columns: repeat(12, minmax(0, 1fr)); }
.col-12 { grid-column: span 12; } .col-9 { grid-column: span 9; } .col-8 { grid-column: span 8; } .col-7 { grid-column: span 7; }
.col-6 { grid-column: span 6; } .col-5 { grid-column: span 5; } .col-4 { grid-column: span 4; } .col-3 { grid-column: span 3; }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-12 > .col-3 { grid-column: span 6; }
  .grid-12 > .col-4, .grid-12 > .col-5, .grid-12 > .col-7, .grid-12 > .col-8 { grid-column: span 12; }
}
@media (max-width: 759px) {
  .grid, .grid-2, .grid-3, .grid-4, .grid-auto, .grid-12 { gap: var(--s-3); }
  .grid-12 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-12 > * { grid-column: 1 / -1; }
  .grid-12 > .col-3 { grid-column: span 1; }
}
@media (max-width: 640px) {
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3); }
  .span-2 { grid-column: auto; }
  .hide-sm { display: none !important; }
}
@media (min-width: 641px) { .show-sm { display: none !important; } }
@media (max-width: 899px) { .hide-md { display: none !important; } }
@media (min-width: 900px) { .show-md { display: none !important; } }
/* Phone breakpoint (bottom tab bar). */
@media (max-width: 759px) { .hide-phone { display: none !important; } }
@media (min-width: 760px) { .show-phone { display: none !important; } }
/* IconButton wraps its <button> in a tooltip anchor; when the button is hidden
   responsively, collapse the anchor too so flex gaps don't leave holes. */
@media (max-width: 640px) { .tooltip-anchor:has(> .hide-sm) { display: none !important; } }
@media (min-width: 641px) { .tooltip-anchor:has(> .show-sm) { display: none !important; } }
@media (max-width: 899px) { .tooltip-anchor:has(> .hide-md) { display: none !important; } }
@media (min-width: 900px) { .tooltip-anchor:has(> .show-md) { display: none !important; } }
@media (max-width: 759px) { .tooltip-anchor:has(> .hide-phone) { display: none !important; } }
@media (min-width: 760px) { .tooltip-anchor:has(> .show-phone) { display: none !important; } }

/* ---------- Apparition: blur → sharp entrance ----------
   .appear on one element (set --i for its stagger slot), or .apparition on a
   parent to stagger its direct children automatically (useApparition() in
   components/phantom.js sets --i on dynamic lists). */
.appear, .apparition > * {
  animation: apparition var(--dur-appear) var(--ease-out) backwards;
  animation-delay: calc(var(--i, 0) * var(--stagger));
}
.apparition > :nth-child(1) { --i: 0; } .apparition > :nth-child(2) { --i: 1; } .apparition > :nth-child(3) { --i: 2; }
.apparition > :nth-child(4) { --i: 3; } .apparition > :nth-child(5) { --i: 4; } .apparition > :nth-child(6) { --i: 5; }
.apparition > :nth-child(7) { --i: 6; } .apparition > :nth-child(8) { --i: 7; } .apparition > :nth-child(9) { --i: 8; }
.apparition > :nth-child(10) { --i: 9; } .apparition > :nth-child(11) { --i: 10; } .apparition > :nth-child(n+12) { --i: 11; }
/* Fill-mode is `backwards`, never `both`: a kept end state (filter: blur(0),
   transform) would make every card a containing block for position:fixed
   children and trap dropdown/tooltip z-index inside it. */
@keyframes apparition {
  0% { opacity: 0; filter: blur(10px); transform: translateY(10px) scale(0.985); }
  60% { opacity: 1; }
  100% { opacity: 1; filter: blur(0); transform: none; }
}
/* Legacy stagger utility now apparates. */
.stagger > * { animation: apparition var(--dur-appear) var(--ease-out) backwards; animation-delay: calc(var(--i, 0) * var(--stagger)); }
.stagger > :nth-child(1) { --i: 0; } .stagger > :nth-child(2) { --i: 1; } .stagger > :nth-child(3) { --i: 2; }
.stagger > :nth-child(4) { --i: 3; } .stagger > :nth-child(5) { --i: 4; } .stagger > :nth-child(6) { --i: 5; }
.stagger > :nth-child(7) { --i: 6; } .stagger > :nth-child(n+8) { --i: 7; }

/* ---------- Keyframes ---------- */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
@keyframes fade-down {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}
@keyframes scale-in {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to { opacity: 1; transform: none; }
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(-4px) scale(0.96); }
  to { opacity: 1; transform: none; }
}
@keyframes slide-in-right { from { transform: translateX(60px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes slide-in-left { from { transform: translateX(-100%); } to { transform: none; } }
@keyframes slide-in-bottom { from { transform: translateY(70px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(14px) scale(0.94); filter: blur(4px); }
  to { opacity: 1; transform: none; filter: none; }
}
@keyframes shimmer {
  0% { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
@keyframes ping {
  0% { transform: scale(0.5); opacity: 0.9; }
  100% { transform: scale(2.2); opacity: 0; }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes grow-y { from { transform: scaleY(0); } }
@keyframes grow-x { from { transform: scaleX(0); } }
@keyframes progress-stripes { from { background-position: 0 0; } to { background-position: 28px 0; } }
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}
/* Ghost mascot */
@keyframes ghost-float {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-3px) rotate(2deg); }
}
@keyframes ghost-shadow { 0%, 100% { transform: scaleX(1); opacity: 0.5; } 50% { transform: scaleX(0.75); opacity: 0.25; } }
@keyframes ghost-blink { 0%, 92%, 100% { transform: scaleY(1); } 94% { transform: scaleY(0.1); } }
@keyframes soul {
  0%, 100% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 18%, transparent), 0 0 8px var(--c); }
  50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--c) 6%, transparent), 0 0 14px var(--c); }
}
@keyframes wisp { 0% { transform: translateX(-60%); } 100% { transform: translateX(60%); } }

.anim-fade-up { animation: fade-up var(--dur-4) var(--ease-out) both; }
.anim-fade-in { animation: fade-in var(--dur-3) var(--ease-out) both; }
.anim-spin { animation: spin 0.8s linear infinite; }
.anim-pulse { animation: pulse 1.6s ease-in-out infinite; }

/* ---------- Reduced motion: final states render straight away ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0ms !important;
    transition-duration: 1ms !important;
  }
  .aurora i, .grain, .tonight::before { animation: none !important; }
  /* Ping halos are decoration whose resting (un-animated) style is a solid ring: hide them. */
  .live-chip-pulse::after { display: none !important; }
  .appear, .apparition > *, .stagger > * { filter: none !important; }
}
