:root {
    --paper-base: #e8dcc4;
    --paper-dark: #c5b395;
    --ink: #2c1e14;
    --gold: #b8860b;
    --magic-glow: rgba(184, 134, 11, 0.5);
    --system-font: "Georgia", serif;
}

body {
    margin: 0;
    background: #0a0806;
    color: var(--paper-base);
    font-family: var(--system-font);
    overflow: hidden;
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
}

.library-vignette {
    position: fixed;
    inset: 0;
    background: radial-gradient(circle, transparent 20%, rgba(0, 0, 0, 0.95));
    pointer-events: none;
    z-index: 100;
}

.dust-particles {
    position: fixed;
    inset: 0;
    background: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMDAiIGhlaWdodD0iMjAwIj48Y2lyY2xlIGN4PSIzIiBjeT0iMyIgcj0iMSIgZmlsbD0icmdiYSgyMzIsIDIyMCwgMTk2LCAwLjIpIi8+PC9zdmc+');
    animation: dust-drift 60s linear infinite;
    pointer-events: none;
    z-index: 50;
}

@keyframes dust-drift {
    from {
        background-position: 0 0;
    }

    to {
        background-position: 1000px 1000px;
    }
}

#main-layout {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}

.ancient-book-frame {
    width: 960px;
    height: 660px;
    background: #3e2723;
    border: 4px solid #2b1b19;
    border-radius: 8px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.9), 0 0 0 10px #3e2723;
    position: relative;
    display: flex;
    z-index: 10;
    overflow: hidden;
}

.book-page {
    flex: 1;
    margin: 15px;
    padding: 40px;
    display: flex;
    flex-direction: column;
    position: relative;
}

.book-page-left {
    background: linear-gradient(to right, #d4c4a8 0%, var(--paper-base) 90%, var(--paper-dark) 100%);
    border-radius: 5px 0 0 5px;
    color: var(--ink);
    border-right: 2px solid rgba(0, 0, 0, 0.3);
}

.book-page-right {
    background: linear-gradient(to left, #d4c4a8 0%, var(--paper-base) 90%, var(--paper-dark) 100%);
    border-radius: 0 5px 5px 0;
    color: var(--ink);
    border-left: 2px solid rgba(255, 255, 255, 0.1);
}

.book-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    /* Added for horizontal centering of children */
    text-align: center;
}

/* メインのテキスト表示エリア */
#current-speech {
    font-size: 1.4rem;
    line-height: 2;
    color: var(--ink);
    padding: 0 20px;
    white-space: pre-wrap;
}

.mysteries-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 25px 20px;
    margin-top: 20px;
    justify-items: center;
    align-items: start;
    width: 100%;
}

/* 最初の1枚（end.jpgなど）を1行目に中央配置する設定 */
.mysteries-grid .illustration-container:first-child {
    grid-column: span 2;
    display: flex;
    justify-content: center;
    width: 100%;
}

.mysteries-grid.final-phase .book-illustration {
    width: 140px;
    /* 他の画像と同じサイズに固定 */
    max-width: 140px;
    height: auto;
}

.mysteries-grid.final-phase-left {
    margin-top: 110px;
    /* 全体的に上に余白を追加 */
}

.illustration-container {
    position: relative;
    cursor: pointer;
    transition: transform 0.3s;
}

.illustration-container:hover {
    transform: scale(1.05);
}

.book-illustration {
    width: 140px;
    height: auto;
    filter: sepia(0.3);
    box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.2);
}

.image-label {
    position: absolute;
    bottom: -25px;
    width: 100%;
    text-align: center;
    color: var(--gold);
    font-weight: bold;
}

#back-to-phase1,
#forward-to-phase2 {
    background: none;
    border: 1px solid var(--ink);
    color: var(--ink);
    font-family: var(--system-font);
    padding: 5px 15px;
    display: inline-block;
    cursor: pointer;
    margin-bottom: 10px;
    transition: all 0.3s;
}

#back-to-phase1:hover,
#forward-to-phase2:hover {
    background: var(--ink);
    color: var(--paper-base);
}

#forward-to-phase2 {
    margin-left: 10px;
}

/* モーダルスタイル */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(8px);
}

.modal-content {
    background: #d4c4a8;
    background-image:
        radial-gradient(circle at center, transparent 0%, rgba(0, 0, 0, 0.05) 100%),
        url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0IiBoZWlnaHQ9IjQiPjxyZWN0IHdpZHRoPSIxIiBoZWlnaHQ9IjEiIGZpbGw9InJnYmEoMCwwLDAsMC4wNSkiLz48L3N2Zz4=');
    padding: 50px;
    /* 50pxの余白 */
    border: none;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 40px;
    position: relative;
    width: 100vw;
    height: 100vh;
    box-shadow: inset 0 0 150px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    overflow: auto;
}

#detail-img {
    max-width: calc(100vw - 100px);
    max-height: calc(100vh - 200px);
    border: 1px solid rgba(62, 39, 35, 0.1);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    object-fit: contain;
}

#modal-answer {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-bottom: 2px solid var(--ink);
    color: var(--ink);
    font-size: 2.5rem;
    text-align: center;
    outline: none;
    padding: 10px;
    width: 500px;
    letter-spacing: 0.5em;
}

.close-button {
    position: absolute;
    top: 30px;
    right: 40px;
    font-size: 4rem;
    color: var(--ink);
    cursor: pointer;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.hidden {
    display: none !important;
}

/* --- アニメーション --- */
.fade-in {
    animation: fadeIn 0.8s forwards;
}

.fade-out {
    animation: fadeOut 0.8s forwards;
}

/* --- モバイル用レイアウトとページめくり演出 --- */
@media screen and (max-width: 768px) {
    .ancient-book-frame {
        width: 100vw;
        height: 100vh;
        height: calc(var(--vh, 1vh) * 100);
        border: none;
        border-radius: 0;
        box-shadow: none;
        /* 3D効果の奥行き */
    }

    .book-page {
        margin: 0;
        padding: 20px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        text-align: center;
        background: var(--paper-base);
        /* スマホでも紙の色を維持 */
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        box-sizing: border-box;
        z-index: 10;
    }

    /* ストーリー表示が消える時の動き（シンプルにフェード） */
    #story-display.fade-out {
        animation: fadeOut 0.6s ease-in-out forwards;
    }

    /* 謎解きエリアが現れる時の動き（シンプルにフェード） */
    #mystery-pages.fade-in {
        animation: fadeIn 0.6s ease-in-out forwards;
        z-index: 20;
    }

    .mysteries-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 30px 15px;
        overflow-y: auto;
        display: grid !important;
    }

    /* スマホでは最初の1枚だけ大きくせず、均等に並べる */
    .mysteries-grid .illustration-container:first-child {
        grid-column: span 1;
    }

    .book-illustration {
        width: 100%;
        max-width: 100%;
        height: auto;
    }

    #current-speech {
        font-size: 1.2rem;
        /* スマホ用に少し小さく調整 */
        padding: 0 10px;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
        filter: blur(0);
    }

    to {
        opacity: 0;
        filter: blur(10px);
    }
}

/* --- ログエリア --- */
#chat-log {
    height: 100%;
    overflow-y: auto;
}

.entry {
    margin-bottom: 15px;
    border-left: 3px solid var(--gold);
    padding-left: 10px;
    opacity: 0;
    animation: fadeIn 0.5s forwards;
}

#phase-instruction {
    margin-top: 50px;
    /* この値を調整して、テキストの表示位置を上下に移動させます */
}

.ability {
    color: var(--gold);
    font-weight: bold;
}