:root {
  --bg: #f6f6fb; --panel: #ffffff; --ink: #1d1d2b; --muted: #6b6b80; --line: #e2e2ee;
  --accent: #5b4bff; --accent-ink: #ffffff; --soft: #ecebff; --ok: #1a7f4b; --err: #c0392b; --warn: #b7791f;
  --shadow: 0 1px 3px rgba(20, 20, 50, .08), 0 8px 24px rgba(20, 20, 50, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12121c; --panel: #1b1b29; --ink: #ececf6; --muted: #9a9ab2; --line: #2c2c40;
    --accent: #8579ff; --accent-ink: #11111a; --soft: #26264a; --ok: #4cc38a; --err: #ff7b6b; --warn: #e5b04a;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  }
}
:root[data-theme="dark"] {
  --bg: #12121c; --panel: #1b1b29; --ink: #ececf6; --muted: #9a9ab2; --line: #2c2c40;
  --accent: #8579ff; --accent-ink: #11111a; --soft: #26264a; --ok: #4cc38a; --err: #ff7b6b; --warn: #e5b04a;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; display: flex; flex-direction: column; min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
.wrap { width: min(1100px, 100% - 32px); margin: 0 auto; padding: 24px 0 48px; }
.narrow { width: min(720px, 100% - 32px); }
header.top { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
header.top .logo { font-weight: 800; font-size: 18px; color: var(--ink); letter-spacing: -.02em; }
header.top .logo span { color: var(--accent); }
header.top nav { display: flex; gap: 14px; flex: 1; }
header.top nav a { color: var(--muted); font-weight: 500; }
header.top nav a:hover, header.top nav a.on { color: var(--ink); text-decoration: none; }
.chip { background: var(--soft); color: var(--accent); border-radius: 999px; padding: 3px 10px; font-weight: 600; font-size: 13px; }
button, .btn { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 8px; padding: 7px 12px; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { border-color: var(--accent); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--err); }
button.mini { padding: 2px 8px; font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }
input, textarea, select { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; color: var(--ink); box-shadow: var(--shadow); }
.tile:hover { border-color: var(--accent); text-decoration: none; }
.tile .thumb { aspect-ratio: 16 / 10; background: linear-gradient(135deg, var(--soft), var(--bg)); display: grid; place-items: center; font-size: 40px; overflow: hidden; }
.tile .thumb img { width: 100%; height: 100%; object-fit: cover; }
.tile .meta { padding: 10px 12px; }
.tile .meta b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .meta small, .muted { color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.grow > * { flex: 1; }
.note { margin: 8px 0; font-size: 14px; }
.note.ok { color: var(--ok); } .note.err { color: var(--err); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
.hero { text-align: center; padding: 64px 0 32px; }
.hero h1 { font-size: clamp(32px, 6vw, 56px); letter-spacing: -.03em; }
.hero p { color: var(--muted); font-size: 18px; max-width: 560px; margin: 0 auto 24px; }
.crumbs { display: flex; gap: 6px; align-items: center; margin-bottom: 12px; color: var(--muted); }
footer.bottom { margin-top: auto; padding: 16px; text-align: center; color: var(--muted); font-size: 13px; }
footer.bottom a { color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 8px 16px; border-radius: 999px; z-index: 50; }
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--ink); padding: 20px; width: min(440px, 92vw); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, .4); }
dialog label { display: block; margin: 10px 0 4px; font-weight: 600; }
dialog textarea, dialog input[type=text] { width: 100%; }

body.editor { height: 100vh; overflow: hidden; }
.bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.bar .title { font-weight: 700; border: 1px solid transparent; background: transparent; min-width: 120px; max-width: 280px; }
.bar .title:hover, .bar .title:focus { border-color: var(--line); background: var(--bg); }
.bar .spacer { flex: 1; }
.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 380px; }
.workspace.chat-hidden { grid-template-columns: 1fr 0; }
.stage { position: relative; background: #000; min-width: 0; }
.stage iframe { width: 100%; height: 100%; border: 0; display: block; background: #111; }
.overlay { position: absolute; inset: 0; background: rgba(10, 10, 20, .9); color: #fff; display: grid; place-content: center; text-align: center; gap: 12px; padding: 24px; }
.overlay[hidden] { display: none; }
.banner { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); background: var(--warn); color: #111; padding: 6px 12px; border-radius: 999px; z-index: 5; display: flex; gap: 10px; align-items: center; }
.banner[hidden], .hint[hidden] { display: none; }
.hint { position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); background: var(--panel); color: var(--ink); padding: 6px 12px; border-radius: 999px; z-index: 5; display: flex; gap: 8px; align-items: center; }
.chat { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-left: 1px solid var(--line); overflow: hidden; }
.chat-hidden .chat { display: none; }
#messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 92%; padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; }
.bubble.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); }
.bubble.assistant { align-self: flex-start; background: var(--bg); border: 1px solid var(--line); }
.bubble.error { align-self: center; background: transparent; border: 1px dashed var(--err); color: var(--err); }
.bubble .est, .bubble .status, .bubble .foot { color: var(--muted); font-size: 13px; }
.bubble .text:empty { display: none; }
form.compose { padding: 10px; border-top: 1px solid var(--line); display: flex; gap: 8px; align-items: flex-end; }
form.compose textarea { flex: 1; resize: none; max-height: 140px; }
.side { position: absolute; top: 0; right: 0; bottom: 0; width: min(340px, 90%); background: var(--panel); border-left: 1px solid var(--line); z-index: 6; overflow-y: auto; padding: 14px; box-shadow: var(--shadow); }
.side[hidden] { display: none; }
.side ul { list-style: none; padding: 0; margin: 0; }
.side li { padding: 8px 0; border-bottom: 1px solid var(--line); display: grid; gap: 4px; }
.side li.now { background: var(--soft); margin: 0 -8px; padding: 8px; border-radius: 8px; }
.side time { color: var(--muted); font-size: 12px; }
.player { display: grid; grid-template-rows: auto 1fr auto; height: calc(100vh - 54px); }
.player .stage { min-height: 300px; }
@media (max-width: 800px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: 55% 45%; }
  .workspace.chat-hidden { grid-template-rows: 1fr 0; }
  .chat { border-left: 0; border-top: 1px solid var(--line); }
}
[hidden] { display: none !important; }
.bubble div:empty { display: none; }
