/* Playground interface — shared styles
   Layout: top bar, model header with tabs, two-column playground
   (inputs on the left, sticky output on the right) that stacks on mobile. */

:root {
  --bg: #fbfbfa;
  --panel: #ffffff;
  --surface: #f3f3f1;
  --fg: #16161a;
  --muted: #6d6d75;
  --line: #e6e6e3;
  --accent: #e8380d;
  --accent-soft: #fde7e0;
  --accent-fg: #ffffff;
  --code-bg: #f4f4f2;
  --ok: #138a4b;
  --warn: #a35a00;
  --check-a: #ecece9;
  --check-b: #ffffff;
  --shadow: 0 1px 2px rgba(22, 22, 26, .04), 0 8px 24px rgba(22, 22, 26, .06);

  --sans: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --r: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0d10;
    --panel: #141418;
    --surface: #1b1b20;
    --fg: #ededf0;
    --muted: #9a9aa4;
    --line: #2a2a31;
    --accent: #ff5a2e;
    --accent-soft: #3a1a10;
    --accent-fg: #ffffff;
    --code-bg: #18181d;
    --ok: #3ccf86;
    --warn: #f0b54a;
    --check-a: #222228;
    --check-b: #18181d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d0d10;
  --panel: #141418;
  --surface: #1b1b20;
  --fg: #ededf0;
  --muted: #9a9aa4;
  --line: #2a2a31;
  --accent: #ff5a2e;
  --accent-soft: #3a1a10;
  --accent-fg: #ffffff;
  --code-bg: #18181d;
  --ok: #3ccf86;
  --warn: #f0b54a;
  --check-a: #222228;
  --check-b: #18181d;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
img { max-width: 100%; }
code, .mono { font-family: var(--mono); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.wrap {
  max-width: 1240px;
  margin: 0 auto;
  padding-left: max(20px, env(safe-area-inset-left, 0px));
  padding-right: max(20px, env(safe-area-inset-right, 0px));
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .wrap { display: flex; align-items: center; gap: 20px; padding-block: 12px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 15px; text-decoration: none; color: var(--fg); }
.brand-mark {
  width: 28px; height: 28px; flex: none; padding: 4px; border-radius: 9px;
  background: linear-gradient(145deg, #ff8a44, var(--accent) 68%, #ba2353);
  box-shadow: 0 2px 6px rgba(22, 22, 26, .14);
}
.topnav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.topnav a {
  color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 6px; font-size: 13.5px;
}
.topnav a:hover { color: var(--fg); background: var(--surface); }
.topnav a.active { color: var(--fg); background: var(--surface); font-weight: 500; }
.theme-btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--fg);
  border-radius: 8px; width: 34px; height: 34px; cursor: pointer; display: grid; place-items: center;
}
.theme-btn svg { width: 16px; height: 16px; }

/* ---------- model header ---------- */
.model-head .wrap { padding-block: 36px 0; }
.crumb { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: clamp(20px, 3vw, 26px); font-weight: 600; letter-spacing: -.01em; }
.avatar {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  color: #fff; font-size: 15px; font-weight: 600;
}
.avatar.video { background: linear-gradient(135deg, #6d4aff, #22c3a6); }
.avatar.image { width: auto; padding-inline: 10px; font-size: 11px; white-space: nowrap; background: linear-gradient(135deg, #16161a, #4b4b55); }
.crumb .owner { color: var(--muted); font-weight: 500; }
.badge {
  font-size: 11px; font-weight: 500; letter-spacing: .05em; text-transform: uppercase;
  border-radius: 999px; padding: 3px 9px; background: var(--accent-soft); color: var(--accent);
}
.desc { max-width: 70ch; color: var(--muted); margin: 12px 0 0; font-size: 15.5px; text-wrap: pretty; }
.meta { display: flex; gap: 18px; color: var(--muted); font-size: 13px; margin-top: 14px; flex-wrap: wrap; }
.meta span { display: inline-flex; align-items: center; gap: 6px; }
.meta b { color: var(--fg); font-weight: 600; font-variant-numeric: tabular-nums; }
.meta svg { width: 14px; height: 14px; }

.tabs { display: flex; gap: 2px; margin-top: 24px; border-bottom: 1px solid var(--line); overflow-x: auto; position: relative; }
.tabs button {
  background: none; border: 0; padding: 11px 14px; font: inherit; color: var(--muted);
  cursor: pointer; white-space: nowrap; position: relative;
}
.tabs button:hover { color: var(--fg); }
.tabs button[aria-selected="true"] { color: var(--fg); font-weight: 500; }
.tab-ink { position: absolute; bottom: -1px; height: 2px; background: var(--fg); transition: left .25s ease, width .25s ease; }

/* ---------- playground ---------- */
.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  gap: 28px;
  padding-block: 28px 64px;
  align-items: start;
}
@media (max-width: 900px) { .grid { grid-template-columns: minmax(0, 1fr); } }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); min-width: 0; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.card-head h2 { font-size: 15px; margin: 0; font-weight: 600; }
.card-body { padding: 20px 18px; }
.out-card { position: sticky; top: 76px; }
@media (max-width: 900px) { .out-card { position: static; } }

.seg { display: inline-flex; background: var(--surface); border-radius: 8px; padding: 3px; gap: 2px; }
.seg button {
  background: none; border: 0; padding: 4px 11px; font: inherit; font-size: 12.5px; color: var(--muted);
  cursor: pointer; border-radius: 6px;
}
.seg button[aria-pressed="true"] { background: var(--panel); color: var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* fields */
form { display: flex; flex-direction: column; gap: 24px; }
.field { display: flex; flex-direction: column; gap: 7px; }
.lbl { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.lbl label, .lbl .name { font-family: var(--mono); font-weight: 500; font-size: 13px; }
.type { font-family: var(--mono); font-size: 11px; color: var(--muted); background: var(--surface); padding: 1px 6px; border-radius: 4px; }
.req { color: var(--accent); font-size: 12px; font-weight: 600; }
.help { color: var(--muted); font-size: 12.5px; margin: 0; }
.help.warn { color: var(--warn); }

input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%; font: inherit; color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px;
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 112px; resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.counter { align-self: flex-end; font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: -4px; }

/* option pills (enums) */
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pills input { position: absolute; opacity: 0; pointer-events: none; }
.pills label {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg); border-radius: 8px;
  padding: 6px 12px; font-size: 13px; font-family: var(--mono); color: var(--muted);
  transition: border-color .15s, background .15s, color .15s;
}
.pills label:hover { color: var(--fg); border-color: color-mix(in srgb, var(--fg) 25%, var(--line)); }
.pills input:checked + label { border-color: var(--accent); background: var(--accent-soft); color: var(--fg); }
.pills input:focus-visible + label { outline: 2px solid var(--accent); outline-offset: 2px; }
.ar-shape { display: inline-block; border: 1.5px solid currentColor; border-radius: 2px; }

/* slider */
.rangerow { display: flex; gap: 14px; align-items: center; }
.rangerow input[type=range] { flex: 1; accent-color: var(--accent); }
.rangerow input[type=number] { width: 76px; text-align: center; }
.ticks { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 10.5px; color: var(--muted); padding-right: 90px; }

/* file drop zone */
.drop {
  border: 1.5px dashed var(--line); border-radius: 10px; padding: 22px 16px; text-align: center;
  color: var(--muted); cursor: pointer; background: var(--surface);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop svg { width: 22px; height: 22px; }
.drop small { font-size: 11.5px; }
.drop .preview { max-height: 130px; border-radius: 6px; }
.drop .x { font-size: 12px; text-decoration: underline; cursor: pointer; background: none; border: 0; color: var(--muted); }
.thumbs { display: flex; flex-wrap: wrap; gap: 10px; }
.thumbs figure { margin: 0; position: relative; width: 78px; }
.thumbs img { width: 78px; height: 78px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; }
.thumbs figcaption { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: 3px; }
.thumbs button {
  position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--panel); background: var(--fg); color: var(--bg); font-size: 12px; line-height: 1; cursor: pointer; padding: 0;
}

details.adv { border-top: 1px solid var(--line); padding-top: 16px; }
details.adv summary { cursor: pointer; font-weight: 500; color: var(--muted); list-style: none; display: flex; align-items: center; gap: 6px; }
details.adv summary::before { content: "›"; display: inline-block; transition: transform .2s; font-size: 16px; }
details.adv[open] summary::before { transform: rotate(90deg); }
details.adv > .inner { display: flex; flex-direction: column; gap: 24px; margin-top: 18px; }

.actions {
  display: flex; gap: 8px; justify-content: flex-end; align-items: center;
  position: sticky; bottom: 0; background: var(--panel);
  margin: 0 -18px -20px; padding: 14px 18px calc(14px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line); border-radius: 0 0 var(--r) var(--r);
}
.actions .cost { margin-right: auto; font-size: 12px; color: var(--muted); font-family: var(--mono); }
.btn {
  font: inherit; font-weight: 500; border-radius: 8px; padding: 9px 16px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel); color: var(--fg);
  display: inline-flex; align-items: center; gap: 8px; transition: transform .1s, filter .15s;
}
.btn:hover { filter: brightness(.97); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.primary:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .6; cursor: progress; }
.kbd { font-family: var(--mono); font-size: 11px; opacity: .75; border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* output */
.stage {
  aspect-ratio: 16/9; max-width: 100%; border-radius: 8px; overflow: hidden; position: relative;
  background: var(--surface); transition: aspect-ratio .3s ease;
}
.stage canvas { width: 100%; height: 100%; display: block; }
.stage .play {
  position: absolute; left: 12px; bottom: 12px; display: flex; align-items: center; gap: 10px;
  background: rgba(0,0,0,.55); color: #fff; border-radius: 999px; padding: 5px 12px 5px 6px; font-size: 12px; font-family: var(--mono);
}
.stage .play button { width: 26px; height: 26px; border-radius: 50%; border: 0; background: #fff; color: #111; cursor: pointer; display: grid; place-items: center; }
.stage .play svg { width: 12px; height: 12px; }

.gallery { display: grid; gap: 10px; grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr)); }
.tile {
  border-radius: 8px; overflow: hidden; position: relative; border: 1px solid var(--line);
  background: repeating-conic-gradient(var(--check-a) 0 25%, var(--check-b) 0 50%) 0 0 / 16px 16px;
}
.tile canvas, .tile img { width: 100%; height: auto; display: block; transition: filter .4s, opacity .4s; }
.tile.loading canvas { opacity: .3; filter: blur(8px); }
.tile .num {
  position: absolute; top: 8px; left: 8px; font-family: var(--mono); font-size: 11px;
  background: rgba(0,0,0,.55); color: #fff; border-radius: 4px; padding: 1px 6px;
}

.bar { height: 4px; background: var(--surface); border-radius: 2px; margin-top: 14px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 2px; }
.status { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; color: var(--muted); margin-top: 10px; gap: 8px; flex-wrap: wrap; }
.pill-status { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.pill-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-status.ok { color: var(--ok); }
.pill-status.run { color: var(--accent); }
.pill-status.err { color: var(--warn); }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 18px 0 0; }
.stats div { background: var(--surface); border-radius: 8px; padding: 10px 12px; min-width: 0; }
.stats dt { font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.stats dd { margin: 2px 0 0; font-family: var(--mono); font-variant-numeric: tabular-nums; font-weight: 500; }

.logs-toggle { margin-top: 16px; background: none; border: 0; color: var(--muted); font: inherit; font-size: 12.5px; cursor: pointer; padding: 0; }
.logs {
  margin-top: 8px; background: var(--code-bg); border-radius: 8px; padding: 12px 14px;
  font-family: var(--mono); font-size: 12px; max-height: 180px; overflow: auto; white-space: pre-wrap; color: var(--muted);
}

/* secondary panels */
.panel { padding-block: 28px 64px; }
.code-wrap { position: relative; }
pre.code {
  background: var(--code-bg); border: 1px solid var(--line); border-radius: var(--r);
  padding: 18px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px; line-height: 1.7; margin: 0;
}
pre.code .k { color: var(--accent); }
pre.code .s { color: var(--ok); }
pre.code .kk { color: var(--fg); font-weight: 500; }
.copy { position: absolute; top: 10px; right: 10px; padding: 5px 10px; font-size: 12px; }
.panel .card-head { border: 0; padding: 0 0 14px; }

.readme { max-width: 72ch; }
.readme h2 { font-size: 22px; margin: 0 0 8px; letter-spacing: -.01em; }
.readme h3 { font-size: 15px; margin: 26px 0 8px; }
.readme li { margin: 5px 0; }
.readme code { background: var(--code-bg); padding: 1px 6px; border-radius: 4px; font-size: 12.5px; }

.ex { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; }
.ex button {
  all: unset; cursor: pointer; display: flex; flex-direction: column; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 10px; transition: transform .15s, box-shadow .15s;
}
.ex button:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.ex button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ex canvas { width: 100%; border-radius: 6px; display: block; }
.ex img { width: 100%; aspect-ratio: 1; object-fit: contain; background: var(--surface); border-radius: 6px; display: block; }
.ex p { margin: 0; font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ex .tag { font-family: var(--mono); font-size: 11px; color: var(--muted); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 13px;
  box-shadow: var(--shadow); z-index: 50; display: none;
}

@media (max-width: 520px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .topnav a:not(.active) { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* output: JSON view */
.out-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
pre.out-json { max-height: 560px; overflow: auto; font-size: 12px; }
