:root {
    --bg: #f7f7fb;
    --surface: #ffffff;
    --surface-soft: #f8f7ff;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e7e5f2;
    --primary: #667eea;
    --primary-dark: #764ba2;
    --primary-soft: #f0f0ff;
    --primary-border: #c7d2fe;
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --success: #20b26b;
    --warning: #f59e0b;
    --danger: #ef4444;
    --shadow: 0 10px 30px rgba(102, 126, 234, 0.1);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

.book-nav,
.workspace-topbar {
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 max(28px, calc((100vw - 1280px) / 2 + 28px));
    background: rgba(255, 255, 255, 0.95);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.brand {
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-decoration: none;
    font-size: 24px;
    font-weight: 700;
}

.nav-actions,
.workspace-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.workspace-actions-wrap {
    display: flex;
    align-items: center;
    gap: 14px;
}

.language-selector {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-soft);
}

.lang-btn {
    min-width: 42px;
    border: 0;
    border-radius: 6px;
    padding: 7px 10px;
    color: var(--muted);
    background: transparent;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.lang-btn.active {
    color: #fff;
    background: var(--primary-gradient);
}

.nav-link {
    color: var(--primary);
    text-decoration: none;
    font-size: 15px;
    font-weight: 600;
}

.credits {
    color: var(--primary);
    font-size: 14px;
    font-weight: 650;
    background: var(--primary-soft);
    padding: 6px 12px;
    border-radius: 20px;
}

.book-entry {
    width: min(1180px, calc(100% - 40px));
    margin: clamp(24px, 5vh, 44px) auto;
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(360px, 0.85fr);
    gap: 26px;
    align-items: start;
}

.upload-panel,
.recent-panel,
.modal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.upload-panel {
    padding: clamp(28px, 4vw, 40px);
}

.upload-panel h1 {
    margin: 0 0 10px;
    font-size: clamp(32px, 3.5vw, 40px);
    line-height: 1.15;
    color: #111827;
}

.upload-panel p {
    margin: 0 0 26px;
    color: var(--muted);
    font-size: 16px;
    line-height: 1.65;
    max-width: 680px;
}

.upload-form {
    display: grid;
    gap: 18px;
}

.field {
    display: grid;
    gap: 8px;
}

.field span,
.toggle-field span {
    font-size: 15px;
    font-weight: 650;
}

.field input[type="text"],
.field input[type="number"],
.field input[type="file"] {
    width: 100%;
    min-height: 48px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 11px 13px;
    font-size: 16px;
    background: var(--surface);
}

.field input[type="text"]:focus,
.field input[type="number"]:focus,
.field input[type="file"]:focus,
.card-field textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.12);
}

.field small {
    color: var(--muted);
    font-size: 13px;
}

.inline-fields {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 18px;
    align-items: end;
}

.toggle-field {
    min-height: 48px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-soft);
}

.toggle-field input {
    width: 20px;
    height: 20px;
    accent-color: var(--primary);
}

.primary-btn,
.secondary-btn,
.danger-btn {
    border: 0;
    border-radius: 8px;
    padding: 12px 18px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
}

.compact-btn {
    padding: 8px 12px;
    font-size: 13px;
}

.primary-btn {
    color: #fff;
    background: var(--primary-gradient);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.22);
}

.primary-btn:hover {
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.32);
}

.primary-btn:disabled,
.secondary-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.secondary-btn {
    color: var(--text);
    background: #f0f0ff;
}

.secondary-btn:hover {
    background: #e5e7ff;
}

.selected-btn {
    color: var(--primary);
    background: var(--primary-soft);
    border: 1px solid var(--primary-border);
}

.danger-btn {
    color: #fff;
    background: var(--danger);
}

.form-message {
    min-height: 20px;
    color: var(--muted);
    font-size: 14px;
}

.form-message.error {
    color: var(--danger);
}

.recent-panel {
    padding: 28px;
}

.section-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 16px;
}

.section-head h2 {
    margin: 0;
    font-size: 24px;
}

.section-head span {
    color: var(--muted);
    font-size: 13px;
}

.recent-list {
    display: grid;
    gap: 14px;
}

.recent-item {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    background: var(--surface-soft);
}

.recent-title {
    font-weight: 700;
    margin-bottom: 8px;
}

.recent-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 12px;
}

.recent-actions {
    display: flex;
    gap: 8px;
}

.modal {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 16px;
    background: rgba(15, 23, 42, 0.35);
    z-index: 20;
}

.modal[hidden] {
    display: none;
}

.modal-card {
    width: min(480px, 100%);
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    padding: 20px;
}

.cleanup-list {
    display: grid;
    gap: 10px;
    margin: 18px 0;
}

.cleanup-list label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.export-dialog-card h2 {
    margin: 0 0 10px;
    font-size: 20px;
}

.export-dialog-card p {
    margin: 0 0 14px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.6;
}

.export-dialog-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--primary-border);
    border-radius: 8px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-weight: 700;
}

.export-dialog-option input {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.export-dialog-option.disabled {
    color: var(--muted);
    border-color: var(--border);
    background: var(--surface-soft);
}

.export-dialog-hint {
    margin: 8px 0 18px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.6;
}

.workspace-body {
    height: 100vh;
    overflow: hidden;
}

.workspace-topbar {
    height: 74px;
}

.workspace-title {
    margin-top: 4px;
    color: var(--muted);
    font-size: 14px;
}

.project-summary {
    height: 54px;
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 0 24px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    font-size: 14px;
}

.summary-pill {
    padding: 6px 10px;
    border-radius: 999px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
}

.warning-pill {
    color: #8a4b00;
    background: #fff7e6;
    border-color: #fed7aa;
}

.status-badge {
    min-width: 72px;
    display: inline-flex;
    justify-content: center;
    padding: 6px 10px;
    border-radius: 999px;
    color: var(--muted);
    background: var(--surface-soft);
    border: 1px solid var(--border);
    font-size: 13px;
    font-weight: 700;
}

.status-badge.active {
    color: var(--primary);
    background: var(--primary-soft);
    border-color: var(--primary-border);
}

.status-badge.success {
    color: #107a47;
    background: #eafaf1;
    border-color: #bbf7d0;
}

.status-badge.warning {
    color: #8a4b00;
    background: #fff7e6;
    border-color: #fed7aa;
}

.workspace-grid {
    height: calc(100vh - 128px);
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr) 420px;
    background: var(--surface);
}

.chapter-pane,
.source-pane,
.cards-pane {
    min-height: 0;
    overflow-y: auto;
    border-right: 1px solid var(--border);
}

.cards-pane {
    border-right: 0;
}

.pane-title {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 14px 18px;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--border);
    font-weight: 700;
}

.chapter-list {
    padding: 8px;
}

.chapter-item {
    width: 100%;
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    border: 0;
    border-radius: 8px;
    padding: 11px 10px;
    background: transparent;
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

.chapter-item:hover,
.chapter-item.active {
    background: var(--primary-soft);
}

.status-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    border: 2px solid #cbd5e1;
}

.status-dot.done {
    border-color: var(--success);
    background: var(--success);
}

.status-dot.generating {
    border-color: var(--primary);
    background: var(--primary);
}

.status-dot.interrupted {
    border-color: var(--warning);
    background: var(--warning);
}

.chapter-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
}

.source-text {
    padding: 24px 28px 80px;
    line-height: 1.9;
    white-space: pre-wrap;
    font-size: 16px;
}

.workspace-card-list {
    padding: 16px;
    display: grid;
    gap: 14px;
}

.workspace-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-soft);
    padding: 14px;
}

.card-type {
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 10px;
}

.card-field {
    display: grid;
    gap: 6px;
    margin-bottom: 12px;
}

.card-field label {
    font-size: 13px;
    font-weight: 700;
}

.card-field textarea {
    width: 100%;
    min-height: 82px;
    resize: vertical;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 9px 10px;
    font-size: 14px;
    line-height: 1.55;
    background: #fff;
}

.card-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.empty-state {
    color: var(--muted);
    padding: 28px 8px;
    text-align: center;
    line-height: 1.6;
}

.plan-box {
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-soft);
}

.plan-box h3 {
    margin: 0 0 8px;
    font-size: 18px;
}

.plan-box p {
    margin: 0 0 12px;
    color: var(--muted);
    line-height: 1.65;
}

.tier-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0;
}

.locked-note {
    padding: 12px 14px;
    border: 1px solid #fed7aa;
    border-radius: 8px;
    color: #8a4b00;
    background: #fff7e6;
    line-height: 1.6;
    font-size: 14px;
}

@media (max-height: 700px) and (min-width: 921px) {
    .book-entry {
        margin: 18px auto;
    }

    .upload-panel {
        padding: 24px 30px;
    }

    .upload-panel h1 {
        font-size: 30px;
        margin-bottom: 8px;
    }

    .upload-panel p {
        margin-bottom: 16px;
        font-size: 15px;
        line-height: 1.5;
    }

    .upload-form {
        gap: 12px;
    }

    .field {
        gap: 6px;
    }

    .field input[type="text"],
    .field input[type="number"],
    .field input[type="file"],
    .toggle-field {
        min-height: 44px;
    }

    .field input[type="text"],
    .field input[type="number"],
    .field input[type="file"] {
        padding: 9px 12px;
    }

    .inline-fields {
        gap: 14px;
    }

    .upload-form > .primary-btn {
        padding: 10px 16px;
    }

    .form-message {
        min-height: 16px;
    }

    .recent-panel {
        padding: 24px;
    }
}

@media (max-width: 920px) {
    .book-entry {
        grid-template-columns: 1fr;
    }

    .inline-fields {
        grid-template-columns: 1fr;
    }

    .workspace-body {
        overflow: auto;
    }

    .workspace-grid {
        height: auto;
        grid-template-columns: 1fr;
    }

    .chapter-pane,
    .source-pane,
    .cards-pane {
        max-height: 70vh;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }
}

@media (max-width: 600px) {
    .book-nav,
    .workspace-topbar {
        height: auto;
        min-height: 64px;
        padding: 12px 16px;
        align-items: flex-start;
        gap: 12px;
        flex-wrap: wrap;
    }

    .brand {
        display: block;
        font-size: 18px;
        line-height: 1.25;
    }

    .workspace-title {
        font-size: 13px;
    }

    .nav-actions,
    .workspace-actions-wrap,
    .workspace-actions {
        margin-left: auto;
        justify-content: flex-end;
        flex-wrap: wrap;
        gap: 8px;
    }

    .workspace-actions .primary-btn,
    .workspace-actions .secondary-btn {
        max-width: 126px;
        padding: 9px 10px;
        white-space: normal;
        line-height: 1.25;
    }

    .project-summary {
        height: auto;
        min-height: 54px;
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px 16px;
    }

    .summary-pill {
        line-height: 1.35;
    }

    .upload-panel,
    .recent-panel {
        padding: 22px;
    }

    .book-entry {
        width: calc(100% - 24px);
        margin: 18px auto;
        gap: 18px;
    }

    .upload-panel h1 {
        font-size: 30px;
    }

    .upload-panel p {
        margin-bottom: 20px;
        font-size: 15px;
    }

    .upload-form {
        gap: 16px;
    }
}
