/**
 * KND OS — visual foundation of the Home's scroll experience.
 *
 * Ported from feature/knd-visual-v2 (assets/css/knd-system.css: fonts, tokens, reset, base, components).
 * Its old global header/footer blocks are NOT ported: the Games shell header (knd-shell.css) owns chrome now.
 * Loaded by index.php only. Palette retuned to the KND Access Gate V2 language: near-black navy canvas,
 * pale-cyan key accent (was warm "bone"), cyan signal, violet rim.
 *
 * Cascade: reset/tokens/base sit in layers (they always yield to legacy CSS); components are unlayered and
 * namespaced .k-* so they beat Bootstrap/legacy defaults without colliding with them.
 * Root font-size stays at the legacy 112.5% (1rem = 18px); type tokens are rem, spacing tokens px.
 */

@layer reset, tokens, base;

/* ─── Fonts (self-hosted, latin, variable; see /assets/fonts/README.md) ─── */
@font-face {
  font-family: 'Archivo';
  src: url('/assets/fonts/archivo-var-latin.woff2') format('woff2');
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Inter';
  src: url('/assets/fonts/inter-var-latin.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('/assets/fonts/jetbrains-mono-var-latin.woff2') format('woff2');
  font-weight: 100 800;
  font-style: normal;
  font-display: swap;
}

/* ════════════════════════════════════════════════════════════════════
   TOKENS — Auth V2 palette
   ════════════════════════════════════════════════════════════════════ */
@layer tokens {
  :root {
    /* Canvas & surfaces (near-black navy) */
    --k-canvas: #04060b;
    --k-canvas-deep: #020308;
    --k-plane: #0a0f18;
    --k-panel: #0e1420;
    --k-overlay: rgba(4, 6, 11, 0.84);

    /* Typography colors */
    --k-text: #eef2f5;
    --k-text-muted: #c7cfd8;
    --k-text-subtle: #a5b0bb;   /* ≥8:1 on canvas (legibility pass 2026-10) */
    --k-text-on-bone: #041217;

    /* Key accent — pale cyan (the Auth V2 highlight); keeps the v2 "bone" token names */
    --k-bone: #a6f0f6;
    --k-bone-strong: #d4fbff;
    --k-bone-dim: color-mix(in srgb, var(--k-bone) 45%, var(--k-canvas));
    --k-bone-veil: color-mix(in srgb, var(--k-bone) 10%, transparent);

    /* Signal + rim */
    --k-signal: #62d9e6;
    --k-signal-dim: color-mix(in srgb, var(--k-signal) 45%, transparent);
    --k-signal-veil: color-mix(in srgb, var(--k-signal) 12%, transparent);
    --k-violet: #8b6cf0;
    --k-violet-soft: color-mix(in srgb, var(--k-violet) 14%, transparent);
    --k-accent-gradient: linear-gradient(100deg, #c9f7fb 0%, #62d9e6 42%, #a996ff 100%);

    /* Semantic status */
    --k-success: #22c55e;
    --k-warning: #ca8a04;
    --k-danger: #ef4444;

    /* Rarity — collectibles / units only */
    --k-rarity-common: #9aa4b2;
    --k-rarity-rare: #4c9dff;
    --k-rarity-epic: #c040ff;
    --k-rarity-legendary: #ffc030;

    /* Lines (border hierarchy) */
    --k-line-subtle: rgba(255, 255, 255, 0.06);
    --k-line: rgba(255, 255, 255, 0.1);
    --k-line-strong: rgba(255, 255, 255, 0.18);
    --k-line-bone: color-mix(in srgb, var(--k-bone) 40%, transparent);
    --k-line-signal: color-mix(in srgb, var(--k-signal) 50%, transparent);

    /* Radius */
    --k-radius-xs: 2px;
    --k-radius-sm: 6px;
    --k-radius-md: 10px;
    --k-radius-lg: 16px;
    --k-radius-pill: 999px;

    /* Spacing (px — independent of the legacy 112.5% root) */
    --k-gutter: clamp(16px, 4vw, 40px);
    --k-container: 1320px;

    /* Type families */
    --k-font-display: 'Archivo', 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --k-font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --k-font-mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Consolas, monospace;
    --k-font-brand: 'Orbitron', var(--k-font-display);

    /* Type scale (1rem = 18px under the legacy root) */
    --k-fs-micro: 0.72rem;
    --k-fs-xs: 0.75rem;
    --k-fs-sm: 0.833rem;
    --k-fs-md: 0.944rem;
    --k-fs-lg: 1.111rem;
    --k-track-label: 0.14em;

    /* Depth */
    --k-shadow-1: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 8px 24px rgba(0, 0, 0, 0.4);
    --k-shadow-2: 0 1px 0 rgba(255, 255, 255, 0.05) inset, 0 24px 64px rgba(0, 0, 0, 0.65);
    --k-light-rim: linear-gradient(180deg, rgba(255, 255, 255, 0.05), transparent 40%);

    /* Motion */
    --k-dur-1: 120ms;
    --k-dur-2: 200ms;
    --k-dur-3: 320ms;
    --k-dur-4: 600ms;
    --k-dur-5: 900ms;
    --k-ease-out: cubic-bezier(.16, 1, .3, 1);
    --k-ease-std: cubic-bezier(.2, 0, 0, 1);
  }
}

/* ════════════════════════════════════════════════════════════════════
   RESET — scoped to .k-* components only
   ════════════════════════════════════════════════════════════════════ */
@layer reset {
  :where([class^="k-"], [class*=" k-"]),
  :where([class^="k-"], [class*=" k-"])::before,
  :where([class^="k-"], [class*=" k-"])::after {
    box-sizing: border-box;
  }
  :where(.k-btn) { -webkit-tap-highlight-color: transparent; }
}

/* ════════════════════════════════════════════════════════════════════
   BASE — accessibility + reduced-motion guarantees
   ════════════════════════════════════════════════════════════════════ */
@layer base {
  :where(.k-home) :where(a, button, [tabindex]:not([tabindex="-1"])):focus-visible {
    outline: 2px solid var(--k-signal) !important;
    outline-offset: 3px !important;
  }
  ::selection {
    background: color-mix(in srgb, var(--k-signal) 32%, transparent);
    color: var(--k-text);
  }
  @media (prefers-reduced-motion: reduce) {
    .k-home *,
    .k-home *::before,
    .k-home *::after {
      animation-duration: 0.01ms !important;
      animation-iteration-count: 1 !important;
      transition-duration: 0.01ms !important;
      scroll-behavior: auto !important;
    }
  }
}

/* ════════════════════════════════════════════════════════════════════
   COMPONENTS (unlayered)
   ════════════════════════════════════════════════════════════════════ */

/* ─── Layout ─── */
.k-container {
  width: 100%;
  max-width: var(--k-container);
  margin-inline: auto;
  padding-inline: var(--k-gutter);
}

/* ─── Sigil (KND hex) ─── */
.k-sigil {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  color: var(--k-bone);
}
.k-sigil svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* ─── Buttons (pill, like the shell header / Auth V2) ─── */
.k-btn {
  --k-btn-h: 46px;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: var(--k-btn-h);
  padding: 0 22px;
  font-family: var(--k-font-sans);
  font-size: var(--k-fs-sm);
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  text-decoration: none !important;
  color: var(--k-text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--k-radius-pill);
  cursor: pointer;
  user-select: none;
  transition:
    background-color var(--k-dur-2) var(--k-ease-std),
    border-color var(--k-dur-2) var(--k-ease-std),
    box-shadow var(--k-dur-2) var(--k-ease-std),
    color var(--k-dur-2) var(--k-ease-std),
    transform var(--k-dur-1) var(--k-ease-std);
}
.k-btn:active { transform: translateY(1px); }
.k-btn__arrow {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  transition: transform var(--k-dur-3) var(--k-ease-out);
}
.k-btn:hover .k-btn__arrow { transform: translateX(3px); }
.k-btn--primary {
  color: var(--k-text-on-bone) !important;
  background: linear-gradient(180deg, #84e6f0, #4cc3d1);
  border-color: rgba(166, 240, 246, 0.6);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35), 0 10px 32px rgba(98, 217, 230, 0.24), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}
.k-btn--primary:hover {
  color: var(--k-text-on-bone) !important;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35), 0 12px 40px rgba(98, 217, 230, 0.38), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}
.k-btn--secondary {
  color: var(--k-text) !important;
  border-color: var(--k-line-strong);
  background: rgba(255, 255, 255, 0.025);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.k-btn--secondary:hover {
  color: var(--k-text) !important;
  border-color: color-mix(in srgb, var(--k-signal) 45%, transparent);
  background: rgba(98, 217, 230, 0.06);
}
.k-btn--lg {
  --k-btn-h: 54px;
  padding: 0 28px;
  font-size: var(--k-fs-sm);
}

/* ─── System label / section identifier ─── */
.k-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--k-font-mono);
  font-size: var(--k-fs-micro);
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: var(--k-track-label);
  text-transform: uppercase;
  color: var(--k-text-subtle);
}
.k-label--bone { color: var(--k-bone); }

.k-sid {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-family: var(--k-font-mono);
  font-size: var(--k-fs-micro);
  font-weight: 500;
  letter-spacing: var(--k-track-label);
  text-transform: uppercase;
  color: var(--k-text-subtle);
}
.k-sid__index { color: var(--k-bone); }
.k-sid__rule {
  width: 32px;
  height: 1px;
  background: linear-gradient(90deg, var(--k-signal), transparent);
  box-shadow: 0 0 8px rgba(98, 217, 230, 0.5);
}

/* ─── Stat rows ─── */
.k-statlist { display: grid; margin: 0; }
.k-stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-top: 1px solid var(--k-line-subtle);
}
.k-stat:first-child { border-top: 0; }
.k-stat__label {
  font-family: var(--k-font-mono);
  font-size: var(--k-fs-micro);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--k-text-subtle);
}
.k-stat__value {
  font-family: var(--k-font-sans);
  font-size: var(--k-fs-sm);
  font-variant-numeric: tabular-nums;
  color: var(--k-text);
  text-align: right;
}

/* ─── Operator identity (callsign) ─── */
.k-callsign {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  line-height: 1.2;
}
.k-callsign__role {
  font-family: var(--k-font-mono);
  font-size: var(--k-fs-micro);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--k-text-subtle);
  flex-shrink: 0;
}
.k-callsign__name {
  font-family: var(--k-font-brand);
  font-weight: 600;
  font-size: var(--k-fs-sm);
  letter-spacing: 0.06em;
  color: var(--k-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── KND Identity plate ─── */
.k-idplate {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 14px 16px;
  align-items: center;
  padding: 18px;
  background: var(--k-light-rim), linear-gradient(180deg, rgba(14, 20, 32, 0.92), rgba(8, 11, 18, 0.92));
  border: 1px solid var(--k-line);
  border-radius: var(--k-radius-lg);
  overflow: hidden;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.k-idplate::before {
  content: '';
  position: absolute;
  inset: 0 0 auto;
  height: 1px;
  background: linear-gradient(90deg, var(--k-signal), rgba(139, 108, 240, 0.5) 45%, transparent 80%);
}
.k-idplate .k-sigil { width: 44px; height: 44px; }
.k-idplate__head { display: grid; gap: 6px; min-width: 0; }
.k-idplate__body { grid-column: 1 / -1; display: grid; gap: 10px; }
