:root {
  --bg: #ffffff;
  --panel: #fffefd;
  --panel-soft: #f7f5f0;
  --ink: #0f0f0e;
  --muted: #6b6b6b;
  --line: #dedede;
  --accent: #111111;
  --shadow: 0 24px 70px rgba(31, 29, 25, 0.08);
  --radius: 7px;
  --serif: Georgia, "Times New Roman", "Songti SC", "SimSun", serif;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
}

button,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.vertical-shell {
  height: 100vh;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(250px, 318px) minmax(0, 1fr);
  gap: clamp(28px, 4.6vw, 86px);
  padding: 22px clamp(30px, 4.2vw, 68px) 18px clamp(30px, 4vw, 64px);
}

.workflow-pane {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: clamp(16px, 2.5vh, 26px);
  padding: 0;
  overflow: visible;
}

.pane-header {
  display: grid;
  gap: 16px;
}

.pane-header > div {
  display: grid;
  gap: 10px;
}

.pane-header span,
.eyebrow {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
}

.pane-header h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(25px, 2.45vw, 34px);
  font-weight: 500;
  line-height: 1.12;
}

.pane-header strong {
  font-family: var(--serif);
  font-size: 22px;
  line-height: 1;
}

.flow-switcher {
  position: relative;
  display: inline-flex;
  width: fit-content;
  min-height: 34px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.flow-switcher::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 2px;
  width: calc((100% - 4px) / 2);
  height: calc(100% - 4px);
  border-radius: 5px;
  background: var(--ink);
  transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

.flow-switcher.is-review::before {
  transform: translateX(100%);
}

.flow-switch-option {
  position: relative;
  z-index: 1;
  min-width: 82px;
  min-height: 28px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  transition:
    background 180ms ease,
    color 180ms ease;
}

.flow-switch-option.active {
  color: #fff;
}

.vertical-flow {
  --flow-row: 54px;
  --flow-gap: 4px;
  --flow-track: 348px;
  position: relative;
  display: grid;
  grid-template-rows: repeat(7, var(--flow-row));
  align-content: start;
  gap: var(--flow-gap);
  overflow: visible;
  padding: 2px 0 0;
}

.vertical-flow::before {
  content: "";
  position: absolute;
  left: 16px;
  top: 29px;
  width: 2px;
  height: var(--flow-track);
  border-radius: 999px;
  background: var(--line);
}

.flow-node {
  position: relative;
  z-index: 1;
  border: 0;
  background: transparent;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  height: var(--flow-row);
  padding: 0;
  color: var(--muted);
  text-align: left;
}

.flow-dot {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--panel);
  border: 2px solid var(--line);
  font-family: var(--serif);
  font-size: 13px;
  font-weight: 700;
  transition:
    transform 220ms ease,
    background 220ms ease,
    color 220ms ease,
    border-color 220ms ease;
}

.flow-node.active .flow-dot {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.flow-node.active .flow-dot {
  transform: scale(1.08);
  animation: pulse 1.7s ease-in-out infinite;
}

.flow-name {
  display: grid;
  gap: 3px;
  line-height: 1.32;
}

.flow-name strong {
  color: var(--ink);
  font-size: 13px;
}

.flow-name span {
  color: var(--muted);
  display: block;
  font-size: 10px;
  overflow: visible;
  white-space: nowrap;
}

.update-meta {
  align-self: end;
  width: fit-content;
  max-width: 100%;
  margin: 0 0 2px;
  padding: 8px 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.4;
}

@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(15, 15, 14, 0);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(15, 15, 14, 0.1);
  }
}

.prompt-pane {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 42px minmax(0, 1fr);
  gap: 6px;
  align-items: stretch;
}

.topbar,
.drawer-header,
.prompt-card-header,
.editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  justify-content: flex-end;
}

.topbar-actions,
.prompt-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.genre-select-wrap,
.episode-switcher,
.creative-mode-switcher {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 42px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.genre-select-wrap {
  position: relative;
  width: clamp(176px, 16vw, 252px);
  padding: 0;
  overflow: hidden;
}

.genre-select-wrap::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  pointer-events: none;
  transform: translateY(-65%) rotate(45deg);
}

#genreSelect {
  width: 100%;
  min-height: 40px;
  border: 0;
  appearance: none;
  background: transparent;
  color: var(--ink);
  padding: 0 30px 0 12px;
  outline: none;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
}

.creative-mode-switcher.is-hidden {
  display: none;
}

.episode-option,
.creative-mode-option {
  min-height: 34px;
  border: 0;
  border-radius: 5px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  transition:
    background 180ms ease,
    color 180ms ease;
}

.episode-option.active,
.creative-mode-option.active {
  background: var(--ink);
  color: #fff;
}

.icon-button,
.primary-button,
.ghost-button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  min-height: 42px;
  border-radius: var(--radius);
  transition:
    transform 180ms ease,
    border-color 180ms ease,
    background 180ms ease,
    color 180ms ease,
    box-shadow 180ms ease;
}

.icon-button {
  width: 42px;
  display: inline-grid;
  place-items: center;
  padding: 0;
}

.primary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 15px;
  font-size: 13px;
  font-weight: 700;
}

.primary-button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.ghost-button {
  color: var(--muted);
}

.icon-button:hover,
.primary-button:hover,
.ghost-button:hover {
  transform: translateY(-1px);
  border-color: var(--ink);
  box-shadow: 0 8px 18px rgba(31, 29, 25, 0.1);
}

.primary-button:hover {
  background: #2a2927;
  color: #fff;
}

.monitor-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  width: min(100%, calc((100vh - 94px) * 1.24), 1120px);
  max-width: 1120px;
  align-self: center;
  justify-self: center;
  overflow: visible;
  cursor: copy;
}

.monitor-image {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  pointer-events: none;
}

.notepad-projection {
  position: absolute;
  left: 22.6%;
  top: 24.2%;
  width: 45.05%;
  height: 39.3%;
  overflow: hidden;
}

#promptPreview {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: auto;
  padding: 8px 12px 14px 22px;
  color: #111;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.46;
  font-family: "Courier New", "Noto Sans Mono", "SFMono-Regular", monospace;
  font-size: clamp(7px, 0.72vw, 12px);
  font-weight: 600;
  background: transparent;
  scrollbar-width: none;
}

#promptPreview::-webkit-scrollbar {
  display: none;
}

.manager-drawer {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

.manager-drawer.open {
  pointer-events: auto;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 25, 24, 0);
  transition: background 220ms ease;
}

.manager-drawer.open .drawer-backdrop {
  background: rgba(16, 25, 24, 0.42);
}

.drawer-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(860px, 100vw);
  height: 100%;
  background:
    radial-gradient(circle, rgba(15, 15, 14, 0.08) 1px, transparent 1.4px),
    var(--panel);
  background-size: 22px 22px;
  border-left: 1px solid var(--line);
  padding: 28px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 20px;
  transform: translateX(100%);
  transition: transform 320ms cubic-bezier(0.22, 1, 0.36, 1);
}

.manager-drawer.open .drawer-panel {
  transform: translateX(0);
}

.drawer-header h2 {
  margin: 0;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 8px;
}

.editor-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: 216px minmax(0, 1fr);
  gap: 18px;
}

.editor-tabs {
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  padding-right: 4px;
}

.editor-tab {
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--muted);
  border-radius: var(--radius);
  padding: 11px;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  text-align: left;
  transition:
    background 180ms ease,
    border-color 180ms ease,
    color 180ms ease;
}

.editor-tab span:first-child {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #fff;
  color: var(--ink);
  font-family: var(--serif);
  font-weight: 700;
  font-size: 12px;
}

.editor-tab span:last-child {
  overflow-wrap: anywhere;
  line-height: 1.35;
}

.editor-tab.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.editor-main {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
}

.editor-mode-switcher {
  justify-self: start;
}

.editor-mode-switcher:not(.is-hidden) {
  grid-row: 2;
}

.editor-mode-switcher:not(.is-hidden) + #promptEditor {
  grid-row: 3;
  min-height: min(470px, 58vh);
}

.editor-mode-switcher:not(.is-hidden) ~ .editor-footer {
  grid-row: 4;
}

.editor-main label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

#promptEditor {
  width: 100%;
  min-height: 0;
  height: 100%;
  min-height: min(520px, 64vh);
  resize: none;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  color: var(--ink);
  line-height: 1.7;
  outline: none;
}

#promptEditor:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 4px rgba(15, 15, 14, 0.08);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 40;
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius);
  padding: 10px 14px;
  box-shadow: var(--shadow);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

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

  .vertical-shell {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    padding: 18px;
    gap: 18px;
  }

  .workflow-pane {
    min-height: auto;
    gap: 12px;
  }

  .vertical-flow {
    grid-template-rows: none;
    grid-auto-flow: column;
    grid-auto-columns: 180px;
    gap: 8px;
    align-content: stretch;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 8px;
  }

  .vertical-flow::before {
    display: none;
  }

  .flow-node {
    grid-template-columns: 42px minmax(0, 1fr);
    height: auto;
    min-height: 58px;
    padding: 4px 0;
  }

  .flow-dot {
    width: 42px;
    height: 42px;
    font-size: 15px;
  }

  .editor-layout {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: center;
  }

  .topbar-actions {
    justify-content: flex-end;
  }

  .monitor-stage {
    width: min(100%, 760px);
    max-width: none;
  }

  .drawer-panel {
    padding: 18px;
  }
}

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