/* Self-hosted fonts (SIL OFL 1.1, latin subset) — no third-party requests. */
@font-face {
  font-family: "Space Grotesk";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("fonts/space-grotesk-700.woff2") format("woff2");
}

@font-face {
  font-family: "Space Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/space-mono-400.woff2") format("woff2");
}

:root {
  /* Tier 1: primitive color tokens */
  --pr-black: #0A0A0B;
  --pr-gold: #C7923E;
  --pr-vermilion: #9E2A2B;
  --pr-slate: #3D5A80;
  --pr-cream: #EAE3D2;
  --pr-emerald: #3FB27F;

  /* Tier 2: Domain Tokens (Agent Mesh System) */
  --color-agent-teamlead: var(--pr-gold);
  --color-agent-expert: var(--pr-vermilion);
  --color-agent-worker: var(--pr-slate);

  /* Tier 2: Semantic UI Tokens */
  --color-surface-base: var(--pr-black);
  --color-text-primary: var(--pr-cream);
  --color-status-success: var(--pr-emerald);

  /* Tier 2: Glassmorphism & Surface Tokens */
  --glass-panel-bg: rgba(14, 14, 18, 0.32);
  --glass-panel-border: rgba(234, 227, 210, 0.16);
  --glass-panel-shadow: 0 20px 40px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  --glass-btn-bg: rgba(10, 10, 11, 0.4);
  --glass-btn-bg-hover: rgba(10, 10, 11, 0.65);
  --glass-btn-border: rgba(234, 227, 210, 0.25);
  --glass-btn-border-hover: rgba(199, 146, 62, 0.6);

  /* Tier 2: Form & Interactive Tokens */
  --input-border: rgba(234, 227, 210, 0.2);
  --input-bg: rgba(234, 227, 210, 0.05);
  --focus-ring: var(--color-agent-teamlead);
  --focus-ring-glow: rgba(199, 146, 62, 0.35);

  /* Tier 2: Feedback & Alert Tokens */
  --alert-bg: rgba(158, 42, 43, 0.12);
  --alert-border: var(--color-agent-expert);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--color-surface-base);
  font-family: "Space Grotesk", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

canvas {
  position: fixed;
  inset: 0;
  display: block;
  width: 100vw;
  height: 100vh;
  cursor: default;
  z-index: 1;
}

.hero-text {
  position: fixed;
  top: 45%;
  left: 10%;
  transform: translateY(-50%);
  max-width: 60vw;
  z-index: 5;
  pointer-events: none;
  user-select: none;
}

.headline {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: clamp(2.5rem, 6vw, 6.5rem);
  line-height: 1;
  color: var(--color-text-primary);
  letter-spacing: -0.02em;
}

.subline {
  margin: 0;
  font-family: "Space Mono", monospace;
  font-weight: 400;
  color: var(--color-text-primary);
  max-width: 50rem;
  text-wrap: balance;
}

.subline-primary {
  margin: 0.55em 0 0 6px;
  font-size: clamp(1rem, 1.6vw, 1.6rem);
  line-height: 1.4;
  opacity: 0.88;
}

.subline-secondary {
  margin: 1.3em 0 0 6px;
  font-size: clamp(0.85rem, 1.05vw, 1.15rem);
  line-height: 1.55;
  opacity: 0.55;
}

.ui {
  display: none !important;
}

.grain-overlay {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  filter: url(#grain);
  opacity: 0.7;
}

@media (prefers-reduced-motion: reduce) {
  .grain-overlay {
    display: none;
  }
}

/* --- App Shell Header --- */
.app-header {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
  pointer-events: none;
}

.app-header > * {
  pointer-events: auto;
}

.account-btn {
  position: relative;
  margin-left: auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--glass-btn-border);
  background: var(--glass-btn-bg);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.account-btn:hover {
  border-color: var(--glass-btn-border-hover);
  background: var(--glass-btn-bg-hover);
}

.account-btn:focus-visible,
.layer-close:focus-visible,
.login-submit:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--color-surface-base), 0 0 0 4px var(--focus-ring);
}

.account-btn svg {
  width: 18px;
  height: 18px;
  fill: var(--color-text-primary);
}

.status-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--color-status-success);
  border: 2px solid var(--color-surface-base);
}

/* --- Layers: Fluent Acrylic flyouts (native <dialog>) ---
   One mechanism for every layer; only the anchor edge differs.
   Integer px anchoring (no centering) keeps text crisp under backdrop-filter.
   allow-discrete keeps display/overlay alive for the exit transition. */
.layer {
  position: fixed;
  width: min(380px, calc(100vw - 48px));
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  overflow: visible;
  color: var(--color-text-primary);
  opacity: 0;
  transform: translateX(var(--layer-shift));
  transition: opacity 0.25s ease, transform 0.25s ease,
              display 0.25s allow-discrete, overlay 0.25s allow-discrete;
}

.layer[open] {
  opacity: 1;
  transform: translateX(0);
}

@starting-style {
  .layer[open] {
    opacity: 0;
    transform: translateX(var(--layer-shift));
  }
}

.layer::backdrop {
  background: transparent;
}

.layer--top-right {
  inset: 80px 24px auto auto;
  max-height: calc(100vh - 104px);
  --layer-shift: 24px;
}

.layer--bottom-left {
  inset: auto auto 64px 24px;
  max-height: calc(100vh - 88px);
  --layer-shift: -24px;
}

.layer-panel {
  max-height: inherit;
  overflow: auto;
  position: relative;
  width: 100%;
  padding: 32px 28px 28px;
  border-radius: 12px;
  background: var(--glass-panel-bg);
  backdrop-filter: blur(10px) saturate(160%);
  -webkit-backdrop-filter: blur(10px) saturate(160%);
  border: 1px solid var(--glass-panel-border);
  box-shadow: var(--glass-panel-shadow);
  isolation: isolate;
  transform: translateZ(0);
  will-change: backdrop-filter, transform;
}

.layer-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: var(--color-text-primary);
  opacity: 0.6;
  cursor: pointer;
  font-family: "Space Mono", monospace;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
}

.layer-close:hover {
  opacity: 1;
}

.layer-headline {
  margin: 0 0 6px;
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: 1.4rem;
  color: var(--color-text-primary);
}

.layer-subline {
  margin: 0 0 22px;
  font-family: "Space Mono", monospace;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  color: var(--color-text-primary);
  opacity: 0.65;
}

.login-field {
  margin-bottom: 16px;
}

.login-field label {
  display: block;
  margin-bottom: 6px;
  font-family: "Space Mono", monospace;
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--color-text-primary);
  opacity: 0.55;
}

.login-field input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 4px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--color-text-primary);
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.login-field input:focus {
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 3px var(--focus-ring-glow);
}

.login-field input:-webkit-autofill,
.login-field input:-webkit-autofill:hover,
.login-field input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--color-text-primary);
  -webkit-box-shadow: 0 0 0px 1000px rgba(24, 24, 30, 0.95) inset;
  transition: background-color 5000s ease-in-out 0s;
}

.login-submit {
  width: 100%;
  padding: 11px;
  margin-top: 6px;
  border: none;
  border-radius: 4px;
  background: var(--color-agent-teamlead);
  color: var(--color-surface-base);
  font-family: "Space Grotesk", sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.login-submit:disabled {
  opacity: 0.7;
  cursor: default;
}

.login-messagebar {
  display: none;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 18px;
  padding: 10px 12px;
  border-radius: 4px;
  background: var(--alert-bg);
  border-left: 3px solid var(--alert-border);
  font-family: "Space Mono", monospace;
  font-size: 0.72rem;
  line-height: 1.4;
  color: var(--color-text-primary);
}

.login-messagebar.show {
  display: flex;
}

/* --- Legal Footer & Legal Layer Content --- */
.app-footer {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 30;
  padding: 16px 28px;
  pointer-events: none;
}

.legal-link {
  pointer-events: auto;
  margin-right: 20px;
  padding: 0;
  border: none;
  background: none;
  color: var(--color-text-primary);
  opacity: 0.45;
  font-family: "Space Mono", monospace;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.legal-link:hover,
.legal-link:focus-visible {
  opacity: 1;
  outline: none;
}

.legal-section {
  margin: 0 0 16px;
  font-family: "Space Mono", monospace;
  font-size: 0.8rem;
  line-height: 1.6;
}

.legal-section p {
  margin: 0;
}

.legal-section:last-child {
  margin-bottom: 0;
}

.legal-label {
  display: block;
  margin: 0 0 6px;
  font-family: "Space Mono", monospace;
  font-weight: 400;
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  opacity: 0.55;
}

.legal-section a {
  color: var(--color-agent-teamlead);
}

/* Hidden host for the SVG grain filter (was an inline style attribute; CSP forbids those). */
.svg-defs {
  position: absolute;
  width: 0;
  height: 0;
  pointer-events: none;
}
