/* ==========================================================================
   Reset, typography, the aurora substrate, and the app shell.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: 16px;            /* never scale the root: it breaks browser zoom */
  background: var(--bg-base);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: transparent;
  overflow-x: hidden;
  font-family: var(--font-ui);
  font-size: var(--t-body);
  line-height: 1.55;
  font-weight: 400;
  color: var(--text-2);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-synthesis-weight: none;
}

h1, h2, h3, h4 {
  margin: 0;
  font-family: var(--font-display);
  color: var(--text-1);
  font-weight: 600;
  letter-spacing: -0.015em;
}
h1 { font-size: var(--t-h1); letter-spacing: -0.02em; }
h2 { font-size: var(--t-h2); }
h3 { font-size: var(--t-h3); }
p  { margin: 0 0 var(--sp-3); }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hi); }

/* A focus ring that is always visible against glass, for keyboard users only. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}
:focus:not(:focus-visible) { outline: none; }

::selection { background: var(--accent-wash); color: var(--text-1); }

/* Scrollbars, themed rather than left as the OS default slab of grey. */
* { scrollbar-width: thin; scrollbar-color: var(--stroke-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--stroke-strong);
  border: 3px solid transparent;
  border-radius: var(--r-pill);
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background-clip: content-box; opacity: .8; }

/* ==========================================================================
   Numbers

   Tabular figures everywhere. A column of prices whose digits change width as
   they update is the single clearest tell of an amateur trading interface.
   ========================================================================== */

.num, .tbl td, .tbl th, .kpi__value, time, .mono {
  font-variant-numeric: tabular-nums lining-nums slashed-zero;
  font-feature-settings: "tnum" 1, "lnum" 1, "zero" 1, "calt" 0;
  font-variant-ligatures: none;
}
.mono { font-family: var(--font-mono); font-size: .8125rem; color: var(--text-3); }

/* Cents recede so the eye lands on the magnitude first. */
.dec { color: var(--text-3); font-size: .74em; font-weight: 550; }

.t-label {
  font-size: var(--t-label);
  font-weight: 600;
  letter-spacing: .075em;
  text-transform: uppercase;
  color: var(--text-3);
}
.t-sm   { font-size: var(--t-sm); }
.t-dim  { color: var(--text-3); }
.t-mute { color: var(--text-4); }

/* ==========================================================================
   Profit / loss

   Never encoded by hue alone — about one man in twelve cannot rely on it. Every
   P&L value carries a sign, and the important ones also carry a caret and, in
   tables, a coloured rail on the row.
   ========================================================================== */

.pnl { font-weight: 600; }
.pnl--up   { color: var(--profit); }
.pnl--down { color: var(--loss); }
/* A figure that is wrong rather than negative (a reconciliation gap): red, no arrow. */
.t-bad { color: var(--loss); font-weight: 600; }
.pnl--flat { color: var(--text-3); }
.pnl--none { color: var(--text-4); }

.pnl--up::before   { content: "▲"; font-size: .68em; margin-inline-end: .3em;
                     vertical-align: .08em; }
.pnl--down::before { content: "▼"; font-size: .68em; margin-inline-end: .3em;
                     vertical-align: .08em; }

/* ==========================================================================
   The aurora substrate

   Liquid glass needs something worth refracting. Four static radial gradients
   do the job: a radial gradient *is* a blur, free, on the compositor — whereas
   filter: blur() on a full-viewport layer forces a huge offscreen buffer and
   repaints on every scroll. One transform-only animation, and a veil on top
   that clamps the luminance band so text contrast stays predictable.
   ========================================================================== */

#aurora {
  position: fixed;
  inset: -12vmax;                  /* overscan so the drift never shows an edge */
  z-index: var(--z-bg);
  pointer-events: none;
  contain: strict;
}

.aurora__blobs {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(38vmax 30vmax at 14% 16%, var(--aurora-1) 0%, transparent 62%),
    radial-gradient(44vmax 34vmax at 86% 10%, var(--aurora-2) 0%, transparent 64%),
    radial-gradient(40vmax 40vmax at 72% 88%, var(--aurora-3) 0%, transparent 66%),
    radial-gradient(52vmax 36vmax at 24% 92%, var(--aurora-4) 0%, transparent 68%);
  background-repeat: no-repeat;
  animation: aurora-drift 68s var(--ease-in-out) infinite alternate;
  will-change: transform;
  transform: translateZ(0);
}

@keyframes aurora-drift {
  0%   { transform: translate3d(0,     0,     0) scale(1);    }
  50%  { transform: translate3d(-2.4%, 1.8%,  0) scale(1.06); }
  100% { transform: translate3d(1.8%, -2.2%,  0) scale(1.03); }
}

.aurora__veil {
  position: absolute; inset: 0;
  background:
    radial-gradient(120% 90% at 50% 0%, transparent 0%, var(--bg-veil) 72%),
    linear-gradient(var(--bg-veil), var(--bg-veil));
}

/* Grain kills gradient banding on 8-bit panels and stops the background
   reading as "a CSS gradient". */
.aurora__grain {
  position: absolute; inset: 0;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 160px 160px;
  mix-blend-mode: overlay;
}
:root[data-theme="light"] .aurora__grain { mix-blend-mode: multiply; }

/* The login screen has no data competing for attention, so the aurora may be
   louder there — it sets the tone before anything else loads. */
body.auth {
  --bg-veil: rgba(7, 10, 15, 0.46);
  --aurora-1: rgba(18, 122, 112, 0.60);
  --aurora-2: rgba(46, 74, 156, 0.56);
  --aurora-3: rgba(86, 56, 140, 0.46);
}
:root[data-theme="light"] body.auth {
  --bg-veil: rgba(246, 248, 252, 0.44);
}

@media (prefers-reduced-motion: reduce) {
  .aurora__blobs { animation: none; }
}
/* Don't burn battery animating on phones or low-refresh displays. */
@media (max-width: 560px), (update: slow) {
  .aurora__blobs { animation: none; }
}

/* ==========================================================================
   App shell
   ========================================================================== */

.shell {
  position: relative;
  z-index: var(--z-content);
  min-height: 100dvh;
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
}

.main {
  min-width: 0;                 /* lets grid children shrink instead of overflow */
  display: flex;
  flex-direction: column;
}

.content {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-6) var(--sp-12);
  display: grid;
  /* minmax(0, 1fr), not the implicit auto: a wide child (a period picker, a
     table) must scroll inside its box, not push the whole page past the
     phone's screen. */
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-5);
  align-content: start;
}
.content > * { min-width: 0; }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
}
.page-head__sub { color: var(--text-3); font-size: var(--t-sm); margin: 0; }

/* Layout primitives ------------------------------------------------------ */

.grid       { display: grid; gap: var(--sp-4); }
.grid > *   { min-width: 0; }
/* min(…, 100%): on a screen narrower than the column minimum the column takes
   the screen, instead of overflowing it. */
.grid--kpi  { grid-template-columns: repeat(auto-fit, minmax(min(212px, 100%), 1fr)); }
.grid--2    { grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); }
.grid--wide { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 1080px) { .grid--wide { grid-template-columns: 1fr; } }
/* Participant cards: as many per row as fit, for any number of people — one
   column on a phone. auto-fill (not auto-fit) keeps a lone card card-sized
   instead of stretching it across the whole row. */
.grid--owners { grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); }

.row { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.stack { display: grid; gap: var(--sp-3); }
.spacer { flex: 1 1 auto; }

@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .content { padding: var(--sp-4) var(--sp-4) var(--sp-12); }
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
