:root {
  color-scheme: dark;
  --background: #111312;
  --surface: #191c1a;
  --surface-raised: #202421;
  --border: #343a36;
  --text: #f0f2ef;
  --muted: #a7afa9;
  --accent: #d4a24c;
  --accent-strong: #f1bd5d;
  --danger: #ff8e86;
  --focus: #7ac6b0;
  --radius: 6px;
  font-family: Inter, "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; overflow: hidden; background: var(--background); color: var(--text); }

body { min-height: 100dvh; }

button, input, select, textarea { font: inherit; letter-spacing: 0; }

button, select { cursor: pointer; }

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.workspace-shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); height: 100dvh; }

.conversation-sidebar { display: grid; grid-template-rows: auto minmax(0, 1fr); min-width: 0; padding: 22px 14px; border-right: 1px solid var(--border); background: #151816; }
.conversation-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 0 4px 18px; }
.conversation-header h2 { margin: 0; font-size: 17px; letter-spacing: 0; }
.new-conversation { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 0 10px; font-size: 13px; font-weight: 700; }
.new-conversation span:first-child { color: var(--accent-strong); font-size: 19px; line-height: 1; }
.new-conversation:hover { border-color: var(--accent); }
.conversation-list { display: flex; flex-direction: column; gap: 4px; min-height: 0; overflow-y: auto; }
.conversation-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px; width: 100%; min-height: 48px; border: 0; border-radius: var(--radius); background: transparent; color: var(--muted); padding: 8px 10px; text-align: left; }
.conversation-item:hover { background: var(--surface); color: var(--text); }
.conversation-item[aria-current="true"] { background: var(--surface-raised); color: var(--text); }
.conversation-item strong { overflow: hidden; font-size: 13px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.conversation-item small { color: var(--muted); font-size: 11px; }

.app-shell { width: min(100% - 32px, 920px); height: 100%; min-width: 0; margin: 0 auto; overflow: hidden; }

.setup-view { height: 100%; overflow-y: auto; padding: 56px 0 64px; }

.setup-heading { display: flex; align-items: center; gap: 16px; margin-bottom: 40px; }

.setup-intro { max-width: 720px; margin: -16px 0 34px 64px; padding-left: 16px; border-left: 2px solid var(--accent); }
.setup-intro p { margin: 0 0 8px; color: var(--muted); font-size: 14px; line-height: 1.65; }
.setup-intro p:first-child { color: var(--text); font-family: "Noto Serif SC", "Songti SC", serif; font-size: 18px; }

.brand-mark { display: grid; place-items: center; width: 48px; height: 48px; border: 1px solid var(--accent); color: var(--accent-strong); font-family: "Noto Serif SC", serif; font-size: 24px; }

.eyebrow { margin: 0 0 6px; color: var(--accent); font-size: 12px; font-weight: 700; }

h1 { margin: 0; font-size: clamp(24px, 4vw, 34px); line-height: 1.2; letter-spacing: 0; }

.setup-form { display: grid; gap: 32px; }

fieldset { margin: 0; padding: 0 0 28px; border: 0; border-bottom: 1px solid var(--border); }

legend { margin-bottom: 18px; color: var(--muted); font-size: 14px; font-weight: 700; }

.field-grid { display: grid; gap: 16px; }
.field-grid-three { grid-template-columns: 1.2fr .7fr 1.4fr; }
.field-grid-two { grid-template-columns: .8fr 1.6fr; margin-top: 16px; }

label { display: grid; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 600; }

input, select, textarea { width: 100%; min-height: 48px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 11px 13px; }

input:hover, select:hover, textarea:hover { border-color: #505851; }

.primary-button { min-height: 50px; border: 0; border-radius: var(--radius); background: var(--accent); color: #19130a; font-weight: 800; }
.primary-button:hover { background: var(--accent-strong); }
button:disabled { cursor: wait; opacity: .48; }

.error-message { min-height: 20px; margin: -16px 0 0; color: var(--danger); font-size: 14px; }

.play-view { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto auto; height: 100%; padding: 24px 0 max(16px, env(safe-area-inset-bottom)); }

.scene-header { display: flex; justify-content: space-between; align-items: end; gap: 24px; padding: 4px 0 18px; border-bottom: 1px solid var(--border); }
.scene-header h1 { font-size: 22px; }
.scene-meta { display: flex; gap: 12px; color: var(--muted); font-size: 13px; }

.model-connection { border-bottom: 1px solid var(--border); }
.model-connection summary { display: flex; justify-content: space-between; align-items: center; min-height: 48px; color: var(--muted); cursor: pointer; font-size: 13px; font-weight: 700; list-style: none; }
.model-connection summary::-webkit-details-marker { display: none; }
.model-connection summary::after { content: "⌄"; margin-left: 10px; color: var(--accent); font-size: 18px; }
.model-connection[open] summary::after { transform: rotate(180deg); }
.model-connection summary span:first-child { flex: 1; }
.model-connection #key-status { color: var(--muted); font-size: 12px; font-weight: 500; }
.connection-fields { display: grid; grid-template-columns: 1.2fr .9fr .9fr; align-items: end; gap: 12px; padding: 0 0 14px; }
.connection-fields input { min-height: 44px; height: 44px; }
.connection-key { grid-column: 1 / 3; }
.connection-actions { display: flex; gap: 8px; }
.connection-actions button { min-height: 44px; }
.connection-save { min-height: 44px; border: 1px solid var(--accent); border-radius: var(--radius); background: transparent; color: var(--accent-strong); padding: 0 16px; font-weight: 700; white-space: nowrap; }
.connection-save:hover { background: rgba(212, 162, 76, .1); }
.connection-test { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 0 14px; font-weight: 700; white-space: nowrap; }
.connection-test:hover { border-color: var(--focus); }
.connection-result { grid-column: 1 / -1; min-height: 18px; margin: 0; color: var(--muted); font-size: 13px; }
.connection-result[data-status="success"] { color: var(--focus); }
.connection-result[data-status="error"] { color: var(--danger); }

.transcript { overflow-y: auto; min-height: 0; padding: 28px max(0px, calc((100% - 700px) / 2)) 36px; scrollbar-color: var(--border) transparent; }
.transcript p { max-width: 68ch; margin: 0 0 18px; font-family: "Noto Serif SC", "Songti SC", serif; font-size: 17px; line-height: 1.8; white-space: pre-wrap; }
.transcript .player-line { margin-left: auto; color: #ccd2cd; font-family: inherit; font-size: 15px; text-align: right; }
.transcript .system-line { color: var(--muted); font-family: inherit; font-size: 13px; font-style: normal; }
.transcript .typing-indicator { display: flex; align-items: center; gap: 8px; color: var(--muted); font-family: inherit; font-size: 13px; font-style: normal; }
.typing-dots { display: inline-flex; align-items: center; gap: 4px; min-width: 28px; }
.typing-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--focus); animation: typing-pulse 1.1s ease-in-out infinite; }
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }

@keyframes typing-pulse {
  0%, 60%, 100% { opacity: .28; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

.composer { display: grid; grid-template-columns: 1fr 48px; gap: 10px; padding-top: 14px; border-top: 1px solid var(--border); }
.composer textarea { resize: none; max-height: 144px; line-height: 1.5; }
.composer button { width: 48px; height: 48px; border: 0; border-radius: var(--radius); background: var(--accent); color: #19130a; font-size: 24px; font-weight: 800; }
.composer button:hover { background: var(--accent-strong); }
.play-view .error-message { margin: 6px 0 0; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

[hidden] { display: none !important; }

@media (max-width: 720px) {
  .workspace-shell { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .conversation-sidebar { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto; gap: 10px; padding: 9px 12px; border-right: 0; border-bottom: 1px solid var(--border); }
  .conversation-header { padding: 0; }
  .conversation-header > div { display: none; }
  .new-conversation { min-height: 38px; }
  .conversation-list { flex-direction: row; gap: 6px; overflow-x: auto; overflow-y: hidden; }
  .conversation-item { width: auto; min-width: 142px; min-height: 38px; padding: 6px 9px; }
  .app-shell { width: min(100% - 24px, 920px); }
  .setup-view { padding: 28px 0 40px; }
  .setup-heading { margin-bottom: 28px; }
  .setup-intro { margin: -8px 0 28px; }
  .field-grid-three, .field-grid-two { grid-template-columns: 1fr; }
  .scene-header { align-items: center; }
  .scene-meta { flex-direction: column; gap: 2px; text-align: right; }
  .connection-fields { grid-template-columns: 1fr; }
  .connection-key { grid-column: auto; }
  .connection-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .connection-save { width: 100%; }
  .transcript { padding: 22px 0 28px; }
  .transcript p { font-size: 16px; line-height: 1.75; }
}

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