/* ===== 设计系统 ===== */
:root {
  --bg-0: #0a0a14;
  --bg-1: #11111f;
  --bg-2: #1a1530;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-2: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f1f0f7;
  --text-2: #a8a4bc;
  --text-3: #6b6780;
  --pri: #a855f7;
  --pri-2: #8b5cf6;
  --acc: #ec4899;
  --acc-2: #f472b6;
  --cyan: #22d3ee;
  --grad: linear-gradient(135deg, #a855f7 0%, #ec4899 100%);
  --grad-soft: linear-gradient(135deg, rgba(168,85,247,.15), rgba(236,72,153,.15));
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 40px rgba(168, 85, 247, 0.25);
  --font: 'Inter', 'Noto Serif SC', -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --font-serif: 'Noto Serif SC', 'Inter', serif;
}
body.light {
  --bg-0: #f4f2fb; --bg-1: #ece9f7; --bg-2: #e4ddf5;
  --surface: rgba(255,255,255,0.65); --surface-2: rgba(255,255,255,0.85);
  --border: rgba(20,10,50,0.08); --border-strong: rgba(20,10,50,0.16);
  --text: #1a1530; --text-2: #5a5470; --text-3: #8a84a0;
  --shadow: 0 8px 32px rgba(80,60,140,0.12);
}
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body { font-family: var(--font); background: var(--bg-0); color: var(--text); overflow: hidden; -webkit-font-smoothing: antialiased; }

/* ===== 全局自定义滚动条 ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 100px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(168,85,247,0.4); background-clip: padding-box; border: 2px solid transparent; }
::-webkit-scrollbar-corner { background: transparent; }
* { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.15) transparent; }
body.light * { scrollbar-color: rgba(100,80,160,0.2) transparent; }

/* ===== 背景 ===== */
.bg-decor { position: fixed; inset: 0; z-index: 0; overflow: hidden; background: radial-gradient(ellipse at top, var(--bg-2), var(--bg-0) 60%); }
.blob { position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.5; animation: float 20s ease-in-out infinite; }
.blob-1 { width: 480px; height: 480px; background: radial-gradient(circle, #a855f7, transparent 70%); top: -120px; left: -80px; }
.blob-2 { width: 420px; height: 420px; background: radial-gradient(circle, #ec4899, transparent 70%); bottom: -100px; right: -60px; animation-delay: -7s; }
.blob-3 { width: 360px; height: 360px; background: radial-gradient(circle, #6366f1, transparent 70%); top: 40%; left: 50%; animation-delay: -14s; opacity: 0.3; }
.grid-overlay { position: absolute; inset: 0; background-image: linear-gradient(rgba(255,255,255,.02) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.02) 1px, transparent 1px); background-size: 48px 48px; mask-image: radial-gradient(ellipse at center, black 30%, transparent 75%); }
@keyframes float { 0%,100% { transform: translate(0,0) scale(1); } 33% { transform: translate(40px,-30px) scale(1.08); } 66% { transform: translate(-30px,40px) scale(.95); } }

/* ===== 登录/注册页 ===== */
.auth-view { position: relative; z-index: 1; height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 400px; max-width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 24px; backdrop-filter: blur(24px); box-shadow: var(--shadow), var(--shadow-glow); padding: 40px 36px; animation: authIn .5s ease; }
@keyframes authIn { from { opacity: 0; transform: translateY(20px) scale(.96); } to { opacity: 1; transform: translateY(0) scale(1); } }
.auth-logo { width: 56px; height: 56px; margin: 0 auto 16px; display: grid; place-items: center; }
.auth-title { text-align: center; font-size: 24px; font-weight: 700; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.auth-sub { text-align: center; font-size: 13px; color: var(--text-3); margin: 6px 0 28px; letter-spacing: 1px; }
.auth-tabs { display: flex; gap: 4px; padding: 4px; background: var(--bg-1); border-radius: 12px; margin-bottom: 24px; }
body.light .auth-tabs { background: rgba(255,255,255,0.5); }
.auth-tab { flex: 1; padding: 9px; border: none; border-radius: 8px; background: transparent; color: var(--text-3); font-size: 14px; font-weight: 500; cursor: pointer; transition: .2s; font-family: inherit; }
.auth-tab.active { background: var(--grad); color: #fff; box-shadow: 0 2px 12px rgba(168,85,247,.4); }
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 8px; }
.auth-submit { width: 100%; margin-top: 8px; }
.auth-hint { text-align: center; font-size: 12px; color: var(--text-3); margin-top: 20px; }

/* ===== 顶部导航 ===== */
.topbar { position: relative; z-index: 10; display: flex; align-items: center; justify-content: space-between; padding: 12px 24px; border-bottom: 1px solid var(--border); backdrop-filter: blur(20px); background: rgba(10,10,20,0.5); gap: 16px; }
body.light .topbar { background: rgba(244,242,251,0.6); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { width: 36px; height: 36px; display: grid; place-items: center; }
.brand-text h1 { font-size: 17px; font-weight: 700; letter-spacing: .5px; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand-sub { font-size: 11px; color: var(--text-3); letter-spacing: 2px; }
.mode-nav { display: flex; gap: 4px; padding: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.mode-btn { display: flex; align-items: center; gap: 6px; padding: 7px 16px; border: none; border-radius: 8px; background: transparent; color: var(--text-3); font-size: 13px; font-weight: 500; cursor: pointer; transition: .2s; font-family: inherit; }
.mode-btn:hover { color: var(--text-2); }
.mode-btn.active { background: var(--grad-soft); color: var(--text); box-shadow: 0 0 0 1px var(--pri); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.status-pill { display: flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 100px; background: var(--surface); border: 1px solid var(--border); font-size: 12px; color: var(--text-2); }
.status-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); transition: .3s; }
.status-pill.ok .dot { background: #34d399; box-shadow: 0 0 8px #34d399; }
.status-pill.err .dot { background: #f87171; box-shadow: 0 0 8px #f87171; }
.user-menu { display: flex; align-items: center; gap: 6px; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 5px 12px 5px 5px; border-radius: 100px; background: var(--surface); border: 1px solid var(--border); color: var(--text); cursor: pointer; transition: .2s; font-family: inherit; font-size: 13px; }
.user-chip:hover { background: var(--surface-2); border-color: var(--border-strong); }
.user-avatar { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 600; color: #fff; background: var(--grad); }
.icon-btn { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); cursor: pointer; transition: .2s; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }

/* ===== 布局 ===== */
.mode-view { display: none; }
.mode-view.active { display: grid; }
.layout { position: relative; z-index: 1; grid-template-columns: 380px 1fr; gap: 18px; padding: 18px 24px; height: calc(100vh - 61px); }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); backdrop-filter: blur(24px); box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; position: relative; }
.panel::before { content: ''; position: absolute; inset: 0; border-radius: var(--radius); padding: 1px; background: linear-gradient(135deg, rgba(168,85,247,0.15), transparent 40%, transparent 60%, rgba(236,72,153,0.1)); -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0); -webkit-mask-composite: xor; mask-composite: exclude; pointer-events: none; }

/* ===== 配置面板 ===== */
.config-panel { overflow-y: auto; }
.config-panel::-webkit-scrollbar { width: 6px; }
.config-panel::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
.panel-header { padding: 20px 22px 4px; }
.panel-header h2 { font-size: 16px; font-weight: 600; }
.panel-desc { font-size: 12px; color: var(--text-3); margin-top: 4px; }
.form-body { padding: 14px 22px; flex: 1; }
.field { margin-bottom: 16px; }
.field-row { display: flex; gap: 12px; margin-bottom: 16px; }
.flex1 { flex: 1; margin-bottom: 0; }
.field-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 8px; letter-spacing: .3px; }
.req { color: var(--acc); }
.field-hint { font-size: 12px; color: var(--text-3); margin-top: 6px; }

/* 类型卡片 */
.type-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.type-card { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 10px 4px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text-2); cursor: pointer; transition: .2s; font-family: inherit; }
.type-card:hover { border-color: var(--border-strong); color: var(--text); transform: translateY(-2px); }
.type-card.active { border-color: transparent; color: var(--text); background: var(--grad-soft); box-shadow: 0 0 0 1.5px var(--pri), 0 4px 16px rgba(168,85,247,.3); }
.type-icon { font-size: 20px; }
.type-name { font-size: 11px; font-weight: 500; }

/* 改写模式卡片 */
.rewrite-modes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.mode-card { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text-2); cursor: pointer; transition: .2s; font-family: inherit; text-align: left; }
.mode-card:hover { border-color: var(--border-strong); color: var(--text); }
.mode-card.active { border-color: transparent; color: var(--text); background: var(--grad-soft); box-shadow: 0 0 0 1.5px var(--pri); }
.rm-icon { font-size: 18px; }
.rm-name { font-size: 13px; font-weight: 500; }

/* 输入控件 */
.input, .textarea, .select { width: 100%; padding: 10px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg-1); color: var(--text); font-size: 13px; font-family: inherit; transition: .2s; resize: vertical; }
body.light .input, body.light .textarea, body.light .select { background: rgba(255,255,255,0.6); }
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--pri); box-shadow: 0 0 0 3px rgba(168,85,247,.15); }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.select { appearance: none; cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23a8a4bc' stroke-width='2'%3E%3Cpath d='M2 4l4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
.rewrite-input { font-family: var(--font-serif); line-height: 1.8; }
.char-count { font-size: 11px; color: var(--text-3); text-align: right; margin-top: 4px; }

/* 滑块 */
.slider-wrap { display: flex; align-items: center; gap: 10px; }
.slider-wrap input[type=range] { flex: 1; accent-color: var(--pri); height: 4px; }
.slider-val { font-size: 12px; color: var(--text-2); min-width: 28px; text-align: right; font-variant-numeric: tabular-nums; }

/* 按钮 */
.panel-footer { padding: 14px 22px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; }
.btn-primary { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 12px; border: none; border-radius: var(--radius-sm); background: var(--grad); color: #fff; font-size: 14px; font-weight: 600; cursor: pointer; transition: .2s; font-family: inherit; box-shadow: 0 4px 20px rgba(168,85,247,.4); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 28px rgba(168,85,247,.55); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-ghost { display: flex; align-items: center; gap: 6px; padding: 12px 18px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-2); font-size: 13px; cursor: pointer; transition: .2s; font-family: inherit; }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

/* ===== 结果面板 ===== */
.result-panel { min-width: 0; }
.result-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.result-tabs { display: flex; gap: 4px; }
.tab { padding: 6px 14px; border-radius: 8px; border: none; background: transparent; color: var(--text-3); font-size: 13px; font-weight: 500; cursor: pointer; transition: .2s; font-family: inherit; }
.tab:hover { color: var(--text-2); }
.tab.active { background: var(--surface-2); color: var(--text); }
.result-actions { display: flex; align-items: center; gap: 8px; }
.word-count { font-size: 12px; color: var(--text-3); margin-right: 4px; font-variant-numeric: tabular-nums; }
.result-body { flex: 1; overflow-y: auto; padding: 28px 36px; position: relative; scroll-behavior: smooth; }
.result-body::-webkit-scrollbar { width: 6px; }
.result-body::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

/* 空状态 */
.empty-state { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 12px; }
.empty-art { width: 120px; height: 120px; opacity: .8; animation: pulse 3s ease-in-out infinite; filter: drop-shadow(0 0 20px rgba(168,85,247,0.3)); }
@keyframes pulse { 0%,100% { transform: scale(1); opacity: .8; } 50% { transform: scale(1.05); opacity: 1; } }
.empty-state h3 { font-size: 18px; font-weight: 600; }
.empty-state p { font-size: 13px; color: var(--text-3); line-height: 1.8; }
.empty-tags { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; justify-content: center; }
.empty-tags span { padding: 4px 12px; border-radius: 100px; font-size: 11px; color: var(--text-2); background: var(--surface); border: 1px solid var(--border); }

/* 剧本内容 */
.script-content { max-width: 720px; margin: 0 auto; animation: fadeIn .4s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.script-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.meta-tag { padding: 5px 12px; border-radius: 100px; font-size: 11px; font-weight: 500; background: var(--grad-soft); color: var(--acc-2); border: 1px solid rgba(236,72,153,.2); }
body.light .meta-tag { color: #be185d; }
.script-text { font-family: var(--font-serif); font-size: 15.5px; line-height: 2.1; color: var(--text); white-space: pre-wrap; word-break: break-word; letter-spacing: 0.2px; }
.script-text :is(h1,h2,h3) { font-weight: 700; line-height: 1.5; margin: 1.4em 0 0.6em; }
.script-text h1 { font-size: 24px; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; letter-spacing: 1px; }
.script-text h2 { font-size: 19px; color: var(--pri); border-left: 3px solid var(--pri); padding-left: 12px; }
.script-text h3 { font-size: 16px; color: var(--acc-2); }
.script-text strong { color: var(--acc-2); font-weight: 600; }
.script-text p { margin: 0.6em 0; }
.cursor-blink { display: inline-block; width: 8px; height: 18px; vertical-align: text-bottom; background: var(--acc); border-radius: 1px; animation: blink 1s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* 状态条 */
.result-status { display: flex; align-items: center; justify-content: space-between; padding: 10px 18px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-3); }
.status-info { display: flex; align-items: center; gap: 8px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--pri); animation: pulse-dot 1.2s infinite; }
@keyframes pulse-dot { 0%,100% { opacity: 1; } 50% { opacity: .3; } }
.status-dot.done { background: #34d399; animation: none; }
.status-dot.err { background: #f87171; animation: none; }

/* ===== 设置页 ===== */
.settings-view { position: relative; z-index: 1; height: calc(100vh - 61px); overflow-y: auto; padding: 28px 24px; display: flex; justify-content: center; }
.settings-card { width: 560px; max-width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); backdrop-filter: blur(24px); box-shadow: var(--shadow); padding-bottom: 28px; }
.settings-body { padding: 18px 28px; }
.key-input-wrap { position: relative; display: flex; gap: 8px; }
.key-input-wrap .input { flex: 1; }
.key-toggle { flex-shrink: 0; }
.settings-actions { margin-top: 8px; }
.settings-actions .btn-primary { width: 200px; flex: none; }
.settings-info { margin-top: 28px; padding: 18px; border-radius: var(--radius-sm); background: var(--bg-1); border: 1px solid var(--border); }
body.light .settings-info { background: rgba(255,255,255,0.5); }
.settings-info h3 { font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 10px; }
.settings-info ul { list-style: none; }
.settings-info li { font-size: 12px; color: var(--text-3); line-height: 2; padding-left: 16px; position: relative; }
.settings-info li::before { content: '•'; position: absolute; left: 0; color: var(--pri); }

/* ===== Toast ===== */
.toast { position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(80px); padding: 12px 24px; border-radius: 12px; font-size: 13px; font-weight: 500; background: var(--bg-2); border: 1px solid var(--border-strong); color: var(--text); box-shadow: var(--shadow); z-index: 100; opacity: 0; transition: .35s; pointer-events: none; }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.success { border-color: rgba(52,211,153,.4); }
.toast.error { border-color: rgba(248,113,113,.4); }

.hidden { display: none !important; }

/* ===== 响应式 ===== */
@media (max-width: 960px) {
  .mode-nav { order: 3; width: 100%; justify-content: center; }
  .topbar { flex-wrap: wrap; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: auto; overflow-y: auto; }
  body { overflow: auto; }
  .config-panel { max-height: none; }
  .result-panel { min-height: 60vh; }
  .topbar { padding: 10px 16px; }
  .layout { padding: 14px; gap: 14px; }
}
@media (max-width: 480px) {
  .type-grid { grid-template-columns: repeat(2, 1fr); }
  .rewrite-modes { grid-template-columns: 1fr; }
  .brand-sub { display: none; }
  .result-body { padding: 16px; }
  .auth-card { padding: 28px 20px; }
  .mode-btn span:not(.rm-icon) { display: none; }
}
