:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --sidebar: #1c1f26;
  --sidebar-2: #252a33;
  --sidebar-text: #d7dde8;
  --sidebar-muted: #8b93a7;
  --accent: #5b8def;
  --accent-2: #3d6fd8;
  --border: #e6e8ee;
  --text: #1a1d24;
  --muted: #6b7280;
  --danger: #c23b3b;
  --shadow: 0 10px 30px rgba(20, 24, 36, 0.08);
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg);
}

.hidden { display: none !important; }

.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 500px at 10% -10%, #dfe8ff 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, #efe8ff 0%, transparent 50%),
    var(--bg);
}
.login-card {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 28px 22px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
}
.login-brand {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.login-sub { margin: -4px 0 8px; color: var(--muted); font-size: 13px; }
.login-card label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}
.login-card input {
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 12px;
  font-size: 15px;
  color: var(--text);
  background: #fafbfc;
}
.login-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 141, 239, 0.18);
  background: #fff;
}
.login-card button {
  margin-top: 6px;
  height: 42px;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.login-card button:hover { filter: brightness(1.05); }
.login-error { min-height: 18px; margin: 0; color: var(--danger); font-size: 13px; }

.app {
  display: grid;
  grid-template-columns: 300px 1fr;
  height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, var(--sidebar), #161920);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid #0f1218;
}
.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 16px 14px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.brand { display: flex; gap: 10px; align-items: center; min-width: 0; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #c9a227, #8b1e2d);
  color: #fff8e7; font-weight: 700; flex: 0 0 auto;
}
.brand-title { font-weight: 700; font-size: 15px; }
.brand-sub { color: var(--sidebar-muted); font-size: 11px; margin-top: 2px; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  background: var(--sidebar-2); color: var(--sidebar-text);
  cursor: pointer;
}
.icon-btn:hover { background: #303746; }

.tree {
  flex: 1;
  overflow: auto;
  padding: 10px 8px 16px;
  font-size: 13px;
}
.tree::-webkit-scrollbar { width: 8px; }
.tree::-webkit-scrollbar-thumb { background: #3a4150; border-radius: 8px; }

.tree-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  color: var(--sidebar-text);
}
.tree-item:hover { background: rgba(255,255,255,0.05); }
.tree-item.active { background: rgba(91,141,239,0.22); color: #fff; }
.tree-item .twisty {
  width: 16px; text-align: center; color: var(--sidebar-muted); flex: 0 0 auto;
}
.tree-item .iname {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tree-children { margin-left: 12px; border-left: 1px solid rgba(255,255,255,0.06); padding-left: 4px; }
.tree-children.collapsed { display: none; }
.badge {
  margin-left: auto;
  font-size: 10px;
  color: var(--sidebar-muted);
  text-transform: uppercase;
}

.sidebar-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid rgba(255,255,255,0.06);
  color: var(--sidebar-muted);
  font-size: 12px;
}
.sidebar-foot button {
  border: 1px solid rgba(255,255,255,0.1);
  background: transparent;
  color: var(--sidebar-text);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}
.sidebar-foot button:hover { background: rgba(255,255,255,0.06); }

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}
.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 20px;
  background: rgba(255,255,255,0.86);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.crumb {
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ghost-btn {
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
}
.ghost-btn:hover { border-color: #c9d0dc; }

.viewer {
  flex: 1;
  overflow: auto;
  padding: 18px 20px 28px;
}
.empty-state {
  height: 100%;
  min-height: 360px;
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--muted);
  gap: 6px;
}
.empty-icon { font-size: 42px; opacity: 0.85; }
.empty-state h2 { margin: 0; color: var(--text); font-size: 20px; }
.empty-state p { margin: 0; }

.preview-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  min-height: 200px;
}
.preview-meta {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  background: #fafbfc;
}
.md-body {
  padding: 22px 28px 36px;
  line-height: 1.75;
  font-size: 15px;
  max-width: 920px;
}
.md-body h1, .md-body h2, .md-body h3 { line-height: 1.3; margin: 1.2em 0 0.5em; }
.md-body h1 { font-size: 1.7em; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.md-body h2 { font-size: 1.35em; }
.md-body h3 { font-size: 1.15em; }
.md-body p { margin: 0.75em 0; }
.md-body ul, .md-body ol { padding-left: 1.4em; }
.md-body code {
  font-family: var(--mono);
  background: #f1f3f7;
  border-radius: 4px;
  padding: 0.1em 0.35em;
  font-size: 0.92em;
}
.md-body pre {
  background: #171a21;
  color: #e8ecf5;
  border-radius: 10px;
  padding: 14px 16px;
  overflow: auto;
}
.md-body pre code { background: transparent; padding: 0; color: inherit; }
.md-body blockquote {
  margin: 1em 0;
  padding: 0.2em 1em;
  border-left: 4px solid #c9d6ef;
  color: #4b5567;
  background: #f7f9fc;
}
.md-body table { border-collapse: collapse; width: 100%; margin: 1em 0; }
.md-body th, .md-body td { border: 1px solid var(--border); padding: 8px 10px; }
.md-body img { max-width: 100%; border-radius: 8px; }

.text-body, .code-body {
  margin: 0;
  padding: 18px 20px;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  background: #171a21;
  color: #e8ecf5;
  min-height: 240px;
}

.media-wrap {
  display: grid;
  place-items: center;
  padding: 24px;
  background: #0f1218;
  min-height: 420px;
}
.media-wrap img {
  max-width: 100%;
  max-height: calc(100vh - 180px);
  object-fit: contain;
  border-radius: 8px;
}
.media-wrap video {
  width: min(100%, 1100px);
  max-height: calc(100vh - 180px);
  background: #000;
  border-radius: 8px;
}

.html-frame {
  width: 100%;
  height: calc(100vh - 160px);
  border: 0;
  background: #fff;
}

.binary-box {
  padding: 40px 24px;
  text-align: center;
  color: var(--muted);
}

.error-box {
  padding: 24px;
  color: var(--danger);
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 42vh 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid #0f1218; }
}

/* —— 剧库书架 —— */
.library-wrap {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(900px 420px at 15% -5%, rgba(180, 150, 110, 0.18) 0%, transparent 55%),
    radial-gradient(700px 380px at 95% 10%, rgba(90, 60, 40, 0.22) 0%, transparent 50%),
    linear-gradient(180deg, #1a1816 0%, #2a2420 40%, #1e1b18 100%);
  color: #f3ebe0;
  position: relative;
}
.library-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 28px 8px;
  flex-wrap: wrap;
}
.library-brand { display: flex; align-items: center; gap: 14px; }
.logo-mark {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  display: block;
  filter: drop-shadow(0 8px 18px rgba(0,0,0,.4));
}
.logo-mark--sm {
  width: 36px;
  height: 36px;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,.35));
}
.library-mark {
  width: 48px; height: 48px; border-radius: 14px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #c9a227, #8b1e2d);
  color: #fff8e7; font-weight: 700; font-size: 18px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.35);
}
.library-title {
  margin: 0;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: #f7efd8;
}
.library-sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: rgba(243, 235, 224, 0.62);
  letter-spacing: 0.08em;
}
.library-actions { display: flex; align-items: center; gap: 10px; }
.library-user { font-size: 13px; color: rgba(243, 235, 224, 0.7); }
.library-wrap .ghost-btn {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.16);
  color: #f3ebe0;
}
.library-wrap .ghost-btn:hover {
  border-color: rgba(201, 162, 39, 0.55);
  background: rgba(201, 162, 39, 0.12);
}

.shelf-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 12px 24px 48px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}
.bookshelf {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 18px 16px;
  align-items: end;
  padding: 8px 8px 0;
}
.shelf-plank {
  height: 14px;
  margin-top: 10px;
  border-radius: 4px;
  background:
    linear-gradient(180deg, #6b4e34 0%, #4a3422 55%, #3a2818 100%);
  box-shadow:
    0 10px 24px rgba(0,0,0,0.45),
    inset 0 1px 0 rgba(255,220,170,0.18);
}

.book {
  position: relative;
  width: 100%;
  aspect-ratio: 9 / 16;
  height: auto;
  border: 0;
  padding: 0;
  cursor: pointer;
  background: transparent;
  text-align: left;
  font: inherit;
  color: inherit;
  perspective: 600px;
}
.book-spine {
  width: 100%;
  height: 100%;
  aspect-ratio: 9 / 16;
  border-radius: 6px 12px 12px 6px;
  padding: 18px 10px 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow:
    4px 8px 18px rgba(0,0,0,0.4),
    inset -6px 0 12px rgba(0,0,0,0.25),
    inset 2px 0 0 rgba(255,255,255,0.08);
  transform: rotateY(-8deg) translateZ(0);
  transition: transform 0.22s ease, box-shadow 0.22s ease, filter 0.22s ease;
  position: relative;
  overflow: hidden;
}
.book-spine::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 7px;
  background: linear-gradient(90deg, rgba(0,0,0,0.35), transparent);
}
.book:hover .book-spine,
.book:focus-visible .book-spine {
  transform: rotateY(-2deg) translateY(-8px);
  box-shadow:
    6px 16px 28px rgba(0,0,0,0.5),
    inset -6px 0 12px rgba(0,0,0,0.22),
    inset 2px 0 0 rgba(255,255,255,0.1);
  outline: none;
}
.book:focus-visible { outline: none; }

.book-title {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.18em;
  line-height: 1.35;
  max-height: 72%;
  overflow: hidden;
}
.book-status {
  font-size: 11px;
  letter-spacing: 0.12em;
  opacity: 0.9;
  padding: 4px 0 0;
  border-top: 1px solid rgba(255,255,255,0.18);
}

.book.active-book .book-spine {
  background: linear-gradient(160deg, #8b1e2d 0%, #5c1220 45%, #3d0e18 100%);
  color: #ffe9b0;
  box-shadow:
    4px 8px 18px rgba(0,0,0,0.45),
    0 0 0 1px rgba(201, 162, 39, 0.45),
    inset -6px 0 12px rgba(0,0,0,0.28),
    inset 0 0 24px rgba(201, 162, 39, 0.12);
}
.book.active-book .book-status {
  color: #f0d078;
  border-top-color: rgba(240, 208, 120, 0.35);
}

.book.idle-book .book-spine {
  background: linear-gradient(160deg, #5a5650 0%, #3e3b37 55%, #2d2b28 100%);
  color: rgba(236, 228, 216, 0.55);
  filter: saturate(0.7);
}
.book.idle-book .book-status {
  color: rgba(236, 228, 216, 0.45);
  border-top-color: rgba(255,255,255,0.1);
}
.book.idle-book:hover .book-spine {
  filter: saturate(0.85) brightness(1.05);
}

.book-tone-1 .book-spine { /* 真名册 gold/wine handled by active */ }
.book-tone-2 .book-spine { background: linear-gradient(160deg, #4f5d6e, #313844); }
.book-tone-3 .book-spine { background: linear-gradient(160deg, #5c4f6a, #372f42); }
.book-tone-4 .book-spine { background: linear-gradient(160deg, #4f5f56, #303a35); }
.book-tone-5 .book-spine { background: linear-gradient(160deg, #6a5548, #40332b); }
.book-tone-6 .book-spine { background: linear-gradient(160deg, #45566a, #2c3643); }
.book-tone-7 .book-spine { background: linear-gradient(160deg, #5a4a4a, #372e2e); }
.book-tone-8 .book-spine { background: linear-gradient(160deg, #4a5a68, #2e3842); }
.book-tone-9 .book-spine { background: linear-gradient(160deg, #55524c, #35322e); }
.book-tone-10 .book-spine { background: linear-gradient(160deg, #4e5560, #30353c); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 36px;
  transform: translateX(-50%);
  background: rgba(28, 24, 20, 0.92);
  color: #f7efd8;
  border: 1px solid rgba(201, 162, 39, 0.35);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  letter-spacing: 0.06em;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  z-index: 40;
  pointer-events: none;
}
.toast.hidden { display: none !important; }

.topbar {
  justify-content: flex-start;
}
.topbar .crumb { flex: 1; min-width: 0; }
.topbar .top-actions { margin-left: auto; }
.back-btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .bookshelf { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
  .library-header { padding: 18px 16px 4px; }
  .shelf-stage { padding: 8px 14px 36px; }
}
@media (max-width: 420px) {
  .bookshelf { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .book-title { font-size: 14px; }
}

.book-face {
  position: relative;
  width: 100%;
  height: 100%;
  aspect-ratio: 9 / 16;
  border-radius: 8px;
  overflow: hidden;
  box-shadow:
    4px 10px 22px rgba(0,0,0,.48),
    0 0 0 1px rgba(201,162,39,.4);
  background: #1a1410;
  transition: transform .22s ease, box-shadow .22s ease;
}
.book.has-cover:hover .book-face,
.book.has-cover:focus-visible .book-face {
  transform: translateY(-8px) scale(1.02);
  box-shadow:
    6px 18px 30px rgba(0,0,0,.55),
    0 0 0 1px rgba(232,197,106,.55);
}
.book-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.book-cover-badge {
  position: absolute;
  left: 8px;
  bottom: 8px;
  padding: 4px 9px;
  border-radius: 999px;
  background: rgba(122, 26, 40, 0.9);
  color: #fff4d2;
  font-size: 11px;
  letter-spacing: 0.08em;
  backdrop-filter: blur(4px);
}
.bookshelf {
  gap: 22px 14px;
}


/* —— 剧本分集编辑工作台 —— */
.primary-btn {
  text-decoration: none;
  color: #fff;
  border: 1px solid transparent;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.primary-btn:hover { filter: brightness(1.05); }
.primary-btn:disabled,
.ghost-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: none;
}
.danger-btn {
  color: var(--danger) !important;
  border-color: rgba(194, 59, 59, 0.35) !important;
}
.danger-btn:hover:not(:disabled) {
  border-color: var(--danger) !important;
  background: rgba(194, 59, 59, 0.06);
}

.script-workbench {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100%;
  min-height: calc(100vh - 96px);
}
.script-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}
.script-toolbar-title {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.04em;
  color: var(--text);
}
.script-toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.script-episodes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.script-ep-tab {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
}
.script-ep-tab:hover {
  border-color: #c9d0dc;
}
.script-ep-tab.active {
  background: linear-gradient(180deg, #8b1e2d, #5c1220);
  border-color: #8b1e2d;
  color: #ffe9b0;
  font-weight: 600;
}
.script-empty {
  color: var(--muted);
  font-size: 13px;
  padding: 4px 2px;
}
.script-editor-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px 14px;
  min-height: 420px;
}
.script-meta {
  font-size: 13px;
  color: var(--muted);
}
.script-editor {
  flex: 1;
  width: 100%;
  min-height: 360px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Noto Sans Mono", monospace;
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
  background: #fafbfc;
  box-sizing: border-box;
}
.script-editor:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 141, 239, 0.15);
  background: #fff;
}
.script-editor:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}
.script-status {
  min-height: 18px;
  font-size: 12px;
  color: var(--muted);
}
.script-status.ok { color: #2f7d4a; }
.script-status.warn { color: #b58105; }
.script-status.error { color: var(--danger); }

@media (max-width: 900px) {
  .script-workbench { min-height: 0; }
  .script-editor { min-height: 280px; }
}

.script-ep-tab.completed {
  background: rgba(46, 160, 90, 0.14);
  border-color: #2f9e5d;
  color: #1f6b3f;
  box-shadow: inset 3px 0 0 #2f9e5d;
  border-radius: 10px;
}
.script-ep-tab.completed.active {
  background: linear-gradient(180deg, #2f9e5d, #1f6b3f);
  border-color: #1f6b3f;
  color: #eafff2;
  box-shadow: none;
}
.script-toolbar-actions .ghost-btn.is-done {
  background: rgba(46, 160, 90, 0.16);
  border-color: #2f9e5d;
  color: #1f6b3f;
}
.script-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 28px;
}
.script-status-row .script-status {
  flex: 1;
  min-width: 0;
}
.script-copy-btn {
  flex-shrink: 0;
  padding: 4px 10px;
  font-size: 12px;
}
.tree-item.episode-done .iname {
  color: #2f9e5d;
  font-weight: 600;
}
.tree-item.episode-done {
  background: rgba(46, 160, 90, 0.10);
  border-left: 3px solid #2f9e5d;
}
.tree-item.script-dir-all-done .iname {
  color: #2f9e5d;
}
.tree-item.script-dir-all-done {
  background: rgba(46, 160, 90, 0.08);
}
.tree-item .twisty {
  cursor: pointer;
  user-select: none;
}

