/* 基础重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* 极简配色 */
    --bg-primary: #000000;
    --bg-panel: rgba(255, 255, 255, 0.03);
    --bg-input: rgba(255, 255, 255, 0.05);
    
    /* 文字颜色 */
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.6);
    --text-muted: rgba(255, 255, 255, 0.4);
    
    /* 边框 */
    --border-light: rgba(255, 255, 255, 0.1);
    --border-normal: rgba(255, 255, 255, 0.15);
    --border-focus: rgba(255, 255, 255, 0.3);
    
    /* 强调色 */
    --accent: #ffffff;
    --accent-dim: rgba(255, 255, 255, 0.8);
    
    /* 圆角 */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    
    /* 字体 */
    --font-primary: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-primary);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
}

#app {
    width: 100%;
    height: 100%;
    position: relative;
}

/* 背景层 - 纯黑 */
.background-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    background: #000000;
}

/* 画布层 */
#timeline-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1;
    cursor: grab;
}

#timeline-canvas:active {
    cursor: grabbing;
}

/* UI层 */
.ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
}

.ui-layer > * {
    pointer-events: auto;
}

/* 标题 - 极简 */
.main-header {
    position: absolute;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    z-index: 100;
}

.glow-text {
    font-size: 1.5rem;
    font-weight: 400;
    letter-spacing: 0.15em;
    color: var(--text-primary);
    text-transform: uppercase;
}

.subtitle {
    margin-top: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    letter-spacing: 0.1em;
}

/* 面板 - 扁平极简 */
.node-panel,
.create-panel {
    position: absolute;
    right: 24px;
    top: 50%;
    transform: translateY(-50%);
    width: 360px;
    max-height: 80vh;
    background: rgba(0, 0, 0, 0.85);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: opacity 0.2s ease, transform 0.2s ease;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 100;
}

.node-panel.hidden,
.create-panel.hidden {
    opacity: 0;
    transform: translateY(-50%) translateX(40px);
    pointer-events: none;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
}

.panel-header h3 {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.close-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    transition: color 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 1000;
    padding: 0;
    margin: 0;
    text-align: center;
    -webkit-appearance: none;
    appearance: none;
}

.close-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: transparent;
    z-index: -1;
}

.close-btn:hover {
    color: #B22222;
}

.panel-content {
    padding: 20px;
    max-height: calc(80vh - 60px);
    overflow-y: auto;
}

.panel-content::-webkit-scrollbar {
    width: 4px;
}

.panel-content::-webkit-scrollbar-track {
    background: transparent;
}

.panel-content::-webkit-scrollbar-thumb {
    background: var(--border-normal);
    border-radius: 2px;
}

/* 故事文本 */
.story-section {
    margin-bottom: 20px;
}

.story-section h4 {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 10px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    font-weight: 500;
}

.story-text {
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text-primary);
    opacity: 0.9;
}

/* 前情提要 */
.backstory-section {
    max-height: 200px;
    overflow-y: auto;
    padding-right: 8px;
}

.backstory-section::-webkit-scrollbar {
    width: 4px;
}

.backstory-section::-webkit-scrollbar-track {
    background: transparent;
}

.backstory-section::-webkit-scrollbar-thumb {
    background: var(--border-normal);
    border-radius: 2px;
}

.backstory-item {
    margin-bottom: 12px;
    padding: 10px 12px;
    background: rgba(255, 255, 255, 0.03);
    border-left: 2px solid var(--border-light);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.backstory-item:last-child {
    margin-bottom: 0;
}

.backstory-node {
    display: inline-block;
    font-size: 0.7rem;
    color: #B22222;
    margin-bottom: 6px;
    letter-spacing: 0.05em;
}

.backstory-item p {
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-secondary);
    margin: 0;
}

/* 当前剧情 */
.current-story-section {
    padding: 14px;
    background: rgba(178, 34, 34, 0.05);
    border-radius: var(--radius-md);
    border: 1px solid rgba(178, 34, 34, 0.1);
}

/* 选择列表 - 极简 */
.choices-section h4 {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 12px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    font-weight: 500;
}

.choices-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.choice-item {
    padding: 14px 16px;
    background: transparent;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.choice-item:hover {
    background: rgba(178, 34, 34, 0.1);
    border-color: #B22222;
}

.choice-item.existing {
    border-color: var(--border-normal);
}

.choice-item.existing::after {
    content: '已存在';
    float: right;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* 创建面板 */
.parent-story {
    margin-bottom: 20px;
    padding: 16px;
    background: var(--bg-input);
    border-radius: var(--radius-md);
}

.parent-story h4 {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    font-weight: 500;
}

.parent-story p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.input-section {
    margin-bottom: 16px;
}

.input-section label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.input-section textarea,
.input-section input[type="text"] {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    resize: vertical;
    transition: border-color 0.15s ease;
}

.input-section textarea:focus,
.input-section input[type="text"]:focus {
    outline: none;
    border-color: #B22222;
}

.input-section textarea::placeholder,
.input-section input[type="text"]::placeholder {
    color: var(--text-muted);
}

.choice-input {
    margin-bottom: 8px;
}

.add-choice-btn {
    width: 100%;
    padding: 10px;
    background: transparent;
    border: 1px dashed var(--border-light);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

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

/* AI 生成按钮 */
.ai-generate-btn {
    width: 100%;
    padding: 14px;
    margin: 16px 0;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.ai-generate-btn:hover {
    background: var(--border-light);
    color: var(--text-primary);
}

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

/* 提交按钮 */
.submit-btn {
    width: 100%;
    padding: 14px;
    background: #B22222;
    border: none;
    border-radius: var(--radius-md);
    color: #ffffff;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s ease;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.submit-btn:hover {
    opacity: 0.9;
}

/* 控制栏 - 极简 */
.controls {
    position: absolute;
    bottom: 24px;
    left: 24px;
    display: flex;
    gap: 8px;
    align-items: center;
}

.control-btn {
    padding: 10px 16px;
    background: var(--bg-panel);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s ease;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.control-btn:hover {
    background: #B22222;
    color: #ffffff;
    border-color: #B22222;
}

.zoom-controls {
    display: flex;
    gap: 4px;
    margin-left: 8px;
}

.zoom-controls .control-btn {
    padding: 10px 14px;
    font-weight: 500;
    min-width: 40px;
}

/* 统计信息 - 极简 */
.stats {
    position: absolute;
    bottom: 24px;
    right: 24px;
    display: flex;
    gap: 24px;
}

.stat-item {
    text-align: left;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 300;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-top: 2px;
}

/* 引导模态框 - 极简 */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    display: none;
}

.modal-content {
    background: var(--bg-panel);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 48px 56px;
    text-align: center;
    max-width: 480px;
}

.modal-content h2 {
    font-size: 1.25rem;
    font-weight: 400;
    margin-bottom: 20px;
    color: var(--text-primary);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.modal-content p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 12px;
}

.start-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 32px;
}

.start-btn {
    padding: 14px 48px;
    background: #B22222;
    border: none;
    border-radius: var(--radius-md);
    color: #ffffff;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.15s ease;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.start-btn:hover {
    opacity: 0.9;
}

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

.start-btn.secondary:hover {
    border-color: #B22222;
    color: #ffffff;
    background: rgba(178, 34, 34, 0.1);
}

/* 响应式 - 平板 */
@media (max-width: 1024px) {
    .node-panel,
    .create-panel {
        width: 320px;
    }
}

/* 响应式 - 手机 */
@media (max-width: 768px) {
    /* 全局触摸优化 */
    button, .control-btn, .start-btn, .choice-item, .add-choice-btn, .ai-generate-btn, .submit-btn, .close-btn {
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        cursor: pointer;
        -webkit-touch-callout: none;
        user-select: none;
    }

    .main-header {
        top: 16px;
        left: 16px;
        right: 16px;
        transform: none;
        text-align: left;
    }
    
    .glow-text {
        font-size: 1.1rem;
        letter-spacing: 0.1em;
    }
    
    .subtitle {
        font-size: 0.75rem;
        margin-top: 4px;
    }
    
    .node-panel,
    .create-panel {
        position: fixed;
        right: 12px;
        left: 12px;
        width: auto;
        top: auto;
        bottom: 12px;
        transform: none;
        max-height: 55vh;
        border-radius: var(--radius-md);
        background: rgba(0, 0, 0, 0.95);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        pointer-events: auto;
        z-index: 1000;
        overflow: visible; /* 确保按钮不被裁剪 */
    }

    /* 有浮动按钮的面板需要额外的顶部padding */
    .create-panel:has(.close-btn-floating) .panel-header,
    .node-panel:has(.close-btn-floating) .panel-header {
        padding-top: 16px;
        padding-right: 56px; /* 为浮动按钮留出空间 */
    }

    .node-panel.hidden,
    .create-panel.hidden {
        transform: translateY(100%);
        opacity: 0;
        pointer-events: none;
    }
    
    .panel-header {
        padding: 12px 16px;
        position: relative;
        min-height: 56px;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .panel-header h3 {
        font-size: 0.85rem;
        margin: 0;
        flex: 0 1 auto;
        max-width: calc(100% - 60px); /* 确保不会覆盖按钮 */
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* 浮动关闭按钮 - 绝对定位确保不被遮挡 */
    .close-btn-floating {
        position: absolute;
        top: 8px;
        right: 8px;
        width: 40px;
        height: 40px;
        background: rgba(178, 34, 34, 0.2);
        border-radius: 50%;
        font-size: 1.5rem;
        z-index: 10000;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(178, 34, 34, 0.3);
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        border: 1px solid rgba(178, 34, 34, 0.3);
        pointer-events: auto;
        cursor: pointer;
        -webkit-touch-callout: none;
        user-select: none;
    }

    .close-btn-floating:active {
        background: rgba(178, 34, 34, 0.5);
        transform: scale(0.95);
    }

    .close-btn:active,
    .close-btn:hover {
        background: transparent;
    }

    .close-btn:active::after,
    .close-btn:hover::after {
        background: rgba(178, 34, 34, 0.3);
        border-color: rgba(178, 34, 34, 0.5);
    }

    /* 确保按钮在触摸时有明显反馈 */
    .close-btn:active::after {
        transform: scale(0.9);
        -webkit-transform: scale(0.9);
    }
    
    .panel-content {
        padding: 16px;
        max-height: calc(55vh - 52px);
    }
    
    .story-text {
        font-size: 0.9rem;
        line-height: 1.6;
    }
    
    .choice-item {
        padding: 12px 14px;
        font-size: 0.85rem;
    }
    
    .controls {
        position: fixed;
        top: auto;
        bottom: calc(55vh + 20px); /* 位于面板上方 */
        right: 12px;
        left: auto;
        flex-direction: row;
        gap: 8px;
        z-index: 100;
    }
    
    .control-btn {
        padding: 10px 14px;
        font-size: 0.8rem;
        min-width: auto;
        text-align: center;
        background: rgba(0, 0, 0, 0.8);
        backdrop-filter: blur(4px);
    }
    
    .zoom-controls {
        margin-left: 0;
        flex-direction: row;
        gap: 8px;
    }
    
    .zoom-controls .control-btn {
        min-width: 36px;
        padding: 10px;
        font-weight: 600;
    }
    
    .stats {
        position: fixed;
        bottom: auto;
        top: 16px;
        right: auto;
        left: 16px;
        flex-direction: row;
        gap: 16px;
        background: rgba(0, 0, 0, 0.7);
        padding: 10px 14px;
        border-radius: var(--radius-md);
        backdrop-filter: blur(4px);
        z-index: 50;
    }
    
    .stat-value {
        font-size: 1.1rem;
    }
    
    .stat-label {
        font-size: 0.65rem;
    }
    
    .modal-content {
        margin: 16px;
        padding: 28px 24px;
        max-width: none;
    }
    
    .modal-content h2 {
        font-size: 1.1rem;
    }
    
    .modal-content p {
        font-size: 0.85rem;
    }
    
    .start-btn {
        margin-top: 24px;
        padding: 16px 36px;
        font-size: 0.85rem;
        min-height: 48px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(178, 34, 34, 0.3);
    }

    .start-btn.secondary {
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(255, 255, 255, 0.1);
    }

    /* 模态框触摸优化 */
    .modal {
        touch-action: auto;
    }

    .modal-content {
        pointer-events: auto;
    }
}

/* Toast 提示 */
.toast-container {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    padding: 12px 24px;
    background: rgba(0, 0, 0, 0.9);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.9rem;
    backdrop-filter: blur(10px);
    animation: toastSlideIn 0.3s ease, toastFadeOut 0.3s ease 2.7s;
    pointer-events: auto;
    min-width: 200px;
    text-align: center;
}

.toast.error {
    border-color: #B22222;
    background: rgba(178, 34, 34, 0.15);
}

.toast.success {
    border-color: #228B22;
    background: rgba(34, 139, 34, 0.15);
}

.toast.warning {
    border-color: #DAA520;
    background: rgba(218, 165, 32, 0.15);
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toastFadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

/* 确认对话框 */
.confirm-content {
    max-width: 400px;
    padding: 32px;
}

.confirm-content h3 {
    font-size: 1rem;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.confirm-content p {
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.5;
}

.confirm-buttons {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.confirm-buttons .control-btn,
.confirm-buttons .submit-btn {
    padding: 10px 24px;
    font-size: 0.85rem;
}

/* 加载遮罩 */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
    transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    text-align: center;
}

.spinner-ring {
    width: 60px;
    height: 60px;
    border: 3px solid var(--border-light);
    border-top-color: #B22222;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

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

.loading-spinner p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 16px;
}

.loading-progress {
    width: 200px;
    height: 4px;
    background: var(--border-light);
    border-radius: 2px;
    overflow: hidden;
    margin: 0 auto;
}

.progress-bar {
    height: 100%;
    background: #B22222;
    border-radius: 2px;
    transition: width 0.3s ease;
    width: 0%;
}

/* 表单字段错误提示 */
.input-error {
    border-color: #B22222 !important;
    background: rgba(178, 34, 34, 0.05) !important;
}

.error-message {
    color: #B22222;
    font-size: 0.8rem;
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.error-message::before {
    content: '⚠';
}

/* 输入字数统计 */
.char-count {
    text-align: right;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.char-count.warning {
    color: #DAA520;
}

/* 自动保存提示 */
.autosave-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 8px;
}

.autosave-indicator.saved::before {
    content: '✓';
    color: #228B22;
}

.autosave-indicator.saving::before {
    content: '⟳';
    animation: spin 1s linear infinite;
}

/* 选择数量提示 */
.choice-limit-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 8px;
    text-align: center;
}

.choice-limit-hint.warning {
    color: #DAA520;
}

/* 响应式 - 小屏手机 */
@media (max-width: 480px) {
    .glow-text {
        font-size: 1rem;
    }
    
    #timeline-canvas {
        width: 100vw;
        height: 100vh;
        touch-action: none; /* 允许触摸操作 */
    }
    
    .node-panel,
    .create-panel {
        max-height: 65vh;
        right: 8px;
        left: 8px;
        bottom: 8px;
    }
    
    .panel-content {
        max-height: calc(65vh - 52px);
    }
    
    .controls {
        top: 12px;
        right: 12px;
    }
    
    .stats {
        top: 60px;
        right: 12px;
        padding: 10px 12px;
    }
}
