/* ==========================================================================
   READVERRA — TWILIGHT THEATER THEME
   Cinematic twilight: midnight + velvet + amber candle + cream + rose.
   Display: Cormorant Garamond (italic).  Body: Manrope.  Mono: JetBrains Mono.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300..700;1,300..700&family=Manrope:wght@200..800&family=JetBrains+Mono:wght@300..700&display=swap');

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

:root {
    /* core surfaces */
    --bg: #0b0e1a;
    --bg-deep: #060812;
    --surface: #14182a;
    --surface2: #1f2238;
    --velvet: #1c1a2e;

    /* brand — amber candle is the new primary, rose is the romantic accent */
    --primary: #e8a955;
    --primary-hover: #f1bd76;
    --primary-soft: rgba(232, 169, 85, 0.12);
    --primary-glow: rgba(232, 169, 85, 0.35);

    --accent: #c2566c;
    --accent-hover: #d46b80;
    --accent-soft: rgba(194, 86, 108, 0.15);

    /* text — cream on midnight */
    --text: #f0e6d2;
    --text-dim: rgba(240, 230, 210, 0.62);
    --text-muted: rgba(240, 230, 210, 0.4);

    /* utility */
    --error: #d97373;
    --error-soft: rgba(217, 115, 115, 0.15);
    --success: #8fb89c;
    --success-soft: rgba(143, 184, 156, 0.15);

    --border: rgba(240, 230, 210, 0.1);
    --border-strong: rgba(232, 169, 85, 0.3);

    --radius: 4px;
    --radius-lg: 8px;

    --serif: 'Cormorant Garamond', 'Georgia', serif;
    --sans: 'Manrope', system-ui, -apple-system, sans-serif;
    --mono: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
}

html {
    overflow-x: hidden;
}

body {
    font-family: var(--sans);
    background:
        radial-gradient(ellipse 70% 50% at 50% 0%, rgba(232, 169, 85, 0.06), transparent 70%),
        radial-gradient(ellipse 60% 80% at 100% 100%, rgba(194, 86, 108, 0.05), transparent 70%),
        var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
    font-weight: 400;
    line-height: 1.55;
    letter-spacing: 0.005em;
    position: relative;
}

/* film grain overlay (whole page) */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 1;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='1.4' numOctaves='2' seed='7'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.06 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
    opacity: 0.7;
}

body > * { position: relative; z-index: 2; }

/* --- Layout ------------------------------------------------------------- */

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

h1, h2, h3, h4 {
    font-family: var(--serif);
    color: var(--text);
    font-weight: 500;
    letter-spacing: -0.005em;
    line-height: 1.15;
}

h1 {
    font-style: italic;
    font-size: 2.4rem;
    margin-bottom: 0.5rem;
    font-weight: 400;
    color: var(--text);
}

.subtitle {
    color: var(--text-dim);
    margin-bottom: 2rem;
    font-family: var(--serif);
    font-style: italic;
    font-size: 1.1rem;
}

/* --- Cards -------------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.6rem 1.5rem;
    margin-bottom: 1rem;
    position: relative;
    transition: border-color 0.25s;
}

.card:hover {
    border-color: rgba(240, 230, 210, 0.18);
}

.card-title {
    font-family: var(--sans);
    font-size: 0.72rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
    color: var(--primary);
    letter-spacing: 0.22em;
    text-transform: uppercase;
}

.card-hint {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-bottom: 1rem;
    font-family: var(--serif);
    font-style: italic;
    line-height: 1.5;
}

/* --- Forms -------------------------------------------------------------- */

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

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

.form-label {
    display: block;
    font-family: var(--sans);
    font-size: 0.7rem;
    color: var(--text-dim);
    margin-bottom: 0.5rem;
    font-weight: 600;
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

.form-group input[type="text"],
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.7rem 0.85rem;
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.95rem;
    font-family: var(--sans);
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.form-group textarea {
    min-height: 86px;
    resize: vertical;
    line-height: 1.55;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
    background: var(--surface);
}

.form-group input::placeholder,
.form-group textarea::placeholder {
    color: var(--text-muted);
}

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

.char-counter {
    display: block;
    margin-top: 0.3rem;
    text-align: right;
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.05em;
    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.45rem;
}

.chip {
    padding: 0.45rem 0.95rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-dim);
    font-size: 0.82rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--sans);
    font-weight: 500;
    user-select: none;
    letter-spacing: 0.02em;
}

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

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

.chip-group.multi .chip {
    border-style: dashed;
}

.chip-group.multi .chip.active {
    border-style: solid;
}

/* --- Advanced seeds accordion ------------------------------------------ */

.advanced-seeds-card {
    padding: 0;
}

.advanced-seeds-card details {
    padding: 0;
}

.advanced-summary {
    cursor: pointer;
    padding: 1rem 1.25rem;
    list-style: none;
    color: var(--text);
    font-weight: 600;
    letter-spacing: 0.02em;
    user-select: none;
}

.advanced-summary::-webkit-details-marker { display: none; }

.advanced-summary::before {
    content: '▸';
    display: inline-block;
    margin-right: 0.5rem;
    transition: transform 0.2s;
    color: var(--text-dim);
}

details[open] .advanced-summary::before { transform: rotate(90deg); }

.advanced-summary-hint {
    font-weight: 400;
    font-size: 0.82rem;
    color: var(--text-dim);
    margin-left: 0.35rem;
}

.advanced-body {
    padding: 0.25rem 1.25rem 1.1rem;
    border-top: 1px solid var(--border);
}

/* --- Dynamic hint rows (world rules, chekhov) -------------------------- */

.hint-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
    margin-bottom: 0.45rem;
}

.hint-row .input-with-counter {
    flex: 1;
}

/* --- Slider ------------------------------------------------------------- */

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

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

.slider-value {
    font-family: var(--serif);
    font-style: italic;
    font-size: 1.8rem;
    font-weight: 500;
    color: var(--primary);
    min-width: 1.8rem;
    text-align: center;
}

.slider-unit {
    font-size: 0.75rem;
    color: var(--text-dim);
    letter-spacing: 0.18em;
    text-transform: uppercase;
}

/* --- Characters --------------------------------------------------------- */

.char-card {
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.95rem 1rem;
    margin-bottom: 0.625rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    transition: border-color 0.2s;
}

.char-card:hover { border-color: rgba(240,230,210,0.18); }

.char-row {
    display: flex;
    gap: 0.85rem;
    align-items: flex-start;
}

.char-deeper {
    border-top: 1px dashed rgba(240,230,210,0.15);
    padding-top: 0.7rem;
}

.char-deeper .form-group {
    margin-bottom: 0.55rem;
}

.form-label-sm {
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    color: var(--text-dim);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
}

.char-expand {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.9rem;
    flex-shrink: 0;
    transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.char-expand:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: rgba(232,169,85,0.08);
}

.char-card.expanded .char-expand {
    color: var(--accent);
    border-color: var(--accent);
}

.char-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.78rem;
    flex-shrink: 0;
    color: var(--bg);
    font-family: var(--sans);
    letter-spacing: 0.05em;
}

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

.char-fields input {
    width: 100%;
    padding: 0.55rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.875rem;
    font-family: var(--sans);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.char-fields input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-soft);
}

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

.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.2s;
}

.char-remove:hover {
    color: var(--error);
    background: var(--error-soft);
}

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

.char-proto:hover:not(.disabled) {
    color: var(--primary);
    background: var(--primary-soft);
}

.char-proto.active {
    color: var(--primary);
}

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

.char-card.is-protagonist {
    border-color: var(--primary);
    box-shadow: 0 0 0 1px var(--primary-soft), 0 0 24px -8px var(--primary-glow);
}

.add-btn {
    width: 100%;
    padding: 0.75rem;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-dim);
    font-size: 0.78rem;
    cursor: pointer;
    font-family: var(--sans);
    font-weight: 600;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    transition: all 0.2s;
}

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

/* --- Relationships ------------------------------------------------------ */

.rel-row {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.55rem 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;
    color: var(--text);
}

.rel-arrow {
    color: var(--primary);
    flex-shrink: 0;
    font-style: italic;
    font-family: var(--serif);
}

.rel-row select {
    padding: 0.4rem 0.55rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.8rem;
    font-family: var(--sans);
    cursor: pointer;
    transition: border-color 0.2s;
}

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

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

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

.toggle {
    position: relative;
    width: 46px;
    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(--bg-deep);
    border: 1px solid var(--border);
    border-radius: 999px;
    transition: 0.25s;
}

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

.toggle input:checked + .toggle-track {
    background: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 0 16px -4px var(--primary-glow);
}

.toggle input:checked + .toggle-track::before {
    transform: translateX(22px);
    background: var(--bg);
}

.toggle-label {
    font-size: 0.95rem;
    cursor: default;
    color: var(--text);
}

/* --- Endings ------------------------------------------------------------ */

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

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

.ending-avatar {
    background: linear-gradient(135deg, var(--accent), var(--primary));
}

.char-fields textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.875rem;
    font-family: var(--sans);
    resize: vertical;
    min-height: 2.5rem;
    line-height: 1.5;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.char-fields textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-soft);
}

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

/* --- Buttons ------------------------------------------------------------ */
/* Twilight signature: ghost border, hover-fill animation. */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    padding: 0.7rem 1.6rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--sans);
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 0.22em;
    transition: color 0.3s, background 0.3s, border-color 0.3s, transform 0.15s;
    position: relative;
    overflow: hidden;
}

.btn:active { transform: translateY(1px); }

.btn-primary {
    color: var(--text);
    border-color: var(--primary);
    background: transparent;
    z-index: 0;
}
.btn-primary::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--primary);
    transform: translateY(101%);
    transition: transform 0.3s ease;
    z-index: -1;
}
.btn-primary:hover {
    color: var(--bg);
}
.btn-primary:hover::before {
    transform: translateY(0);
}
.btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    color: var(--text-dim);
    border-color: var(--border);
}
.btn-primary:disabled:hover { color: var(--text-dim); }
.btn-primary:disabled:hover::before { transform: translateY(101%); }

.btn-secondary {
    background: transparent;
    color: var(--text-dim);
    border-color: var(--border);
}
.btn-secondary:hover {
    color: var(--text);
    border-color: var(--text-dim);
    background: rgba(240, 230, 210, 0.04);
}

.btn-accent {
    color: var(--text);
    border-color: var(--accent);
    background: transparent;
    z-index: 0;
}
.btn-accent::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--accent);
    transform: translateY(101%);
    transition: transform 0.3s ease;
    z-index: -1;
}
.btn-accent:hover {
    color: var(--text);
}
.btn-accent:hover::before {
    transform: translateY(0);
}
.btn-accent:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    border-color: var(--border);
}

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

/* --- Wizard ------------------------------------------------------------- */

.wizard-stepper {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 1.75rem;
    flex-wrap: wrap;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
}

.wizard-step-pill {
    flex: 1 1 0;
    min-width: 110px;
    padding: 0.65rem 0.85rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s;
    user-select: none;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.wizard-step-pill.completed {
    color: var(--text);
    border-color: rgba(232, 169, 85, 0.4);
}

.wizard-step-pill.active {
    color: var(--bg);
    background: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 0 24px -8px var(--primary-glow);
}

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

.wizard-step-pill.completed .wizard-step-num {
    background: var(--primary-soft);
    color: var(--primary);
}

.wizard-step-pill.active .wizard-step-num {
    background: var(--bg);
    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.55rem;
    cursor: pointer;
    font-size: 0.95rem;
    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.82rem;
    color: var(--text-dim);
    margin-top: 0.3rem;
    margin-left: 1.7rem;
    font-family: var(--serif);
    font-style: italic;
}

/* --- Radio group -------------------------------------------------------- */

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

.radio-option {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.25s;
}

.radio-option:hover {
    border-color: rgba(240, 230, 210, 0.2);
}

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

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

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

.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.2s;
}

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

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

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

.radio-desc {
    font-size: 0.85rem;
    color: var(--text-dim);
    line-height: 1.45;
    font-family: var(--serif);
    font-style: italic;
}

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

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

.scenario-preview h2 {
    margin-bottom: 1.25rem;
    font-size: 1.7rem;
    font-style: italic;
    font-family: var(--serif);
    font-weight: 400;
}

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

.scenario-title-input {
    width: 100%;
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 0.85rem;
    color: var(--text);
    font-size: 1.4rem;
    font-weight: 500;
    font-family: var(--serif);
    font-style: italic;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.scenario-title-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.scenario-title-status {
    min-height: 1rem;
    margin-top: 0.3rem;
    font-size: 0.78rem;
    color: var(--text-dim);
    font-family: var(--mono);
}

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

.scene-card {
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.15rem;
    margin-bottom: 0.75rem;
    transition: border-color 0.2s;
}

.scene-card:hover { border-color: rgba(240, 230, 210, 0.18); }

.scene-card h3 {
    font-family: var(--mono);
    font-size: 0.72rem;
    color: var(--primary);
    margin-bottom: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.22em;
    font-weight: 600;
}

.scene-card p {
    font-size: 0.92rem;
    color: var(--text-dim);
    line-height: 1.6;
    font-family: var(--serif);
}

.scene-description-text {
    margin-bottom: 0.75rem;
    white-space: pre-wrap;
    font-style: italic;
}

.scene-card .scene-meta {
    margin-top: 0.55rem;
    font-size: 0.78rem;
    color: var(--text-dim);
    font-family: var(--sans);
}

.scene-card .scene-meta-label {
    color: var(--primary);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.68rem;
    letter-spacing: 0.18em;
    font-family: var(--mono);
}

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

.character-badge {
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.4rem 0.8rem;
    font-size: 0.78rem;
    font-family: var(--sans);
    color: var(--text-dim);
}

.scenario-tropes {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    align-items: center;
}

.trope-chip {
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.18rem 0.55rem;
    font-size: 0.72rem;
    font-family: var(--sans);
    color: var(--text-dim);
}

.scenario-meta-label {
    color: var(--primary);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.66rem;
    letter-spacing: 0.16em;
    font-family: var(--mono);
    margin-right: 0.4rem;
}

.plot-overview,
.endings-overview {
    margin: 1.25rem 0 0.5rem;
}

.plot-overview h3,
.endings-overview h3 {
    font-family: var(--mono);
    font-size: 0.72rem;
    color: var(--primary);
    margin-bottom: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.22em;
    font-weight: 600;
}

.plot-overview > div p {
    font-family: var(--serif);
    font-size: 0.94rem;
    line-height: 1.65;
    color: var(--text-dim);
    margin: 0 0 0.7rem;
}

.plot-overview > div p:last-child {
    margin-bottom: 0;
}

.endings-overview ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 0.6rem;
}

.ending-card {
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius);
    padding: 0.75rem 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.ending-title {
    font-family: var(--sans);
    font-size: 0.88rem;
    color: var(--text);
    font-weight: 600;
    letter-spacing: 0.02em;
}

.ending-teaser {
    font-family: var(--serif);
    font-size: 0.9rem;
    line-height: 1.55;
    color: var(--text-dim);
}

.scenes-spoiler {
    margin: 1.5rem 0 0.5rem;
    padding: 1rem;
    border: 1px dashed var(--border);
    border-radius: 6px;
    background: rgba(232,169,85,0.04);
}

.spoiler-warning {
    margin: 0 0 0.75rem;
    color: var(--accent);
    font-size: 0.88rem;
    line-height: 1.45;
}

.spoiler-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

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

/* --- Progress ----------------------------------------------------------- */

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

/* candle glow on progress card */
.progress-section::before {
    content: '';
    position: absolute;
    top: -100px; left: 50%;
    transform: translateX(-50%);
    width: 400px; height: 400px;
    background: radial-gradient(circle, var(--primary-glow), transparent 60%);
    opacity: 0.5;
    pointer-events: none;
    animation: candle-flicker 4s ease-in-out infinite;
}

@keyframes candle-flicker {
    0%, 100% { opacity: 0.45; transform: translateX(-50%) scale(1); }
    50%      { opacity: 0.65; transform: translateX(-50%) scale(1.07); }
}

.progress-section > * { position: relative; z-index: 1; }

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

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

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

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

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

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

.step-label { flex: 1; }

.step-detail {
    font-size: 0.75rem;
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    min-width: 60px;
    text-align: right;
    color: var(--text-muted);
}

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

.progress-status {
    color: var(--text-dim);
    margin-top: 0.6rem;
    font-size: 0.85rem;
    font-family: var(--serif);
    font-style: italic;
}

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

.novels-section { margin-top: 2rem; }

.section-cta {
    margin-top: 1.5rem;
    display: flex;
    justify-content: center;
}

.novels-section h2 {
    margin-bottom: 1.25rem;
    font-size: 1.6rem;
    font-style: italic;
    font-weight: 400;
    color: var(--text);
}

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

.novel-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: border-color 0.3s, transform 0.3s;
    cursor: pointer;
}

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

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

.novel-card-image {
    width: 100%;
    height: 170px;
    object-fit: cover;
    background: var(--velvet);
    display: block;
    transition: transform 0.6s;
}

.novel-card:hover .novel-card-image {
    transform: scale(1.04);
}

/* gradient fade at bottom of cover for label legibility */
.novel-card-image-wrapper::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(to top, rgba(11,14,26,0.55) 0%, transparent 40%);
}

.rating-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 1.4;
    letter-spacing: 0.1em;
    font-family: var(--mono);
    z-index: 2;
    backdrop-filter: blur(6px);
}

.rating-16 {
    background: rgba(232, 169, 85, 0.85);
    color: var(--bg);
}

/* Admin-only featured toggle. Placed top-left to avoid the rating-badge
   (top-right). Filled state uses the accent colour so an admin can see at
   a glance which novels are currently on the home page. */
.novel-card-star {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 3;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: 999px;
    background: rgba(11, 14, 26, 0.55);
    color: rgba(255, 255, 255, 0.85);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    user-select: none;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(6px);
    transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.novel-card-star:hover {
    transform: scale(1.08);
    background: rgba(11, 14, 26, 0.75);
    color: #fff;
}

.novel-card-star:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.novel-card-star:disabled {
    opacity: 0.5;
    cursor: progress;
}

.novel-card-star--on {
    background: var(--accent);
    color: #fff;
}

.novel-card-star--on:hover {
    background: var(--accent-hover);
}

.novel-card-body {
    padding: 1.1rem 1.1rem 1.2rem;
}

.novel-card-body h3 {
    font-family: var(--serif);
    font-style: italic;
    font-weight: 500;
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
    line-height: 1.2;
    color: var(--text);
}

.novel-card-body .novel-meta {
    font-size: 0.78rem;
    color: var(--text-dim);
    margin-bottom: 0.85rem;
    font-family: var(--sans);
}

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

.empty-state {
    text-align: center;
    color: var(--text-dim);
    padding: 2.5rem 1rem;
    font-family: var(--serif);
    font-style: italic;
    font-size: 1.05rem;
}

/* --- Error -------------------------------------------------------------- */

.error-message {
    background: var(--error-soft);
    border: 1px solid var(--error);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    color: var(--error);
    margin-bottom: 1rem;
    display: none;
    font-family: var(--sans);
    font-size: 0.9rem;
}

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

.nav-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 2.5rem;
    padding-bottom: 1.25rem;
    align-items: center;
    min-width: 0;
    border-bottom: 1px solid var(--border);
}

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

.nav-auth-link {
    padding: 0.55rem 1.1rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-dim);
    text-decoration: none;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    font-family: var(--sans);
    transition: all 0.25s;
}

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

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

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

.account-dropdown { position: relative; }

.account-trigger {
    display: inline-flex;
    gap: 0.4rem;
    align-items: center;
    padding: 0.55rem 0.95rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    font-size: 0.85rem;
    font-family: var(--sans);
    cursor: pointer;
    transition: border-color 0.2s;
}

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

.account-caret {
    font-size: 0.65rem;
    color: var(--primary);
}

.account-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 0.4rem);
    min-width: 180px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 12px 32px rgba(0,0,0,0.55);
    display: flex;
    flex-direction: column;
    padding: 0.3rem;
    z-index: 50;
    backdrop-filter: blur(10px);
}

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

.account-menu a,
.account-menu button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.55rem 0.8rem;
    border-radius: var(--radius);
    background: transparent;
    border: none;
    color: var(--text);
    font: inherit;
    font-family: var(--sans);
    font-size: 0.88rem;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

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

/* nav links */
.nav-bar a {
    padding: 0.55rem 1rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-dim);
    text-decoration: none;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    font-family: var(--sans);
    transition: all 0.25s;
    position: relative;
}

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

.nav-bar a.active {
    color: var(--text);
}

.nav-bar a.active::after {
    content: '';
    position: absolute;
    left: 1rem;
    right: 1rem;
    bottom: -1.3rem;
    height: 1px;
    background: var(--primary);
}

/* --- Hero --------------------------------------------------------------- */

.hero {
    text-align: center;
    padding: 3rem 1rem 3.5rem;
    position: relative;
    overflow: visible;
}

/* candle glow behind hero */
.hero::before {
    content: '';
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    width: 700px;
    height: 500px;
    max-width: 100%;
    background: radial-gradient(ellipse, var(--primary-glow), transparent 65%);
    opacity: 0.35;
    pointer-events: none;
    animation: candle-flicker 5s ease-in-out infinite;
    z-index: -1;
}

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

.hero-logo {
    width: 64px;
    height: 64px;
    object-fit: contain;
    filter: drop-shadow(0 4px 18px rgba(232, 169, 85, 0.35));
}

.hero-eyebrow {
    font-family: var(--sans, inherit);
    font-style: normal;
    font-size: 0.8rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--accent, var(--text-dim));
    margin: 0 0 1.25rem;
    max-width: none;
}

.hero h1 {
    font-family: var(--serif);
    font-style: italic;
    font-weight: 400;
    font-size: clamp(2.5rem, 6vw, 4rem);
    margin: 0;
    /* no purple gradient — clean cream italic */
    color: var(--text);
    background: none;
    -webkit-text-fill-color: initial;
    letter-spacing: -0.005em;
    line-height: 1;
}

.hero p {
    color: var(--text-dim);
    font-family: var(--serif);
    font-style: italic;
    font-size: 1.2rem;
    max-width: 560px;
    margin: 1.25rem auto 2.25rem;
    line-height: 1.6;
}

@media (max-width: 480px) {
    .hero-logo { width: 52px; height: 52px; }
    .hero h1 { font-size: 2.2rem; }
    .hero p { font-size: 1.05rem; }
}

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

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

.search-input {
    width: 100%;
    padding: 0.7rem 0.85rem;
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.95rem;
    font-family: var(--sans);
    margin-bottom: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

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

/* --- 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.75rem;
}

.load-more-btn {
    padding: 0.75rem 2.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: transparent;
    color: var(--text-dim);
    font-size: 0.7rem;
    cursor: pointer;
    font-family: var(--sans);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.22em;
    transition: all 0.25s;
}

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

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

.section-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    padding-bottom: 0.85rem;
    border-bottom: 1px solid var(--border);
    gap: 1rem;
}

.section-header h2 {
    font-family: var(--serif);
    font-style: italic;
    font-weight: 400;
    font-size: 1.6rem;
    margin: 0;
    color: var(--text);
}

.section-header a {
    color: var(--primary);
    text-decoration: none;
    font-size: 0.7rem;
    font-family: var(--sans);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.22em;
    flex-shrink: 0;
}

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

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

.lang-switcher {
    position: fixed;
    top: 1rem;
    right: 1rem;
    display: flex;
    gap: 0.25rem;
    padding: 0.3rem;
    background: rgba(11, 14, 26, 0.7);
    border: 1px solid var(--border);
    border-radius: 999px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 1000;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}

.lang-flag {
    appearance: none;
    border: none;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    padding: 0.4rem 0.75rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    line-height: 1;
    font-family: var(--sans);
    transition: all 0.2s;
}

.lang-flag:hover {
    background: var(--primary-soft);
    color: var(--primary);
}

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

/* --- 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;
    scrollbar-color: var(--border) transparent;
    padding-bottom: 0.75rem;
}

.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::-webkit-scrollbar-thumb:hover { background: var(--primary); }

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

.templates-carousel-btn {
    position: absolute;
    top: 75px;
    transform: translateY(-50%);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: rgba(20, 24, 42, 0.9);
    backdrop-filter: blur(8px);
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    line-height: 1;
    z-index: 2;
    transition: all 0.2s;
    opacity: 0.9;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.templates-carousel-btn:hover {
    border-color: var(--primary);
    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-lg);
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    display: block;
    transition: border-color 0.3s, transform 0.3s;
}

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

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

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

.template-card:hover .template-card-image { transform: scale(1.04); }

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

.template-card-body h3 {
    font-family: var(--serif);
    font-style: italic;
    font-weight: 500;
    font-size: 1.15rem;
    margin-bottom: 0.4rem;
    color: var(--text);
}

.template-tagline {
    font-size: 0.85rem;
    color: var(--text-dim);
    line-height: 1.45;
    margin: 0;
    font-family: var(--serif);
    font-style: italic;
}

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

.btn-link-secondary {
    color: var(--text-dim);
    text-decoration: none;
    font-size: 0.92rem;
    padding: 0.55rem 0.85rem;
    border-radius: var(--radius);
    transition: color 0.2s, background 0.2s;
    font-family: var(--serif);
    font-style: italic;
}

.btn-link-secondary:hover {
    color: var(--primary);
    background: var(--primary-soft);
}

/* --- Template picker chips --------------------------------------------- */

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

/* --- Active-template banner -------------------------------------------- */

.template-banner {
    background: var(--primary-soft);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 0.75rem 1.1rem;
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.92rem;
}

.template-banner-label {
    color: var(--text-dim);
    font-family: var(--sans);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    font-weight: 600;
}

.template-banner-name {
    color: var(--text);
    font-family: var(--serif);
    font-style: italic;
    font-size: 1.05rem;
    font-weight: 500;
}

.template-banner-clear {
    margin-left: auto;
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0.3rem 0.55rem;
    border-radius: var(--radius);
    font-family: var(--sans);
    transition: all 0.2s;
}

.template-banner-clear:hover {
    background: var(--surface);
    color: var(--accent);
}

/* --- Mobile nav toggle (hamburger) -------------------------------------- */

.nav-toggle { display: none; }

/* --- Responsive --------------------------------------------------------- */

@media (max-width: 600px) {
    .container { padding: 1rem 1rem 2rem; }
    .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.5rem; }

    /* Collapsed nav: only the hamburger button is visible. */
    .nav-bar {
        flex-wrap: wrap;
        gap: 0;
        padding-right: 5.5rem; /* clearance for the absolute lang-switcher */
        margin-bottom: 1.5rem;
        padding-bottom: 0.75rem;
    }
    .nav-bar > *:not(.nav-toggle) {
        display: none;
    }
    .nav-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        padding: 0;
        border-radius: var(--radius);
        border: 1px solid var(--border);
        background: transparent;
        color: var(--text);
        font-size: 1.25rem;
        line-height: 1;
        cursor: pointer;
        font-family: var(--sans);
        transition: border-color 0.2s, color 0.2s;
    }
    .nav-toggle:hover,
    .nav-toggle[aria-expanded="true"] {
        border-color: var(--primary);
        color: var(--primary);
    }

    /* Open state: links and account slot drop in as a vertical panel. */
    .nav-bar--open > *:not(.nav-toggle) {
        display: flex;
        flex-basis: 100%;
        width: 100%;
    }
    .nav-bar--open > a {
        padding: 0.75rem 1rem;
        margin-top: 0.4rem;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        text-align: left;
        align-items: center;
    }
    .nav-bar--open > a.active {
        border-color: var(--primary);
        color: var(--text);
    }
    .nav-bar--open > a.active::after {
        display: none;
    }
    .nav-bar--open > .nav-account-slot {
        flex-direction: column;
        gap: 0.4rem;
        margin: 0.6rem 0 0;
        padding-top: 0.6rem;
        border-top: 1px solid var(--border);
    }
    .nav-bar--open .nav-auth-link,
    .nav-bar--open .account-trigger {
        width: 100%;
        justify-content: center;
        text-align: center;
    }
    .nav-bar--open .account-dropdown {
        width: 100%;
    }

    .wizard-step-pill {
        min-width: 0;
        padding: 0.5rem 0.5rem;
        font-size: 0.65rem;
    }
    .wizard-nav { flex-wrap: wrap; }
    .templates-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
    .hero { padding: 2rem 0.5rem 2.5rem; }
}

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

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

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem 1.75rem 1.75rem;
    max-width: 440px;
    width: 100%;
    position: relative;
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.5);
}

/* faint gold edge top-left as theatrical corner-mark */
.auth-card::before {
    content: '';
    position: absolute;
    top: -1px; left: -1px;
    width: 28px; height: 28px;
    border-top: 1px solid var(--primary);
    border-left: 1px solid var(--primary);
    border-top-left-radius: var(--radius-lg);
    pointer-events: none;
}
.auth-card::after {
    content: '';
    position: absolute;
    bottom: -1px; right: -1px;
    width: 28px; height: 28px;
    border-bottom: 1px solid var(--primary);
    border-right: 1px solid var(--primary);
    border-bottom-right-radius: var(--radius-lg);
    pointer-events: none;
}

.auth-card h1,
.auth-card h2 {
    font-family: var(--serif);
    font-style: italic;
    font-weight: 400;
    font-size: 1.7rem;
    margin-bottom: 1rem;
    -webkit-text-fill-color: initial;
    background: none;
    color: var(--text);
}

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

.auth-tab {
    flex: 1;
    padding: 0.7rem 0.75rem;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-dim);
    font: inherit;
    font-family: var(--sans);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    cursor: pointer;
    margin-bottom: -1px;
    transition: color 0.2s, border-color 0.2s;
}

.auth-tab:hover { color: var(--text); }

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

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

.auth-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.7rem;
    color: var(--text-dim);
    font-family: var(--sans);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.18em;
}

.auth-field input {
    padding: 0.7rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-deep);
    color: var(--text);
    font: inherit;
    font-family: var(--sans);
    font-size: 0.95rem;
    text-transform: none;
    letter-spacing: normal;
    font-weight: 400;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.auth-field input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.auth-field small {
    color: var(--text-muted);
    font-size: 0.72rem;
    text-transform: none;
    letter-spacing: normal;
    font-weight: 400;
    font-family: var(--serif);
    font-style: italic;
}

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

.auth-meta {
    font-size: 0.92rem;
    color: var(--text-dim);
    margin-top: 0.6rem;
    font-family: var(--serif);
    font-style: italic;
}

.auth-meta a { color: var(--primary); text-decoration: none; }
.auth-meta a:hover { text-decoration: underline; text-underline-offset: 3px; }

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

.auth-alert {
    padding: 0.75rem 0.9rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.88rem;
    font-family: var(--sans);
}

.auth-alert--error {
    background: var(--error-soft);
    border: 1px solid rgba(217, 115, 115, 0.4);
    color: var(--error);
}

.auth-alert--info {
    background: var(--primary-soft);
    border: 1px solid var(--border-strong);
    color: var(--primary);
}

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

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

.novel-card-author {
    font-size: 0.78rem;
    color: var(--text-dim);
    margin-bottom: 0.4rem;
    font-family: var(--sans);
}

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

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

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

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

.profile-header {
    margin: 1rem 0 1.5rem;
}

.profile-header h1 {
    font-size: 2.2rem;
    margin-bottom: 0.3rem;
    font-style: italic;
    font-weight: 400;
    color: var(--text);
}

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

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

.profile-account h2 {
    font-family: var(--serif);
    font-style: italic;
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
    -webkit-text-fill-color: initial;
    background: none;
    color: var(--text);
    font-weight: 400;
}

.profile-novels h2 {
    font-family: var(--serif);
    font-style: italic;
    font-size: 1.4rem;
    margin-bottom: 1rem;
    -webkit-text-fill-color: initial;
    background: none;
    color: var(--text);
    font-weight: 400;
}

/* --- Player author link in header (legacy class) ----------------------- */

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

.player-author-link:hover {
    color: var(--primary);
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* --- Drafts ------------------------------------------------------------- */

.drafts-picker {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    margin: 0 0 1.25rem 0;
    padding: 0.75rem 1rem;
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    flex-wrap: wrap;
}

.drafts-picker label {
    font-size: 0.7rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.18em;
    font-weight: 600;
    font-family: var(--sans);
}

.drafts-picker select {
    flex: 1;
    min-width: 180px;
    padding: 0.45rem 0.65rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--sans);
    font-size: 0.9rem;
}

.btn-small {
    padding: 0.4rem 0.85rem;
    font-size: 0.65rem;
    letter-spacing: 0.18em;
}

.btn-danger {
    color: var(--error);
    border-color: var(--error);
    background: transparent;
}
.btn-danger::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--error);
    transform: translateY(101%);
    transition: transform 0.3s;
    z-index: -1;
}
.btn-danger:hover { color: var(--bg); }
.btn-danger:hover::before { transform: translateY(0); }

/* Modal */
.draft-modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.draft-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(6, 8, 18, 0.75);
    backdrop-filter: blur(6px);
}

.draft-modal-body {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.75rem;
    width: min(440px, 92vw);
    max-height: 88vh;
    overflow-y: auto;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

.draft-modal-wide { width: min(660px, 96vw); }

.draft-modal-body h3 {
    margin: 0 0 0.6rem 0;
    font-family: var(--serif);
    font-style: italic;
    font-weight: 500;
    font-size: 1.4rem;
}

.draft-modal-hint {
    color: var(--text-dim);
    font-size: 0.92rem;
    margin: 0 0 1.1rem 0;
    font-family: var(--serif);
    font-style: italic;
    line-height: 1.5;
}

.draft-modal-body input[type="text"] {
    width: 100%;
    padding: 0.7rem 0.85rem;
    background: var(--bg-deep);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1rem;
    font-family: var(--sans);
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.draft-modal-body input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.draft-modal-error {
    color: var(--error);
    font-size: 0.85rem;
    min-height: 1.1em;
    margin-top: 0.4rem;
    font-family: var(--sans);
}

.draft-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.25rem;
}

.draft-section { margin-top: 1.1rem; }

.draft-section h4 {
    margin: 0 0 0.6rem 0;
    font-size: 0.7rem;
    color: var(--primary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.22em;
    font-family: var(--sans);
}

.draft-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 0.5rem;
    border-bottom: 1px solid var(--border);
}

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

.draft-row-main {
    flex: 1;
    min-width: 0;
}

.draft-row-name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: var(--serif);
    font-style: italic;
    font-size: 1.05rem;
    color: var(--text);
}

.draft-row-meta {
    font-size: 0.75rem;
    color: var(--text-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: var(--mono);
}

.draft-row-actions {
    display: flex;
    gap: 0.35rem;
    flex-shrink: 0;
    flex-wrap: wrap;
    justify-content: flex-end;
}

/* Toast */
.draft-toast {
    position: fixed;
    bottom: 1.75rem;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.7rem 1.25rem;
    font-size: 0.9rem;
    font-family: var(--sans);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s, transform 0.25s;
    z-index: 1100;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

.draft-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.draft-toast.ok { border-color: var(--success); color: var(--success); }
.draft-toast.err { border-color: var(--error); color: var(--error); }

/* --- Site footer -------------------------------------------------------- */

.site-footer {
    max-width: 960px;
    margin: 4rem auto 0;
    padding: 2rem 1.5rem;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.78rem;
    line-height: 1.7;
    text-align: center;
    font-family: var(--mono);
    letter-spacing: 0.05em;
}

.site-footer .footer-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.3rem 1.5rem;
}

.site-footer .footer-row span { white-space: nowrap; }

.site-footer .footer-row a {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
    transition: color 0.15s, border-color 0.15s;
}

.site-footer .footer-row a:hover {
    color: var(--accent, #e8a955);
    border-bottom-color: currentColor;
}

@media (max-width: 600px) {
    .site-footer {
        margin-top: 2.5rem;
        padding: 1.25rem;
        font-size: 0.72rem;
    }
}

/* --- Per-language visibility (used by legal pages) ---------------------- */

html[lang="ru"] [data-lang="en"]:not(.lang-flag),
html[lang="en"] [data-lang="ru"]:not(.lang-flag) {
    display: none !important;
}

/* --- Legal pages (terms / privacy / refund) ----------------------------- */

.legal-page {
    max-width: 820px;
    margin: 2.5rem auto;
    padding: 0 1.5rem 3rem;
    color: var(--text);
    line-height: 1.7;
}

.legal-page .legal-back {
    display: inline-block;
    margin-bottom: 1.5rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
}

.legal-page .legal-back:hover {
    color: var(--accent, #e8a955);
}

.legal-page h1 {
    margin: 0 0 0.5rem;
    font-size: 1.8rem;
}

.legal-page .legal-meta {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 2rem;
}

.legal-page h2 {
    margin-top: 2.2rem;
    font-size: 1.2rem;
}

.legal-page h3 {
    margin-top: 1.5rem;
    font-size: 1rem;
    color: var(--text-muted);
}

.legal-page p,
.legal-page li {
    font-size: 0.95rem;
}

.legal-page ul,
.legal-page ol {
    padding-left: 1.4rem;
}

.legal-page li {
    margin-bottom: 0.4rem;
}

.legal-page a {
    color: var(--accent, #e8a955);
}

@media (max-width: 600px) {
    .legal-page {
        margin: 1.5rem auto;
        padding: 0 1rem 2rem;
    }
    .legal-page h1 { font-size: 1.4rem; }
    .legal-page h2 { font-size: 1.05rem; }
}


/* ── Pre-flight content gate (preview screen) ──────────────────────── */
.gate-banner {
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    margin: 0 0 1rem;
    line-height: 1.45;
}
.gate-banner strong { display: block; margin-bottom: 0.25rem; font-size: 0.95rem; }
.gate-banner p { margin: 0.25rem 0 0; font-size: 0.88rem; }
.gate-banner-hint { color: var(--text-dim); }

.gate-banner-warning {
    background: rgba(255, 200, 80, 0.10);
    border: 1px solid rgba(255, 200, 80, 0.45);
    color: #ffd178;
}
.gate-banner-warning .gate-banner-hint { color: rgba(255, 220, 170, 0.85); }

/* When the warning banner sits below the action buttons it doubles as a
   footnote — smaller type, dimmer, with a top margin so it visually
   separates from the Confirm/Start Over row. */
#gateBannerBelow {
    margin-top: 1.25rem;
}
#gateBannerBelow .gate-banner {
    padding: 0.7rem 0.9rem;
    margin: 0;
}
#gateBannerBelow .gate-banner strong { font-size: 0.82rem; }
#gateBannerBelow .gate-banner p { font-size: 0.76rem; }

/* Character descriptions inside the scenes spoiler. */
.preview-char-descriptions {
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px dashed var(--border);
}
.preview-char-descriptions h4 {
    margin: 0 0 0.5rem;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-dim);
    font-weight: 600;
}
.preview-char-row {
    margin-bottom: 0.35rem;
    line-height: 1.45;
    font-size: 0.9rem;
}
.preview-char-row strong {
    color: var(--text);
    margin-right: 0.4rem;
}
.preview-char-row span {
    color: var(--text-dim);
}

.gate-banner-block {
    background: rgba(220, 80, 80, 0.10);
    border: 1px solid rgba(220, 80, 80, 0.55);
    color: #ff9a9a;
}
.gate-banner-block .gate-banner-hint { color: rgba(255, 200, 200, 0.85); }

.scene-card-warning {
    border-left: 3px solid rgba(255, 200, 80, 0.7);
    background: rgba(255, 200, 80, 0.03);
}
.scene-card-blocked {
    border-left: 3px solid rgba(220, 80, 80, 0.8);
    background: rgba(220, 80, 80, 0.04);
}

.scene-gate-flag {
    margin-top: 0.7rem;
    padding-top: 0.65rem;
    border-top: 1px dashed rgba(255, 200, 80, 0.25);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.scene-card-blocked .scene-gate-flag {
    border-top-color: rgba(220, 80, 80, 0.3);
}
.scene-gate-reason {
    margin: 0;
    font-size: 0.85rem;
    color: rgba(255, 220, 170, 0.85);
    font-style: italic;
}
.scene-card-blocked .scene-gate-reason { color: rgba(255, 200, 200, 0.9); }

.btn-small {
    padding: 0.35rem 0.85rem;
    font-size: 0.82rem;
    align-self: flex-start;
}


/* ───────── Chat creation flow ───────── */

#chatRoot {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-width: 720px;
    margin: 1rem auto 2rem;
    width: 100%;
}

#chatMessages {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    min-height: 240px;
    max-height: 60vh;
    overflow-y: auto;
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    scroll-behavior: smooth;
}

.chat-msg {
    padding: 0.7rem 0.95rem;
    border-radius: 14px;
    font-size: 0.95rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
.chat-msg-bot {
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    border-top-left-radius: 4px;
}
.chat-msg-user {
    align-self: flex-end;
    max-width: 72%;
    background: var(--accent-soft);
    color: var(--text);
    border: 1px solid rgba(194, 86, 108, 0.35);
    border-top-right-radius: 4px;
}

.chat-bot-block {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    align-self: flex-start;
    max-width: 86%;
}

.chat-msg-typing {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 0.32rem;
    padding: 0.55rem 0.85rem;
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 14px;
    border-top-left-radius: 4px;
    max-width: 72%;
}
.chat-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    opacity: 0.45;
    animation: chat-typing-bounce 1.2s ease-in-out infinite;
}
.chat-typing-dot:nth-child(2) {
    animation-delay: 0.15s;
}
.chat-typing-dot:nth-child(3) {
    animation-delay: 0.3s;
}
@keyframes chat-typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.35;
    }
    30% {
        transform: translateY(-3px);
        opacity: 0.9;
    }
}
@media (prefers-reduced-motion: reduce) {
    .chat-typing-dot {
        animation: none;
        opacity: 0.55;
    }
}

.chat-inline-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding-left: 0.4rem;
}
.chat-inline-chips-inert .chat-chip {
    opacity: 0.45;
    pointer-events: none;
}

#chatComposer {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    padding: 0.85rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.chat-chip {
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.4rem 0.9rem;
    font-size: 0.85rem;
    cursor: pointer;
    font-family: inherit;
    transition: border-color 120ms ease, color 120ms ease, background 120ms ease;
}
.chat-chip:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-soft);
}
.chat-chip:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
/* Multi-select state for style-phase radio groups (style + music). */
.chat-chip-selected,
.chat-chip-selected:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--surface2);
    box-shadow: inset 0 0 0 1px var(--primary);
}
/* Plot-direction cards — rendered above the chip row on the plot_directions
   phase. Each card is a clickable button with title + middle + twist + ending
   lines, taller than a regular chip because the body matters as much as the
   label. The chip row below mirrors the titles so single-handed users can
   still pick from a familiar surface. */
.chat-direction-cards {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.6rem;
    margin-left: 0.3rem;
}
.chat-direction-card {
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.7rem 0.9rem;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.88rem;
    line-height: 1.4;
    transition: border-color 120ms ease, background 120ms ease;
}
.chat-direction-card:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
}
.chat-direction-card-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: var(--primary);
}
.chat-direction-card-line {
    margin-top: 0.2rem;
    opacity: 0.92;
}
.chat-direction-cards-inert .chat-direction-card {
    pointer-events: none;
    opacity: 0.55;
}

/* Confirm-picks button — appears after the multi-axis chip group on the
   style phase. Disabled until one chip from each group is selected. */
.chat-chip-confirm {
    border-style: solid;
    font-weight: 600;
}
.chat-chip-confirm:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
}
.chat-chip-skip {
    background: transparent;
    color: var(--text-dim);
    border-style: dashed;
}
.chat-chip-skip:hover {
    color: var(--primary);
    border-color: var(--primary);
    background: var(--primary-soft);
}

/* Transition chip ("Дальше — Сеттинг") — visually distinct from
   multi-select chips so the user reads it as a single, decisive action.
   Click is wired by chat.js to advancePhase() instead of sendMessage(). */
.chat-chip--transition {
    background: var(--primary-soft);
    color: var(--primary);
    border-color: var(--primary);
    font-weight: 600;
}
.chat-chip--transition:hover {
    background: var(--primary);
    color: var(--text);
    border-color: var(--primary);
}

/* Phase progress indicator above the message log. Pills are clickable when
   completed (back-nav via jumpToPhase), passive when current/future. */
.chat-phase-indicator {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.45rem;
    margin-bottom: 0.85rem;
    padding: 0.5rem 0.6rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}
.chat-phase-indicator[hidden] {
    display: none;
}
.phase-pill {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.25rem 0.7rem;
    font-size: 0.8rem;
    font-family: inherit;
    cursor: default;
    transition: border-color 120ms ease, color 120ms ease, background 120ms ease;
}
.phase-pill--completed {
    color: var(--primary);
    border-color: var(--primary);
    background: var(--primary-soft);
    cursor: pointer;
}
.phase-pill--completed::before {
    content: '✓ ';
}
.phase-pill--completed:hover {
    background: var(--primary);
    color: var(--text);
}
.phase-pill--current {
    color: var(--text);
    border-color: var(--primary);
    background: var(--surface2);
    box-shadow: inset 0 0 0 1px var(--primary);
    font-weight: 600;
}
.phase-pill--future {
    color: var(--text-dim);
    opacity: 0.55;
}
.phase-pill-sep {
    color: var(--text-dim);
    font-size: 0.75rem;
    opacity: 0.6;
}

.chat-input-row {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

#chatInput {
    flex: 1;
    min-height: 44px;
    max-height: 8em;
    padding: 0.6rem 0.85rem;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.95rem;
    line-height: 1.45;
    resize: none;
    outline: none;
    transition: border-color 120ms ease;
}
#chatInput:focus {
    border-color: var(--primary);
}

#chatSendBtn {
    height: 44px;
    min-width: 44px;
    padding: 0 0.95rem;
    background: var(--accent);
    color: var(--text);
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 120ms ease;
}
#chatSendBtn:hover:not(:disabled) {
    background: var(--accent-hover);
}
#chatSendBtn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.chat-finalize-bar {
    width: 100%;
    padding: 0.7rem 1rem;
    background: var(--accent);
    color: var(--text);
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 0 0 1px var(--primary-soft);
    transition: background 120ms ease, opacity 120ms ease;
}
.chat-finalize-bar:hover:not(:disabled) {
    background: var(--accent-hover);
}
.chat-finalize-bar:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.chat-finalize-bar[hidden] {
    display: none;
}

.chat-reset-row {
    display: flex;
    justify-content: flex-end;
}
.chat-reset-btn {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 0.85rem;
    padding: 0.2rem 0.4rem;
    cursor: pointer;
    text-decoration: underline;
    text-decoration-color: transparent;
    transition: color 120ms ease, text-decoration-color 120ms ease;
}
.chat-reset-btn:hover {
    color: var(--text);
    text-decoration-color: currentColor;
}
.chat-reset-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Expand-fandoms chip — opens the catalog as a second bot bubble.
   Dashed border signals "this isn't a regular reply, it's a doorway". */
.chat-chip--expand {
    border-style: dashed;
    color: var(--primary);
    border-color: var(--primary);
}
.chat-chip--expand:hover {
    background: var(--primary-soft);
}

.chat-fandoms-intro {
    margin: 0 0 0.7rem 0;
    color: var(--text);
}
.chat-fandom-group-title {
    margin-top: 0.6rem;
    margin-bottom: 0.3rem;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-dim);
}
.chat-fandom-list {
    list-style: none;
    margin: 0 0 0.4rem 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.chat-fandom-list-inert {
    pointer-events: none;
    opacity: 0.55;
}
.chat-fandom-row {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    color: var(--text);
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 0.45rem 0.6rem;
    cursor: pointer;
    font: inherit;
    line-height: 1.35;
    transition: background 120ms ease, border-color 120ms ease;
}
.chat-fandom-row:hover:not(:disabled) {
    background: var(--surface2);
    border-color: var(--border);
}
.chat-fandom-row:disabled {
    cursor: default;
}
.chat-fandom-row-title {
    font-weight: 600;
    color: var(--text);
}
.chat-fandom-row-tagline {
    color: var(--text-dim);
}

.chat-banner {
    margin-top: 0.5rem;
    padding: 1rem;
    border-radius: var(--radius-lg);
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    align-items: flex-start;
}
.chat-banner-info {
    border-color: var(--border-strong);
}
.chat-banner-warn {
    border-color: rgba(217, 115, 115, 0.5);
    background: var(--error-soft);
}
.chat-banner p {
    margin: 0;
    color: var(--text);
    font-size: 0.95rem;
}

.chat-toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translate(-50%, 1rem);
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 0.7rem 1rem;
    font-size: 0.88rem;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease, transform 180ms ease;
    z-index: 9999;
    max-width: min(90vw, 420px);
}
.chat-toast.chat-toast-visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

@media (max-width: 600px) {
    .chat-msg-user {
        max-width: 86%;
    }
    .chat-bot-block {
        max-width: 94%;
    }
    .phase-pill {
        font-size: 0.72rem;
        padding: 0.2rem 0.55rem;
    }
    .phase-pill-sep {
        display: none;
    }
}
