/* The studio (signed-in app). */
body.app { min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar-in { max-width: 1240px; margin: 0 auto; padding: 0.6rem 1.25rem; display: flex; align-items: center; gap: 1rem; }
.brand { font: 700 1.25rem var(--serif); letter-spacing: -0.02em; text-decoration: none; display: inline-flex; align-items: center; gap: 0.5rem; }
.brand .dot { width: 0.8em; height: 0.8em; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 0.22em var(--accent-soft); }
.grow { flex: 1; }
.credits { cursor: pointer; border: 0; font: inherit; }
main.view { max-width: 1240px; margin: 0 auto; padding: 1.75rem 1.25rem 5rem; }
.crumbs { font-size: 0.9rem; color: var(--muted); margin-bottom: 0.75rem; }
.crumbs a { color: var(--muted); }
.page-head { display: flex; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.page-head h1 { margin: 0; }

.banner { display: flex; gap: 0.75rem; align-items: flex-start; padding: 0.85rem 1rem; border-radius: 10px; margin-bottom: 1.25rem; border: 1px solid var(--line); background: var(--surface-2); font-size: 0.93rem; }
.banner.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); color: var(--ink); }
.banner.err { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 30%, transparent); }
.banner strong { font-weight: 650; }

/* auth */
.auth { max-width: 420px; margin: 7vh auto 0; padding: 2rem; }
.auth h1 { font-size: 2rem; }
.auth .switch { margin-top: 1rem; text-align: center; font-size: 0.93rem; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.error-text { color: var(--err); font-size: 0.92rem; min-height: 1.4em; margin: 0.25rem 0 0.75rem; }

/* shows grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1.1rem; }
.show-card { display: flex; flex-direction: column; text-decoration: none; overflow: hidden; transition: transform 0.12s ease, box-shadow 0.12s ease; }
.show-card:hover { transform: translateY(-2px); }
.show-card img { width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--surface-2); display: block; }
.show-card .body { padding: 0.9rem 1rem 1.1rem; }
.show-card h3 { margin: 0 0 0.25rem; }
.empty { text-align: center; padding: 3.5rem 1.5rem; }
.empty h2 { margin-bottom: 0.4rem; }

/* show page */
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--line); margin-bottom: 1.5rem; }
.tab { background: none; border: 0; font: 600 0.95rem var(--sans); padding: 0.7rem 1rem; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.ep-row { display: flex; gap: 1rem; align-items: center; padding: 1rem 1.15rem; text-decoration: none; }
.ep-row + .ep-row { border-top: 1px solid var(--line); }
.ep-row:hover { background: var(--surface-2); }
.ep-no { font: 700 1.3rem var(--serif); color: var(--muted); width: 2.2rem; text-align: right; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.feedbox { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }
.feedbox code { flex: 1; min-width: 200px; padding: 0.7em 0.8em; }

/* wizard */
.wizard { max-width: 760px; }
.steps { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.step { display: inline-flex; gap: 0.5rem; align-items: center; font-size: 0.9rem; color: var(--muted); font-weight: 600; }
.step b { display: inline-grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 50%; background: var(--surface-2); color: var(--ink-2); font-size: 0.85rem; }
.step.on { color: var(--ink); }
.step.on b { background: var(--accent); color: var(--accent-ink); }
.step.done b { background: var(--ok-soft); color: var(--ok); }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; font: 600 0.9rem var(--sans); padding: 0.65em 1em; min-height: 42px; cursor: pointer; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.dropzone { border: 2px dashed var(--line-strong); border-radius: 12px; padding: 2rem 1rem; text-align: center; cursor: pointer; background: var(--surface); }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.preview { background: var(--surface-2); border-radius: 10px; padding: 0.9rem 1rem; font-size: 0.92rem; }
.preview p { margin: 0.4em 0 0; color: var(--ink-2); }
.range-row { display: flex; align-items: center; gap: 1rem; }
.range-row input[type=range] { flex: 1; accent-color: var(--accent); }
.range-val { font: 700 1.1rem var(--serif); min-width: 5.5ch; text-align: right; }
.check { display: flex; gap: 0.7rem; align-items: flex-start; font-weight: 400; }
.check input { margin-top: 0.3em; width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }

/* studio */
.studio { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 1.5rem; align-items: start; }
.studio-head input.title { font: 650 clamp(1.5rem, 3vw, 2rem) var(--serif); letter-spacing: -0.015em; border: 1px solid transparent; background: transparent; padding: 0.2em 0.3em; margin-left: -0.3em; min-height: 0; }
.studio-head input.title:hover { border-color: var(--line); }
.studio-head textarea.summary { border-color: transparent; background: transparent; padding: 0.3em; margin-left: -0.3em; color: var(--ink-2); min-height: 0; }
.studio-head textarea.summary:hover { border-color: var(--line); }
.savestate { font-size: 0.85rem; color: var(--muted); }
.turns { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 1rem; }
.chapter-mark { font: 700 0.78rem var(--sans); letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); margin: 1.1rem 0 -0.1rem 0.2rem; display: flex; gap: 0.5rem; align-items: center; }
.turn { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--line-strong); border-radius: 10px; padding: 0.7rem 0.8rem 0.6rem; transition: border-color 0.15s, background 0.15s; }
.turn.A { border-left-color: var(--accent); }
.turn.B { border-left-color: #3d6fd9; }
.turn.has-error { background: var(--err-soft); }
.turn.playing { box-shadow: 0 0 0 2px var(--focus); }
.turn-head { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 0.35rem; }
.turn-head select { width: auto; min-height: 32px; padding: 0.25em 0.5em; font-weight: 650; font-size: 0.88rem; border-radius: 8px; }
.turn-head .tools { margin-left: auto; display: flex; gap: 0.1rem; opacity: 0.55; }
.turn:hover .tools, .turn:focus-within .tools { opacity: 1; }
.icon { width: 32px; height: 32px; min-height: 32px; padding: 0; display: inline-grid; place-items: center; border-radius: 8px; border: 0; background: transparent; cursor: pointer; color: var(--ink-2); font-size: 0.95rem; }
.icon:hover { background: var(--surface-2); }
.turn textarea { border: 0; background: transparent; padding: 0.2em 0.1em; min-height: 0; font-size: 1.02rem; line-height: 1.55; resize: none; overflow: hidden; }
.turn textarea:focus { outline: none; }
.turn-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 0.4rem 0.8rem; font-size: 0.82rem; color: var(--muted); }
.cites { display: inline-flex; align-items: center; gap: 0.3rem; }
.cites input { width: 8.5ch; min-height: 26px; padding: 0.1em 0.4em; font-size: 0.82rem; border-radius: 6px; }
.chip { font: 600 0.78rem var(--sans); border: 1px solid var(--line-strong); background: var(--surface); border-radius: 999px; padding: 0.1em 0.6em; cursor: pointer; color: var(--ink-2); }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.flag { display: flex; gap: 0.6rem; align-items: flex-start; width: 100%; padding: 0.45rem 0.65rem; border-radius: 8px; font-size: 0.86rem; margin-top: 0.2rem; }
.flag.error { background: var(--err-soft); color: var(--err); }
.flag.warn { background: var(--warn-soft); color: var(--warn); }
.flag.kept { background: var(--surface-2); color: var(--muted); }
.flag .txt { flex: 1; color: var(--ink); }
.flag b { font-weight: 700; }
.add-row { display: flex; justify-content: center; }
.add-turn { opacity: 0; }
.turns:hover .add-turn, .add-turn:focus-visible { opacity: 0.7; }

.side { position: sticky; top: 4.5rem; display: flex; flex-direction: column; gap: 1rem; max-height: calc(100vh - 5.5rem); overflow: auto; padding: 2px; }
.panel { padding: 1.1rem 1.15rem; }
.panel h3 { font-size: 1.05rem; margin-bottom: 0.6rem; }
.kv { display: flex; justify-content: space-between; gap: 1rem; font-size: 0.92rem; padding: 0.25rem 0; }
.kv b { font-weight: 650; }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 0.6rem 0 0.3rem; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width 0.4s ease; }
.bar.indeterminate i { width: 35% !important; animation: slide 1.2s ease-in-out infinite alternate; }
@keyframes slide { from { margin-left: 0; } to { margin-left: 65%; } }
.passages { max-height: 340px; overflow: auto; display: flex; flex-direction: column; gap: 0.5rem; }
.passage { font-size: 0.86rem; border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem 0.65rem; background: var(--surface); }
.passage.hit { border-color: var(--accent); background: var(--accent-soft); }
.passage b { color: var(--accent); margin-right: 0.35rem; }
audio.player { width: 100%; margin: 0.4rem 0 0.8rem; }
.chapters-list { list-style: none; padding: 0; margin: 0 0 0.8rem; font-size: 0.9rem; }
.chapters-list button { background: none; border: 0; padding: 0.25rem 0; cursor: pointer; font: inherit; text-align: left; width: 100%; display: flex; gap: 0.7rem; }
.chapters-list button:hover { color: var(--accent); }
.chapters-list .t { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 3.2rem; }
.sidetabs { display: flex; gap: 0.25rem; }
.sidetabs .tab { padding: 0.5rem 0.75rem; font-size: 0.88rem; }
.writeup { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 0.75rem; }
.writeup header { display: flex; align-items: center; justify-content: space-between; padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--line); font-weight: 650; font-size: 0.9rem; }
.writeup pre { margin: 0; padding: 0.75rem; white-space: pre-wrap; word-wrap: break-word; font: 0.86rem/1.55 var(--sans); max-height: 260px; overflow: auto; }

.toast-wrap { position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 0.5rem; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; background: var(--ink); color: var(--bg); padding: 0.7rem 1rem; border-radius: 10px; font-size: 0.93rem; box-shadow: var(--shadow); max-width: min(92vw, 520px); }
.toast.err { background: var(--err); color: #fff; }

.modal-back { position: fixed; inset: 0; background: rgba(20, 15, 8, 0.5); display: grid; place-items: center; z-index: 40; padding: 1rem; }
.modal { max-width: 520px; width: 100%; padding: 1.5rem; max-height: 90vh; overflow: auto; }

.spinner { width: 1em; height: 1em; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; display: inline-block; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 980px) {
  .studio { grid-template-columns: 1fr; }
  .side { position: static; max-height: none; }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .topbar-in { padding: 0.5rem 0.9rem; gap: 0.5rem; }
  main.view { padding: 1.25rem 0.9rem 4rem; }
  .turn-head .tools { opacity: 1; }
  .add-turn { opacity: 0.7; }
}
