:root {
    --bg: #f5f0eb;
    --bg2: #efe5db;
    --surface: rgba(255, 255, 255, 0.88);
    --surface-strong: #ffffff;
    --ink: #4f453f;
    --muted: #7b7068;
    --rule: #ddd2c7;
    --accent: #c58f70;
    --accent-dark: #b07b5e;
    --accent-soft: #f2e4da;
    --accent2: #92aea1;
    --warn-soft: #f7e7d4;
    --warn-ink: #8a613f;
    --crisis-bg: #fff0ec;
    --crisis-rule: #efb3a4;
    --shadow: 0 20px 40px rgba(101, 78, 63, 0.08);
    --font: 'InstrumentSans', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrainsMono', monospace;
    --max: 1120px;
}

@font-face {
    font-family: 'InstrumentSans';
    src: url('./_shared/fonts/InstrumentSans-Regular.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
}

@font-face {
    font-family: 'InstrumentSans';
    src: url('./_shared/fonts/InstrumentSans-Bold.ttf') format('truetype');
    font-weight: 700;
    font-style: normal;
}

@font-face {
    font-family: 'JetBrainsMono';
    src: url('./_shared/fonts/JetBrainsMono-Regular.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
}

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

html,
body {
    min-height: 100%;
}

body {
    font-family: var(--font);
    background:
        radial-gradient(circle at top, rgba(255, 255, 255, 0.75), transparent 34%),
        linear-gradient(180deg, #f9f4ef 0%, var(--bg) 100%);
    color: var(--ink);
    line-height: 1.65;
}

button,
input,
textarea {
    font: inherit;
}

a {
    color: inherit;
}

.container {
    max-width: var(--max);
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.3rem 1.5rem 1rem;
}

.logo {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--accent-dark);
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 1rem;
    color: var(--muted);
    font-size: 0.95rem;
}

.nav-copy {
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.55);
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.section-active {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    padding: 0 1.5rem 1.5rem;
}

.section-hidden {
    display: none;
}

.hero-card,
.mode-entry-card,
.ai-status-bar,
.ai-config-panel,
.role-section,
.chat-container {
    background: var(--surface);
    border: 1px solid rgba(255, 255, 255, 0.75);
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
}

.hero-card,
.mode-entry-card,
.ai-config-panel,
.role-section {
    border-radius: 28px;
    padding: 1.6rem;
}

.hero-card {
    display: flex;
    flex-direction: column;
    gap: 0.95rem;
}

.hero-eyebrow {
    color: var(--accent-dark);
    font-size: 0.95rem;
    letter-spacing: 0.04em;
}

.hero-card h1 {
    font-size: clamp(2rem, 5vw, 3.4rem);
    line-height: 1.08;
}

.hero-lead {
    max-width: 760px;
    color: var(--muted);
    font-size: 1.05rem;
}

.promise-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
}

.promise-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.45rem 0.85rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(197, 143, 112, 0.15);
    color: var(--ink);
    font-size: 0.92rem;
    cursor: default;
}

.hero-promise-text {
    color: var(--muted);
    font-size: 0.95rem;
}

.how-it-works {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    padding: 1rem 1.6rem;
    background: var(--surface);
    border: 1px solid rgba(255, 255, 255, 0.75);
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
    border-radius: 22px;
}

.step-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    font-size: 0.85rem;
    font-weight: 700;
    flex-shrink: 0;
}

.step-text {
    font-size: 0.95rem;
    color: var(--ink);
    font-weight: 500;
}

.step-arrow {
    color: var(--accent);
    font-size: 1.2rem;
}

.hero-cta {
    display: flex;
    gap: 0.8rem;
    justify-content: center;
}

.hero-start-btn {
    padding: 0.9rem 1.8rem;
    font-size: 1.05rem;
}

.hero-demo-btn {
    padding: 0.9rem 1.5rem;
    font-size: 1rem;
}

.section-heading {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin-bottom: 1rem;
}

.section-heading h2,
.section-heading h3 {
    font-size: 1.35rem;
}

.section-heading p {
    color: var(--muted);
}

.section-heading.compact {
    margin-bottom: 1.15rem;
}

.mode-entry-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.mode-entry-btn,
.back-btn,
.send-btn,
.primary-btn,
.secondary-btn,
.suggestion-btn,
.branch-choice,
.text-link-btn,
.character-card {
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, background-color 0.18s ease, color 0.18s ease;
}

.mode-entry-btn {
    border: 1px solid var(--rule);
    border-radius: 20px;
    background: var(--surface-strong);
    padding: 1.05rem 1.15rem;
    text-align: left;
    font-weight: 700;
    font-size: 1rem;
    color: var(--ink);
    cursor: pointer;
}

.mode-entry-btn.active,
.mode-entry-btn:hover {
    transform: translateY(-1px);
    border-color: rgba(197, 143, 112, 0.45);
    background: linear-gradient(180deg, #fff8f3 0%, #fff 100%);
    box-shadow: 0 10px 20px rgba(197, 143, 112, 0.12);
}

.ai-status-bar {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    border-radius: 22px;
    padding: 1rem 1.2rem;
}

.ai-status-bar[data-route="default"] {
    background: rgba(255, 255, 255, 0.9);
}

.ai-status-bar[data-route="user"] {
    background: rgba(235, 247, 240, 0.95);
}

.ai-status-bar[data-route="fallback"] {
    background: rgba(255, 248, 240, 0.95);
}

.ai-status-title {
    font-weight: 700;
}

.ai-status-text,
.ai-status-meta {
    color: var(--muted);
    font-size: 0.94rem;
}

.ai-status-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.45rem;
}

.text-link-btn {
    border: none;
    background: transparent;
    color: var(--accent-dark);
    cursor: pointer;
    padding: 0;
}

.ai-config-panel {
    border-radius: 22px;
}

.ai-config-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.9rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.input-group span {
    font-size: 0.93rem;
    color: var(--muted);
}

.input-group input,
textarea {
    border: 1px solid var(--rule);
    border-radius: 16px;
    padding: 0.88rem 1rem;
    background: rgba(255, 255, 255, 0.94);
    color: var(--ink);
}

.input-group input:focus,
textarea:focus {
    outline: none;
    border-color: rgba(197, 143, 112, 0.55);
    box-shadow: 0 0 0 3px rgba(197, 143, 112, 0.12);
}

.ai-config-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1rem;
}

.primary-btn,
.secondary-btn,
.back-btn,
.send-btn {
    border-radius: 14px;
    padding: 0.8rem 1.1rem;
    cursor: pointer;
    font-weight: 600;
}

.primary-btn,
.send-btn {
    border: none;
    background: var(--accent);
    color: white;
}

.primary-btn:hover,
.send-btn:hover {
    background: var(--accent-dark);
}

.secondary-btn,
.back-btn {
    border: 1px solid var(--rule);
    background: rgba(255, 255, 255, 0.9);
    color: var(--ink);
}

.secondary-btn:hover,
.back-btn:hover {
    background: white;
}

.character-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}

.character-card {
    border: 1px solid transparent;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.84);
    padding: 1.2rem 1rem;
    text-align: center;
    cursor: pointer;
}

.character-card:hover,
.character-card.active {
    transform: translateY(-2px);
    border-color: rgba(197, 143, 112, 0.4);
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 14px 24px rgba(122, 98, 83, 0.1);
}

.avatar-circle,
.chat-header-avatar,
.chat-avatar {
    overflow: hidden;
    border-radius: 50%;
    flex-shrink: 0;
}

.avatar-circle {
    width: 84px;
    height: 84px;
    margin: 0 auto 0.9rem;
    background: var(--bg2);
}

.avatar-circle img,
.chat-header-avatar img,
.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.character-card h4 {
    margin-bottom: 0.2rem;
    font-size: 1.08rem;
}

.character-title {
    color: var(--accent-dark);
    font-size: 0.92rem;
}

.character-intro {
    margin-top: 0.45rem;
    color: var(--muted);
    font-size: 0.94rem;
}

.chat-container {
    border-radius: 28px;
    min-height: 70vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1.15rem 1.2rem;
    border-bottom: 1px solid rgba(221, 210, 199, 0.8);
    background: rgba(255, 255, 255, 0.72);
}

.chat-header-main {
    display: flex;
    align-items: center;
    gap: 0.9rem;
}

.chat-header-avatar {
    width: 58px;
    height: 58px;
    background: var(--bg2);
}

.chat-header-topline {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    align-items: center;
}

.current-character-name {
    font-size: 1.2rem;
    font-weight: 700;
}

.current-character-role,
.current-ai-route {
    color: var(--muted);
    font-size: 0.94rem;
}

.mode-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.28rem 0.7rem;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-dark);
    font-size: 0.84rem;
    font-weight: 700;
}

.branch-invite-bar,
.branch-panel {
    margin: 0 1.2rem;
    border-radius: 18px;
}

.branch-invite-bar {
    margin-top: 1rem;
    padding: 0.9rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    background: var(--warn-soft);
    border: 1px solid rgba(214, 176, 136, 0.35);
}

.branch-invite-copy {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    color: var(--warn-ink);
}

.branch-invite-copy strong {
    font-size: 0.98rem;
}

.branch-invite-actions {
    display: flex;
    gap: 0.6rem;
    align-items: center;
}

.branch-panel {
    margin-top: 1rem;
}

.branch-card {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(197, 143, 112, 0.18);
    border-radius: 22px;
    padding: 1.2rem;
    box-shadow: 0 12px 24px rgba(122, 98, 83, 0.08);
}

.branch-card.is-result {
    background: rgba(247, 241, 233, 0.94);
}

.branch-kicker,
.message-label {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.58rem;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-dark);
    font-size: 0.8rem;
    font-weight: 700;
    margin-bottom: 0.55rem;
}

.branch-title {
    font-size: 1.1rem;
    margin-bottom: 0.45rem;
}

.branch-setup,
.branch-progress,
.branch-action {
    color: var(--muted);
}

.branch-question {
    margin: 1rem 0 0.85rem;
    font-size: 1rem;
}

.branch-choices {
    display: grid;
    gap: 0.7rem;
}

.branch-choice {
    width: 100%;
    border: 1px solid var(--rule);
    border-radius: 16px;
    background: white;
    padding: 0.9rem 1rem;
    text-align: left;
    cursor: pointer;
    color: var(--ink);
}

.branch-choice:hover,
.branch-choice.primary {
    border-color: rgba(197, 143, 112, 0.45);
    box-shadow: 0 10px 20px rgba(197, 143, 112, 0.1);
}

.branch-choice.primary {
    background: var(--accent);
    color: white;
    text-align: center;
}

.chat-progress-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    padding: 0.7rem 1.2rem;
    background: rgba(255, 255, 255, 0.5);
}

.progress-step {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    opacity: 0.4;
    transition: opacity 0.3s ease;
}

.progress-step.active {
    opacity: 1;
}

.progress-dot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--rule);
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
}

.progress-step.active .progress-dot {
    background: var(--accent);
}

.progress-label {
    font-size: 0.82rem;
    color: var(--muted);
    font-weight: 500;
}

.progress-line {
    width: 30px;
    height: 2px;
    background: var(--rule);
}

.chat-messages {
    flex: 1;
    padding: 1.2rem;
    overflow-y: auto;
}

.chat-bubble {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    align-items: flex-start;
}

.user-message {
    flex-direction: row-reverse;
}

.chat-avatar {
    width: 42px;
    height: 42px;
    background: var(--bg2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-dark);
    font-size: 0.9rem;
    font-weight: 700;
}

.user-avatar {
    background: rgba(197, 143, 112, 0.15);
}

.chat-message {
    max-width: min(78%, 640px);
    background: white;
    border-radius: 18px;
    padding: 0.95rem 1.05rem;
    box-shadow: 0 10px 20px rgba(93, 74, 61, 0.06);
}

.user-message .chat-message {
    background: linear-gradient(180deg, #c9987d 0%, #bb8769 100%);
    color: white;
}

.chat-bubble.is-crisis .chat-message {
    background: var(--crisis-bg);
    border: 1px solid var(--crisis-rule);
}

.chat-bubble.is-notice .chat-message {
    background: rgba(255, 251, 245, 0.95);
    border: 1px dashed rgba(197, 143, 112, 0.45);
}

.message-line + .message-line {
    margin-top: 0.42rem;
}

.chat-input-area {
    padding: 1rem 1.2rem 1.2rem;
    border-top: 1px solid rgba(221, 210, 199, 0.8);
    background: rgba(255, 255, 255, 0.72);
}

.quick-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    margin-bottom: 0.7rem;
}

.suggestion-btn {
    border: 1px solid var(--rule);
    border-radius: 999px;
    background: white;
    color: var(--muted);
    padding: 0.48rem 0.82rem;
    cursor: pointer;
}

.suggestion-btn:hover {
    color: var(--accent-dark);
    border-color: rgba(197, 143, 112, 0.4);
}

.privacy-note {
    color: var(--muted);
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}

.input-wrapper {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

textarea {
    flex: 1;
    min-height: 58px;
    max-height: 140px;
    resize: vertical;
}

.send-btn:disabled {
    cursor: not-allowed;
    opacity: 0.68;
}

.safety-footer {
    padding: 1.15rem 1.5rem 1.8rem;
}

.safety-callout {
    background: rgba(255, 255, 255, 0.76);
    border-radius: 18px;
    border: 1px solid rgba(221, 210, 199, 0.8);
    padding: 1rem 1.15rem;
    color: var(--muted);
}

.footer-info {
    margin-top: 0.8rem;
    color: var(--muted);
    text-align: center;
    font-size: 0.92rem;
}

@media (max-width: 860px) {
    .ai-status-bar,
    .branch-invite-bar,
    .chat-header,
    .top-nav,
    .input-wrapper,
    .ai-config-grid,
    .mode-entry-actions {
        grid-template-columns: 1fr;
        flex-direction: column;
        align-items: stretch;
    }

    .top-nav {
        gap: 0.75rem;
    }

    .nav-links {
        justify-content: space-between;
    }

    .ai-status-actions,
    .branch-invite-actions {
        align-items: stretch;
    }

    .chat-header-main {
        align-items: flex-start;
    }

    .back-btn,
    .send-btn,
    .primary-btn,
    .secondary-btn {
        width: 100%;
        justify-content: center;
    }

    .chat-message {
        max-width: 100%;
    }
}

@media (max-width: 620px) {
    .section-active {
        padding: 0 1rem 1rem;
    }

    .hero-card,
    .mode-entry-card,
    .ai-config-panel,
    .role-section,
    .chat-container {
        border-radius: 22px;
    }

    .character-cards {
        grid-template-columns: 1fr;
    }

    .how-it-works {
        flex-direction: column;
        gap: 0.6rem;
    }

    .step-arrow {
        transform: rotate(90deg);
    }

    .hero-cta {
        flex-direction: column;
    }
}

.session-id-display {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--muted);
    background: var(--accent-soft);
    padding: 0.25rem 0.6rem;
    border-radius: 8px;
}

.summary-wrapper {
    display: flex;
    justify-content: center;
    padding: 1rem 0;
}

.summary-card {
    background: linear-gradient(135deg, #fffaf5 0%, #fff5ed 100%);
    border-radius: 28px;
    box-shadow: 0 24px 48px rgba(101, 78, 63, 0.12), 0 2px 8px rgba(101, 78, 63, 0.06);
    padding: 2.2rem;
    max-width: 480px;
    width: 100%;
    border: 1px solid rgba(197, 143, 112, 0.15);
    position: relative;
    overflow: hidden;
}

.summary-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
}

.summary-kicker {
    font-size: 0.8rem;
    color: var(--accent);
    font-weight: 700;
    text-align: center;
    margin-bottom: 1.2rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.summary-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-bottom: 1.25rem;
    margin-bottom: 1.25rem;
    border-bottom: 1px solid var(--rule);
}

.summary-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}

.summary-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.summary-header-text {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.summary-character-name {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--ink);
}

.summary-character-role {
    font-size: 0.9rem;
    color: var(--muted);
}

.summary-section {
    margin-bottom: 1.25rem;
}

.summary-label {
    font-size: 0.78rem;
    color: var(--muted);
    font-weight: 500;
    margin-bottom: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.summary-topic {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--ink);
}

.summary-takeaway {
    font-size: 0.98rem;
    line-height: 1.6;
    color: var(--ink);
}

.summary-action {
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent-dark);
    line-height: 1.5;
}

.summary-quote-section {
    background: linear-gradient(135deg, var(--accent-soft) 0%, rgba(242, 228, 218, 0.5) 100%);
    border-radius: 16px;
    padding: 1.2rem 1.4rem;
    position: relative;
}

.summary-quote-section::before {
    content: '"';
    position: absolute;
    top: 0.3rem;
    left: 0.6rem;
    font-size: 2.5rem;
    color: var(--accent);
    opacity: 0.2;
    font-family: Georgia, serif;
    line-height: 1;
}

.summary-quote {
    font-size: 0.95rem;
    font-style: italic;
    color: var(--ink);
    line-height: 1.6;
}

.summary-session {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--muted);
    text-align: center;
    padding: 1rem 0 0;
    border-top: 1px dashed var(--rule);
    margin-top: 0.5rem;
}

.summary-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.summary-actions .primary-btn,
.summary-actions .secondary-btn {
    flex: 1;
    justify-content: center;
}

.primary-btn,
.secondary-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.7rem 1.2rem;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

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

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

.secondary-btn {
    background: var(--accent-soft);
    color: var(--accent-dark);
}

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

.branch-result-actions {
    display: flex;
    gap: 0.6rem;
    margin-top: 1rem;
}

.branch-result-actions .branch-choice {
    flex: 1;
    justify-content: center;
}

.branch-choice.secondary {
    background: var(--accent-soft);
    color: var(--accent-dark);
}

@media (max-width: 620px) {
    .summary-card {
        padding: 1.5rem;
        border-radius: 20px;
    }

    .summary-actions {
        flex-direction: column;
    }
}
