/* 音坊 · 游戏音频工坊 — design tokens and components. Warm paper and ink like the image studio, teal for sound. */
:root {
  --bg: oklch(98.2% 0.011 75);
  --surface: oklch(100% 0 0);
  --surface-2: oklch(96.4% 0.016 75);
  --surface-3: oklch(93.5% 0.02 72);
  --ink: oklch(31% 0.03 40);
  --ink-soft: oklch(45% 0.03 40);
  --muted: oklch(55% 0.025 45);
  --line: oklch(90.5% 0.02 62);
  --line-strong: oklch(84% 0.03 60);
  --primary: oklch(50% 0.105 200);
  --primary-hover: oklch(45% 0.1 200);
  --primary-soft: oklch(95% 0.035 200);
  --primary-line: oklch(84% 0.06 200);
  --accent: oklch(80% 0.14 78);
  --accent-soft: oklch(96% 0.05 85);
  --success: oklch(52% 0.12 150);
  --success-soft: oklch(95.5% 0.04 150);
  --warning: oklch(58% 0.13 65);
  --warning-soft: oklch(96% 0.05 80);
  --danger: oklch(53% 0.17 27);
  --danger-soft: oklch(95.5% 0.03 27);
  --font: ui-rounded, "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  --text-xs: 12px; --text-sm: 14px; --text-md: 16px; --text-lg: 18px; --text-xl: 20px; --text-2xl: 24px; --text-3xl: 30px;
  --r-sm: 8px; --r-md: 12px; --r-lg: 18px; --r-pill: 999px;
  --shadow-1: 0 1px 2px oklch(31% 0.03 40 / 0.06);
  --shadow-2: 0 10px 30px -18px oklch(31% 0.03 40 / 0.35);
  --shadow-pop: 0 18px 50px -20px oklch(31% 0.04 40 / 0.45);
  --ease: cubic-bezier(.2, .8, .2, 1);
  --fast: 160ms;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.7 var(--font); }
a { color: var(--primary); text-underline-offset: 3px; }
h1, h2, h3, h4 { margin: 0; line-height: 1.35; font-weight: 700; }
p { margin: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--primary-line); outline-offset: 2px; border-radius: var(--r-sm); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: var(--text-sm); }
.tiny { font-size: var(--text-xs); }
.mono { font-family: var(--mono); font-size: 13px; word-break: break-all; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack { display: grid; gap: 12px; }

/* ---------- header ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: oklch(98.2% 0.011 75 / 0.86); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1240px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); flex-shrink: 0; }
.brand svg { width: 34px; height: 34px; }
.brand-name { font-size: var(--text-lg); font-weight: 800; letter-spacing: .02em; }
.brand-sub { font-size: var(--text-xs); color: var(--muted); display: block; line-height: 1.2; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { border: 0; background: transparent; color: var(--ink-soft); font: inherit; font-size: var(--text-sm); padding: 7px 14px; border-radius: var(--r-pill); cursor: pointer; white-space: nowrap; text-decoration: none; }
.tab:hover { background: var(--surface-2); color: var(--ink); }
.tab[aria-current="page"] { background: var(--ink); color: var(--surface); }
.tab .soon { font-size: 11px; color: var(--muted); margin-left: 4px; }
.tab[aria-current="page"] .soon { color: oklch(85% 0.02 60); }
.top-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-shrink: 0; }

/* GPU status pill */
.gpu-pill { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font: inherit; font-size: var(--text-sm); padding: 6px 12px; border-radius: var(--r-pill); cursor: pointer; }
.gpu-pill:hover { border-color: var(--ink-soft); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line-strong); flex-shrink: 0; }
.dot.ok { background: var(--success); }
.dot.busy { background: var(--accent); animation: pulse 1.4s var(--ease) infinite; }
.dot.bad { background: var(--danger); }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- layout ---------- */
main { max-width: 1240px; margin: 0 auto; padding: 20px 20px 64px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { font-size: var(--text-2xl); }
.page-head p { color: var(--ink-soft); font-size: var(--text-sm); }
.page-head .page-note { color: var(--muted); font-size: var(--text-xs); max-width: 360px; }
.studio { display: grid; grid-template-columns: minmax(340px, 420px) 1fr; gap: 24px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-1); }
.panel-body { padding: 20px; }
.panel h2 { font-size: var(--text-lg); }
/* The form scrolls inside itself when it is taller than the window, so「生成」never ends up out of reach. */
.sticky { position: sticky; top: 76px; max-height: calc(100dvh - 92px); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.section-title { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.section-title h2 { font-size: var(--text-lg); }

/* ---------- banners ---------- */
.banner { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--r-md); border: 1px solid var(--warning); background: var(--warning-soft); margin-bottom: 18px; }
.banner.info { border-color: var(--primary-line); background: var(--primary-soft); }
.banner strong { display: block; }
.banner .btn { margin-left: auto; flex-shrink: 0; }

/* ---------- form controls ---------- */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.label-row { display: flex; align-items: center; gap: 6px; font-size: var(--text-sm); font-weight: 600; color: var(--ink); }
.help-toggle { width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--line-strong); background: var(--surface); color: var(--muted); font: 600 12px/1 var(--font); cursor: pointer; padding: 0; }
.help-toggle[aria-expanded="true"] { background: var(--primary-soft); color: var(--primary); border-color: var(--primary-line); }
.help-text { font-size: var(--text-sm); color: var(--ink-soft); background: var(--surface-2); border-radius: var(--r-sm); padding: 8px 10px; }
input[type="text"], input[type="password"], input[type="number"], textarea, select {
  width: 100%; font: inherit; font-size: var(--text-md); color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-md); padding: 10px 12px; transition: border-color var(--fast) var(--ease);
}
textarea { resize: vertical; min-height: 80px; line-height: 1.6; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.field-note { font-size: var(--text-xs); color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.field-error { font-size: var(--text-sm); color: var(--danger); }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: var(--r-md); }
.segmented button { border: 0; background: transparent; font: inherit; font-size: var(--text-sm); color: var(--ink-soft); padding: 8px 6px; border-radius: var(--r-sm); cursor: pointer; line-height: 1.3; }
.segmented button small { display: block; font-size: 11px; color: var(--muted); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 700; box-shadow: var(--shadow-1); }

.range-row { display: flex; align-items: center; gap: 12px; }
.range-row input[type="range"] { flex: 1; accent-color: var(--primary); }
.range-row input[type="number"] { width: 92px; text-align: center; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: var(--r-md); font: inherit; font-size: var(--text-sm); font-weight: 600; padding: 9px 16px; cursor: pointer; transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease); text-decoration: none; min-height: 40px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-secondary:hover:not(:disabled) { border-color: var(--ink-soft); }
.btn-ghost { background: transparent; color: var(--ink-soft); padding: 6px 10px; min-height: 34px; }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--danger-soft); }
.btn-danger:hover:not(:disabled) { border-color: var(--danger); }
.btn-big { width: 100%; font-size: var(--text-md); min-height: 48px; border-radius: var(--r-md); }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-soft); display: inline-grid; place-items: center; cursor: pointer; padding: 0; font: 700 15px/1 var(--font); }
.icon-btn:hover { color: var(--ink); border-color: var(--ink-soft); }
.icon-btn svg { width: 18px; height: 18px; }
.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

details.advanced { border-top: 1px dashed var(--line-strong); padding-top: 12px; margin-bottom: 16px; }
details.advanced summary { cursor: pointer; font-size: var(--text-sm); font-weight: 600; color: var(--ink-soft); list-style: none; display: flex; align-items: center; gap: 6px; }
details.advanced summary::before { content: "▸"; transition: transform var(--fast) var(--ease); }
details.advanced[open] summary::before { transform: rotate(90deg); }
details.advanced .advanced-body { padding-top: 12px; }
.fixed-note { font-size: var(--text-xs); color: var(--muted); }
.form-foot { position: sticky; bottom: 0; z-index: 1; margin: 0 -20px -20px; padding: 14px 20px 20px; display: grid; gap: 6px; background: linear-gradient(to bottom, oklch(100% 0 0 / 0), var(--surface) 14px); }

/* ---------- templates ---------- */
.templates { display: grid; gap: 8px; margin-bottom: 14px; }
.template-tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--line); }
.template-tabs button { border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; background: transparent; font: inherit; font-size: var(--text-sm); color: var(--muted); padding: 4px 8px; cursor: pointer; }
.template-tabs button:hover { color: var(--ink); }
.template-tabs button[aria-pressed="true"] { color: var(--ink); font-weight: 700; border-bottom-color: var(--primary); }
.template-group { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 34px; }
.chip { border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font: inherit; font-size: var(--text-sm); padding: 5px 12px; border-radius: var(--r-pill); cursor: pointer; }
.chip:hover { border-color: var(--primary-line); background: var(--primary-soft); }
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip .loop-mark { font-size: 11px; opacity: .8; margin-left: 4px; }

/* ---------- jobs ---------- */
.job-list { display: grid; gap: 14px; }
.job { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px; box-shadow: var(--shadow-1); }
.job-head { display: flex; gap: 10px; align-items: flex-start; }
.job-title { font-weight: 700; font-size: var(--text-md); overflow-wrap: anywhere; }
.job-meta { font-size: var(--text-xs); color: var(--muted); }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-xs); font-weight: 700; padding: 3px 10px; border-radius: var(--r-pill); white-space: nowrap; background: var(--surface-2); color: var(--ink-soft); }
.status.running { background: var(--accent-soft); color: var(--warning); }
.status.done { background: var(--success-soft); color: var(--success); }
.status.error { background: var(--danger-soft); color: var(--danger); }
.job-error { margin-top: 10px; padding: 10px 12px; border-radius: var(--r-sm); background: var(--danger-soft); color: var(--danger); font-size: var(--text-sm); }
.variants { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; margin-top: 14px; }
.variant { border: 1px solid var(--line); border-radius: var(--r-md); padding: 10px; background: var(--surface-2); display: grid; gap: 8px; }
.variant-head { display: flex; align-items: center; gap: 8px; font-size: var(--text-xs); color: var(--muted); }
.variant-head > span > svg { width: 16px; height: 16px; display: block; color: var(--primary); }
.wave { height: 56px; border-radius: var(--r-sm); background: var(--surface); cursor: pointer; }
.wave.placeholder { display: grid; place-items: center; color: var(--muted); font-size: var(--text-xs); }
.play { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--ink); color: #fff; display: grid; place-items: center; cursor: pointer; flex-shrink: 0; }
.play svg { width: 14px; height: 14px; }
.play.loop-on { background: var(--primary); }
.variant-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.variant-actions a { font-size: var(--text-xs); font-weight: 700; text-decoration: none; padding: 3px 8px; border-radius: var(--r-pill); border: 1px solid var(--line-strong); color: var(--ink-soft); background: var(--surface); }
.variant-actions a:hover { color: var(--primary); border-color: var(--primary-line); }
.job-actions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.job-detail { margin-top: 10px; font-size: var(--text-sm); background: var(--surface-2); border-radius: var(--r-sm); padding: 10px 12px; display: grid; gap: 4px; }
.progress-line { height: 4px; border-radius: 4px; background: var(--surface-3); overflow: hidden; margin-top: 12px; }
.progress-line span { display: block; height: 100%; width: 40%; background: var(--accent); border-radius: 4px; animation: slide 1.6s var(--ease) infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(260%); } }
.empty { text-align: center; padding: 48px 20px; border: 1px dashed var(--line-strong); border-radius: var(--r-lg); color: var(--ink-soft); background: var(--surface); }
.empty svg { width: 56px; height: 56px; color: var(--primary-line); margin-bottom: 8px; }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; border-radius: var(--r-lg); height: 140px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- GPU drawer ---------- */
dialog { border: 0; padding: 0; border-radius: var(--r-lg); box-shadow: var(--shadow-pop); color: var(--ink); background: var(--surface); max-width: min(560px, calc(100vw - 24px)); width: 100%; }
dialog::backdrop { background: oklch(25% 0.02 40 / 0.35); }
.dialog-head { display: flex; align-items: center; gap: 12px; padding: 18px 20px 6px; }
.dialog-head h2 { font-size: var(--text-xl); }
.dialog-body { padding: 8px 20px 20px; display: grid; gap: 14px; }
.dialog-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 0 20px 20px; flex-wrap: wrap; }
.state-line { font-size: var(--text-md); font-weight: 600; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.steps li { display: flex; align-items: center; gap: 10px; font-size: var(--text-sm); color: var(--muted); }
.steps li::before { content: ""; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line-strong); flex-shrink: 0; box-sizing: border-box; }
.steps li.done { color: var(--ink-soft); }
.steps li.done::before { background: var(--success); border-color: var(--success); box-shadow: inset 0 0 0 3px var(--surface); }
.steps li.active { color: var(--ink); font-weight: 700; }
.steps li.active::before { border-color: var(--accent); border-right-color: transparent; animation: spin .9s linear infinite; }
.steps li.error { color: var(--danger); font-weight: 700; }
.steps li.error::before { background: var(--danger); border-color: var(--danger); }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.fact { background: var(--surface-2); border-radius: var(--r-md); padding: 10px 12px; }
.fact .label { font-size: var(--text-xs); color: var(--muted); }
.fact .value { font-size: var(--text-lg); font-weight: 700; font-variant-numeric: tabular-nums; }
.notice { font-size: var(--text-sm); padding: 10px 12px; border-radius: var(--r-sm); background: var(--surface-2); color: var(--ink-soft); }
.notice.error { background: var(--danger-soft); color: var(--danger); }
.notice.warn { background: var(--warning-soft); color: var(--warning); }

/* ---------- settings ---------- */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.settings-grid .wide { grid-column: 1 / -1; }
.setup-step { display: grid; grid-template-columns: 32px 1fr; gap: 12px; padding: 14px 0; border-top: 1px solid var(--line); }
.setup-step:first-of-type { border-top: 0; }
.step-badge { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; background: var(--surface-3); color: var(--ink-soft); }
.step-badge.ok { background: var(--success); color: #fff; }
.guide-list { margin: 8px 0 0; padding-left: 20px; display: grid; gap: 6px; font-size: var(--text-sm); color: var(--ink-soft); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.switch-row:first-of-type { border-top: 0; }
.switch { position: relative; width: 46px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; position: absolute; inset: 0; z-index: 1; }
.switch span { position: absolute; inset: 0; background: var(--line-strong); border-radius: var(--r-pill); transition: background var(--fast) var(--ease); }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform var(--fast) var(--ease); box-shadow: var(--shadow-1); }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 3px solid var(--primary-line); outline-offset: 2px; }
.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 280px; overflow: auto; }
.events li { font-size: var(--text-sm); display: grid; grid-template-columns: 92px 1fr; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.events li.error .msg { color: var(--danger); }
.meter { height: 8px; border-radius: 8px; background: var(--surface-3); overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--primary); }

/* ---------- help ---------- */
.help { max-width: 820px; display: grid; gap: 16px; }
.help .panel-body { display: grid; gap: 10px; }
.help h2 { font-size: var(--text-lg); }
.help ul, .help ol { margin: 0; padding-left: 22px; display: grid; gap: 6px; }
.help table { border-collapse: collapse; width: 100%; font-size: var(--text-sm); }
.help th, .help td { border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: left; vertical-align: top; }
.soon-card { max-width: 640px; }
.soon-card .panel-body { display: grid; gap: 10px; }

/* ---------- toast ---------- */
.toasts { position: fixed; z-index: 60; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; width: min(440px, calc(100vw - 24px)); }
.toast { background: var(--ink); color: var(--surface); padding: 12px 16px; border-radius: var(--r-md); box-shadow: var(--shadow-pop); font-size: var(--text-sm); animation: rise var(--fast) var(--ease); }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--success); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

/* ---------- login ---------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(400px, 100%); }
.login-card .brand { justify-content: center; margin-bottom: 18px; }
.login-card .brand svg { width: 48px; height: 48px; }

/* ---------- guide (driver.js) ---------- */
.driver-popover.yin-guide { font-family: var(--font); border-radius: var(--r-lg); color: var(--ink); max-width: 340px; }
.driver-popover.yin-guide .driver-popover-title { font-size: var(--text-md); font-family: var(--font); }
.driver-popover.yin-guide .driver-popover-description { font-size: var(--text-sm); line-height: 1.7; color: var(--ink-soft); font-family: var(--font); }
.driver-popover.yin-guide .driver-popover-footer button { font-family: var(--font); text-shadow: none; border-radius: var(--r-sm); padding: 5px 12px; }
.driver-popover.yin-guide .driver-popover-next-btn { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .studio, .settings-grid { grid-template-columns: 1fr; }
  .sticky { position: static; max-height: none; overflow: visible; }
  .form-foot { position: static; background: none; }
}
@media (max-width: 720px) {
  .topbar-inner { flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  .tabs { order: 3; width: 100%; margin: 0 -4px; }
  .tab { padding: 6px 11px; }
  .tab .soon { display: none; }
  .brand-sub { display: none; }
  main { padding: 16px 12px 48px; }
  .panel-body { padding: 16px; }
  .form-foot { margin: 0 -16px -16px; padding: 14px 16px 16px; }
  .variants { grid-template-columns: 1fr; }
  .events li { grid-template-columns: 1fr; gap: 0; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
