/* Sage on Black: tokens from DESIGN.md. Sizes are rem so the TV breakpoint scales everything. */
:root {
  --canvas: #000000;
  --surface: #101211;
  --surface-hover: #171918;
  --surface-active: #202221;
  --fg: #eceeed;
  --fg-muted: #adb5b2;
  --fg-subtle: #717d79;
  --border: #272a29;
  --border-control: #373b39;
  --border-control-hover: #444947;
  --primary: #ffffff;
  --primary-hover: #eceeed;
  --on-primary: #000000;
  --fill-ghost: rgba(240, 242, 241, 0.03);
  --fill-subtle: rgba(243, 245, 244, 0.07);
  --fill-subtle-hover: rgba(242, 254, 253, 0.1);
  --fill-subtle-active: rgba(241, 251, 250, 0.13);
  --error: #e5484d;
  --error-subtle: rgba(255, 23, 63, 0.18);
  --on-error-subtle: #ff9592;
  --success-subtle: rgba(34, 255, 153, 0.12);
  --on-success-subtle: #3bd88c;
  --warning-subtle: rgba(251, 106, 0, 0.15);
  --on-warning-subtle: #ffa057;
  --info-subtle: rgba(0, 119, 255, 0.23);
  --on-info-subtle: #70b8ff;
  --hairline: rgba(235, 253, 246, 0.34);

  --l1: 0.125rem;
  --l2: 0.25rem;
  --l3: 0.375rem;

  --font: "Outfit", ui-sans-serif, system-ui, sans-serif;
  --code: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --gutter: 1rem;
  --gap: 1rem;
  --card-pad: 1.5rem;
  --control: 2.75rem;          /* lg on phones */
  --fast: 150ms;
  --faster: 100ms;
  --z-sticky: 1100;
  --mobile-bar-h: 0rem;
  --focus-ring-width: 2px;
  --focus-ring-offset: 2px;
}

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

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--canvas);
  color: var(--fg);
  font: 400 1rem/1.5rem var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  padding-bottom: var(--mobile-bar-h);
  overflow-x: hidden;
}

.sprite { position: absolute; }

h1, h2, h3, p { margin: 0; }

a { color: inherit; font-weight: 500; text-decoration: underline; text-underline-offset: 0.2em; }

:focus-visible {
  outline: var(--focus-ring-width) solid var(--primary);
  outline-offset: var(--focus-ring-offset);
}

.icon { width: 1.125rem; height: 1.125rem; flex: none; }
.icon-sm { width: 0.875rem; height: 0.875rem; flex: none; }

.page {
  width: 100%;
  max-width: 80rem;
  margin: 0 auto;
  padding:
    max(1rem, env(safe-area-inset-top))
    max(var(--gutter), env(safe-area-inset-right))
    2rem
    max(var(--gutter), env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  min-height: var(--control);
}

.brand {
  display: inline-flex; align-items: center; gap: 0.5rem;
  min-height: var(--control);
  color: var(--fg); font: 600 1.125rem/1.75rem var(--font); text-decoration: none;
}
.brand-dim { color: var(--fg-muted); font-weight: 400; }

.links { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.links a {
  display: inline-flex; align-items: center; gap: 0.375rem;
  min-height: var(--control); padding: 0 0.75rem;
  color: var(--fg-muted); font: 500 0.875rem/1.25rem var(--font);
  text-decoration: none; border-radius: var(--l2);
  transition: color var(--fast), background-color var(--fast);
}

/* ---------- Badges ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 0.25rem;
  height: 1.25rem; padding: 0 0.5rem; border-radius: var(--l2);
  font: 500 0.75rem/1.125rem var(--font); white-space: nowrap;
  color: var(--fg); background: var(--fill-subtle);
}
.badge[data-tone="success"] { color: var(--on-success-subtle); background: var(--success-subtle); }
.badge[data-tone="info"] { color: var(--on-info-subtle); background: var(--info-subtle); }
.badge[data-tone="warning"] { color: var(--on-warning-subtle); background: var(--warning-subtle); }
.badge[data-tone="error"] { color: var(--on-error-subtle); background: var(--error-subtle); }

/* ---------- Hero ---------- */

.hero { display: flex; flex-direction: column; gap: 0.75rem; padding-top: 0.5rem; }
.hero h1 { font: 600 1.875rem/2.375rem var(--font); text-wrap: balance; max-width: 22ch; }
.lede { color: var(--fg-muted); max-width: 65ch; text-wrap: pretty; }

/* ---------- Cards ---------- */

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--gap);
  align-items: start;
}

.card {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--l3);
  padding: var(--card-pad);
}

.card-title { font: 600 1.125rem/1.75rem var(--font); }

.controls { display: flex; flex-direction: column; gap: 1.5rem; }

.field { margin: 0; padding: 0; border: 0; min-width: 0; display: flex; flex-direction: column; gap: 0.375rem; }
.field-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem; width: 100%; padding: 0; }
.field-label, .field-head label { font: 500 0.875rem/1.25rem var(--font); color: var(--fg); }
.helper { color: var(--fg-muted); font: 400 0.875rem/1.25rem var(--font); }

textarea {
  width: 100%;
  min-height: 8rem;
  resize: vertical;
  padding: 0.75rem;
  color: var(--fg);
  font: 400 1rem/1.5rem var(--font);
  background: var(--surface);
  border: 1px solid var(--border-control);
  border-radius: var(--l2);
  transition: border-color var(--fast), box-shadow var(--fast);
}
textarea::placeholder { color: var(--fg-subtle); }
textarea:focus-visible { outline: none; border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }

/* Example prompts: scroll sideways on phones, never wrap. */
.chips {
  display: flex; gap: 0.5rem; margin-top: 0.375rem;
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  height: var(--control); padding: 0 0.875rem; flex: none;
  font: 600 0.875rem/1.25rem var(--font); white-space: nowrap;
  border: 1px solid transparent; border-radius: var(--l2); cursor: pointer;
  color: var(--fg); background: transparent;
  transition: background-color var(--fast), border-color var(--fast), color var(--fast);
  -webkit-tap-highlight-color: transparent;
}
.btn[hidden] { display: none; }
.btn:disabled { opacity: 0.67; filter: grayscale(1); cursor: not-allowed; }
.btn-solid { color: var(--on-primary); background: var(--primary); }
.btn-outline { border-color: var(--border-control); }
.btn-outline:active { background: var(--fill-subtle); }
.btn-plain:active { background: var(--fill-subtle-hover); }
.btn-solid:active { background: var(--primary-hover); }

/* ---------- Precision picker ---------- */

.variants { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0.5rem; }

.variant { position: relative; display: block; cursor: pointer; }
.variant input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.variant-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.25rem 0.75rem;
  min-height: 3.5rem;
  padding: 0.625rem 0.75rem;
  border-radius: var(--l2);
  background: var(--surface);
  border: 1px solid var(--border-control);
  transition: background-color var(--fast), border-color var(--fast);
}
.radio {
  grid-row: span 2;
  width: 1.25rem; height: 1.25rem; border-radius: 9999px;
  border: 1px solid var(--border-control); display: grid; place-items: center;
}
.radio::after { content: ""; width: 40%; height: 40%; border-radius: 9999px; background: var(--on-primary); opacity: 0; }
.variant-name { font: 500 1rem/1.5rem var(--font); }
.variant-size { color: var(--fg-muted); font: 400 0.875rem/1.25rem var(--font); text-align: right; }
.variant-meta { grid-column: 2 / -1; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; color: var(--fg-muted); font: 400 0.875rem/1.25rem var(--font); }

.variant input:checked + .variant-card { background: var(--surface-active); border-color: var(--border-control-hover); }
.variant input:checked + .variant-card .radio { background: var(--primary); border-color: var(--primary); }
.variant input:checked + .variant-card .radio::after { opacity: 1; }
.variant input:focus-visible + .variant-card { outline: var(--focus-ring-width) solid var(--primary); outline-offset: var(--focus-ring-offset); }
.variant input:active + .variant-card { background: var(--surface-active); }

/* ---------- Sampling settings (accordion) ---------- */

.settings { border-top: 1px solid var(--border); padding-top: 0.5rem; }
.settings summary {
  display: flex; align-items: center; justify-content: space-between;
  min-height: var(--control); cursor: pointer; list-style: none; user-select: none;
  font: 600 1rem/1.5rem var(--font);
}
.settings summary::-webkit-details-marker { display: none; }
.settings .chevron { color: var(--fg-muted); transition: transform var(--fast); }
.settings[open] .chevron { transform: rotate(180deg); }

.sliders { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem 1.5rem; padding: 0.5rem 0 0.75rem; }
.slider { display: flex; flex-direction: column; gap: 0.375rem; }
.slider-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.slider-head label { font: 500 0.875rem/1.25rem var(--font); }
.slider-head output { color: var(--fg-muted); font: 400 0.875rem/1.25rem var(--font); }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: var(--control); margin: 0; background: transparent; cursor: pointer;
  --fill: 50%;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 0.375rem; border-radius: var(--l1);
  background: linear-gradient(to right, var(--primary) var(--fill), var(--fill-subtle-active) var(--fill));
}
input[type="range"]::-moz-range-track { height: 0.375rem; border-radius: var(--l1); background: var(--fill-subtle-active); }
input[type="range"]::-moz-range-progress { height: 0.375rem; border-radius: var(--l1); background: var(--primary); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 1.25rem; height: 1.25rem; margin-top: -0.4375rem; border-radius: 9999px;
  background: var(--primary); border: 0; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.6), 0 0 1px var(--hairline) inset;
}
input[type="range"]::-moz-range-thumb { width: 1.25rem; height: 1.25rem; border-radius: 9999px; background: var(--primary); border: 0; }

/* ---------- Actions ---------- */

.actions { display: flex; align-items: center; gap: 0.5rem; }
.actions .btn-solid, .actions .btn-outline { flex: 1 1 auto; }

.kbd-hint { display: none; align-items: center; gap: 0.25rem; color: var(--fg-muted); font: 400 0.875rem/1.25rem var(--font); }
kbd {
  display: inline-grid; place-items: center; min-width: 1.5rem; height: 1.5rem; padding: 0 0.375rem;
  font: 500 0.75rem/1 var(--code); color: var(--fg); background: var(--fill-subtle);
  border: 1px solid var(--border-control); border-radius: var(--l2);
}

/* ---------- Output ---------- */

.output { display: flex; flex-direction: column; gap: 1rem; }
.output-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; }
.output-title { display: flex; align-items: center; gap: 0.75rem; }
.output-tools { display: flex; gap: 0.5rem; }

.output-body {
  min-height: 14rem;
  max-height: 60dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1rem;
  border-radius: var(--l2);
  background: var(--fill-subtle);
  font: 400 1rem/1.5rem var(--font);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  scrollbar-width: thin;
  scrollbar-color: var(--border-control) transparent;
}
.output-body p { max-width: 65ch; }
.output-body .placeholder { color: var(--fg-muted); white-space: normal; }
.output-body .prompt-text { color: var(--fg-muted); }
.output-body .gen-text { color: var(--fg); }
.output-body .error-text { color: var(--error); }
.caret {
  display: inline-block; width: 0.5em; height: 1.1em; margin-left: 1px;
  vertical-align: text-bottom; background: var(--primary); border-radius: var(--l1);
  animation: blink 1s steps(2, start) infinite;
}

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; margin: 0; }
.stat { min-width: 0; padding: 0.75rem; border-radius: var(--l2); background: var(--fill-subtle); }
.stat dt { color: var(--fg-muted); font: 400 0.875rem/1.25rem var(--font); }
.stat dd { margin: 0.25rem 0 0; font: 600 1.25rem/1.875rem var(--font); white-space: nowrap; }
.stat small { margin-left: 0.25rem; color: var(--fg-muted); font: 400 0.875rem/1.25rem var(--font); }

/* ---------- Benchmarks ---------- */

.benchmarks { display: flex; flex-direction: column; gap: 1rem; }
.section-title { font: 600 1.5rem/2rem var(--font); }
.benchmarks .helper { max-width: 65ch; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--l3); }
.bench-table { width: 100%; min-width: 40rem; border-collapse: collapse; }
.bench-table th {
  padding: 0.75rem; text-align: left; white-space: nowrap;
  color: var(--fg); font: 600 0.75rem/1.125rem var(--font);
  border-bottom: 1px solid var(--border);
}
.bench-table td {
  padding: 0.75rem; vertical-align: middle;
  color: var(--fg-muted); font: 400 0.875rem/1.25rem var(--font);
  border-bottom: 1px solid var(--border);
}
.bench-table tr:last-child td { border-bottom: 0; }
.bench-build { display: flex; flex-direction: column; }
.bench-build strong { color: var(--fg); font-weight: 500; }

.progress { display: flex; align-items: center; gap: 0.75rem; min-width: 10rem; }
.progress-track { flex: 1; height: 0.625rem; border-radius: var(--l1); background: var(--fill-subtle); overflow: hidden; }
.progress-range { height: 100%; border-radius: var(--l1); background: var(--primary); }
.progress span { min-width: 4.5rem; text-align: right; color: var(--fg); }

/* ---------- Footer ---------- */

.footer { color: var(--fg-muted); font: 400 0.875rem/1.25rem var(--font); }
.footer p { max-width: 65ch; }

/* ---------- Bottom action bar (phones and tablets) ---------- */

.mobile-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-sticky);
  display: flex; gap: 0.5rem;
  padding:
    0.75rem
    max(var(--gutter), env(safe-area-inset-right))
    max(0.75rem, env(safe-area-inset-bottom))
    max(var(--gutter), env(safe-area-inset-left));
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.mobile-bar .btn { flex: 1 1 auto; }

/* ---------- Input mode ---------- */

@media (hover: hover) and (pointer: fine) {
  :root { --control: 2.5rem; }
  .links a:hover { color: var(--fg); background: var(--fill-subtle); }
  .btn-solid:hover { background: var(--primary-hover); }
  .btn-outline:hover { background: var(--fill-ghost); }
  .btn-plain:hover { background: var(--fill-subtle); }
  .variant:hover .variant-card { background: var(--surface-hover); border-color: var(--border-control-hover); }
  .variant input:checked + .variant-card { background: var(--surface-active); }
  textarea:hover { border-color: var(--border-control-hover); }
}

/* ---------- Breakpoints (mobile first) ---------- */

@media (min-width: 640px) {
  .variants { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .variants .variant:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .sliders { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 768px) {
  :root { --gutter: 1.5rem; }
  .hero h1 { font-size: 2.25rem; line-height: 2.75rem; letter-spacing: -0.02em; }
  .controls { max-width: none; }
}

@media (max-width: 1023.98px) {
  :root { --mobile-bar-h: calc(4.25rem + env(safe-area-inset-bottom)); }
  .actions { display: none; }
  .output { scroll-margin-top: 1rem; }
}

@media (min-width: 1024px) {
  :root { --gutter: 2rem; --gap: 1.5rem; }
  .mobile-bar { display: none; }
  .workspace { grid-template-columns: minmax(22rem, 26rem) minmax(0, 1fr); }
  .output {
    position: sticky; top: 1rem;
    height: calc(100dvh - 2rem); min-height: 32rem; max-height: 52rem;
  }
  .output-body { flex: 1; min-height: 0; max-height: none; }
  .variants .variant:last-child:nth-child(odd) { grid-column: auto; }
  .variants { grid-template-columns: minmax(0, 1fr); }
  .chips { flex-wrap: wrap; overflow: visible; }
  .kbd-hint { display: inline-flex; }
}

@media (min-width: 1280px) {
  .workspace { grid-template-columns: 28rem minmax(0, 1fr); }
}

/* TV and large screens: the screen is always 96rem wide, content stays inside a 5% safe margin. */
@media (min-width: 1920px) {
  html { font-size: calc(100vw / 96); }
  :root { --control: 2.75rem; --focus-ring-width: 0.2rem; --focus-ring-offset: 0.1rem; }
  .page { max-width: none; padding: 2.7rem 4.8rem; gap: 2rem; }
  .hero h1 { font-size: 3rem; line-height: 3.75rem; max-width: 26ch; }
  .workspace { grid-template-columns: 30rem minmax(0, 1fr); gap: 2rem; }
  .output { top: 2.7rem; height: calc(100dvh - 5.4rem); max-height: none; }
  .bench-table td, .bench-table th { padding: 1rem; font-size: 1rem; line-height: 1.5rem; }
  .helper, .footer, .variant-meta, .variant-size, .stat dt, .slider-head label, .slider-head output { font-size: 1rem; line-height: 1.5rem; }
  .actions .btn-solid { height: 3rem; font-size: 1rem; }
}

@keyframes blink { to { visibility: hidden; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
