/*
 * ArcForge Labs — Key (/key), standalone styles.
 *
 * This page is NOT a Next route: it is plain HTML served from public/, so it
 * cannot import app/globals.css. The token block below is therefore a
 * deliberate COPY of the tokens in app/globals.css, and
 * scripts/key-guard.test.mjs fails the build if the two ever drift.
 * Add tokens there first, then mirror them here.
 *
 * Motion contract (inherited): every animation lives inside
 * @media (prefers-reduced-motion: no-preference). This page ships no inline
 * motion-gate script, so html[data-motion-ok] is never set and the wordmark
 * arc renders fully drawn — the documented no-JS state. A tool page paints
 * composed and usable at first paint; there are no scroll reveals here.
 */

/* ── display face (self-hosted, same file the app router uses) ───────── */
@font-face {
  font-family: "Clash Display";
  src: url("./ClashDisplay-Variable.woff2") format("woff2-variations");
  font-weight: 200 700;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: dark;

  /* ── color ─────────────────────────────────────────── */
  --bg: #0a0a0f;
  --surface: #16161f;
  --surface-elevated: #1e1e2a;
  --green: #4ade80;
  --green-2: #22c55e;
  --text: #f5f5f5;
  --text-body: rgba(255, 255, 255, 0.72);
  --muted: rgba(255, 255, 255, 0.56);
  --ink-on-green: #06220f;
  --hairline-1: rgba(255, 255, 255, 0.08);
  --hairline-2: rgba(255, 255, 255, 0.16);
  --hairline-focus: rgba(255, 255, 255, 0.32);

  /* ── type ──────────────────────────────────────────── */
  --font-display: "Clash Display";
  --font-body: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas,
    monospace;
  --display-2: clamp(2rem, 5vw, 3.5rem);
  --h3: clamp(1.25rem, 2.5vw, 1.5rem);
  --body: 1.0625rem;
  --mono-label: 0.75rem;

  /* ── layout ────────────────────────────────────────── */
  --space-section: 96px;
  --container: 1120px;
  --prose: 68ch;
  --r-btn: 8px;
  --r-mid: 12px;
  --r-card: 16px;

  /* ── motion ────────────────────────────────────────── */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur-fast: 150ms;
  --dur-base: 250ms;

  /* ── key page only: entropy semantics ──────────────────
     Strength is state, not brand: only "strong" and above borrow the
     studio green, so the accent still means one thing on this page. */
  --key-weak: #f0736b;
  --key-fair: #e8b45c;
  --key-strong: var(--green);
  --key-excellent: #5eead4;
  --key-digit: #e8b45c;
  --key-symbol: #5eead4;
}

@media (min-width: 1024px) {
  :root {
    --space-section: 144px;
  }
}

/* ── base ────────────────────────────────────────────── */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--body);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

::selection {
  background: rgba(74, 222, 128, 0.28);
  color: var(--text);
}

svg {
  max-width: 100%;
  height: auto;
}

a {
  color: var(--text);
}

:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
  border-radius: 4px;
}

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

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--green);
  color: var(--ink-on-green);
  padding: 10px 16px;
  border-radius: var(--r-btn);
  font-weight: 600;
  z-index: 200;
}
.skip-link:focus {
  left: 16px;
  top: 16px;
}

.container {
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 24px;
}

/* ── grain overlay (data-URI, zero requests, zero JS) ── */
.grain {
  position: fixed;
  inset: 0;
  z-index: 80;
  pointer-events: none;
  opacity: 0.04;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 180px 180px;
}

/* ── mono labels ─────────────────────────────────────── */
.mono-label {
  font-family: var(--font-mono);
  font-size: var(--mono-label);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

/* ── display type ────────────────────────────────────── */
.display-2,
.h3 {
  font-family: var(--font-display), var(--font-body);
  margin: 0;
}
.display-2 {
  font-size: var(--display-2);
  font-weight: 600;
  line-height: 1.08;
  letter-spacing: -0.025em;
}
.h3 {
  font-size: var(--h3);
  font-weight: 500;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.lead {
  font-size: clamp(1.0625rem, 1.5vw, 1.1875rem);
  line-height: 1.6;
  color: var(--text-body);
  max-width: 52ch;
}

/* ── inline link: green underline draw ───────────────── */
.link-draw,
.prose a:not(.btn) {
  color: var(--text);
  text-decoration: none;
  background-image: linear-gradient(var(--green), var(--green));
  background-repeat: no-repeat;
  background-position: 0 100%;
  background-size: 100% 1px;
  padding-bottom: 1px;
}

/* ── nav ─────────────────────────────────────────────── */
/* Glass is the default here permanently: this page ships no NavScroll
   island, and glass is the state that is safe over scrolled content. */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10, 10, 15, 0.72);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--hairline-1);
}
.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  height: 64px;
}
.brand {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  color: var(--text);
}
.nav-links {
  display: flex;
  align-items: center;
  gap: 16px;
  list-style: none;
  margin: 0;
  padding: 0;
}
.nav-links a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
  background-image: linear-gradient(var(--green), var(--green));
  background-repeat: no-repeat;
  background-position: 0 calc(100% - 12px);
  background-size: 0 1px;
  display: inline-block;
  padding: 13px 6px;
}
.nav-links a[aria-current="page"] {
  color: var(--text);
  background-size: 100% 1px;
}
@media (max-width: 640px) {
  .wordmark-labs {
    display: none;
  }
  .nav-links {
    gap: 6px;
    font-size: 0.9rem;
  }
  .nav-links a {
    padding: 13px 5px;
  }
}
@media (max-width: 380px) {
  .nav-links {
    gap: 0;
    font-size: 0.85rem;
  }
  .nav-links a {
    padding: 13px 4px;
  }
}

/* ── wordmark ────────────────────────────────────────── */
.wordmark {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
}
.wordmark-name {
  font-family: var(--font-display), var(--font-body);
  font-weight: 600;
  font-size: 1.1875rem;
  letter-spacing: -0.03em;
  line-height: 1;
  display: inline-flex;
  align-items: baseline;
}
.wordmark-glyph {
  width: 0.82em;
  height: 0.82em;
  margin: 0 0.045em;
  align-self: center;
  transform: translateY(0.02em);
  flex: none;
}
.wordmark-labs {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--muted);
}

/* ── buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 22px;
  border-radius: var(--r-btn);
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
}
.btn-primary {
  background: var(--green);
  color: var(--ink-on-green);
  min-width: 8.5rem;
}
.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--hairline-2);
}
.btn-ghost:focus-visible {
  border-color: var(--hairline-focus);
}

/* ── page head ───────────────────────────────────────── */
.page-head {
  padding: 72px 0 0;
  display: grid;
  gap: 20px;
  justify-items: start;
}

/* ── the tool ────────────────────────────────────────── */
.key-tool {
  margin: 40px 0 0;
  background: var(--surface);
  border: 1px solid var(--hairline-1);
  border-radius: var(--r-card);
  padding: 24px;
  max-width: 760px;
}
@media (max-width: 560px) {
  .key-tool {
    padding: 18px;
  }
}

/* segmented control — mono labels, hairline track */
.key-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 20px;
  background: var(--bg);
  border: 1px solid var(--hairline-1);
  border-radius: var(--r-btn);
}
.key-tab {
  appearance: none;
  background: none;
  border: 0;
  border-radius: 5px;
  padding: 9px 16px;
  font-family: var(--font-mono);
  font-size: var(--mono-label);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  cursor: pointer;
}
.key-tab.is-active {
  background: var(--surface-elevated);
  color: var(--text);
}

/* the secret */
.key-out {
  background: var(--bg);
  border: 1px solid var(--hairline-1);
  border-radius: var(--r-mid);
  padding: 20px;
}
.key-secret {
  display: block;
  font-family: var(--font-mono);
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  line-height: 1.6;
  overflow-wrap: anywhere;
  color: var(--text);
}
.key-secret .ch-d {
  color: var(--key-digit);
}
.key-secret .ch-s {
  color: var(--key-symbol);
}

.key-actions {
  display: flex;
  gap: 12px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.key-die.spin {
  animation: none;
}
@media (prefers-reduced-motion: no-preference) {
  .key-die.spin {
    animation: key-roll var(--dur-base) var(--ease-out);
  }
  @keyframes key-roll {
    from {
      transform: rotate(0deg);
    }
    to {
      transform: rotate(180deg);
    }
  }
}

/* ── entropy meter ───────────────────────────────────── */
.key-meter {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--hairline-1);
}
.key-read {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}
.key-bits {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.key-bits-unit {
  font-family: var(--font-mono);
  font-size: var(--mono-label);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.key-pill {
  font-family: var(--font-mono);
  font-size: var(--mono-label);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid currentColor;
}
.key-pill.weak {
  color: var(--key-weak);
}
.key-pill.fair {
  color: var(--key-fair);
}
.key-pill.strong {
  color: var(--key-strong);
}
.key-pill.excellent {
  color: var(--key-excellent);
}
.key-detail {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: var(--mono-label);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.key-gauge {
  position: relative;
  height: 3px;
  margin-top: 16px;
  background: var(--hairline-1);
  border-radius: 2px;
}
.key-gauge-fill {
  height: 100%;
  width: 0;
  border-radius: 2px;
  background: var(--muted);
}
@media (prefers-reduced-motion: no-preference) {
  .key-gauge-fill {
    transition: width var(--dur-base) var(--ease-out),
      background-color var(--dur-base) var(--ease-out);
  }
}
.key-gauge-fill.weak {
  background: var(--key-weak);
}
.key-gauge-fill.fair {
  background: var(--key-fair);
}
.key-gauge-fill.strong {
  background: var(--key-strong);
}
.key-gauge-fill.excellent {
  background: var(--key-excellent);
}

.key-tick {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 1px;
  background: var(--hairline-2);
}
/* thresholds from strength_label(), on the gauge's 0–160 bit scale */
.key-tick-fair {
  left: 37.5%;
}
.key-tick-strong {
  left: 46.875%;
}
.key-tick-excellent {
  left: 80%;
}

.key-scale {
  position: relative;
  height: 1.1rem;
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.key-mark {
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
}
.key-mark-fair {
  left: 37.5%;
}
.key-mark-strong {
  left: 46.875%;
}
.key-mark-excellent {
  left: 80%;
}
@media (max-width: 560px) {
  .key-mark-fair,
  .key-detail {
    display: none;
  }
}

/* ── controls ────────────────────────────────────────── */
.key-controls {
  margin: 24px 0 0;
  padding: 20px 0 0;
  border: 0;
  border-top: 1px solid var(--hairline-1);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px 32px;
}
/* author display beats the UA [hidden] rule — restate it */
.key-controls[hidden] {
  display: none;
}
@media (max-width: 560px) {
  .key-controls {
    grid-template-columns: 1fr;
  }
}

.key-field > label,
.key-field > .key-field-label {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--mono-label);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 10px;
}
.key-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

input[type="range"] {
  flex: 1;
  accent-color: var(--green);
  margin: 0;
  min-height: 24px;
}

input[type="number"],
input[type="text"],
select {
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  background: var(--bg);
  border: 1px solid var(--hairline-1);
  border-radius: var(--r-btn);
  color: var(--text);
  padding: 10px 12px;
  min-height: 44px;
}
input[type="number"] {
  width: 5.5rem;
}
select {
  width: 100%;
}

.key-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.9375rem;
  color: var(--text-body);
  cursor: pointer;
  padding: 6px 0;
}
.key-check input {
  accent-color: var(--green);
  width: 18px;
  height: 18px;
  margin: 0;
  flex: none;
  translate: 0 2px;
}
.key-hint {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-top: 2px;
}

/* ── prose ───────────────────────────────────────────── */
.prose {
  max-width: var(--prose);
  padding-bottom: var(--space-section);
  margin-top: 8px;
}
.prose p,
.prose li {
  color: var(--text-body);
  line-height: 1.7;
}
.prose h2 {
  font-family: var(--font-display), var(--font-body);
  font-size: 1.375rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  margin: 48px 0 12px;
  padding-top: 24px;
  border-top: 1px solid var(--hairline-1);
}
.prose code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  color: var(--text);
}
.prose pre {
  background: var(--surface);
  border: 1px solid var(--hairline-1);
  border-radius: var(--r-mid);
  padding: 18px 20px;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.8;
  overflow-x: auto;
  color: var(--text);
}
.prose pre .cmt {
  color: var(--muted);
}

/* ── footer ──────────────────────────────────────────── */
.footer {
  border-top: 1px solid var(--hairline-1);
  padding: 56px 0 64px;
}
.footer-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 40px;
}
.footer-links {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0;
  align-content: start;
}
.footer-links a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
  background-image: linear-gradient(var(--green), var(--green));
  background-repeat: no-repeat;
  background-position: 0 calc(100% - 11px);
  background-size: 0 1px;
  display: inline-block;
  padding: 12px 0;
}
.footer-cols {
  display: flex;
  gap: 64px;
  flex-wrap: wrap;
  align-items: flex-start;
}
.footer p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.9rem;
  max-width: 44ch;
}
.footer-legal {
  margin-top: 24px;
  font-size: 0.82rem;
}
.footer-legal,
.footer-legal a {
  color: var(--muted);
}

/* ── hover/motion, gated ─────────────────────────────── */
@media (prefers-reduced-motion: no-preference) {
  .nav-links a,
  .footer-links a {
    transition: background-size var(--dur-base) var(--ease-out),
      color var(--dur-fast) var(--ease-out);
  }
  .btn {
    transition: transform var(--dur-fast) var(--ease-out),
      border-color var(--dur-fast) var(--ease-out),
      background-color var(--dur-fast) var(--ease-out);
  }
  .btn:active {
    transform: scale(0.98);
  }
}
.nav-links a:hover,
.footer-links a:hover {
  color: var(--text);
  background-size: 100% 1px;
}
.btn-ghost:hover {
  border-color: var(--hairline-focus);
}
.btn-primary:hover {
  background: var(--green-2);
}
