/* glen-design: v1 */
/* ============================================================================
   Base: reset, type, surfaces, controls, states, ambient layer, entrances.
   Adapted from glen-design assets/base.css plus the Apple layer proven in
   the SIMS and VALO. Components read tokens only.
   ========================================================================== */

*, *::before, *::after{ box-sizing: border-box; }
html{ -webkit-text-size-adjust: 100%; background: var(--bg); }
body{
  margin: 0; min-height: 100dvh;
  background:
    radial-gradient(120% 90% at 50% -10%, var(--surface-1), transparent 60%),
    linear-gradient(180deg, var(--bg), var(--bg-deep));
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}
h1,h2,h3,h4{ font-family: var(--font-display); line-height: 1.08; letter-spacing: -.025em; margin: 0; font-weight: 700; }
h1{ font-size: var(--fs-2xl); }
h2{ font-size: var(--fs-xl); }
h3{ font-size: var(--fs-lg); letter-spacing: -.015em; }
p{ margin: 0 0 var(--s4); max-width: 68ch; }
a{ color: var(--accent); text-underline-offset: 3px; }
button{ font: inherit; color: inherit; }
img, svg{ display: block; }
::selection{ background: var(--tint-2); }
:focus-visible{ outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }
[hidden]{ display: none !important; }
.sr-only{ position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* numbers: mono for tables and labels, light display for hero figures */
.num{ font-family: var(--font-mono); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.fig{ font-family: var(--font-display); font-weight: 300; letter-spacing: -.035em; font-variant-numeric: tabular-nums; line-height: 1; }
.label{ font-size: var(--fs-sm); color: var(--ink-dim); font-weight: 600; letter-spacing: 0; }
.meta{ font-size: var(--fs-sm); color: var(--ink-dim); }
.eyebrow{
  display: inline-flex; align-items: center; gap: var(--s2);
  font-family: var(--font-mono); font-size: var(--fs-micro); letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-dim);
}
.eyebrow::before{ content: ''; width: var(--s4); height: 1px; background: var(--accent); }
.good{ color: var(--ok); } .bad{ color: var(--bad); } .warnc{ color: var(--warn); }

/* --- AMBIENT LAYER: one per screen, behind everything -------------------- */
.ambient{ position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.ambient i{
  position: absolute; display: block; width: 62vmax; height: 62vmax; border-radius: 50%;
  filter: blur(110px); will-change: transform;
}
.ambient i:nth-child(1){ background: radial-gradient(circle, var(--aurora-1), transparent 64%); top: -26%; left: -14%; }
.ambient i:nth-child(2){ background: radial-gradient(circle, var(--aurora-2), transparent 64%); bottom: -30%; right: -16%; }
.ambient i:nth-child(3){ background: radial-gradient(circle, var(--aurora-1), transparent 68%); top: 34%; left: 52%; opacity: .6; }
.grain{
  position: fixed; inset: 0; z-index: 60; pointer-events: none; opacity: .035; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.75' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)'/%3E%3C/svg%3E");
}
:root[data-theme="night"] .grain{ mix-blend-mode: overlay; opacity: .05; }
.app{ position: relative; z-index: 1; }

/* --- SURFACES ------------------------------------------------------------ */
@property --spot{ syntax: '<color>'; initial-value: transparent; inherits: false; }
.card{
  position: relative;
  background-color: var(--surface-1);
  background-image: radial-gradient(360px circle at var(--mx,50%) var(--my,50%), var(--spot), transparent 62%);
  border-radius: var(--r);
  box-shadow: var(--shadow-1), var(--ring);
  padding: var(--s5);
  transition: --spot var(--dur-slow) var(--ease-out),
              transform var(--dur-base) var(--ease-out),
              box-shadow var(--dur-base) var(--ease-out);
}
.panel{
  background: var(--mat-float);
  -webkit-backdrop-filter: var(--mat-blur); backdrop-filter: var(--mat-blur);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2), inset 0 0 0 1px var(--line);
}
@supports not (backdrop-filter: blur(1px)){ .panel{ background: var(--surface-1); } }
.card-head{ display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s4); }
.card-head h3{ font-size: var(--fs-base); font-family: var(--font-body); font-weight: 600; letter-spacing: 0; }
.card-head .meta{ font-size: var(--fs-sm); }
.hair{ height: 1px; background: var(--line); border: 0; margin: var(--s4) 0; }

/* --- CONTROLS ------------------------------------------------------------ */
.btn{
  --btn-bg: var(--surface-2);
  --btn-bg-hover: var(--surface-3);
  --btn-ink: var(--ink);
  font: 600 var(--fs-sm)/1 var(--font-body);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--h-control); padding: 0 var(--s4);
  border: 0; border-radius: var(--r-sm);
  background: var(--btn-bg); color: var(--btn-ink);
  box-shadow: var(--ring); cursor: pointer; white-space: nowrap;
  transition: transform var(--dur-instant) var(--ease-out),
              background var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
.btn svg{ width: 16px; height: 16px; flex: none; }
.btn--primary{ --btn-bg: var(--accent); --btn-bg-hover: var(--accent); --btn-ink: var(--on-accent); box-shadow: 0 6px 18px var(--glow); }
.btn--tint{ --btn-bg: var(--tint); --btn-bg-hover: var(--tint-2); --btn-ink: var(--accent); box-shadow: none; }
.btn--ghost{ --btn-bg: transparent; --btn-bg-hover: var(--surface-2); box-shadow: none; }
.btn--icon{ width: var(--h-control); padding: 0; }
.btn--sm{ min-height: 30px; padding: 0 var(--s3); font-size: var(--fs-micro); }
.btn[disabled], .btn[aria-disabled="true"]{ opacity: .42; pointer-events: none; }
.btn.is-busy{ pointer-events: none; }
.btn.is-busy::after{
  content: ''; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
}
@media (prefers-reduced-motion: no-preference){ .btn.is-busy::after{ animation: spin calc(var(--loop-load) / 2) linear infinite; } }
@keyframes spin{ to{ transform: rotate(360deg); } }

.field{
  width: 100%; min-height: var(--h-control); padding: 0 var(--s3);
  border: 0; border-radius: var(--r-sm); background: var(--surface-2); color: var(--ink);
  font: 400 var(--fs-base)/1.4 var(--font-body); box-shadow: var(--ring);
  transition: box-shadow var(--dur-fast) var(--ease-out);
}
.field:focus{ outline: none; box-shadow: 0 0 0 2px var(--accent); }
textarea.field{ padding: var(--s2) var(--s3); min-height: 88px; resize: vertical; }

/* segmented control */
.seg{ display: inline-flex; padding: var(--s1); gap: var(--s1); border-radius: var(--r-sm); background: var(--surface-3); box-shadow: inset 0 0 0 1px var(--line); }
.seg button{
  border: 0; background: transparent; min-height: 30px; padding: 0 var(--s3); border-radius: 6px;
  font: 600 var(--fs-sm)/1 var(--font-body); color: var(--ink-dim); cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out), transform var(--dur-instant) var(--ease-out);
}
.seg button[aria-pressed="true"]{ background: var(--surface-1); color: var(--ink); box-shadow: var(--shadow-1), var(--ring); }

/* switch */
.switch{ position: relative; width: 44px; height: 28px; border-radius: var(--r-pill); border: 0; padding: 0; cursor: pointer;
  background: var(--surface-3); box-shadow: inset 0 0 0 1px var(--line-2); transition: background var(--dur-base) var(--ease-out); flex: none; }
.switch::after{ content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: var(--r-pill);
  background: var(--surface-1); box-shadow: var(--shadow-1); transform-origin: left center; transition: transform var(--dur-base) var(--ease-drawer); }
.switch[aria-checked="true"]{ background: var(--accent); }
.switch[aria-checked="true"]::after{ transform: translateX(16px); }

/* chips and status pills */
.chip{
  display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 0 var(--s3);
  border-radius: var(--r-pill); background: var(--surface-2); box-shadow: var(--ring);
  font-size: var(--fs-micro); font-weight: 600; color: var(--ink-dim); white-space: nowrap;
}
.chip b{ color: var(--ink); font-family: var(--font-mono); font-weight: 500; }
.chip--ok{ background: var(--ok-tint); color: var(--ok); box-shadow: none; }
.chip--warn{ background: var(--warn-tint); color: var(--warn); box-shadow: none; }
.chip--bad{ background: var(--bad-tint); color: var(--bad); box-shadow: none; }
.chip--ai{ background: var(--tint); color: var(--accent); box-shadow: none; }
.chip svg{ width: 13px; height: 13px; }
button.chip{ border: 0; cursor: pointer; transition: transform var(--dur-instant) var(--ease-out), background var(--dur-fast) var(--ease-out); }

.dot{ width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; position: relative; }
.dot--warn{ background: var(--warn); } .dot--bad{ background: var(--bad); } .dot--idle{ background: var(--ink-faint); }
.live .dot::after{ content: ''; position: absolute; inset: 0; border-radius: 50%; background: inherit; }
@media (prefers-reduced-motion: no-preference){
  .live .dot::after{ animation: ping calc(var(--ambient-c) / 8) var(--ease-out) infinite; }
  .live .dot--bad::after{ animation: none; }
}
@keyframes ping{ from{ transform: scale(1); opacity: .55; } to{ transform: scale(3); opacity: 0; } }

.kbd{ font: 500 var(--fs-micro)/1 var(--font-mono); padding: 3px 6px; border-radius: 6px; background: var(--surface-3); box-shadow: inset 0 -1px 0 var(--line-2); color: var(--ink-dim); }
.avatar{ width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent); font: 600 var(--fs-micro)/1 var(--font-body); }

/* --- LISTS AND TABLES ---------------------------------------------------- */
.rows{ display: grid; }
.row{
  display: flex; align-items: center; gap: var(--s3); min-height: 48px; padding: var(--s2) var(--s3);
  border-radius: var(--r-sm); position: relative;
  transition: background var(--dur-fast) var(--ease-out), transform var(--dur-base) var(--ease-out);
}
.row + .row::before{ content: ''; position: absolute; left: var(--s3); right: var(--s3); top: 0; height: 1px; background: var(--line); }
.row .grow{ flex: 1; min-width: 0; display: grid; gap: 1px; line-height: 1.3; }
.row .t{ display: block; font-weight: 600; font-size: var(--fs-base); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .s{ display: block; font-size: var(--fs-sm); color: var(--ink-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
button.row, a.row{ width: 100%; border: 0; background: transparent; text-align: left; cursor: pointer; color: inherit; text-decoration: none; }

.table{ width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-sm); }
.table th{ text-align: left; font-weight: 600; color: var(--ink-dim); padding: var(--s2) var(--s3); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td{ padding: var(--s3); border-bottom: 1px solid var(--line); vertical-align: middle; }
.table td.num, .table th.num{ text-align: right; }
.table tbody tr{ transition: background var(--dur-fast) var(--ease-out); }

/* --- PROGRESS ------------------------------------------------------------ */
.bar{ height: 6px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; }
.bar > i{ display: block; height: 100%; width: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), color-mix(in oklab, var(--accent) 60%, var(--hot)));
  transform-origin: left; transform: scaleX(var(--p, 0)); transition: transform var(--dur-reveal) var(--ease-out); }
.bar--ok > i{ background: var(--ok); } .bar--warn > i{ background: var(--warn); } .bar--bad > i{ background: var(--bad); }

@property --p{ syntax: '<number>'; initial-value: 0; inherits: true; }
.ring{
  --p: 0; --size: 64px; --thick: 7px; --c: var(--accent);
  position: relative; width: var(--size); aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), var(--surface-3) 0);
}
.ring::before{ content: ''; position: absolute; inset: var(--thick); border-radius: 50%; background: var(--surface-1); }
.ring > *{ position: relative; font: 500 var(--fs-sm)/1 var(--font-mono); }
@media (prefers-reduced-motion: no-preference){ .ring{ transition: --p var(--dur-reveal) var(--ease-out); } }

.spark{ width: 100%; height: 36px; overflow: visible; }
.spark .area{ fill: var(--tint); stroke: none; }
.spark .line{ fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.spark .now{ fill: var(--accent); filter: drop-shadow(0 0 6px var(--glow)); transform-box: fill-box; transform-origin: center; }
@media (prefers-reduced-motion: no-preference){
  .spark.live .now{ animation: now-pulse calc(var(--ambient-c) / 8) var(--ease-in-out) infinite; }
  @keyframes now-pulse{ 50%{ transform: scale(1.6); opacity: .7; } }
}

/* --- STATES -------------------------------------------------------------- */
.skeleton{ position: relative; overflow: hidden; border-radius: var(--r-sm); background: var(--surface-3); min-height: 1em; color: transparent; }
@media (prefers-reduced-motion: no-preference){
  .skeleton::after{ content: ''; position: absolute; inset: 0;
    background: linear-gradient(105deg, transparent 35%, var(--surface-1) 50%, transparent 65%);
    transform: translateX(-100%); animation: sweep var(--loop-load) var(--ease-in-out) infinite; }
}
@keyframes sweep{ 40%, 100%{ transform: translateX(100%); } }
.empty, .failed{ display: grid; place-items: center; gap: var(--s3); padding: var(--s7) var(--s5); text-align: center; color: var(--ink-dim); }
.empty svg, .failed svg{ width: 28px; height: 28px; opacity: .7; }
.failed{ color: var(--bad); }

/* --- ENTRANCE CHOREOGRAPHY ---------------------------------------------- */
.reveal{ opacity: 1; }
@media (prefers-reduced-motion: no-preference){
  .reveal{
    opacity: 0; transform: translateY(var(--s3)) scale(.97);
    transition: opacity var(--dur-reveal) var(--ease-out), transform var(--dur-reveal) var(--ease-out);
    transition-delay: calc(var(--i, 0) * var(--stagger));
  }
  .reveal.in{ opacity: 1; transform: none; }
  .settled .reveal{ transition: none; opacity: 1; transform: none; }
}

/* --- AMBIENT + PRIMITIVES ------------------------------------------------ */
@property --angle{ syntax: '<angle>'; initial-value: 0deg; inherits: false; }
@media (prefers-reduced-motion: no-preference){
  .ambient i:nth-child(1){ animation: drift-a var(--ambient-a) var(--ease-in-out) infinite alternate; }
  .ambient i:nth-child(2){ animation: drift-b var(--ambient-b) var(--ease-in-out) infinite alternate-reverse; }
  .ambient i:nth-child(3){ animation: drift-c var(--ambient-c) var(--ease-in-out) infinite alternate; }
  @keyframes drift-a{ to{ transform: translate3d(9vw, 7vh, 0) scale(1.18); } }
  @keyframes drift-b{ to{ transform: translate3d(-7vw,-9vh, 0) scale(.88); } }
  @keyframes drift-c{ to{ transform: translate3d(-5vw, 6vh, 0) scale(1.10); } }

  .beam{ position: relative; }
  .beam::before, .beam::after{
    content: ''; position: absolute; inset: -1.5px; z-index: -1; border-radius: inherit;
    background: conic-gradient(from var(--angle), transparent 0deg 300deg, var(--accent) 332deg, var(--hot) 346deg, var(--accent) 360deg);
    animation: orbit var(--loop-beam) linear infinite;
  }
  .beam::before{ filter: blur(14px); opacity: .5; }
  @keyframes orbit{ to{ --angle: 360deg; } }
}
.motion-paused .ambient i, .motion-paused .beam::before, .motion-paused .beam::after,
.motion-paused .skeleton::after, .motion-paused .spark .now{ animation-play-state: paused; }

.reticle::before{
  content: ''; position: absolute; inset: -1px; pointer-events: none; opacity: .75; border-radius: inherit;
  background:
    linear-gradient(var(--accent), var(--accent)) 0 0 / 12px 1.5px no-repeat,
    linear-gradient(var(--accent), var(--accent)) 0 0 / 1.5px 12px no-repeat,
    linear-gradient(var(--accent), var(--accent)) 100% 100% / 12px 1.5px no-repeat,
    linear-gradient(var(--accent), var(--accent)) 100% 100% / 1.5px 12px no-repeat;
}
.dotgrid{
  background-image: radial-gradient(var(--line-2) 1px, transparent 1px); background-size: 24px 24px;
  -webkit-mask-image: radial-gradient(ellipse at 50% 30%, var(--mask) 30%, transparent 76%);
          mask-image: radial-gradient(ellipse at 50% 30%, var(--mask) 30%, transparent 76%);
}

/* --- HOVER + PRESS (hover only where hover is real) ---------------------- */
@media (hover: hover) and (pointer: fine){
  .btn:hover{ background: var(--btn-bg-hover); }
  .btn--primary:hover{ filter: brightness(1.08); box-shadow: 0 10px 28px var(--glow); }
  .card.lift:hover{ transform: translateY(-3px); box-shadow: var(--shadow-2), var(--ring); --spot: var(--aurora-1); }
  .card:hover{ --spot: var(--aurora-1); }
  .seg button:hover{ color: var(--ink); }
  button.chip:hover{ background: var(--surface-3); transform: translateY(-1px); }
  button.chip.chip--ai:hover{ background: var(--tint-2); }
  button.row:hover, a.row:hover{ background: var(--surface-2); transform: translateX(2px); }
  .table tbody tr:hover{ background: var(--surface-2); }
  .zoom{ transition: transform var(--dur-base) var(--ease-out), filter var(--dur-base) var(--ease-out); transform-box: fill-box; transform-origin: center; }
  .zoom:hover{ transform: scale(1.12); filter: drop-shadow(0 0 8px var(--glow)); }
}
.btn:active, .seg button:active, button.chip:active{ transform: scale(.97); }
button.row:active, a.row:active{ transform: scale(.99); }
.switch:active::after{ transform: scaleX(1.2); }
.switch[aria-checked="true"]:active::after{ transform: translateX(16px) scaleX(1.2); }

@media (prefers-reduced-motion: reduce){
  *, *::before, *::after{
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: var(--dur-fast) !important; scroll-behavior: auto !important;
  }
}
.keep-case{ text-transform: none; }
