:root {
  --workspace-rail: 320px;
  --bg: #f5f4fa;
  --panel: #ffffff;
  --panel-2: #faf9fd;
  --field: #ffffff;
  --line: #e5e3ed;
  --line-2: #ccc8d8;
  --text: #202231;
  --muted: #70758a;
  --soft: #989cad;
  --blue: #6550df;
  --blue-2: #523cc6;
  --blue-soft: #f1efff;
  --green: #168866;
  --green-soft: #edf9f5;
  --amber: #c97919;
  --amber-soft: #fff7ea;
  --red: #cf3f4f;
  --red-soft: #fff1f3;
  --accent-border: #cec8ff;
  --focus-ring: rgba(101, 80, 223, .16);
  --shadow: 0 16px 40px rgba(40, 36, 66, .08);
  --radius-control: 9px;
  --radius-panel: 12px;
  --radius-modal: 16px;
}

body.dark {
  --bg: #11111a;
  --panel: #181821;
  --panel-2: #1e1e29;
  --field: #15151e;
  --line: #30303d;
  --line-2: #464657;
  --text: #f0eff7;
  --muted: #b1afc0;
  --soft: #858297;
  --blue: #9b8cff;
  --blue-2: #b4a9ff;
  --blue-soft: rgba(155, 140, 255, .14);
  --green: #63caa7;
  --green-soft: rgba(99, 202, 167, .12);
  --amber: #efb15f;
  --amber-soft: rgba(239, 177, 95, .12);
  --red: #ff8793;
  --red-soft: rgba(255, 135, 147, .12);
  --accent-border: #5b527f;
  --focus-ring: rgba(155, 140, 255, .2);
  --shadow: 0 18px 46px rgba(0, 0, 0, .28);
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  text-rendering: optimizeLegibility;
}

* {
  scrollbar-width: thin;
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-thumb {
  border-width: 2px;
}

button,
.primary-btn,
.secondary-btn,
.danger-btn,
.ghost-btn,
.icon-btn {
  font-weight: 600;
}

.primary-btn,
.secondary-btn,
.danger-btn,
.ghost-btn,
.icon-btn,
.input,
.textarea,
.select {
  border-radius: var(--radius-control);
}

.primary-btn {
  background: var(--blue);
  box-shadow: 0 6px 14px rgba(101, 80, 223, .16);
}

.primary-btn:hover {
  background: var(--blue-2);
  transform: translateY(-1px);
}

.primary-btn:active {
  transform: translateY(0);
}

.secondary-btn,
.ghost-btn,
.icon-btn {
  border-color: var(--line);
}

.secondary-btn:hover,
.ghost-btn:hover,
.icon-btn:hover {
  color: var(--blue);
  border-color: var(--accent-border);
  background: var(--blue-soft);
}

.icon-btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.icon-btn.project-danger:hover {
  border-color: color-mix(in srgb, var(--red) 28%, var(--line));
  background: var(--red-soft);
  color: var(--red);
}

.danger-btn {
  border-color: color-mix(in srgb, var(--red) 30%, var(--line));
}

.input,
.textarea,
.select {
  border-color: var(--line);
  background: var(--field);
}

.input:hover,
.textarea:hover,
.select:hover {
  border-color: var(--line-2);
}

.input:focus,
.textarea:focus,
.select:focus,
.preset-row input:focus,
.preset-row textarea:focus,
.repair-common-textarea:focus,
.repair-comment-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .01em;
}

.textarea {
  line-height: 1.75;
}

#authOverlay {
  background: rgba(245, 244, 250, .92);
  backdrop-filter: blur(14px);
}

body.dark #authOverlay {
  background: rgba(17, 17, 26, .92);
}

#authOverlay .auth-card,
#projectSettingsModal .auth-card {
  border-radius: var(--radius-modal);
  border-color: var(--line);
}

.app {
  height: auto;
  min-height: 100vh;
  grid-template-columns: var(--workspace-rail) minmax(0, 1fr);
  align-items: start;
  overflow: visible;
  background: var(--bg);
}

.app.sidebar-collapsed {
  grid-template-columns: 62px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
  background: var(--panel);
  border-color: var(--line);
}

.brand {
  height: 64px;
  padding: 12px 12px 12px 16px;
  border-color: var(--line);
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex-basis: 38px;
  border-radius: 11px;
  box-shadow: 0 5px 16px rgba(101, 80, 223, .16);
}

.brand h1 {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: .01em;
}

.brand-toggle {
  width: 32px;
  height: 32px;
  min-height: 32px;
  border-color: transparent;
}

.app.sidebar-collapsed .brand {
  height: 64px;
  padding: 12px;
}

.side-actions {
  padding: 14px 14px 10px;
}

.project-form {
  padding: 0;
  gap: 8px;
  border: 0;
  background: transparent;
}

.project-form .primary-btn,
.project-form .secondary-btn {
  min-height: 38px;
}

.project-tree-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 14px 8px 18px;
  color: var(--muted);
}

.project-tree-head > span {
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .02em;
}

.project-tree-head .button-row {
  gap: 2px;
}

.project-tree-head .icon-btn {
  width: 30px;
  height: 30px;
  min-height: 30px;
  border-color: transparent;
}

.project-list {
  flex: 1 1 auto;
  min-height: 150px;
  max-height: none;
  overflow-y: auto;
  padding: 0 12px 12px;
  border-bottom: 1px solid var(--line);
}

.project-nodes {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.project-tree-node {
  min-width: 0;
}

.project-item {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  width: 100%;
  min-height: 46px;
  margin: 0;
  padding: 6px 10px;
  border-color: transparent;
  border-radius: 9px;
  text-align: left;
}

.project-item:hover {
  border-color: var(--line);
  background: var(--panel-2);
}

.project-item.active {
  border-color: var(--accent-border);
  background: var(--blue-soft);
  box-shadow: none;
}

.project-chevron {
  width: 15px;
  height: 15px;
  color: var(--soft);
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  transition: transform .18s ease, color .18s ease;
}

.project-item.active .project-chevron {
  color: var(--blue);
  transform: rotate(90deg);
}

.project-row-copy {
  display: block;
  min-width: 0;
}

.project-title,
.project-meta {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-title {
  font-size: 13px;
  font-weight: 650;
}

.project-meta {
  margin-top: 2px;
  color: var(--soft);
  font-size: 10px;
  font-weight: 500;
}

.project-children-host {
  position: relative;
  margin: 2px 0 6px 17px;
  padding-left: 13px;
}

.project-children-host::before {
  position: absolute;
  inset: 0 auto 5px 0;
  width: 1px;
  background: var(--line);
  content: "";
}

.episode-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}

.episode-panel[hidden] {
  display: none;
}

.episode-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 0;
  overflow: visible;
  padding-right: 4px;
  scrollbar-gutter: stable;
}

.episode-row {
  flex: 0 0 auto;
  min-height: 36px;
  height: 36px;
  padding: 5px 44px 5px 10px;
  border-color: transparent;
  border-radius: 8px;
}

.episode-row:hover {
  border-color: var(--line);
  background: var(--panel-2);
}

.episode-row.active {
  border-color: var(--accent-border);
  background: var(--blue-soft);
  box-shadow: inset 2px 0 0 var(--blue);
}

.episode-no {
  font-size: 12px;
  font-weight: 650;
}

.episode-count {
  color: var(--soft);
  font-size: 10px;
  font-weight: 500;
}

.status {
  font-size: 10px;
  font-weight: 550;
}

.status::before {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--soft);
  content: "";
}

.status.done::before {
  background: var(--green);
}

.status.busy::before {
  background: var(--amber);
}

.status.ready {
  color: var(--blue);
}

.status.ready::before {
  background: var(--blue);
}

.status.draft {
  color: var(--amber);
}

.status.draft::before {
  background: var(--amber);
}

.status.empty {
  padding: 0;
  text-align: inherit;
}

.tree-empty {
  display: grid;
  gap: 4px;
  padding: 18px 10px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
  text-align: center;
}

.tree-empty strong {
  color: var(--text);
  font-size: 12px;
  font-weight: 650;
}

.tree-empty.compact {
  padding: 14px 6px 10px;
}

.project-cost-panel {
  padding: 10px 14px 14px;
}

.project-cost-panel .cost-panel {
  gap: 7px;
  padding: 11px 12px;
  border-color: var(--line);
  border-radius: 10px;
  background: var(--panel-2);
}

.cost-head strong {
  font-size: 11px;
  font-weight: 650;
}

.cost-model {
  max-width: 120px;
  overflow: hidden;
  color: var(--soft);
  font-size: 9px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cost-balance {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.cost-balance .stat-k {
  font-size: 11px;
}

.cost-balance .stat-v {
  color: var(--blue);
  font-size: 18px;
  font-weight: 650;
}

.cost-meta,
.cost-token-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--soft);
  font-size: 10px;
  line-height: 1.5;
}

.cost-meta strong,
.cost-token-meta strong {
  color: var(--muted);
  font-weight: 600;
}

.cost-meta .dot,
.cost-token-meta .dot {
  color: var(--line-2);
}

.app.sidebar-collapsed .project-tree-head {
  display: none;
}

.main {
  height: auto;
  min-height: 100vh;
  grid-template-rows: 64px auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  padding: 10px 18px 10px 22px;
  gap: 14px;
  border-color: var(--line);
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  backdrop-filter: blur(14px);
}

body.dark .topbar {
  background: color-mix(in srgb, var(--panel) 94%, transparent);
}

.top-title {
  flex: 1 1 320px;
}

.top-title h2,
.inline-title-input,
.episode-suffix {
  font-size: 16px;
  font-weight: 650;
}

.top-title p {
  margin-top: 1px;
  font-size: 11px;
}

.inline-title-input {
  border-radius: 6px;
}

.inline-title-input:focus {
  background: var(--blue-soft);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.top-actions {
  flex: 0 1 auto;
  gap: 6px;
  flex-wrap: nowrap;
}

.top-actions .secondary-btn,
.top-actions .ghost-btn {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
}

.user-badge {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  padding: 6px 11px;
  border-color: var(--accent-border);
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 11px;
  font-weight: 650;
}

.workspace {
  min-height: calc(100vh - 64px);
  grid-template-columns: minmax(0, 1fr) var(--workspace-rail);
  align-items: start;
  overflow: visible;
  gap: 14px;
  padding: 14px 14px 14px 28px;
  background: var(--bg);
}

.panel {
  border-color: var(--line);
  border-radius: var(--radius-panel);
  box-shadow: none;
}

.panel-head {
  min-height: 54px;
  padding: 12px 16px;
  border-color: var(--line);
}

.panel-head h3 {
  font-size: 14px;
  font-weight: 650;
}

.result-panel {
  grid-column: 1;
  min-height: calc(100vh - 92px);
  overflow: visible;
  background: var(--panel);
}

.editor-panel {
  grid-column: 2;
  position: sticky;
  top: 78px;
  max-height: calc(100vh - 92px);
  background: var(--panel);
}

.result-panel .panel-head h3::before {
  content: "正文 · ";
  color: var(--soft);
  font-weight: 500;
}

.run-status {
  color: var(--muted);
  font-size: 11px;
}

.output-wrap {
  flex: 0 0 auto;
  min-height: calc(100vh - 148px);
  overflow: visible;
  background: var(--panel-2);
}

.output-toolbar {
  min-height: 58px;
  padding: 10px 14px;
  border-color: var(--line);
  background: var(--panel);
}

.version-controls {
  flex-wrap: nowrap;
}

.version-controls label {
  font-weight: 600;
}

.version-select {
  width: min(210px, 26vw);
  min-width: 132px;
}

.output-toolbar .select,
.output-toolbar .secondary-btn,
.output-toolbar .ghost-btn {
  min-height: 34px;
  padding-block: 6px;
  font-size: 12px;
}

.output-toolbar .button-row {
  gap: 3px;
  flex-wrap: nowrap;
}

.output-toolbar .ghost-btn {
  border-color: transparent;
}

.output {
  flex: 0 0 auto;
  align-self: center;
  width: calc(100% - 36px);
  max-width: 860px;
  min-height: clamp(560px, calc(100vh - 230px), 760px);
  margin: 18px auto;
  padding: 34px 42px 72px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font-size: 16px;
  line-height: 1.9;
  box-shadow: 0 10px 30px rgba(40, 36, 66, .04);
  overflow: visible;
}

.output-editor {
  height: auto;
  overflow: hidden;
}

.output.placeholder {
  color: var(--soft);
}

.thinking-output,
.progress-panel {
  border-color: var(--line);
}

.progress-panel {
  background: var(--panel);
}

.progress-step {
  border-color: var(--line);
  background: var(--panel-2);
}

.progress-step.active {
  border-color: var(--accent-border);
  background: var(--blue-soft);
}

.progress-dot {
  box-shadow: 0 0 0 5px var(--focus-ring);
}

.editor-panel .panel-body {
  padding: 15px 16px 18px;
}

.editor-grid {
  gap: 12px;
}

.stats-panel {
  padding: 0 0 13px;
  border-bottom: 1px solid var(--line);
}

.stats-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
}

.stats-grid .stat-tile {
  padding: 2px 12px;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.stats-grid .stat-tile:first-child {
  padding-left: 0;
  border-right: 1px solid var(--line);
}

.stats-grid .stat-k {
  font-size: 10px;
}

.stats-grid .stat-v {
  margin-top: 2px;
  color: var(--blue);
  font-size: 20px;
  font-weight: 650;
}

.episode-config-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.episode-config-grid .field {
  min-width: 0;
}

.episode-config-grid .field > label,
.episode-config-grid .field-label-row {
  height: 26px;
  min-height: 26px;
}

.episode-config-grid .field > label {
  display: flex;
  align-items: center;
}

.episode-config-grid .select {
  width: 100%;
  height: 42px;
  min-height: 42px;
}

.field-label-row {
  min-height: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.field-icon-btn {
  width: 26px;
  min-width: 26px;
  min-height: 24px;
  height: 24px;
  padding: 0;
  font-size: 11px;
}

#episodeEditor .field:has(#episodeSynopsisInput) {
  min-height: 0;
}

#episodeSynopsisInput {
  height: clamp(180px, 26vh, 260px);
  min-height: 180px !important;
  max-height: 38vh;
  padding: 12px 13px;
}

#episodeEditor .context-row {
  justify-content: space-between;
  padding: 1px 0;
  color: var(--muted);
  line-height: 1.6;
}

#episodeEditor .context-row input {
  border-color: var(--line);
  border-radius: 7px;
}

#episodeEditor .episode-context-row {
  justify-content: flex-start;
  gap: 6px;
  white-space: nowrap;
}

#episodeEditor .episode-context-row input {
  margin-left: auto;
}

.context-availability {
  margin-left: 4px;
  color: var(--soft);
  font-variant-numeric: tabular-nums;
}

#episodeEditor > .button-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

#episodeEditor > .generation-action-row {
  grid-template-columns: minmax(0, 1fr) minmax(110px, 1fr);
}

.generation-count-control {
  min-width: 0;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 5px 9px;
  background: color-mix(in srgb, var(--panel) 82%, var(--blue-soft));
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.generation-count-control input {
  width: 54px;
  min-height: 30px;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 3px 5px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.generation-count-control input:focus {
  outline: 0;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.generation-count-control input:disabled {
  cursor: not-allowed;
  opacity: .6;
}

.repair-canvas-actions {
  height: auto;
  min-height: 60px;
}

.repair-canvas-actions .repair-generation-count {
  margin-left: auto;
}

#generateEpisodeBtn {
  min-height: 42px;
}

.repair-box {
  margin-top: 2px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  gap: 9px;
}

.repair-box::before {
  content: none;
}

.repair-box-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.repair-box-head strong {
  color: var(--text);
  font-size: 12px;
  font-weight: 650;
}

.repair-box-head span {
  color: var(--soft);
  font-size: 10px;
}

#toggleRepairCanvasBtn {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-color: var(--accent-border);
  background: var(--panel);
  color: var(--text);
}

#toggleRepairCanvasBtn:hover {
  border-color: var(--accent-border);
  background: var(--blue-soft);
  color: var(--blue);
}

.context-pill,
.tab-btn.active {
  border-color: var(--accent-border);
}

.tab-btn {
  font-weight: 600;
}

.preset-picker-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.preset-picker-row .select {
  min-width: 0;
  flex: 1 1 auto;
}

.preset-picker-row .secondary-btn {
  flex: 0 0 auto;
  min-height: 38px;
  white-space: nowrap;
}

.parameter-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  align-items: center;
  gap: 10px;
}

.parameter-control .input {
  width: 112px;
}

.parameter-range {
  width: 100%;
  min-width: 0;
  margin: 0;
  cursor: pointer;
  accent-color: var(--blue);
}

.parameter-range:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 3px;
}

.parameter-range:disabled {
  cursor: not-allowed;
  opacity: .5;
}

.field-help {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.parameter-field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.parameter-field-grid .field {
  min-width: 0;
}

.parameter-field-grid .field:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.parameter-field-grid .field label {
  min-height: 36px;
  display: flex;
  align-items: flex-end;
}

#swPanelApi {
  min-height: 392px;
}

.modal-bg {
  background: rgba(32, 34, 49, .32);
  backdrop-filter: blur(8px);
}

.modal {
  border-color: var(--line);
  border-radius: var(--radius-modal);
  box-shadow: var(--shadow);
}

.modal-head,
.modal-foot {
  border-color: var(--line);
}

.modal-head h3 {
  font-weight: 650;
}

.fullscreen-editor {
  background: var(--bg);
}

.fullscreen-head,
.fullscreen-foot {
  border-color: var(--line);
  background: var(--panel);
}

.fullscreen-body {
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  overflow: hidden;
  background: var(--panel-2);
}

.fullscreen-textarea {
  width: min(960px, 100%);
  height: 100%;
  max-height: 100%;
  margin: 0;
  padding: 44px 56px 100px;
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--panel);
  font-size: 16px;
  line-height: 1.95;
  box-shadow: 0 10px 32px rgba(40, 36, 66, .05);
}

.modal.repair-canvas-modal {
  border-radius: var(--radius-modal);
}

.repair-canvas-main,
.repair-canvas-sourcebar,
.repair-canvas-sidebar-head,
.repair-common-panel,
.repair-canvas-actions {
  border-color: var(--line);
}

.repair-comment-card {
  border-radius: 10px;
  box-shadow: 0 8px 22px rgba(40, 36, 66, .07);
}

.repair-comment-card.active {
  border-color: var(--blue);
  border-left-color: var(--blue);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.toast-item {
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.quick-chat-panel {
  position: fixed;
  z-index: 45;
  top: 78px;
  right: 16px;
  bottom: 16px;
  width: min(430px, calc(100vw - 32px));
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(34, 29, 64, .2);
}

.quick-chat-head {
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 12px 11px 15px;
  border-bottom: 1px solid var(--line);
}

.quick-chat-head h3 {
  margin: 0;
  font-size: 16px;
}

.quick-chat-head > div:first-child {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.quick-chat-model-label,
#quickChatModelLabel {
  overflow: hidden;
  color: var(--soft);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quick-chat-head-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.quick-chat-head-actions .ghost-btn {
  min-height: 30px;
  padding: 4px 7px;
  border-color: transparent;
  color: var(--muted);
  font-size: 13px;
}

.quick-chat-head-actions .icon-btn {
  width: 32px;
  min-height: 32px;
  font-size: 18px;
}

.quick-chat-switchers {
  display: grid;
  grid-template-columns: minmax(0, .9fr) auto minmax(0, 1.15fr);
  align-items: end;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.quick-chat-switch-field {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.quick-chat-switch-field > span {
  color: var(--soft);
  font-size: 11px;
  font-weight: 650;
}

.quick-chat-switch-field .select,
.quick-chat-switchers .secondary-btn {
  min-height: 38px;
  font-size: 13px;
}

.quick-chat-switch-field .select {
  width: 100%;
  min-width: 0;
  padding-inline: 9px 28px;
  text-overflow: ellipsis;
}

.quick-chat-switchers .secondary-btn {
  padding-inline: 11px;
  white-space: nowrap;
}

.quick-chat-messages {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  padding: 18px 15px 24px;
  background: color-mix(in srgb, var(--panel-2) 72%, var(--panel));
  scrollbar-gutter: stable;
}

.quick-chat-empty {
  min-height: 100%;
  display: grid;
  place-content: center;
  gap: 6px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.quick-chat-empty strong {
  color: var(--text);
  font-size: 17px;
}

.quick-chat-empty span {
  max-width: 250px;
  font-size: 13px;
  line-height: 1.6;
}

.quick-chat-message {
  max-width: 88%;
  display: grid;
  gap: 4px;
}

.quick-chat-message.user {
  align-self: flex-end;
  justify-items: end;
}

.quick-chat-message.assistant {
  align-self: flex-start;
  justify-items: start;
}

.quick-chat-role {
  padding: 0 3px;
  color: var(--soft);
  font-size: 11px;
  font-weight: 650;
}

.quick-chat-copy {
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 11px 11px 11px 4px;
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
  line-height: 1.65;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.quick-chat-message.user .quick-chat-copy {
  border-color: var(--blue);
  border-radius: 11px 11px 4px 11px;
  background: var(--blue);
  color: #fff;
}

.quick-chat-message.streaming .quick-chat-copy::after {
  display: inline-block;
  width: 5px;
  height: 13px;
  margin-left: 3px;
  border-radius: 2px;
  background: var(--blue);
  vertical-align: -2px;
  animation: quick-chat-caret 1s steps(2, end) infinite;
  content: "";
}

.quick-chat-message.interrupted .quick-chat-copy {
  border-color: color-mix(in srgb, var(--red) 24%, var(--line));
  color: var(--muted);
}

@keyframes quick-chat-caret {
  50% { opacity: .2; }
}

.quick-chat-composer {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

#quickChatInput {
  width: 100%;
  min-height: 76px;
  max-height: 160px;
  resize: vertical;
  padding: 10px 11px;
  font-size: 14px;
  line-height: 1.55;
}

.quick-chat-compose-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
}

.quick-chat-compose-actions > span {
  margin-right: auto;
  color: var(--soft);
  font-size: 11px;
}

.quick-chat-compose-actions .primary-btn,
.quick-chat-compose-actions .danger-btn {
  min-width: 66px;
  min-height: 34px;
  padding: 6px 12px;
  font-size: 13px;
}

@media (max-width: 1280px) {
  :root {
    --workspace-rail: 280px;
  }

  .app {
    grid-template-columns: var(--workspace-rail) minmax(0, 1fr);
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr) var(--workspace-rail);
  }

  .topbar {
    padding-inline: 16px;
  }

  .top-actions .secondary-btn,
  .top-actions .ghost-btn {
    padding-inline: 8px;
  }

  .output {
    padding-inline: 34px;
  }
}

@media (max-width: 1120px) {
  body {
    overflow-x: hidden;
    overflow-y: auto;
  }

  .app {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 228px minmax(0, 1fr);
  }

  .main {
    height: auto;
    min-height: 100vh;
  }

  .top-actions {
    max-width: 58%;
    justify-content: flex-start;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .top-actions::-webkit-scrollbar {
    display: none;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr);
    align-content: start;
    padding: 14px;
    overflow: visible;
  }

  .editor-panel {
    grid-column: 1;
    order: 1;
    position: static;
    max-height: none;
    min-height: 560px;
  }

  .result-panel {
    grid-column: 1;
    order: 2;
    min-height: 720px;
  }

  #episodeSynopsisInput {
    height: clamp(180px, 30vh, 240px);
    min-height: 180px !important;
  }
}

@media (max-width: 760px) {
  body {
    overflow: auto;
  }

  .app,
  .app.sidebar-collapsed {
    display: block;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .sidebar {
    position: static;
    height: auto;
    overflow: visible;
    min-height: 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand,
  .app.sidebar-collapsed .brand {
    height: 58px;
    padding: 10px 12px;
    justify-content: flex-start;
  }

  .app.sidebar-collapsed .brand-copy {
    display: block;
  }

  .app.sidebar-collapsed .brand-toggle {
    display: inline-flex;
    margin-left: auto;
  }

  .app.sidebar-collapsed .side-actions,
  .app.sidebar-collapsed .project-tree-head,
  .app.sidebar-collapsed .project-list,
  .app.sidebar-collapsed .project-cost-panel {
    display: none;
  }

  .app.sidebar-collapsed .brand-mark {
    cursor: default;
  }

  .side-actions {
    padding: 10px 12px 6px;
  }

  .project-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .project-list {
    flex: 0 0 auto;
    max-height: min(44dvh, 420px);
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 0 12px 12px;
  }

  .project-item {
    width: 100%;
    min-height: 46px;
    margin: 0;
  }

  .episode-panel {
    max-height: none;
  }

  .episode-list {
    flex-direction: column;
    gap: 3px;
    overflow: visible;
  }

  .episode-row {
    flex: 0 0 auto;
    width: 100%;
  }

  .project-cost-panel {
    padding: 0 12px 12px;
  }

  .project-cost-panel .cost-panel {
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
  }

  .cost-head {
    grid-column: 1 / -1;
  }

  .cost-token-meta {
    display: none;
  }

  .main {
    height: auto;
    min-height: 0;
    display: block;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: 58px;
    padding: 9px 12px;
    flex-direction: row;
    align-items: center;
  }

  .top-title {
    width: min(44vw, 210px);
    flex: 0 1 auto;
  }

  .top-title h2,
  .inline-title-input,
  .episode-suffix {
    font-size: 14px;
  }

  .top-actions {
    width: auto;
    max-width: none;
    flex: 1 1 auto;
    justify-content: flex-start;
    overflow-x: auto;
  }

  .workspace {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px;
    overflow: visible;
  }

  .quick-chat-panel {
    z-index: 40;
    inset: 58px 0 0;
    width: 100%;
    border-width: 1px 0 0;
    border-radius: 0;
  }

  .editor-panel {
    order: 1;
    min-height: 560px;
  }

  .result-panel {
    order: 2;
    min-height: 700px;
  }

  .panel-head {
    min-height: 50px;
  }

  .output-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .version-controls,
  .output-toolbar .button-row {
    width: 100%;
  }

  .version-select {
    width: auto;
    flex: 1;
  }

  .output-toolbar .button-row {
    justify-content: flex-start;
    overflow-x: auto;
  }

  .output {
    width: calc(100% - 20px);
    min-height: 520px;
    margin: 10px auto;
    padding: 28px 22px 72px;
    font-size: 15px;
  }

  .fullscreen-head {
    align-items: flex-start;
  }

  .fullscreen-actions {
    overflow-x: auto;
  }

  .fullscreen-textarea {
    width: 100%;
    margin: 0;
    padding: 28px 22px 88px;
  }
}

@media (max-width: 460px) {
  .quick-chat-switchers {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .quick-chat-switch-field:last-child {
    grid-column: 1 / -1;
  }

  .brand h1 {
    font-size: 16px;
  }

  .project-form {
    grid-template-columns: 1fr;
  }

  .top-title {
    width: 38vw;
  }

  .top-title p {
    display: none;
  }

  .top-actions .secondary-btn,
  .top-actions .ghost-btn {
    min-height: 40px;
  }

  .editor-panel {
    min-height: 600px;
  }

  #episodeSynopsisInput {
    height: 220px;
    min-height: 200px !important;
  }

  .episode-config-grid {
    grid-template-columns: 1fr;
  }

  #episodeEditor > .button-row {
    grid-template-columns: 1fr;
  }

  #episodeEditor > .generation-action-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .repair-canvas-actions .repair-generation-count {
    width: 100%;
    margin-left: 0;
  }

  .modal-bg {
    padding: 10px;
  }

  .modal {
    max-width: calc(100vw - 20px);
    border-radius: 12px;
  }

  .preset-picker-row {
    align-items: stretch;
    flex-direction: column;
  }

  .preset-picker-row .secondary-btn {
    width: 100%;
  }

  .parameter-field-grid {
    grid-template-columns: 1fr;
  }

  .parameter-field-grid .field:last-child:nth-child(odd) {
    grid-column: auto;
  }

  .parameter-field-grid .field label {
    min-height: 0;
  }
}
