:root {
    --bg: #faf7f2;
    --surface: #ffffff;
    --text: #2b2620;
    --text-muted: #767066;
    --border: #e7e1d8;
    --primary: #c1622d;
    --primary-hover: #a84f22;
    --primary-contrast: #ffffff;
    --accent: #7a8b69;
    --danger: #c0392b;
    --success: #4a7c59;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(43, 38, 32, 0.08), 0 1px 2px rgba(43, 38, 32, 0.06);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1c1a17;
        --surface: #262320;
        --text: #ece7de;
        --text-muted: #a39c8f;
        --border: #3a352e;
        --primary: #e08a4f;
        --primary-hover: #f0995c;
        --primary-contrast: #1c1a17;
        --accent: #9db589;
        --danger: #e07568;
        --success: #83b592;
        --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.24);
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
    line-height: 1.6;
}

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 20px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.site-header {
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 64px;
}
.brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
}
.brand:hover { text-decoration: none; }
.nav { display: flex; align-items: center; gap: 18px; }
.nav-user { color: var(--text-muted); font-weight: 600; }

.main-content { padding: 32px 20px 80px; min-height: 60vh; }

.site-footer {
    border-top: 1px solid var(--border);
    padding: 24px 0;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
}

h1 { font-size: 1.75rem; margin: 0 0 8px; }
h2 { font-size: 1.2rem; margin: 0 0 12px; }
.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }

/* buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.95rem;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { border-color: var(--primary); text-decoration: none; }
.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--primary-contrast);
    font-weight: 600;
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-lg { padding: 12px 24px; font-size: 1.05rem; }
.btn:disabled { opacity: 0.6; cursor: default; }

.ai-btn { border-color: var(--accent); color: var(--accent); font-size: 0.85rem; padding: 6px 12px; }
.ai-btn:hover { background: var(--accent); color: var(--primary-contrast); }

.icon-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 4px 8px;
}
.icon-btn:hover { color: var(--danger); }

/* forms */
.form { display: flex; flex-direction: column; gap: 14px; max-width: 640px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.9rem; }
input[type="text"], input[type="password"], textarea {
    font-family: inherit;
    font-size: 1rem;
    padding: 10px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    resize: vertical;
}
textarea.content-editor { font-size: 1.05rem; line-height: 1.9; min-height: 420px; }
input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.form-actions { display: flex; gap: 10px; align-items: center; }

/* flash */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 0.9rem; }
.flash-success { background: rgba(74, 124, 89, 0.15); color: var(--success); }
.flash-error { background: rgba(192, 57, 43, 0.12); color: var(--danger); }

/* auth */
.auth-box { max-width: 400px; margin: 40px auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 32px; box-shadow: var(--shadow); }
.auth-box h1 { text-align: center; margin-bottom: 20px; }

/* landing */
.hero { text-align: center; padding: 60px 0 40px; }
.hero h1 { font-size: 2.2rem; }
.hero-sub { color: var(--text-muted); font-size: 1.1rem; margin-bottom: 28px; }
.hero-actions { display: flex; gap: 14px; justify-content: center; }
.workflow { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-top: 48px; }
.workflow-step { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; text-align: center; box-shadow: var(--shadow); }
.workflow-num { width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: var(--primary-contrast); display: flex; align-items: center; justify-content: center; margin: 0 auto 12px; font-weight: 700; }
.workflow-step h3 { margin: 0 0 8px; }
.workflow-step p { margin: 0; color: var(--text-muted); font-size: 0.9rem; }

/* dashboard */
.dashboard-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.novel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.novel-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.novel-card h3 { margin: 4px 0; }
.novel-card-top { display: flex; justify-content: space-between; align-items: center; }
.empty-state { text-align: center; padding: 60px 0; color: var(--text-muted); }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; background: var(--border); color: var(--text-muted); }
.badge-inspiration { background: rgba(122, 139, 105, 0.18); color: var(--accent); }
.badge-outline { background: rgba(193, 98, 45, 0.15); color: var(--primary); }
.badge-detail { background: rgba(193, 98, 45, 0.22); color: var(--primary); }
.badge-writing { background: rgba(74, 124, 89, 0.18); color: var(--success); }
.badge-completed { background: rgba(74, 124, 89, 0.32); color: var(--success); }

dialog { border: none; border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); background: var(--surface); color: var(--text); max-width: 420px; width: 100%; }
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* novel workbench */
.novel-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 20px; }
.stage-tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.stage-tab { padding: 10px 18px; color: var(--text-muted); border-bottom: 2px solid transparent; font-weight: 600; }
.stage-tab:hover { text-decoration: none; color: var(--text); }
.stage-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; margin-bottom: 20px; box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }

.inspiration-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.inspiration-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.inspiration-card p { margin: 0 0 8px; }
.inspiration-meta { display: flex; justify-content: space-between; align-items: center; }

.ref-inspirations { margin-bottom: 14px; color: var(--text-muted); font-size: 0.9rem; }
.ref-inspirations summary { cursor: pointer; font-weight: 600; }

.chapter-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.chapter-row { display: flex; align-items: center; gap: 14px; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.chapter-order { width: 28px; height: 28px; border-radius: 50%; background: var(--bg); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 0.85rem; font-weight: 700; flex-shrink: 0; }
.chapter-info { flex: 1; min-width: 0; }
.chapter-info p { margin: 2px 0 0; }
.chapter-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.chapter-actions form { display: inline; }

.drag-handle {
    cursor: grab;
    color: var(--text-muted);
    font-size: 1.1rem;
    line-height: 1;
    padding: 4px;
    flex-shrink: 0;
    user-select: none;
    touch-action: none;
}
.drag-handle:active { cursor: grabbing; }
.chapter-row.dragging, .paragraph-row.dragging { opacity: 0.4; }

.stage-next { margin-top: 20px; display: flex; justify-content: flex-end; }

.paragraph-list { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
.paragraph-row { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.paragraph-meta { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.paragraph-meta-left { display: flex; align-items: center; gap: 8px; }
.paragraph-meta-actions { display: flex; gap: 2px; }
.paragraph-meta-actions form { display: inline; }
.paragraph-order { width: 24px; height: 24px; border-radius: 50%; background: var(--bg); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 700; flex-shrink: 0; }

.paragraph-body { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: start; }
.paragraph-mid { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; }
.paragraph-mid .btn { white-space: nowrap; }
.paragraph-body textarea { width: 100%; resize: none; overflow: hidden; min-height: 72px; }
.paragraph-content-text { font-size: 0.95rem; line-height: 1.7; }

@media (max-width: 720px) {
    .paragraph-body { grid-template-columns: 1fr; }
    .paragraph-mid { flex-direction: row; }
}

@media (max-width: 720px) {
    .workflow { grid-template-columns: repeat(2, 1fr); }
    .novel-head { flex-direction: column; gap: 12px; }
    .chapter-row { flex-wrap: wrap; }
}
