/* PlotForge — Design System */

/* ===== CSS Variables ===== */
:root {
    /* Colors - Deep Indigo Dark Theme */
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-tertiary: #1a2035;
    --bg-elevated: #1e2642;
    --bg-glass: rgba(30, 38, 66, 0.7);
    --bg-glass-hover: rgba(40, 52, 90, 0.8);

    /* Accent - Warm Amber Gold */
    --accent-primary: #f59e0b;
    --accent-secondary: #d97706;
    --accent-glow: rgba(245, 158, 11, 0.15);
    --accent-gradient: linear-gradient(135deg, #f59e0b, #ef4444);

    /* Text */
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-tertiary: #64748b;
    --text-inverse: #0a0e1a;

    /* Borders */
    --border-primary: rgba(148, 163, 184, 0.12);
    --border-hover: rgba(245, 158, 11, 0.3);
    --border-accent: rgba(245, 158, 11, 0.5);

    /* Semantic */
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;

    /* AI Panel colors */
    --ai-bg: #0d1220;
    --ai-user-msg: rgba(59, 130, 246, 0.12);
    --ai-assistant-msg: rgba(16, 185, 129, 0.08);

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Typography */
    --font-sans: 'Noto Sans JP', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    --text-xs: 0.75rem;
    --text-sm: 0.8125rem;
    --text-base: 0.9375rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 2rem;

    /* Radii */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px var(--accent-glow);

    /* Layout */
    --sidebar-width: 220px;
    --sidebar-collapsed: 64px;
    --ai-panel-width: 380px;
    --header-height: 48px;
    --status-height: 28px;

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== Reset & Base ===== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: var(--text-base);
    line-height: 1.6;
    overflow: hidden;
    height: 100vh;
}

a {
    color: var(--accent-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--accent-secondary);
}

h1,
h2,
h3,
h4 {
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-primary);
}

input,
textarea,
select,
button {
    font-family: var(--font-sans);
    font-size: var(--text-sm);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--text-tertiary);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ===== App Layout ===== */
.app-shell {
    display: flex;
    height: calc(100vh - var(--status-height));
    overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-primary);
    display: flex;
    flex-direction: column;
    transition: width var(--transition-base), min-width var(--transition-base);
    z-index: 10;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border-primary);
    height: var(--header-height);
}

.brand-icon {
    font-size: 1.4rem;
}

.brand-text {
    font-size: var(--text-lg);
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sidebar-project-name {
    padding: var(--space-sm) var(--space-lg);
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    border-bottom: 1px solid var(--border-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-nav {
    list-style: none;
    padding: var(--space-sm) var(--space-sm);
    flex: 1;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 1px solid transparent;
    background: none;
    width: 100%;
    text-align: left;
}

.nav-item:hover {
    background: var(--bg-glass);
    color: var(--text-primary);
    border-color: var(--border-primary);
}

.nav-item.active {
    background: var(--accent-glow);
    color: var(--accent-primary);
    border-color: var(--border-accent);
}

.nav-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.nav-label {
    white-space: nowrap;
}

.sidebar-bottom {
    border-top: 1px solid var(--border-primary);
    padding: var(--space-sm);
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-xl);
    min-width: 0;
}

.view {
    display: none;
}

.view.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== AI Panel ===== */
.ai-panel {
    width: var(--ai-panel-width);
    min-width: var(--ai-panel-width);
    background: var(--ai-bg);
    border-left: 1px solid var(--border-primary);
    display: flex;
    flex-direction: column;
    transition: width var(--transition-base), min-width var(--transition-base), opacity var(--transition-base);
    position: relative;
    overflow: hidden;
}

.ai-panel.collapsed {
    width: 48px;
    min-width: 48px;
}

.ai-panel.collapsed .ai-panel-content {
    opacity: 0;
    pointer-events: none;
}

.ai-panel-toggle {
    position: absolute;
    left: 0;
    top: 0;
    width: 48px;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    z-index: 2;
    transition: all var(--transition-fast);
    writing-mode: vertical-rl;
}

.ai-panel-toggle:hover {
    color: var(--accent-primary);
    background: var(--bg-glass);
}

.ai-panel:not(.collapsed) .ai-panel-toggle {
    width: 32px;
    height: 32px;
    top: var(--space-sm);
    left: var(--space-sm);
    writing-mode: horizontal-tb;
    border-radius: var(--radius-sm);
}

.toggle-icon {
    font-size: 1.2rem;
}

.toggle-label {
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: 0.1em;
}

.ai-panel:not(.collapsed) .toggle-label {
    display: none;
}

.ai-panel-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    margin-left: 48px;
    transition: opacity var(--transition-base);
}

.ai-panel:not(.collapsed) .ai-panel-content {
    margin-left: 0;
}

.ai-panel-header {
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    min-height: var(--header-height);
}

.ai-panel-header h3 {
    font-size: var(--text-sm);
    font-weight: 600;
    white-space: nowrap;
}

.ai-session-controls {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.ai-session-select {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    padding: 2px 6px;
    font-size: var(--text-xs);
    max-width: 120px;
}

/* AI Context Bar */
.ai-context-bar {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
    background: rgba(245, 158, 11, 0.05);
    border-bottom: 1px solid var(--border-primary);
    flex-wrap: wrap;
    min-height: 36px;
}

.context-label {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    white-space: nowrap;
}

.context-items {
    display: flex;
    gap: var(--space-xs);
    flex-wrap: wrap;
    flex: 1;
}

.context-chip {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 8px;
    background: var(--accent-glow);
    border: 1px solid var(--border-accent);
    border-radius: var(--radius-xl);
    font-size: var(--text-xs);
    color: var(--accent-primary);
    cursor: default;
    animation: chipIn 0.2s ease;
}

@keyframes chipIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.context-chip .remove {
    cursor: pointer;
    opacity: 0.6;
    margin-left: 2px;
    transition: opacity var(--transition-fast);
}

.context-chip .remove:hover {
    opacity: 1;
}

/* AI Quick Actions */
.ai-quick-actions {
    display: flex;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--border-primary);
    flex-wrap: wrap;
}

.quick-action-btn {
    padding: 3px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-xl);
    color: var(--text-secondary);
    font-size: var(--text-xs);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.quick-action-btn:hover {
    background: var(--bg-glass-hover);
    color: var(--text-primary);
    border-color: var(--border-hover);
}

/* AI Messages */
.ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.ai-welcome {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-tertiary);
    font-size: var(--text-sm);
    padding: var(--space-xl);
}

.ai-msg {
    padding: var(--space-md);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    line-height: 1.6;
    animation: msgIn 0.3s ease;
    max-width: 100%;
    overflow-wrap: break-word;
}

@keyframes msgIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-msg.user {
    background: var(--ai-user-msg);
    border: 1px solid rgba(59, 130, 246, 0.2);
    align-self: flex-end;
}

.ai-msg.assistant {
    background: var(--ai-assistant-msg);
    border: 1px solid rgba(16, 185, 129, 0.15);
}

.ai-msg .msg-role {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    margin-bottom: var(--space-xs);
    font-weight: 600;
}

.ai-msg .msg-content {
    white-space: pre-wrap;
}

.ai-msg .msg-content p {
    margin-bottom: var(--space-sm);
}

.ai-msg .msg-content p:last-child {
    margin-bottom: 0;
}

.ai-msg .msg-content strong {
    color: var(--accent-primary);
}

.ai-msg .msg-actions {
    display: flex;
    gap: var(--space-sm);
    margin-top: var(--space-sm);
    padding-top: var(--space-sm);
    border-top: 1px solid var(--border-primary);
}

/* AI Input Area */
.ai-input-area {
    padding: var(--space-md);
    border-top: 1px solid var(--border-primary);
    display: flex;
    gap: var(--space-sm);
    align-items: flex-end;
}

.ai-input-area textarea {
    flex: 1;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    padding: var(--space-sm) var(--space-md);
    resize: none;
    transition: border-color var(--transition-fast);
    line-height: 1.5;
}

.ai-input-area textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.btn-send {
    height: 38px;
    min-width: 60px;
}

/* ===== Status Bar ===== */
.status-bar {
    height: var(--status-height);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-md);
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}

.status-ai-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.status-ai-indicator::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--danger);
}

.status-ai-indicator.connected::before {
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: var(--text-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 1px solid transparent;
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent-gradient);
    color: var(--text-inverse);
    border-color: transparent;
}

.btn-primary:hover {
    filter: brightness(1.1);
    box-shadow: var(--shadow-glow);
}

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border-primary);
}

.btn-secondary:hover {
    background: var(--bg-glass-hover);
    border-color: var(--border-hover);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}

.btn-ghost:hover {
    background: var(--bg-glass);
    color: var(--text-primary);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.12);
    color: var(--danger);
    border-color: rgba(239, 68, 68, 0.2);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.2);
}

.btn-sm {
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--text-xs);
}

.btn-lg {
    padding: var(--space-md) var(--space-lg);
    font-size: var(--text-base);
}

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

/* ===== Cards ===== */
.card {
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    transition: all var(--transition-base);
}

.card:hover {
    border-color: var(--border-hover);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-lg);
}

/* ===== Forms ===== */
.form-group {
    margin-bottom: var(--space-md);
}

.form-group label {
    display: block;
    margin-bottom: var(--space-xs);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
}

.form-input,
.form-textarea,
.form-select {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: var(--text-sm);
    transition: border-color var(--transition-fast);
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

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

.form-select {
    cursor: pointer;
}

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 560px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from {
        transform: scale(0.95) translateY(10px);
        opacity: 0;
    }

    to {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-primary);
}

.modal-header h2 {
    font-size: var(--text-lg);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: var(--space-xs);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.modal-close:hover {
    color: var(--text-primary);
    background: var(--bg-glass);
}

.modal-body {
    padding: var(--space-lg);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border-primary);
}

/* ===== Settings ===== */
.setting-group {
    margin-bottom: var(--space-lg);
}

.setting-group label {
    display: block;
    margin-bottom: var(--space-xs);
    font-weight: 500;
    color: var(--text-secondary);
    font-size: var(--text-sm);
}

.setting-group input,
.setting-group select {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: var(--text-sm);
}

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

.api-key-input-group {
    display: flex;
    gap: var(--space-xs);
}

.api-key-input-group input {
    flex: 1;
}

.setting-hint {
    margin-top: var(--space-xs);
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    line-height: 1.4;
}

/* ===== View Headers ===== */
.view-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-xl);
}

.view-header h1 {
    font-size: var(--text-2xl);
    font-weight: 700;
}

.view-header-actions {
    display: flex;
    gap: var(--space-sm);
}

/* ===== Status Tabs (Draft / Finalized) ===== */
.status-tabs {
    display: flex;
    gap: var(--space-xs);
    margin-bottom: var(--space-lg);
    padding: 3px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    width: fit-content;
}

.status-tab {
    padding: var(--space-sm) var(--space-md);
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-sans);
}

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

.status-tab.active {
    background: var(--bg-elevated);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}


/* ===== Dashboard Specific ===== */
.project-card {
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.project-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--accent-gradient);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform var(--transition-base);
}

.project-card:hover::before {
    transform: scaleX(1);
}

.project-card-title {
    font-size: var(--text-lg);
    font-weight: 600;
    margin-bottom: var(--space-sm);
}

.project-card-genre {
    display: inline-block;
    padding: 2px 10px;
    background: var(--accent-glow);
    border-radius: var(--radius-xl);
    font-size: var(--text-xs);
    color: var(--accent-primary);
    margin-bottom: var(--space-sm);
}

.project-card-summary {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.project-card-meta {
    margin-top: var(--space-md);
    display: flex;
    gap: var(--space-md);
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}

.new-project-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    min-height: 200px;
    border-style: dashed;
    cursor: pointer;
}

.new-project-card:hover {
    border-color: var(--accent-primary);
    background: var(--accent-glow);
}

.new-project-icon {
    font-size: 2.5rem;
    opacity: 0.5;
    transition: opacity var(--transition-fast);
}

.new-project-card:hover .new-project-icon {
    opacity: 1;
}

/* ===== Plot Editor ===== */
.act-container {
    margin-bottom: var(--space-xl);
}

.act-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    background: var(--bg-glass);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.act-header:hover {
    border-color: var(--border-hover);
}

.act-title {
    font-size: var(--text-lg);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.act-badge {
    padding: 2px 8px;
    border-radius: var(--radius-xl);
    font-size: var(--text-xs);
    font-weight: 600;
}

.act-badge.act-1 {
    background: rgba(59, 130, 246, 0.15);
    color: var(--info);
}

.act-badge.act-2 {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
}

.act-badge.act-3 {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.chapters-container {
    padding-left: var(--space-lg);
}

.chapter-item {
    background: var(--bg-glass);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-md);
    overflow: hidden;
}

.chapter-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.chapter-header:hover {
    background: var(--bg-glass-hover);
}

.chapter-title {
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.chapter-number {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    font-weight: 600;
}

.scenes-container {
    padding: 0 var(--space-md) var(--space-md);
}

.scene-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    padding: var(--space-md);
    margin-bottom: var(--space-sm);
    cursor: grab;
    transition: all var(--transition-fast);
}

.scene-card:hover {
    border-color: var(--border-hover);
    transform: translateX(4px);
}

.scene-card.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.scene-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-xs);
}

.scene-title {
    font-weight: 600;
    font-size: var(--text-sm);
}

.scene-tone {
    padding: 1px 6px;
    border-radius: var(--radius-xl);
    font-size: 0.6875rem;
    font-weight: 500;
}

.scene-tone.tension-low {
    background: rgba(16, 185, 129, 0.12);
    color: var(--success);
}

.scene-tone.tension-mid {
    background: rgba(245, 158, 11, 0.12);
    color: var(--warning);
}

.scene-tone.tension-high {
    background: rgba(239, 68, 68, 0.12);
    color: var(--danger);
}

.scene-summary {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    line-height: 1.4;
}

.scene-meta {
    display: flex;
    gap: var(--space-md);
    margin-top: var(--space-sm);
    font-size: 0.6875rem;
    color: var(--text-tertiary);
}

.add-btn {
    width: 100%;
    padding: var(--space-sm);
    background: transparent;
    border: 1px dashed var(--border-primary);
    border-radius: var(--radius-md);
    color: var(--text-tertiary);
    font-size: var(--text-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

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

/* ===== Character Cards ===== */
.character-card {
    position: relative;
}

.character-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: var(--space-md);
    border: 2px solid var(--border-primary);
}

.character-name {
    font-size: var(--text-lg);
    font-weight: 600;
    margin-bottom: var(--space-xs);
}

.character-role {
    font-size: var(--text-xs);
    color: var(--accent-primary);
    margin-bottom: var(--space-sm);
}

.character-traits {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    margin-top: var(--space-sm);
}

.trait-tag {
    padding: 2px 8px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-xl);
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

/* ===== World Building ===== */
.world-category {
    margin-bottom: var(--space-xl);
}

.world-category-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
}

.world-category-title {
    font-size: var(--text-lg);
    font-weight: 600;
}

.world-item {
    background: var(--bg-glass);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    margin-bottom: var(--space-sm);
    transition: all var(--transition-fast);
}

.world-item:hover {
    border-color: var(--border-hover);
}

/* ===== Timeline ===== */
.timeline-container {
    position: relative;
    padding-left: var(--space-xl);
}

.timeline-line {
    position: absolute;
    left: 12px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border-primary);
}

.timeline-item {
    position: relative;
    padding-bottom: var(--space-lg);
    padding-left: var(--space-lg);
}

.timeline-dot {
    position: absolute;
    left: calc(-1 * var(--space-xl) + 6px);
    top: 4px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--accent-primary);
    background: var(--bg-primary);
}

.timeline-item-content {
    background: var(--bg-glass);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: var(--space-md);
}

/* ===== Tension Curve ===== */
.tension-curve-container {
    background: var(--bg-glass);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    margin-bottom: var(--space-xl);
}

.tension-curve-canvas {
    width: 100%;
    height: 120px;
}

/* ===== Context Modal (AI) ===== */
.context-modal-list {
    max-height: 300px;
    overflow-y: auto;
}

.context-modal-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.context-modal-item:hover {
    background: var(--bg-glass);
}

.context-modal-item input[type="checkbox"] {
    accent-color: var(--accent-primary);
}

/* ===== Empty States ===== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-2xl);
    text-align: center;
    color: var(--text-tertiary);
    gap: var(--space-md);
    min-height: 200px;
}

.empty-state-icon {
    font-size: 3rem;
    opacity: 0.4;
}

.empty-state-text {
    font-size: var(--text-sm);
}

/* ===== Loading ===== */
.loading-dots::after {
    content: '';
    animation: dots 1.5s infinite;
}

@keyframes dots {

    0%,
    20% {
        content: '';
    }

    40% {
        content: '.';
    }

    60% {
        content: '..';
    }

    80%,
    100% {
        content: '...';
    }
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -100%;
        height: 100%;
        z-index: 100;
        transition: left var(--transition-base);
    }

    .sidebar.open {
        left: 0;
    }

    .ai-panel {
        position: fixed;
        right: -100%;
        height: calc(100vh - var(--status-height));
        z-index: 100;
        transition: right var(--transition-base);
    }

    .ai-panel:not(.collapsed) {
        right: 0;
    }

    .main-content {
        padding: var(--space-md);
    }
}

/* ====== AI Panel Extras ====== */
.btn-danger {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    border: none;
}

.btn-danger:hover {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
}

.context-modal-item {
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
    font-size: var(--text-sm);
}

.context-modal-item:hover {
    background: var(--bg-glass-hover);
}

.context-chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    padding: 2px 8px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.context-chip .remove {
    cursor: pointer;
    opacity: 0.6;
    font-weight: 700;
}

.context-chip .remove:hover {
    opacity: 1;
    color: var(--error);
}

.quick-action-btn {
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-primary);
    background: var(--bg-glass);
    color: var(--text-secondary);
    font-size: var(--text-xs);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.quick-action-btn:hover {
    background: var(--bg-glass-hover);
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

.ai-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-md);
}

.loading-dots::after {
    content: '';
    animation: dots 1.4s steps(4) infinite;
}

@keyframes dots {
    0% {
        content: '';
    }

    25% {
        content: '.';
    }

    50% {
        content: '..';
    }

    75% {
        content: '...';
    }
}

.ai-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: var(--space-xl);
    color: var(--text-secondary);
}

.ai-msg {
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--border-primary);
}

.ai-msg.user {
    background: rgba(245, 158, 11, 0.05);
}

.ai-msg.assistant {
    background: transparent;
}

.msg-role {
    font-size: var(--text-xs);
    font-weight: 600;
    margin-bottom: var(--space-xs);
    color: var(--text-tertiary);
}

.msg-content {
    font-size: var(--text-sm);
    line-height: 1.7;
    color: var(--text-primary);
    word-break: break-word;
}

.ai-input-area {
    display: flex;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-top: 1px solid var(--border-primary);
    align-items: flex-end;
}

.ai-input-area textarea {
    flex: 1;
    resize: none;
}

.ai-context-bar {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-md);
    border-bottom: 1px solid var(--border-primary);
    flex-wrap: wrap;
    font-size: var(--text-xs);
}

.context-label {
    color: var(--text-tertiary);
    font-weight: 500;
    white-space: nowrap;
}

/* ====== Timeline Table (Spreadsheet) ====== */
.timeline-table-wrap {
    overflow-x: auto;
    margin-top: var(--space-md);
}

.tl-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
    table-layout: fixed;
}

.tl-table th,
.tl-table td {
    border: 1px solid var(--border-primary);
    padding: var(--space-xs) var(--space-sm);
    vertical-align: top;
}

.tl-table thead th {
    background: var(--bg-tertiary);
    font-weight: 600;
    font-size: var(--text-xs);
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tl-time-col {
    width: 100px;
    min-width: 100px;
}

.tl-action-col {
    width: 40px;
    min-width: 40px;
}

.tl-char-col {
    min-width: 140px;
}

.tl-time-cell {
    background: var(--bg-tertiary);
    font-weight: 600;
    font-size: var(--text-xs);
    text-align: center;
    white-space: nowrap;
}

.tl-time-label {
    color: var(--accent-primary);
}

.tl-cell {
    cursor: pointer;
    transition: background var(--transition-fast);
    min-height: 48px;
}

.tl-cell:hover {
    background: var(--bg-glass-hover);
}

.tl-cell-content {
    min-height: 32px;
}

.tl-action {
    font-size: var(--text-xs);
    color: var(--text-primary);
    line-height: 1.4;
}

.tl-location {
    font-size: 10px;
    color: var(--text-tertiary);
    margin-top: 2px;
}

.tl-note {
    font-size: 10px;
    color: var(--info);
    font-style: italic;
    margin-top: 2px;
}

.tl-empty {
    color: var(--text-tertiary);
    opacity: 0.3;
    text-align: center;
    font-size: var(--text-xs);
}

.tl-action-cell {
    text-align: center;
    background: var(--bg-tertiary);
}

/* ====== Floor Plan Editor ====== */
.fp-toolbar {
    padding: var(--space-xs) 0;
}

.fp-hint {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}

.fp-canvas-wrap {
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    overflow: hidden;
    margin-top: var(--space-sm);
    background: #0f172a;
}

#fp-canvas {
    display: block;
    width: 100%;
    cursor: crosshair;
}

.fp-color-picker {
    display: flex;
    gap: var(--space-xs);
    flex-wrap: wrap;
    margin-top: var(--space-xs);
}

.fp-color-swatch {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color var(--transition-fast);
}

.fp-color-swatch:hover {
    border-color: var(--text-secondary);
}

/* ====== Scenario Writer ====== */
.sw-layout {
    display: flex;
    gap: var(--space-sm);
    height: calc(100vh - 120px);
    overflow: hidden;
}

.sw-sidebar {
    width: 240px;
    min-width: 200px;
    overflow-y: auto;
    border-right: 1px solid var(--border-primary);
    padding-right: var(--space-sm);
}

.sw-editor {
    flex: 1;
    overflow-y: auto;
    padding: 0 var(--space-sm);
}

.sw-editor-inner {
    max-width: 800px;
}

.sw-placeholder {
    color: var(--text-tertiary);
    text-align: center;
    padding: var(--space-xl);
    font-size: var(--text-sm);
}

.sw-empty {
    color: var(--text-tertiary);
    font-size: var(--text-xs);
    text-align: center;
    padding: var(--space-md);
}

/* シーン一覧 */
.sw-chapter-group {
    margin-bottom: var(--space-sm);
}

.sw-chapter-title {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--accent-primary);
    padding: var(--space-xs) 0;
    border-bottom: 1px solid var(--border-primary);
    margin-bottom: var(--space-xxs);
}

.sw-scene-item {
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.sw-scene-item:hover {
    background: var(--bg-tertiary);
}

.sw-scene-item.active {
    background: rgba(var(--accent-primary-rgb, 245, 158, 11), 0.15);
    border-left: 3px solid var(--accent-primary);
}

.sw-scene-label {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    font-weight: 600;
}

.sw-scene-title {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}

.sw-scene-count {
    font-size: 10px;
    color: var(--text-tertiary);
}

/* メタデータセクション */
.sw-meta-section {
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: var(--space-sm);
    margin-bottom: var(--space-md);
    border: 1px solid var(--border-primary);
}

.sw-meta-row {
    display: flex;
    gap: var(--space-sm);
    margin-bottom: var(--space-xs);
}

.sw-meta-field {
    flex: 1;
    margin-bottom: 0 !important;
}

.sw-meta-field label {
    font-size: 10px;
    margin-bottom: 2px;
}

/* コンテンツセクション */
.sw-content-section,
.sw-buttons-section {
    margin-bottom: var(--space-md);
}

.sw-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-sm);
}

.sw-section-header h3 {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-primary);
}

.sw-add-buttons {
    display: flex;
    gap: var(--space-xxs);
    flex-wrap: wrap;
}

/* コンテンツブロック */
.sw-blocks {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.sw-block {
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    padding: var(--space-xs);
    background: var(--bg-secondary);
}

.sw-block-narration {
    border-left: 3px solid #94a3b8;
}

.sw-block-speech {
    border-left: 3px solid #3b82f6;
}

.sw-block-card {
    border-left: 3px solid #f59e0b;
}

.sw-block-investigation {
    border-left: 3px solid #10b981;
}

.sw-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-xxs);
}

.sw-block-type {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
}

.sw-block-controls {
    display: flex;
    gap: 2px;
}

.sw-textarea {
    font-size: var(--text-xs) !important;
    line-height: 1.6;
    resize: vertical;
    min-height: 48px;
}

.sw-speech-row {
    display: flex;
    gap: var(--space-xs);
    align-items: flex-start;
}

.sw-speaker-select {
    width: 120px;
    min-width: 120px;
    font-size: var(--text-xs) !important;
}

.sw-empty-blocks {
    color: var(--text-tertiary);
    font-size: var(--text-xs);
    text-align: center;
    padding: var(--space-sm);
}

/* ボタン設定 */
.sw-button-row {
    display: flex;
    gap: var(--space-xs);
    align-items: center;
    margin-bottom: var(--space-xxs);
}

.sw-danger-zone {
    border-top: 1px solid var(--border-primary);
    padding-top: var(--space-sm);
    margin-top: var(--space-lg);
}

.form-input-sm {
    font-size: var(--text-xs) !important;
    padding: var(--space-xxs) var(--space-xs);
}

.btn-xs {
    font-size: 11px;
    padding: 2px 8px;
}