/* ==========================================
   麦田与候鸟 · 视觉小说 Web Demo
   ========================================== */

:root {
    --bg-color: #0a0a0f;
    --text-primary: #e0ddd8;
    --text-secondary: #6e6e76;
    --accent-wheat: #d8c3a5;
    --accent-warm: #c9a96e;
    --dialog-bg: rgba(8, 8, 16, 0.88);
    --font-main: 'Noto Serif SC', 'SimSun', serif;
    --font-title: 'ZCOOL XiaoWei', 'Noto Serif SC', serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-main);
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    cursor: pointer;
    user-select: none;
    -webkit-font-smoothing: antialiased;
}

/* ---------- 通用层控制 ---------- */
.layer {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    pointer-events: none;
    transition: opacity 1.5s ease;
    z-index: 0;
}

.layer.active {
    opacity: 1;
    pointer-events: auto;
    z-index: 10;
}

/* ==========================================
   Loading 层
   ========================================== */
.loading-layer {
    background: var(--bg-color);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    transition: opacity 1s ease;
}

.loading-content {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2.5rem;
    position: relative;
    z-index: 2;
}

.loading-title {
    font-family: var(--font-title);
    font-size: 3rem;
    color: var(--accent-wheat);
    letter-spacing: 0.3em;
    font-weight: 400;
    text-shadow: 0 0 40px rgba(216, 195, 165, 0.15);
    margin-right: -0.3em;
}

.loading-bar-track {
    width: 240px;
    height: 2px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 1px;
    overflow: hidden;
}

.loading-bar-fill {
    height: 100%;
    width: 0%;
    background: var(--accent-wheat);
    border-radius: 1px;
    transition: width 0.3s ease;
}

.loading-text {
    font-size: 0.8rem;
    color: var(--text-secondary);
    letter-spacing: 0.2em;
}

/* ==========================================
   序章层
   ========================================== */
#prologue-layer {
    background: radial-gradient(circle at 50% 40%, #13141a 0%, var(--bg-color) 100%);
    display: flex;
    justify-content: center;
    align-items: center;
}

.noise-overlay {
    position: absolute;
    inset: 0;
    opacity: 0.035;
    pointer-events: none;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.7' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.prologue-content {
    position: relative;
    z-index: 2;
    width: 85%;
    max-width: 680px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 60vh;
}

.story-container {
    display: flex;
    flex-direction: column;
    gap: 2.2rem;
}

.story-line {
    font-size: 1.35rem;
    line-height: 2;
    letter-spacing: 0.08em;
    font-weight: 300;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 1.6s cubic-bezier(.25, .46, .45, .94),
        transform 1.6s cubic-bezier(.25, .46, .45, .94),
        filter 1.6s ease-out;
    filter: blur(4px);
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.story-line.visible {
    opacity: 0.85;
    transform: translateY(0);
    filter: blur(0);
}

.story-line.faded {
    opacity: 0.2;
}

.highlight {
    color: var(--accent-wheat);
    font-weight: 400;
}

.interaction-hint {
    position: fixed;
    bottom: 6vh;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.78rem;
    color: var(--text-secondary);
    letter-spacing: 0.3em;
    opacity: 0;
    transition: opacity 1.2s ease;
    animation: pulse 3.5s infinite ease-in-out;
}

.interaction-hint.visible {
    opacity: 0.6;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 0.15;
    }

    50% {
        opacity: 0.65;
    }
}

/* ==========================================
   转场层
   ========================================== */
.transition-layer {
    background: var(--bg-color);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 5;
}

.transition-layer.active {
    z-index: 20;
}

.transition-text {
    font-family: var(--font-title);
    font-size: 2rem;
    color: var(--accent-wheat);
    letter-spacing: 0.35em;
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 2s ease, transform 2s ease;
    text-shadow: 0 0 30px rgba(216, 195, 165, 0.15);
}

.transition-text.visible {
    opacity: 0.9;
    transform: scale(1);
}

/* ==========================================
   视觉小说层
   ========================================== */
.vn-layer {
    background: #000;
}

/* --- 背景 --- */
.vn-bg-container {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

.vn-bg {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity 1.8s ease;
    opacity: 1;
}

.vn-bg-next {
    opacity: 0;
}

.vn-atmosphere {
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom,
            rgba(0, 0, 0, 0.05) 0%,
            rgba(0, 0, 0, 0.1) 50%,
            rgba(0, 0, 0, 0.55) 100%);
    pointer-events: none;
}

/* --- 角色立绘 --- */
.vn-character-container {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 45%;
    max-width: 500px;
    height: 90%;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    pointer-events: none;
}

.vn-character {
    max-height: 100%;
    max-width: 100%;
    object-fit: contain;
    object-position: bottom center;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 1.2s ease, transform 1.2s ease;
    filter: drop-shadow(0 4px 20px rgba(0, 0, 0, 0.5));
}

.vn-character.visible {
    opacity: 1;
    transform: translateY(0);
}

/* --- 对话框 --- */
.vn-dialog-box {
    position: absolute;
    bottom: 5vh;
    left: 10vw;
    right: 10vw;
    min-height: 180px;
    padding: 32px 50px 36px;
    background: linear-gradient(180deg,
            rgba(10, 10, 15, 0.4) 0%,
            rgba(12, 12, 18, 0.85) 40%,
            rgba(8, 8, 12, 0.95) 100%);
    border: 1px solid rgba(216, 195, 165, 0.15);
    border-top: 1px solid rgba(216, 195, 165, 0.35);
    /* stronger top glow */
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), inset 0 1px 10px rgba(216, 195, 165, 0.05);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 0.8s ease, transform 0.8s ease;
    display: none;
}

.vn-dialog-box.visible {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

.vn-speaker {
    font-family: var(--font-title);
    font-size: 1rem;
    color: var(--accent-wheat);
    letter-spacing: 0.2em;
    margin-bottom: 14px;
    min-height: 1.2em;
}

.vn-text {
    font-size: 1.15rem;
    line-height: 2;
    letter-spacing: 0.06em;
    font-weight: 300;
    color: var(--text-primary);
    min-height: 3em;
    white-space: pre-wrap;
}

.vn-continue-indicator {
    position: absolute;
    bottom: 14px;
    right: 28px;
    font-size: 0.7rem;
    color: var(--text-secondary);
    animation: blink 1.5s infinite;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.vn-continue-indicator.visible {
    opacity: 0.6;
}

@keyframes blink {

    0%,
    100% {
        opacity: 0.2;
    }

    50% {
        opacity: 0.8;
    }
}

/* --- 全屏旁白（覆盖在背景上的独白文字） --- */
.vn-narration-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(6, 6, 12, 0.75);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    opacity: 0;
    transition: opacity 1s ease;
    pointer-events: none;
    padding: 10%;
}

.vn-narration-overlay.visible {
    opacity: 1;
}

.vn-narration-text {
    font-size: 1.5rem;
    line-height: 2.4;
    letter-spacing: 0.12em;
    font-weight: 300;
    text-align: center;
    color: var(--text-primary);
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
    max-width: 600px;
    white-space: pre-wrap;
}

/* ==========================================
   新系统层：标题、章节、控制栏、提示
   ========================================== */

/* ---------- 标题层 ---------- */
.title-layer {
    background:
        radial-gradient(circle at 50% 40%, rgba(21, 22, 28, 0.6) 0%, rgba(10, 10, 15, 0.95) 100%),
        url('assets/contryside.webp') center center/cover no-repeat;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 30;
}

.title-content {
    position: relative;
    z-index: 2;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3rem;
}

.game-title {
    font-family: var(--font-title);
    font-size: 4.5rem;
    color: var(--accent-wheat);
    letter-spacing: 0.3em;
    font-weight: 400;
    text-shadow: 0 0 40px rgba(216, 195, 165, 0.15);
    margin-right: -0.3em;
    /* compensate for letter spacing on center */
}

.game-subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    letter-spacing: 0.5em;
    text-transform: uppercase;
    margin-top: -1.5rem;
    margin-right: -0.5em;
}

.title-menu {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-top: 2rem;
}

.menu-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 1.2rem;
    letter-spacing: 0.4em;
    padding: 10px 30px;
    cursor: pointer;
    transition: all 0.4s ease;
    opacity: 0.7;
    position: relative;
    overflow: hidden;
}

.menu-btn::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 1px;
    background: var(--accent-wheat);
    transition: width 0.4s ease;
}

.menu-btn:hover {
    opacity: 1;
    color: var(--accent-wheat);
    text-shadow: 0 0 15px rgba(216, 195, 165, 0.4);
}

.menu-btn:hover::before {
    width: 40%;
}


/* ---------- 章节选择层 ---------- */
.chapter-layer {
    background: rgba(10, 10, 15, 0.95);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 40;
}

.chapter-content {
    position: relative;
    z-index: 2;
    width: 80%;
    max-width: 800px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3rem;
}

.chapter-content h2 {
    font-family: var(--font-title);
    font-size: 2rem;
    color: var(--accent-wheat);
    letter-spacing: 0.3em;
    font-weight: 400;
}

.chapter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 2rem;
    width: 100%;
}

.chapter-card {
    background: rgba(20, 20, 25, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 2rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.4s ease;
}

.chapter-card:hover {
    background: rgba(216, 195, 165, 0.05);
    border-color: rgba(216, 195, 165, 0.3);
    transform: translateY(-5px);
}

.chapter-card .ch-num {
    font-size: 0.8rem;
    color: var(--text-secondary);
    letter-spacing: 0.2em;
    margin-bottom: 0.8rem;
}

.chapter-card .ch-title {
    font-size: 1.3rem;
    color: var(--text-primary);
    letter-spacing: 0.2em;
}

.back-btn {
    margin-top: 2rem;
    font-size: 1rem;
}

/* ---------- 游戏内菜单栏 ---------- */
.in-game-menu {
    position: absolute;
    bottom: calc(5vh + 195px);
    /* 位于对话框上方 */
    right: 10vw;
    display: flex;
    gap: 1rem;
    opacity: 0;
    /* 默认隐藏，或者淡化 */
    pointer-events: none;
    transition: opacity 0.5s ease;
    z-index: 15;
}

/* 当 vnLayer 活跃，且不处于纯演出状态时显示（通过 JS 控制 class） */
.in-game-menu.visible {
    opacity: 0.3;
    pointer-events: auto;
}

.in-game-menu.visible:hover {
    opacity: 1;
}

.ig-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.85rem;
    letter-spacing: 0.15em;
    cursor: pointer;
    padding: 4px 8px;
    transition: color 0.3s, text-shadow 0.3s;
}

.ig-btn:hover {
    color: var(--accent-wheat);
}

.ig-btn.active-state {
    color: var(--accent-warm);
    text-shadow: 0 0 8px rgba(201, 169, 110, 0.6);
}

/* ---------- 通用弹窗底层 ---------- */
.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(6, 6, 12, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.modal-content {
    position: relative;
    z-index: 2;
    width: 90%;
    max-width: 600px;
    margin: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    padding: 3rem 2rem;
}

.modal-content h2 {
    font-family: var(--font-title);
    font-size: 1.8rem;
    color: var(--accent-wheat);
    letter-spacing: 0.3em;
    font-weight: 400;
}

/* ---------- 存档弹窗 ---------- */
.save-modal {
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 50;
}

.save-slots {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
}

.save-slot {
    background: rgba(20, 20, 25, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.06);
    padding: 1.2rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.save-slot:hover {
    background: rgba(216, 195, 165, 0.06);
    border-color: rgba(216, 195, 165, 0.25);
}

.save-slot .slot-name {
    font-size: 1rem;
    color: var(--text-primary);
    letter-spacing: 0.15em;
}

.save-slot .slot-info {
    font-size: 0.8rem;
    color: var(--text-secondary);
    letter-spacing: 0.08em;
    text-align: right;
}

.save-slot.empty .slot-info {
    font-style: italic;
    opacity: 0.5;
}

/* ---------- 设置面板 ---------- */
.settings-layer {
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 50;
}

.settings-content {
    max-width: 480px;
}

.settings-group {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.settings-label {
    font-size: 0.95rem;
    color: var(--text-primary);
    letter-spacing: 0.1em;
    min-width: 80px;
    flex-shrink: 0;
}

.settings-slider {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 2px;
    background: rgba(255, 255, 255, 0.12);
    border-radius: 1px;
    outline: none;
    cursor: pointer;
}

.settings-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent-wheat);
    cursor: pointer;
    box-shadow: 0 0 8px rgba(216, 195, 165, 0.3);
    transition: transform 0.2s ease;
}

.settings-slider::-webkit-slider-thumb:hover {
    transform: scale(1.3);
}

.settings-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent-wheat);
    cursor: pointer;
    border: none;
    box-shadow: 0 0 8px rgba(216, 195, 165, 0.3);
}

.settings-value {
    font-size: 0.85rem;
    color: var(--text-secondary);
    min-width: 30px;
    text-align: right;
}

/* ---------- 历史回顾面板 ---------- */
.history-layer {
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 50;
}

.history-content {
    max-width: 650px;
    max-height: 80vh;
}

.history-list {
    width: 100%;
    max-height: 50vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    padding-right: 8px;
}

/* Custom scrollbar for history */
.history-list::-webkit-scrollbar {
    width: 3px;
}

.history-list::-webkit-scrollbar-track {
    background: transparent;
}

.history-list::-webkit-scrollbar-thumb {
    background: rgba(216, 195, 165, 0.2);
    border-radius: 2px;
}

.history-entry {
    padding: 0.8rem 1rem;
    border-left: 2px solid rgba(216, 195, 165, 0.1);
    transition: border-color 0.3s ease;
}

.history-entry:hover {
    border-left-color: rgba(216, 195, 165, 0.4);
}

.history-entry .history-speaker {
    font-size: 0.8rem;
    color: var(--accent-wheat);
    letter-spacing: 0.15em;
    margin-bottom: 0.3rem;
    opacity: 0.8;
}

.history-entry .history-text {
    font-size: 0.95rem;
    line-height: 1.8;
    color: var(--text-primary);
    opacity: 0.7;
    white-space: pre-wrap;
}

/* ---------- 系统提示 Toast ---------- */
.sys-toast {
    position: fixed;
    top: 40px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: rgba(20, 20, 25, 0.85);
    border: 1px solid rgba(216, 195, 165, 0.2);
    color: var(--accent-wheat);
    padding: 10px 24px;
    font-size: 0.9rem;
    letter-spacing: 0.1em;
    border-radius: 4px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease, transform 0.4s ease;
    z-index: 100;
}

.sys-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ---------- 响应式 ---------- */
@media (max-width: 768px) {
    .game-title {
        font-size: 2.8rem;
        letter-spacing: 0.2em;
        margin-right: -0.2em;
    }

    .game-subtitle {
        font-size: 0.75rem;
        letter-spacing: 0.3em;
        margin-right: -0.3em;
    }

    .title-menu {
        gap: 1.2rem;
        margin-top: 1.5rem;
    }

    .menu-btn {
        font-size: 1rem;
        letter-spacing: 0.3em;
        padding: 8px 20px;
    }

    .loading-title {
        font-size: 2.2rem;
    }

    .story-line {
        font-size: 1.1rem;
    }

    .transition-text {
        font-size: 1.5rem;
    }

    .vn-dialog-box {
        padding: 20px 24px 24px;
        min-height: 170px;
    }

    .vn-text {
        font-size: 1rem;
    }

    .vn-narration-text {
        font-size: 1.2rem;
    }

    .vn-character-container {
        width: 60%;
    }

    .chapter-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .chapter-card {
        padding: 1.5rem 1rem;
    }

    .in-game-menu {
        bottom: 180px;
        right: 20px;
        gap: 0.5rem;
    }

    .ig-btn {
        font-size: 0.75rem;
    }

    .modal-content {
        padding: 2rem 1.5rem;
        gap: 1.5rem;
    }

    .settings-group {
        flex-wrap: wrap;
    }

    .settings-label {
        min-width: 70px;
        font-size: 0.85rem;
    }
}

@media (max-width: 480px) {
    .game-title {
        font-size: 2rem;
        letter-spacing: 0.15em;
        margin-right: -0.15em;
    }

    .game-subtitle {
        font-size: 0.65rem;
        letter-spacing: 0.2em;
        margin-right: -0.2em;
    }

    .menu-btn {
        font-size: 0.9rem;
        letter-spacing: 0.2em;
        padding: 6px 16px;
    }

    .loading-title {
        font-size: 1.8rem;
    }

    .loading-bar-track {
        width: 180px;
    }

    .story-line {
        font-size: 1rem;
    }

    .vn-narration-text {
        font-size: 1.05rem;
        line-height: 2;
    }

    .in-game-menu {
        bottom: 180px;
        right: 12px;
        gap: 0.3rem;
        flex-wrap: wrap;
        max-width: 200px;
        justify-content: flex-end;
    }

    .ig-btn {
        font-size: 0.7rem;
        padding: 3px 5px;
    }
}