:root {
  /* 纸感底色与墨色文字 */
  --paper: #f6f4ef;
  --paper-2: #efebe2;
  --paper-3: #e7e2d7;
  --card: #fbfaf7;
  --card-hover: #f2efe7;

  --ink: #1e1c18;
  --ink-2: #55504a;
  --ink-3: #8a837b;

  --rule: rgba(30, 28, 24, 0.14);
  --rule-strong: rgba(30, 28, 24, 0.3);

  --accent: #a2412c;
  --accent-ink: #7d3020;
  --accent-soft: rgba(162, 65, 44, 0.08);
  --ok: #5d7a5a;

  --bg: var(--paper);
  --line: var(--rule);
  --line-strong: var(--rule-strong);
  --text: var(--ink);
  --muted: var(--ink-3);
  --danger: var(--accent);
  --radius: 4px;

  --font-display: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, 'Songti SC', 'Noto Serif SC', serif;
  --font-sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', 'PingFang SC', 'Microsoft YaHei', sans-serif;

  --shadow-soft: 0 1px 2px rgba(30, 28, 24, 0.04), 0 12px 28px rgba(30, 28, 24, 0.06);
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
h1, h2, h3 { margin: 0; font-weight: 400; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }

::selection { background: var(--accent); color: var(--paper); }

/* 顶栏 */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 26px;
  height: 62px;
  padding: 0 30px;
  background: rgba(246, 244, 239, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--rule);
}

.brand, .auth-brand {
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 400;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.brand span, .auth-brand span { color: var(--accent); }

.nav { display: flex; align-items: center; gap: 22px; white-space: nowrap; }

.nav-item {
  padding: 6px 0;
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  box-shadow: inset 0 -1px 0 transparent;
  transition: color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}
.nav-item:hover { color: var(--ink); }
.nav-item.active { color: var(--ink); box-shadow: inset 0 -1px 0 var(--accent); }

.userbar {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 12px;
  white-space: nowrap;
}
.credits { color: var(--accent); font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.uname { color: var(--ink-3); max-width: 120px; overflow: hidden; text-overflow: ellipsis; }

.main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 40px 30px 100px;
}

/* 页面标题 */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 26px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--rule);
}
.page-head h1 {
  font-family: var(--font-display);
  font-size: clamp(28px, 3vw, 38px);
  letter-spacing: -0.015em;
  line-height: 1.1;
}
.page-head .sub { color: var(--ink-3); font-size: 12.5px; letter-spacing: 0.04em; margin-top: 8px; }

/* 卡片 */
.card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 22px;
  box-shadow: var(--shadow-soft);
}
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
}
.card-head h2 { font-family: var(--font-display); font-size: 20px; color: var(--ink); }
.counter { color: var(--ink-3); font-size: 12px; font-variant-numeric: tabular-nums; letter-spacing: 0.04em; }
.hint { color: var(--ink-3); font-size: 12px; line-height: 1.6; letter-spacing: 0.02em; }

/* 表单 */
.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 16px; }
.field > span {
  color: var(--ink-3);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  height: 44px;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0 13px;
  color: var(--ink);
  outline: none;
  transition: border-color 0.18s var(--ease);
}
input:focus, select:focus, textarea:focus { border-color: var(--ink); }
textarea { height: auto; padding: 12px 13px; resize: vertical; min-height: 190px; line-height: 1.7; }

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--ink);
  -webkit-box-shadow: 0 0 0 1000px var(--card) inset;
  caret-color: var(--ink);
  transition: background-color 9999s ease-out 0s;
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 18px;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  color: var(--ink);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.18s var(--ease), color 0.18s var(--ease), border-color 0.18s var(--ease), transform 0.18s var(--ease);
  white-space: nowrap;
}
.btn:hover { border-color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn.primary:hover { background: var(--accent); border-color: var(--accent); color: var(--paper); }
.btn.ghost { border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { border-color: transparent; color: var(--accent); background: transparent; }
.btn.danger { color: var(--accent); border-color: var(--rule); }
.btn.block { width: 100%; }

.icon { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* 登录 */
.auth-wrap { max-width: 420px; margin: 9vh auto 0; text-align: center; }
.auth-brand { font-size: 36px; }
.auth-sub { color: var(--ink-3); font-size: 12.5px; letter-spacing: 0.04em; margin: 10px 0 26px; }
.auth-card { text-align: left; padding: 26px; }
.auth-tabs { display: flex; gap: 24px; margin-bottom: 22px; border-bottom: 1px solid var(--rule); }
.auth-tab {
  padding: 8px 0;
  border-bottom: 1px solid transparent;
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 0.18s var(--ease), border-color 0.18s var(--ease);
}
.auth-tab:hover { color: var(--ink); }
.auth-tab.active { color: var(--ink); border-bottom-color: var(--accent); }
.footnote { color: var(--ink-3); font-size: 11px; letter-spacing: 0.06em; margin-top: 20px; }

/* 创作 */
.create-grid { display: grid; gap: 18px; }

.dropzone {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px;
  margin-top: 14px;
  border: 1px dashed var(--rule-strong);
  border-radius: var(--radius);
  transition: border-color 0.18s var(--ease), background 0.18s var(--ease);
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }

.refs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 10px;
  margin-top: 14px;
}
.ref-item {
  position: relative;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--paper-2);
}
.ref-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  background: var(--paper-3);
}
.ref-file {
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-3);
  font-size: 12px;
  text-align: center;
  padding: 8px;
  word-break: break-all;
}
.ref-tag {
  position: absolute;
  left: 6px;
  bottom: 6px;
  padding: 1px 6px;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--ink-2);
  background: rgba(251, 250, 247, 0.9);
  border: 1px solid var(--rule);
  border-radius: 2px;
}
.ref-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: rgba(251, 250, 247, 0.9);
  border: 1px solid var(--rule);
  border-radius: 2px;
  color: var(--ink-2);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
}
.ref-del:hover { color: var(--accent); border-color: var(--accent); }
.ref-pending { color: var(--ink-3); font-size: 12px; padding: 14px 6px; text-align: center; }

.param-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 16px; }
.param-grid .field { margin-bottom: 12px; }

.switch-row { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--ink-3); cursor: pointer; margin-top: 4px; }
.switch-row input { display: none; }
.switch {
  width: 34px;
  height: 18px;
  background: var(--paper-3);
  border: 1px solid var(--rule);
  border-radius: 10px;
  position: relative;
  transition: background 0.18s var(--ease), border-color 0.18s var(--ease);
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  background: var(--ink-3);
  border-radius: 50%;
  transition: transform 0.18s var(--ease), background 0.18s var(--ease);
}
.switch-row input:checked + .switch { background: var(--accent-soft); border-color: var(--accent); }
.switch-row input:checked + .switch::after { transform: translateX(16px); background: var(--accent); }

.submit-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 0 0;
  background: linear-gradient(to top, var(--paper) 70%, transparent);
}
.cost { color: var(--ink-3); font-size: 12px; letter-spacing: 0.02em; font-variant-numeric: tabular-nums; }

/* 生成中提示 */
.active-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  margin-bottom: 18px;
  border: 1px solid var(--rule);
  border-left: 2px solid var(--accent);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow-soft);
}
.active-card .text { flex: 1; min-width: 0; }
.active-card .title { font-size: 13px; }
.active-card .meta { color: var(--ink-3); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spinner {
  width: 16px;
  height: 16px;
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--paper-3);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 作品 */
.works { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.work-card { display: flex; flex-direction: column; gap: 12px; padding: 16px; }
.work-media { width: 100%; border-radius: 4px; overflow: hidden; background: var(--paper-3); border: 1px solid var(--rule); }
.work-media video { display: block; width: 100%; max-height: 340px; background: #000; }
.work-media .placeholder {
  aspect-ratio: 16 / 9;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--ink-3);
  font-size: 12px;
}
.work-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border: 1px solid var(--rule);
  border-radius: 2px;
  color: var(--ink-2);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge .dot { width: 5px; height: 5px; border-radius: 50%; background: var(--ink-3); }
.badge.completed .dot { background: var(--ok); }
.badge.failed .dot { background: var(--accent); }
.badge.processing .dot { background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }
.work-prompt {
  font-size: 13px;
  line-height: 1.7;
  color: var(--ink-2);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.work-tags { display: flex; flex-wrap: wrap; gap: 6px; color: var(--ink-3); font-size: 11px; letter-spacing: 0.04em; }
.work-tags span { border: 1px solid var(--rule); border-radius: 2px; padding: 1px 6px; }
.work-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.work-actions .spacer { flex: 1; }
.work-actions .btn { padding: 6px 11px; font-size: 10px; }
.text-btn {
  background: none;
  border: 0;
  padding: 4px;
  color: var(--ink-3);
  cursor: pointer;
  font-size: 12px;
  letter-spacing: 0.02em;
  transition: color 0.18s var(--ease);
}
.text-btn:hover { color: var(--accent); }

.empty {
  grid-column: 1 / -1;
  padding: 54px 20px;
  text-align: center;
  border: 1px dashed var(--rule);
  border-radius: var(--radius);
  color: var(--ink-3);
  font-size: 12.5px;
  letter-spacing: 0.04em;
}

/* 账户 */
.account-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.user-card { display: flex; flex-direction: column; gap: 20px; }
.user-main { display: flex; align-items: center; gap: 16px; }
.avatar {
  width: 56px;
  height: 56px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper-2);
  font-family: var(--font-display);
  font-size: 24px;
  color: var(--ink);
}
.user-name { font-family: var(--font-display); font-size: 24px; color: var(--ink); }
.user-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; padding-top: 16px; border-top: 1px solid var(--rule); }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat b { font-family: var(--font-display); font-size: 30px; font-weight: 400; letter-spacing: 0.01em; }
.stat span { color: var(--ink-3); font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase; }

/* 提示 */
.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translate(-50%, 12px);
  max-width: min(90vw, 460px);
  padding: 11px 18px;
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  color: var(--paper);
  font-size: 12.5px;
  letter-spacing: 0.02em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--accent-ink); border-color: var(--accent-ink); color: var(--paper); }

/* 响应式 */
@media (max-width: 900px) {
  .param-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .works { grid-template-columns: 1fr; }
  .account-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .topbar { gap: 14px; height: 54px; padding: 0 14px; }
  .brand { font-size: 15px; }
  .nav { gap: 14px; }
  .nav-item { font-size: 10px; letter-spacing: 0.08em; }
  .userbar { gap: 8px; font-size: 11.5px; }
  .uname { display: none; }
  .main { padding: 24px 14px 96px; }
  .page-head { margin-bottom: 20px; padding-bottom: 12px; }
  .page-head h1 { font-size: 26px; }
  .card { padding: 16px; }
  .auth-wrap { margin-top: 5vh; }
  .auth-brand { font-size: 30px; }
  .submit-bar { flex-direction: column; align-items: stretch; gap: 10px; }
  .submit-bar .btn { width: 100%; }
  .cost { text-align: center; }
  textarea { min-height: 160px; }
  .work-actions .btn { padding: 8px 12px; }
}

/* 管理后台 */
.key-hint { color: var(--accent); font-size: 12px; }
.admin-users { display: grid; gap: 14px; margin-bottom: 20px; }
.admin-user { padding: 18px; }
.admin-user-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.admin-user-name { font-family: var(--font-display); color: var(--ink); font-size: 19px; margin-right: 6px; }
.badge.admin { border: 1px solid var(--accent); border-radius: 2px; padding: 1px 7px; color: var(--accent); font-size: 9.5px; }
.admin-user-meta { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--ink-3); font-size: 12px; margin: 10px 0 12px; }
.key-wrap { flex: 1 1 100%; }
.key-state.ok { color: var(--ok); }
.key-state.no { color: var(--accent); }
.key-full {
  display: inline-block;
  max-width: 100%;
  padding: 2px 7px;
  background: var(--paper-2);
  border: 1px solid var(--rule);
  border-radius: 2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--ink-2);
  word-break: break-all;
}
.admin-user-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 14px; }
.admin-user-actions .spacer, .admin-work-head .spacer { flex: 1; }
.text-btn.danger { color: var(--accent); }
.admin-work { padding: 14px 0; border-top: 1px solid var(--rule); }
.admin-work:first-child { border-top: 0; padding-top: 0; }
.admin-work-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.admin-work-prompt {
  margin: 0 0 8px;
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.7;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.error-text { color: var(--accent); }

@media (max-width: 640px) {
  .admin-user-head { flex-direction: column; align-items: flex-start; gap: 2px; }
}

/* 素材库 */
.create-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 18px; align-items: start; }
.asset-panel { position: sticky; top: 78px; padding: 16px; }
.asset-panel .card-head { margin-bottom: 12px; padding-bottom: 10px; }
.asset-panel .card-head h2 { font-size: 18px; }
.drama-new { display: flex; gap: 6px; margin-bottom: 10px; }
.drama-new input { height: 34px; font-size: 12.5px; }
.drama-new .btn { padding: 0 11px; font-size: 10px; }
.drama-list { display: flex; flex-direction: column; max-height: 210px; overflow: auto; border-top: 1px solid var(--rule); }
.drama-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 8px;
  border: 0;
  border-bottom: 1px solid var(--rule);
  border-left: 2px solid transparent;
  background: none;
  color: var(--ink-2);
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
  transition: color 0.18s var(--ease), background 0.18s var(--ease), border-color 0.18s var(--ease);
}
.drama-item:hover { color: var(--ink); background: var(--paper-2); }
.drama-item.active { color: var(--ink); background: var(--paper-2); border-left-color: var(--accent); }
.drama-count { color: var(--ink-3); font-size: 11px; font-variant-numeric: tabular-nums; }

.asset-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 12px 0 8px; }
.asset-toolbar .hint { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.asset-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.asset-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 3px;
  overflow: hidden;
  background: var(--paper-3);
  cursor: pointer;
}
.asset-tile img { display: block; width: 100%; height: 100%; object-fit: cover; }
.asset-tile:hover { border-color: var(--ink-3); }
.asset-tile.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.asset-icon { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--ink-3); font-size: 20px; }
.asset-tag {
  position: absolute;
  left: 4px;
  bottom: 4px;
  padding: 0 5px;
  border-radius: 2px;
  background: rgba(30, 28, 24, 0.72);
  color: var(--paper);
  font-size: 9.5px;
  letter-spacing: 0.08em;
}
.asset-check {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 17px;
  height: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--paper);
  font-size: 10px;
}
.asset-empty {
  grid-column: 1 / -1;
  padding: 20px 8px;
  border: 1px dashed var(--rule);
  border-radius: 3px;
  color: var(--ink-3);
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
}

@media (max-width: 900px) {
  .create-layout { grid-template-columns: 1fr; }
  .asset-panel { position: static; }
  .drama-list { flex-direction: row; max-height: none; overflow-x: auto; border-top: 0; padding-bottom: 2px; }
  .drama-item {
    width: auto;
    margin-right: 6px;
    padding: 5px 10px;
    border: 1px solid var(--rule);
    border-left-width: 1px;
    border-radius: 2px;
    white-space: nowrap;
  }
  .drama-item.active { border-color: var(--accent); background: var(--accent-soft); }
  .asset-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 480px) {
  .asset-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
