:root {
  --paper: #f5f2ec;
  --card: #fffdf9;
  --ink: #1f2328;
  --muted: #6f6a61;
  --line: #e4ded2;
  --line-strong: #d3cabb;
  --accent: #a33a2b;
  --accent-soft: #f3e3df;
  --ok: #2f7a4f;
  --warn: #a8681a;
  --info: #2f5f8f;
  --purple: #6b4c9a;
  --gray: #7b756b;
  --shadow: 0 1px 2px rgba(40, 32, 20, .05), 0 8px 24px rgba(40, 32, 20, .06);
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Noto Sans SC", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  width: min(1080px, 100% - 40px);
  margin: 0 auto;
}

/* ---------- 顶栏 ---------- */
.topbar {
  background: rgba(255, 253, 249, .92);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(8px);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 0;
}

.brand h1 {
  margin: 0;
  font-size: 19px;
  letter-spacing: .02em;
}

.sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12.5px;
}

.save-state {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gray);
  flex: none;
}

.save-state[data-state="ok"] .dot { background: var(--ok); }
.save-state[data-state="saving"] .dot { background: var(--warn); animation: pulse 1s infinite; }
.save-state[data-state="error"] .dot { background: var(--accent); }
.save-state[data-state="dirty"] .dot { background: var(--warn); }

@keyframes pulse { 50% { opacity: .3; } }

/* ---------- 统计 ---------- */
.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 22px 0 18px;
}

.stat {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 13px;
  font-size: 12.5px;
  color: var(--muted);
}

.stat b {
  font-size: 15px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.stat.total {
  background: var(--ink);
  border-color: var(--ink);
  color: #f3efe6;
}

.stat.total b { color: #fff; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  overflow: hidden;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}

.card-head h2 {
  margin: 0;
  font-size: 15.5px;
  letter-spacing: .02em;
}

.hint {
  color: var(--muted);
  font-size: 12px;
}

/* ---------- 集数表 ---------- */
.table-wrap { overflow-x: auto; }

.ep-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.ep-table th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .06em;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: #faf7f1;
  white-space: nowrap;
}

.ep-table td {
  padding: 11px 20px;
  border-bottom: 1px solid #efeae0;
  vertical-align: middle;
}

.ep-table tbody tr {
  cursor: pointer;
  transition: background .12s ease;
}

.ep-table tbody tr:hover { background: #faf6ed; }
.ep-table tbody tr:last-child td { border-bottom: 0; }

.c-ep { width: 96px; }
.c-status { width: 140px; }

.ep-id {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  letter-spacing: .03em;
  color: var(--ink);
  white-space: nowrap;
}

.ep-table tr[data-ep="EP00"] .ep-id { color: var(--accent); }

.title-cell { color: var(--ink); }

.row-go {
  color: var(--muted);
  font-size: 12px;
  margin-left: 8px;
  opacity: 0;
  transition: opacity .12s ease;
  white-space: nowrap;
}

.ep-table tbody tr:hover .row-go,
.ep-table tbody tr:focus-visible .row-go { opacity: 1; }

/* ---------- 状态下拉 ---------- */
.status-select {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
  line-height: 1.4;
  padding: 5px 28px 5px 12px;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  min-width: 108px;
}

.status-select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.status-select[data-status="未开始"] { background-color: #f2f0eb; border-color: #ddd7cb; color: #6d675e; }
.status-select[data-status="定稿中"] { background-color: #fdf2e0; border-color: #ecd3a8; color: #8a5a12; }
.status-select[data-status="已定稿"] { background-color: #e8f0f9; border-color: #c3d6ec; color: #2c5a86; }
.status-select[data-status="已渲染"] { background-color: #efe9f8; border-color: #d4c6ea; color: #5d4090; }
.status-select[data-status="已发布"] { background-color: #e6f3ea; border-color: #bfdcc9; color: #266b45; }

/* ---------- 资产 ---------- */
.asset-list { padding: 6px 0; }

.asset-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid #efeae0;
}

.asset-row:last-child { border-bottom: 0; }

.asset-name {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.asset-mark {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--line-strong);
  flex: none;
}

.asset-row[data-status="已定版"] .asset-mark { background: var(--ok); }

/* ---------- 抽屉 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 26, 20, .38);
  z-index: 40;
  opacity: 0;
  transition: opacity .18s ease;
}

.overlay.show { opacity: 1; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(620px, 100%);
  background: var(--card);
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 40px rgba(30, 26, 20, .16);
  z-index: 50;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .22s ease;
}

.drawer.show { transform: translateX(0); }

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--line);
}

.drawer-title-block { min-width: 0; }

.ep-chip {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .08em;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 2px 8px;
  margin-bottom: 8px;
  font-variant-numeric: tabular-nums;
}

.drawer-head h2 {
  margin: 0;
  font-size: 17px;
  line-height: 1.45;
  font-weight: 600;
}

.icon-btn {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--muted);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  flex: none;
}

.icon-btn:hover { background: #f6f2ea; color: var(--ink); }

.drawer-body {
  padding: 20px 24px 8px;
  overflow-y: auto;
  flex: 1;
  overscroll-behavior: contain;
}

.field { margin-bottom: 20px; }

.field-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 8px;
}

.count {
  font-weight: 400;
  color: var(--muted);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

textarea, input[type="text"] {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  line-height: 1.75;
  padding: 11px 13px;
  resize: vertical;
  transition: border-color .12s ease, box-shadow .12s ease;
}

textarea:focus, input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(163, 58, 43, .12);
}

textarea { min-height: 120px; }

#storyboard { min-height: 190px; }

.thumbs-toggle {
  margin-top: 10px;
  border: 1px dashed var(--line-strong);
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 7px 12px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.thumbs-toggle:hover { border-color: var(--accent); color: var(--accent); }

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
  gap: 8px;
  margin-top: 12px;
  max-height: 340px;
  overflow-y: auto;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbf8f2;
}

.thumb {
  position: relative;
  border: 2px solid transparent;
  border-radius: 7px;
  background: #fff;
  padding: 0;
  cursor: pointer;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.thumb img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  display: block;
  filter: grayscale(15%);
}

.thumb span {
  font-size: 11px;
  color: var(--muted);
  padding: 2px 0 3px;
  font-variant-numeric: tabular-nums;
  background: #fff;
}

.thumb:hover { border-color: var(--line-strong); }

.thumb.selected { border-color: var(--accent); }
.thumb.selected span { color: var(--accent); font-weight: 600; }
.thumb.selected img { filter: none; }

.drawer-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 24px;
  border-top: 1px solid var(--line);
  background: #fbf8f2;
}

.dirty {
  margin-right: auto;
  color: var(--warn);
  font-size: 12px;
}

.btn {
  font: inherit;
  font-size: 13.5px;
  border-radius: 9px;
  padding: 9px 18px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .12s ease, border-color .12s ease;
}

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

.btn.primary:hover { background: #8d3023; }
.btn.primary:disabled { opacity: .55; cursor: default; }

.btn.ghost {
  background: #fff;
  border-color: var(--line-strong);
  color: var(--ink);
}

.btn.ghost:hover { background: #f6f2ea; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #f7f3ea;
  font-size: 13px;
  padding: 9px 18px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(30, 26, 20, .22);
  z-index: 80;
  max-width: calc(100% - 40px);
}

.toast.error { background: var(--accent); }

.footnote {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  margin: 26px 0 40px;
}

.footnote code {
  background: #efe9de;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11.5px;
}

/* ---------- 窄屏 ---------- */
@media (max-width: 640px) {
  .wrap { width: calc(100% - 24px); }
  .topbar-inner { align-items: flex-start; flex-direction: column; gap: 6px; }
  .stats { margin-top: 16px; }
  .card-head { flex-direction: column; gap: 2px; padding: 14px 16px; }
  .ep-table th, .ep-table td { padding-left: 14px; padding-right: 14px; }
  .c-ep { width: 74px; }
  .c-status { width: 118px; }
  .row-go { display: none; }
  .drawer-head, .drawer-body, .drawer-foot { padding-left: 16px; padding-right: 16px; }
  .thumb-grid { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }
}
