* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #0f0f1a;
    --surface: #1a1a2e;
    --surface2: #222240;
    --primary: #7c3aed;
    --primary-hover: #6d28d9;
    --text: #e2e8f0;
    --text-dim: #94a3b8;
    --accent: #f59e0b;
    --error: #ef4444;
    --success: #22c55e;
    --border: #334155;
    --radius: 8px;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* --- Layout --- */

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    color: var(--text-dim);
    margin-bottom: 2rem;
}

/* --- Cards --- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.card-hint {
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 1rem;
}

/* --- Forms --- */

.form-group {
    margin-bottom: 1rem;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-dim);
    margin-bottom: 0.375rem;
    font-weight: 500;
}

.form-group input[type="text"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.625rem 0.75rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9375rem;
    font-family: inherit;
}

.form-group textarea {
    min-height: 80px;
    resize: vertical;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.input-with-counter {
    position: relative;
    width: 100%;
}

.char-counter {
    display: block;
    margin-top: 0.25rem;
    text-align: right;
    font-size: 0.72rem;
    color: var(--text-dim);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
    pointer-events: none;
}

.char-counter.at-limit {
    color: var(--accent);
    font-weight: 600;
}

.form-row {
    display: flex;
    gap: 1rem;
}

.form-row .form-group {
    flex: 1;
}

/* --- Chips --- */

.chip-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.chip {
    padding: 0.4rem 0.875rem;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text-dim);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    user-select: none;
}

.chip:hover {
    border-color: var(--text-dim);
    color: var(--text);
}

.chip.active {
    background: var(--text);
    color: var(--bg);
    border-color: var(--text);
    font-weight: 600;
}

/* --- Slider --- */

.slider-row {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.slider-row input[type="range"] {
    flex: 1;
    accent-color: var(--primary);
}

.slider-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    min-width: 1.5rem;
    text-align: center;
}

.slider-unit {
    font-size: 0.85rem;
    color: var(--text-dim);
}

/* --- Characters --- */

.char-card {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.875rem 1rem;
    margin-bottom: 0.625rem;
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
}

.char-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
    flex-shrink: 0;
    color: white;
}

.char-fields {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.char-fields input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.875rem;
    font-family: inherit;
}

.char-fields input:focus {
    outline: none;
    border-color: var(--primary);
}

.char-fields input::placeholder {
    color: var(--text-dim);
}

.char-remove {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 1.25rem;
    cursor: pointer;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
}

.char-remove:hover {
    color: var(--error);
    background: rgba(239, 68, 68, 0.15);
}

.char-proto {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 1.1rem;
    cursor: pointer;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
}

.char-proto:hover:not(.disabled) {
    color: #f59e0b;
    background: rgba(245, 158, 11, 0.15);
}

.char-proto.active {
    color: #f59e0b;
}

.char-proto.disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.char-card.is-protagonist {
    border-color: #f59e0b;
    box-shadow: 0 0 0 1px rgba(245, 158, 11, 0.3);
}

.add-btn {
    width: 100%;
    padding: 0.625rem;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-dim);
    font-size: 0.875rem;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}

.add-btn:hover {
    border-color: var(--primary);
    color: var(--text);
}

/* --- Relationships --- */

.rel-row {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}

.rel-row:last-child {
    border-bottom: none;
}

.rel-name {
    min-width: 90px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rel-arrow {
    color: var(--text-dim);
    flex-shrink: 0;
}

.rel-row select {
    padding: 0.375rem 0.5rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
}

.rel-row select:focus {
    outline: none;
    border-color: var(--primary);
}

/* --- Toggle switch --- */

.toggle-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.toggle {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
    display: inline-block;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.toggle-track {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 12px;
    transition: 0.2s;
}

.toggle-track::before {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    left: 2px;
    bottom: 2px;
    background: var(--text-dim);
    border-radius: 50%;
    transition: 0.2s;
}

.toggle input:checked + .toggle-track {
    background: var(--primary);
    border-color: var(--primary);
}

.toggle input:checked + .toggle-track::before {
    transform: translateX(20px);
    background: white;
}

.toggle-label {
    font-size: 0.9375rem;
    cursor: default;
}

/* --- Endings (cards, indented under branching toggle) --- */

.endings-section {
    margin-top: 1rem;
    margin-left: 3.25rem;
}

.endings-section .form-label {
    margin-bottom: 0.25rem;
}

.endings-section .card-hint {
    margin-bottom: 0.75rem;
}

.ending-avatar {
    background: var(--accent);
}

.char-fields textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.875rem;
    font-family: inherit;
    resize: vertical;
    min-height: 2.5rem;
}

.char-fields textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.char-fields textarea::placeholder {
    color: var(--text-dim);
}

/* --- Buttons --- */

.btn {
    display: inline-block;
    padding: 0.625rem 1.5rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9375rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    font-family: inherit;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-accent {
    background: var(--accent);
    color: #0f0f1a;
}

.btn-accent:hover {
    background: #e89209;
}

.btn-accent:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.generate-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 0.5rem;
    margin-bottom: 2rem;
}

/* --- Wizard (multi-step form) --- */

.wizard-stepper {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.wizard-step-pill {
    flex: 1 1 0;
    min-width: 110px;
    padding: 0.625rem 0.875rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    user-select: none;
}

.wizard-step-pill.completed {
    color: var(--text);
    border-color: var(--primary);
}

.wizard-step-pill.active {
    color: #fff;
    background: var(--primary);
    border-color: var(--primary);
}

.wizard-step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    font-weight: 600;
    font-size: 0.78rem;
    flex-shrink: 0;
}

.wizard-step-pill.completed .wizard-step-num {
    background: rgba(124, 58, 237, 0.25);
    color: var(--text);
}

.wizard-step-pill.active .wizard-step-num {
    background: #fff;
    color: var(--primary);
}

.wizard-step {
    display: none;
}

.wizard-step.active {
    display: block;
}

.wizard-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.5rem;
    margin-bottom: 2rem;
}

.wizard-nav-left,
.wizard-nav-right {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

/* --- Checkbox --- */

.checkbox-group {
    margin-bottom: 0.5rem;
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9375rem;
    color: var(--text);
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
}

.checkbox-hint {
    display: block;
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-top: 0.25rem;
    margin-left: 1.625rem;
}

/* --- Radio group (plot style) --- */

.radio-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.radio-option {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.radio-option:hover {
    border-color: var(--text-dim);
}

.radio-option:has(input:checked) {
    border-color: var(--primary);
    background: rgba(124, 58, 237, 0.08);
}

.radio-option input[type="radio"] {
    display: none;
}

.radio-mark {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 1px;
    position: relative;
    transition: border-color 0.15s;
}

.radio-option:has(input:checked) .radio-mark {
    border-color: var(--primary);
}

.radio-mark::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    transform: scale(0);
    transition: transform 0.15s;
}

.radio-option:has(input:checked) .radio-mark::after {
    transform: scale(1);
}

.radio-content {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.radio-title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text);
}

.radio-desc {
    font-size: 0.8rem;
    color: var(--text-dim);
    line-height: 1.4;
}

/* --- Scenario preview --- */

.scenario-preview {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 2rem;
    display: none;
}

.scenario-preview h2 {
    margin-bottom: 1rem;
    font-size: 1.25rem;
}

.scenario-title-edit {
    margin-bottom: 1rem;
}

.scenario-title-input {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.625rem 0.75rem;
    color: var(--text);
    font-size: 1.25rem;
    font-weight: 600;
    font-family: inherit;
}

.scenario-title-input:focus {
    outline: none;
    border-color: var(--primary);
}

.scenario-title-status {
    min-height: 1rem;
    margin-top: 0.25rem;
    font-size: 0.85rem;
    color: var(--text-dim);
}

.scenario-title-status.saving {
    color: var(--text-dim);
}

.scenario-title-status.saved {
    color: var(--primary);
}

.scenario-title-status.error {
    color: var(--accent);
}

.scene-card {
    background: var(--surface2);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
}

.scene-card h3 {
    font-size: 1rem;
    color: var(--accent);
    margin-bottom: 0.375rem;
}

.scene-card p {
    font-size: 0.875rem;
    color: var(--text-dim);
    line-height: 1.5;
}

.scene-description-text {
    margin-bottom: 0.625rem;
    white-space: pre-wrap;
}

.scene-description-input {
    width: 100%;
    min-height: 84px;
    padding: 0.6rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: inherit;
    font-size: 0.875rem;
    line-height: 1.5;
    resize: vertical;
    overflow: hidden;
    transition: border-color 0.15s;
}

.scene-description-input:focus {
    outline: none;
    border-color: var(--primary);
}

.scene-description-input:disabled {
    opacity: 0.6;
    cursor: wait;
}

.scene-edit-row {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.625rem;
    align-items: flex-start;
}

.scene-hint-wrap {
    flex: 1;
    min-width: 0;
}

.scene-hint-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: inherit;
    font-size: 0.85rem;
}

.scene-hint-wrap .char-counter {
    margin-top: 0.2rem;
    font-size: 0.7rem;
}

.scene-hint-input:focus {
    outline: none;
    border-color: var(--primary);
}

.scene-hint-input:disabled {
    opacity: 0.6;
}

.scene-regen-btn {
    padding: 0.5rem 0.9rem;
    font-size: 0.85rem;
    white-space: nowrap;
    flex-shrink: 0;
}

.scene-regen-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}

.scene-edit-status {
    margin-top: 0.4rem;
    font-size: 0.78rem;
    min-height: 1.1em;
    color: var(--text-dim);
}

.scene-edit-status.saving {
    color: var(--text-dim);
}

.scene-edit-status.saved {
    color: var(--success);
}

.scene-edit-status.error {
    color: var(--error);
}

.scene-card .scene-meta {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-dim);
}

.scene-card .scene-meta-label {
    color: var(--text-muted);
    font-weight: 600;
}

.characters-list {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.character-badge {
    background: var(--surface2);
    border-radius: 20px;
    padding: 0.375rem 0.75rem;
    font-size: 0.8rem;
}

.preview-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

/* --- Progress --- */

.progress-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 2rem;
    display: none;
    text-align: center;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 1rem auto;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.progress-steps {
    text-align: left;
    max-width: 400px;
    margin: 1.5rem auto;
}

.progress-step {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0;
    border-bottom: 1px solid var(--border);
    color: var(--text-dim);
    transition: color 0.3s;
}

.progress-step:last-child { border-bottom: none; }
.progress-step.step-done { color: var(--success); }
.progress-step.step-active { color: var(--text); }
.progress-step.step-skipped { opacity: 0.5; }

.step-icon {
    width: 24px;
    text-align: center;
    font-weight: 600;
    flex-shrink: 0;
}

.step-label { flex: 1; }

.step-detail {
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
    min-width: 60px;
    text-align: right;
}

.spinner-small {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.progress-status {
    color: var(--text-dim);
    margin-top: 0.5rem;
    font-size: 0.85rem;
}

/* --- Novel list --- */

.novels-section h2 {
    margin-bottom: 1rem;
    font-size: 1.25rem;
}

.novels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1rem;
}

.novel-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color 0.2s;
}

.novel-card:hover {
    border-color: var(--primary);
}

.novel-card-image-wrapper {
    position: relative;
}

.novel-card-image {
    width: 100%;
    height: 150px;
    object-fit: cover;
    background: var(--surface2);
}

.rating-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1.4;
    letter-spacing: 0.02em;
}

.rating-16 {
    background: rgba(245, 158, 11, 0.85);
    color: #fff;
}

.novel-card-body {
    padding: 1rem;
}

.novel-card-body h3 {
    font-size: 1rem;
    margin-bottom: 0.375rem;
}

.novel-card-body .novel-meta {
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 0.75rem;
}

.novel-card-body .btn {
    width: 100%;
    text-align: center;
}

.empty-state {
    text-align: center;
    color: var(--text-dim);
    padding: 2rem;
}

/* --- Error --- */

.error-message {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--error);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    color: var(--error);
    margin-bottom: 1rem;
    display: none;
}

/* --- Nav bar --- */

.nav-bar {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 2rem;
    align-items: center;
}

.nav-account-slot {
    margin-left: auto;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.nav-auth-link {
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-dim);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s;
}

.nav-auth-link:hover {
    border-color: var(--primary);
    color: var(--text);
}

.nav-auth-link--primary {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.nav-auth-link--primary:hover {
    background: var(--primary-hover);
    color: white;
}

.account-dropdown {
    position: relative;
}

.account-trigger {
    display: inline-flex;
    gap: 0.4rem;
    align-items: center;
    padding: 0.5rem 0.85rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.875rem;
    cursor: pointer;
}

.account-trigger:hover {
    border-color: var(--primary);
}

.account-caret {
    font-size: 0.7rem;
    color: var(--text-dim);
}

.account-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 0.35rem);
    min-width: 160px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,0.45);
    display: flex;
    flex-direction: column;
    padding: 0.25rem;
    z-index: 50;
}

.account-menu[hidden] {
    display: none;
}

.account-menu a,
.account-menu button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-radius: calc(var(--radius) - 2px);
    background: transparent;
    border: none;
    color: var(--text);
    font: inherit;
    text-decoration: none;
    cursor: pointer;
}

.account-menu a:hover,
.account-menu button:hover {
    background: var(--surface2);
}

.nav-bar a {
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-dim);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s;
}

.nav-bar a:hover {
    border-color: var(--primary);
    color: var(--text);
}

.nav-bar a.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* --- Hero --- */

.hero {
    text-align: center;
    padding: 2.5rem 0 2rem;
}

.hero-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.9rem;
    margin-bottom: 0.75rem;
}

.hero-logo {
    width: 72px;
    height: 72px;
    object-fit: contain;
    filter: drop-shadow(0 4px 14px rgba(102, 51, 102, 0.35));
}

.hero h1 {
    font-size: 2.75rem;
    margin: 0;
    background: linear-gradient(135deg, #c084fc 0%, #e879b8 60%, #f0abfc 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    letter-spacing: 0.5px;
}

.hero p {
    color: var(--text-dim);
    font-size: 1.15rem;
    max-width: 620px;
    margin: 0 auto 2rem;
    line-height: 1.6;
}

@media (max-width: 480px) {
    .hero-logo { width: 56px; height: 56px; }
    .hero h1 { font-size: 2.1rem; }
    .hero p { font-size: 1rem; }
}

.hero-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* --- Search input --- */

.search-input {
    width: 100%;
    padding: 0.625rem 0.75rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9375rem;
    font-family: inherit;
    margin-bottom: 1rem;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
}

.search-input::placeholder {
    color: var(--text-dim);
}

/* --- Filter bar --- */

.filter-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.filter-bar .chip-group {
    flex: 1;
}

/* --- Load more --- */

.load-more-wrapper {
    text-align: center;
    margin-top: 1.5rem;
}

.load-more-btn {
    padding: 0.625rem 2rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text-dim);
    font-size: 0.9375rem;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}

.load-more-btn:hover {
    border-color: var(--primary);
    color: var(--text);
}

/* --- Section header --- */

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.section-header h2 {
    font-size: 1.25rem;
    margin: 0;
}

.section-header a {
    color: var(--primary);
    text-decoration: none;
    font-size: 0.875rem;
}

.section-header a:hover {
    text-decoration: underline;
}

/* --- Language switcher --- */

.lang-switcher {
    position: fixed;
    top: 1rem;
    right: 1rem;
    display: flex;
    gap: 0.25rem;
    padding: 0.25rem;
    background: rgba(26, 26, 46, 0.85);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    backdrop-filter: blur(8px);
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.lang-flag {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    padding: 0.35rem 0.7rem;
    border-radius: calc(var(--radius) - 2px);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    line-height: 1;
    transition: background 0.15s, color 0.15s;
    font-family: inherit;
}

.lang-flag:hover {
    background: rgba(124, 58, 237, 0.15);
    color: var(--text);
}

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

/* --- Templates gallery --- */

.templates-section {
    margin-top: 3rem;
    margin-bottom: 2.5rem;
}

.templates-carousel {
    position: relative;
}

.templates-grid {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
    scroll-behavior: smooth;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    padding-bottom: 0.5rem;
}

.templates-grid::-webkit-scrollbar {
    height: 6px;
}

.templates-grid::-webkit-scrollbar-track {
    background: transparent;
}

.templates-grid::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.templates-grid > .empty-state {
    flex: 1 0 100%;
}

.templates-carousel-btn {
    position: absolute;
    top: 75px;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    line-height: 1;
    z-index: 2;
    transition: background 0.15s, border-color 0.15s, opacity 0.2s;
    opacity: 0.9;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.templates-carousel-btn:hover {
    background: var(--surface2);
    border-color: var(--primary);
    opacity: 1;
}

.templates-carousel-btn[disabled] {
    opacity: 0;
    pointer-events: none;
}

.templates-carousel-btn--prev {
    left: -18px;
}

.templates-carousel-btn--next {
    right: -18px;
}

@media (max-width: 600px) {
    .templates-carousel-btn {
        display: none;
    }
}

.template-card {
    flex: 0 0 240px;
    scroll-snap-align: start;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    display: block;
    transition: border-color 0.2s, transform 0.15s;
}

.template-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
}

.template-card-image-wrapper {
    position: relative;
}

.template-card-image {
    width: 100%;
    height: 150px;
    object-fit: cover;
    background: linear-gradient(135deg, var(--surface2), var(--surface));
    display: block;
}

.template-card-body {
    padding: 1rem;
}

.template-card-body h3 {
    font-size: 1rem;
    margin-bottom: 0.375rem;
}

.template-tagline {
    font-size: 0.85rem;
    color: var(--text-dim);
    line-height: 1.4;
    margin: 0;
}

.hero-actions-secondary {
    justify-content: center;
    margin-top: 0.75rem;
}

.btn-link-secondary {
    color: var(--text-dim);
    text-decoration: none;
    font-size: 0.95rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    transition: color 0.15s, background 0.15s;
}

.btn-link-secondary:hover {
    color: var(--text);
    background: var(--surface2);
}

/* --- Template picker chips (wizard Step 1) --- */

.chip-group-loading {
    color: var(--text-dim);
    font-size: 0.85rem;
    padding: 0.5rem 0;
}

/* --- Active-template banner in wizard --- */

.template-banner {
    background: rgba(124, 58, 237, 0.12);
    border: 1px solid rgba(124, 58, 237, 0.4);
    border-radius: var(--radius);
    padding: 0.625rem 1rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
}

.template-banner-label {
    color: var(--text-dim);
}

.template-banner-name {
    color: var(--text);
    font-weight: 600;
}

.template-banner-clear {
    margin-left: auto;
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-family: inherit;
}

.template-banner-clear:hover {
    background: var(--surface2);
    color: var(--text);
}

/* --- Responsive --- */

@media (max-width: 600px) {
    .container { padding: 1rem; }
    .form-row { flex-direction: column; gap: 0; }
    .rel-row { flex-wrap: wrap; }
    .lang-switcher { top: 0.5rem; right: 0.5rem; padding: 0.2rem; }
    .lang-flag { padding: 0.3rem 0.45rem; }
    .wizard-step-pill {
        min-width: 0;
        padding: 0.5rem 0.5rem;
        font-size: 0.75rem;
    }
    .wizard-nav { flex-wrap: wrap; }
    .templates-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

/* --- Auth pages --- */

.auth-wrap {
    display: flex;
    justify-content: center;
    padding: 1rem 0 3rem;
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.75rem 1.5rem 1.5rem;
    max-width: 420px;
    width: 100%;
}

.auth-card h1,
.auth-card h2 {
    font-size: 1.4rem;
    margin-bottom: 0.75rem;
    -webkit-text-fill-color: initial;
    background: none;
    color: var(--text);
}

.auth-tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.auth-tab {
    flex: 1;
    padding: 0.6rem 0.75rem;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-dim);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: -1px;
}

.auth-tab.active {
    color: var(--text);
    border-bottom-color: var(--primary);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.auth-field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.875rem;
    color: var(--text-dim);
}

.auth-field input {
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

.auth-field input:focus {
    outline: none;
    border-color: var(--primary);
}

.auth-field small {
    color: var(--text-dim);
    font-size: 0.75rem;
}

.auth-submit {
    margin-top: 0.25rem;
}

.auth-meta {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-top: 0.5rem;
}

.auth-meta a {
    color: var(--primary);
}

.auth-link-btn {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    padding: 0;
    font: inherit;
    text-decoration: underline;
}

.auth-alert {
    padding: 0.6rem 0.75rem;
    border-radius: var(--radius);
    margin-bottom: 0.9rem;
    font-size: 0.875rem;
}

.auth-alert--error {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.5);
    color: #fecaca;
}

.auth-alert--info {
    background: rgba(124, 58, 237, 0.15);
    border: 1px solid rgba(124, 58, 237, 0.5);
    color: #ddd6fe;
}

.auth-verify h2 {
    font-size: 1.15rem;
}

/* --- Novel card author line --- */

.novel-card-author {
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 0.35rem;
}

.novel-card-author a {
    color: var(--text);
    text-decoration: none;
}

.novel-card-author a:hover {
    color: var(--primary);
    text-decoration: underline;
}

.novel-card-author--anon {
    font-style: italic;
}

/* --- Profile page --- */

.profile-header {
    margin: 0.5rem 0 1.25rem;
}

.profile-header h1 {
    font-size: 1.8rem;
    margin-bottom: 0.25rem;
}

.profile-meta {
    color: var(--text-dim);
    font-size: 0.9rem;
}

.profile-account {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
}

.profile-account h2 {
    font-size: 1rem;
    margin-bottom: 0.4rem;
    -webkit-text-fill-color: initial;
    background: none;
    color: var(--text);
}

.profile-novels h2 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
    -webkit-text-fill-color: initial;
    background: none;
    color: var(--text);
}

/* --- Player: author link in header --- */

.player-author-link {
    color: rgba(255, 255, 255, 0.55);
    text-decoration: none;
}

.player-author-link:hover {
    color: #fff;
    text-decoration: underline;
}

