:root {
  /* Surfaces */
  --bg-0: #0d1117;
  --bg-1: #151a20;
  --bg-2: #1b2027;
  --bg-3: #262b33;
  --bg-deep: #0a0c10;

  /* Borders */
  --border: #232830;
  --border-soft: #1a1e24;
  --border-strong: #353c47;

  /* Text — tuned so every tier clears WCAG AA (4.5:1) on bg-0..bg-3.
     text-3 is the dimmest tier and still clears AA for placeholder text. */
  --text-0: #f0f3f6;
  --text-1: #c9d1da;
  --text-2: #9aa2ac;
  --text-3: #7d8590;

  /* Semantic — brightened so each clears WCAG AA on the dark surfaces.
     Use these for text/icons; the -dim pair is for borders & fills only. */
  --blue: #79b1ff;
  --blue-dim: #2c5fb0;
  --green: #6cc77d;
  --green-dim: #2a6e3a;
  --yellow: #e0b34e;
  --red: #f47b72;
  --red-dim: #9c322f;
  --purple: #b7a3ea;
  --purple-dim: #5a4a8a;
  --magenta: #f472b6;
  --magenta-dim: #8a2a58;
  --orange: #fb923c;
  --orange-dim: #9a4a12;
  /* Mac Studio tier accent — electric cyan so a 3px bar reads at a glance
     (docs teal #5eead4 sat too close to dual green on dark surfaces). Sits
     in the cool gap between prebook blue and dual green, clear of RTX
     magenta and spark-4 orange. */
  --cyan: #2ee9ff;
  --cyan-dim: #0f7a8a;

  /* Focus ring — single accent reused for every focusable element */
  --focus: #79b1ff;

  /* Geometry — square-ish, terminal vibe */
  --radius: 2px;
  --radius-lg: 3px;
  --radius-xl: 4px;

  /* Type — mono everywhere, system stack for low-key terminal feel */
  --font: ui-monospace, SFMono-Regular, "SF Mono", "Cascadia Mono", Menlo,
          Consolas, "Liberation Mono", monospace;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", "Cascadia Mono", Menlo,
          Consolas, "Liberation Mono", monospace;
}

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

/* Visible keyboard focus for every interactive element. focus-visible keeps
   the ring off mouse clicks while guaranteeing keyboard users a clear target. */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
:focus:not(:focus-visible) { outline: none; }

/* Skip link — first tab stop, off-screen until focused, so keyboard users
   can bypass the header and jump straight to the main content. */
.skip-link {
  position: absolute;
  left: 8px;
  top: -48px;
  z-index: 1000;
  padding: 8px 12px;
  background: var(--bg-2);
  color: var(--text-0);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  text-decoration: none;
  transition: top .12s;
}
.skip-link:focus { top: 8px; }

/* Honor reduced-motion globally — animations and transitions collapse to
   near-instant so vestibular-sensitive users avoid spin/slide motion. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

html, body {
  background: var(--bg-0);
}

body {
  font-family: var(--font);
  color: var(--text-1);
  line-height: 1.5;
  min-height: 100vh;
  font-size: 13.5px;
  letter-spacing: -0.005em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.screen { display: none; }
.screen.active { display: block; }

.loading-screen {
  display: none;
  height: 100vh;
  align-items: center;
  justify-content: center;
}
.loading-screen.active { display: flex; }

.spinner {
  width: 28px; height: 28px;
  border: 2px solid var(--bg-3);
  border-top-color: var(--text-1);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
}

/* Inputs ----------------------------------------------------------------- */

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea {
  font-family: var(--font);
  font-size: 14px;
  padding: 9px 12px;
  background: var(--bg-deep);
  color: var(--text-0);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color .12s;
  width: 100%;
}
select:focus { border-color: var(--focus); }
select[hidden] { display: none; }
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text-0);
  -webkit-box-shadow: 0 0 0 1000px var(--bg-deep) inset;
  box-shadow: 0 0 0 1000px var(--bg-deep) inset;
  transition: background-color 5000s ease-out 0s;
}
input:focus, textarea:focus {
  border-color: var(--focus);
}
input::placeholder, textarea::placeholder { color: var(--text-3); }
textarea {
  resize: vertical;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
}

/* Buttons ---------------------------------------------------------------- */

.btn {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 6px 12px;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s, opacity .12s;
  line-height: 1.4;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--text-0);
  color: var(--bg-0);
  border-color: var(--text-0);
}
.btn-primary:hover:not(:disabled) {
  background: #ffffff;
  border-color: #ffffff;
}

.btn-blue {
  background: transparent;
  color: var(--blue);
  border-color: var(--border-strong);
}
.btn-blue:hover:not(:disabled) {
  background: rgba(121, 177, 255, 0.12);
  border-color: var(--blue);
}

.btn-danger {
  background: transparent;
  color: var(--red);
  border-color: var(--border-strong);
}
.btn-danger:hover:not(:disabled) {
  background: rgba(244, 123, 114, 0.12);
  border-color: var(--red);
}

.btn-warning {
  background: transparent;
  color: var(--yellow);
  border-color: var(--border-strong);
}
.btn-warning:hover:not(:disabled) {
  background: rgba(224, 179, 78, 0.12);
  border-color: var(--yellow);
}

.btn-ghost {
  background: transparent;
  color: var(--text-2);
  border-color: var(--border);
  padding: 5px 11px;
}
.btn-ghost:hover:not(:disabled) {
  color: var(--text-0);
  border-color: var(--border-strong);
}

.btn-sm { font-size: 12px; padding: 3px 9px; }
.btn-lg { font-size: 13.5px; padding: 9px 18px; }

/* Copy button (reusable; pairs with copyButton()/initCopyDelegation()) ---- */

.copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  flex-shrink: 0;
  background: transparent;
  color: var(--text-3);
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: color .12s, border-color .12s, background .12s;
}
.copy-btn:hover {
  color: var(--text-1);
  background: var(--bg-2);
  border-color: var(--border);
}
.copy-btn .copy-icon { width: 13px; height: 13px; }
.copy-btn .copy-icon-check { display: none; }
.copy-btn.copied { color: var(--green); }
.copy-btn.copied .copy-icon-copy { display: none; }
.copy-btn.copied .copy-icon-check { display: inline; }

/* Toast ------------------------------------------------------------------ */

.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  padding: 9px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 200;
  transform: translateY(120%);
  opacity: 0;
  transition: transform .2s ease, opacity .2s ease;
  max-width: 400px;
  border: 1px solid var(--border-strong);
  background: var(--bg-2);
  color: var(--text-0);
}
.toast.visible {
  transform: translateY(0);
  opacity: 1;
}
.toast-success { color: var(--text-0); border-color: var(--border-strong); }
.toast-error   { color: var(--red); border-color: var(--red); }

/* Keyboard hint ---------------------------------------------------------- */

kbd {
  font-family: var(--mono); font-size: 11px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 5px; color: var(--text-1);
}
