html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    font-family: sans-serif;
    background: transparent;
    position: relative;
    z-index: 1;
}

/* 背景画像 */
#background {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    z-index: 0;
}

/* テキストウィンドウ（ノベルゲーム風） */
#textBox {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    min-height: 140px;

    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    padding: 20px;
    border-radius: 12px;

    font-size: 20px;
    line-height: 1.8;
    user-select: none;

    z-index: 10;
}

/* 選択肢ボタン */
#choices {
    position: fixed;
    bottom: 180px;
    left: 50%;
    transform: translateX(-50%);
    width: 70%;
    text-align: center;
    z-index: 10;
}

#choices button {
    display: block;
    width: 100%;
    margin: 8px 0;
    padding: 12px;
    font-size: 18px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.85);
    border: none;
}

/* 次へボタン（右下に固定） */
#nextButton {
    position: fixed;
    bottom: 20px;
    right: 20px;

    padding: 12px 20px;
    font-size: 18px;
    border-radius: 8px;

    background: rgba(255, 255, 255, 0.85);
    border: none;

    z-index: 10;
}

/* 自動セーブボタン */
#toggleSave {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 20; /* ★ 背景より前に出す */
    background: rgba(255, 255, 255, 0.85);
    color: #000;
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    font-size: 16px;
}

#openSaveMenu {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 20;
    padding: 10px 20px;
    background: rgba(255,255,255,0.85);
    border: none;
    border-radius: 8px;
}

#saveMenu {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 70%;
    max-width: 600px;
    background: rgba(0,0,0,0.8);
    color: #fff;
    padding: 20px;
    border-radius: 12px;
    z-index: 3050; /* メニュー・タイトル画面より手前に出す */
}

#saveMenu.hidden {
    display: none;
}

#saveSlots {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.saveSlot {
    background: rgba(255,255,255,0.1);
    padding: 10px;
    border-radius: 8px;
    display: flex;
    gap: 10px;
    align-items: center;
    margin-left: 10px;
}

.saveSlot img {
    width: 120px;
    height: 70px;
    object-fit: cover;
    border-radius: 6px;
}

.saveSlot button {
    margin-left: auto;
    padding: 8px 12px;
    background: rgba(255,255,255,0.85);
    border: none;
    border-radius: 6px;
}

/* ★ メニュー画面の背景（半透明） */
#menuScreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

#menuScreen.hidden {
    display: none;
}

/* ★ メニューウィンドウ */
.menuWindow {
    background: #ffffff;
    padding: 30px;
    width: 300px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 0 20px rgba(0,0,0,0.4);
}

/* ★ メニュータイトル */
.menuWindow h2 {
    margin-bottom: 20px;
    font-size: 24px;
}

/* ★ メニューボタン */
.menuBtn {
    display: block;
    width: 100%;
    padding: 12px;
    margin: 10px 0;
    font-size: 18px;
    border: none;
    border-radius: 8px;
    background: #4a90e2;
    color: white;
    cursor: pointer;
}

.menuBtn:hover {
    background: #357ab8;
}

/* ★ 閉じるボタン */
.menuClose {
    margin-top: 20px;
    padding: 10px;
    width: 100%;
    background: #aaa;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

.menuClose:hover {
    background: #888;
}

.menuIcon {
    position: fixed;
    top: 20px;
    right: 20px;
    font-size: 28px;
    background: rgba(0,0,0,0.4);
    color: white;
    border: none;
    padding: 10px 14px;
    border-radius: 8px;
    cursor: pointer;
    z-index: 1500;
}

/* ★ マップ画面の背景（半透明） */
#mapScreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

#mapScreen.hidden {
    display: none;
}

/* ★ マップウィンドウ */
.mapWindow {
    background: #ffffff;
    padding: 30px;
    width: 400px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 0 20px rgba(0,0,0,0.4);
}

/* ★ マップ画像 */
#mapImage {
    width: 100%;
    border-radius: 8px;
    margin-bottom: 20px;
}

/* ★ 現在地の名前 */
#currentLocationName {
    font-size: 18px;
    margin-bottom: 20px;
}

/* ★ 閉じるボタン */
.mapClose {
    padding: 10px;
    width: 100%;
    background: #aaa;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

.mapClose:hover {
    background: #888;
}

/* ★ 写真帳画面の背景（半透明） */
#photoScreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

#photoScreen.hidden {
    display: none;
}

/* ★ 写真帳ウィンドウ */
.photoWindow {
    background: #fff;
    padding: 30px;
    width: 600px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 0 20px rgba(0,0,0,0.4);
}

/* ★ 写真帳の左右ページ */
.photoBook {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.photoLeft, .photoRight {
    width: 50%;
    background: #f7f7f7;
    padding: 15px;
    border-radius: 8px;
}

/* 写真 */
#photoImage {
    width: 100%;
    border-radius: 6px;
}

/* メッセージ */
#photoMessage {
    font-size: 16px;
    line-height: 1.6;
}

/* ページ送り */
.photoNav {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-bottom: 20px;
}

.photoNav button {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    background: #4a90e2;
    color: #fff;
    cursor: pointer;
}

.photoNav button:hover {
    background: #357ab8;
}

/* 閉じるボタン */
.photoClose {
    padding: 10px;
    width: 100%;
    background: #aaa;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

.photoClose:hover {
    background: #888;
}

/* ★ ページめくりアニメーション */
.pageFlip {
    transition: transform 0.4s ease, opacity 0.4s ease;
    transform-origin: left center;
}

/* めくるときに一瞬傾ける */
.pageFlip.flip {
    transform: rotateY(-70deg);
    opacity: 0;
}

/* ★ ページめくりアニメーション強化版 */
.pageFlip {
    transition: transform 0.6s ease, opacity 0.6s ease, box-shadow 0.6s ease;
    transform-origin: left center;
    box-shadow: 0 0 0 rgba(0,0,0,0);
}

/* めくる瞬間の立体感 */
.pageFlip.flip {
    transform: rotateY(-120deg) scale(0.98);
    opacity: 0;
    box-shadow: -20px 0px 40px rgba(0,0,0,0.3);
}

/* めくり終わりの “ふわっと戻る” */
.pageFlip.return {
    transform: rotateY(0deg) scale(1);
    opacity: 1;
    box-shadow: 0 0 0 rgba(0,0,0,0);
}

/* ========================================
   古い街角・探索画面
   ======================================== */

#explorationScreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 3000;
}

#explorationScreen.hidden {
    display: none;
}

#explorationArea {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

#explorationImage {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* 探索ポイント */
.searchPoint {
    position: absolute;

    background: rgba(255, 0, 0, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.7);

    cursor: pointer;
}

/* 仮の位置 */
#oldtownPoint1 {
    left: 10%;
    top: 20%;
    width: 15%;
    height: 20%;
}

#oldtownPoint2 {
    left: 35%;
    top: 25%;
    width: 20%;
    height: 20%;
}

#oldtownPoint3 {
    left: 60%;
    top: 30%;
    width: 15%;
    height: 25%;
}

#oldtownPoint4 {
    left: 78%;
    top: 55%;
    width: 12%;
    height: 20%;
}

#riverPoint1 {
    left:10%;
    top:20%;
    width:15%;
    height:20%;
}

#riverPoint2 {
    left:35%;
    top:25%;
    width:20%;
    height:20%;
}

#riverPoint3 {
    left:60%;
    top:30%;
    width:15%;
    height:25%;
}

#riverPoint4 {
    left:80%;
    top:55%;
    width:10%;
    height:20%;
}

#schoolPoint1 {
    left:10%;
    top:20%;
    width:15%;
    height:20%;
}

#schoolPoint2 {
    left:35%;
    top:25%;
    width:20%;
    height:20%;
}

#schoolPoint3 {
    left:60%;
    top:30%;
    width:15%;
    height:25%;
}

#schoolPoint4 {
    left:80%;
    top:55%;
    width:10%;
    height:20%;
}

#shoppingPoint1 {
    left:10%;
    top:20%;
    width:15%;
    height:20%;
}

#shoppingPoint2 {
    left:35%;
    top:25%;
    width:20%;
    height:20%;
}

#shoppingPoint3 {
    left:60%;
    top:30%;
    width:15%;
    height:25%;
}

#shoppingPoint4 {
    left:80%;
    top:55%;
    width:10%;
    height:20%;
}

#factoryPoint1 {
    left:10%;
    top:20%;
    width:15%;
    height:20%;
}

#factoryPoint2 {
    left:35%;
    top:25%;
    width:20%;
    height:20%;
}

#factoryPoint3 {
    left:60%;
    top:30%;
    width:15%;
    height:25%;
}

#factoryPoint4 {
    left:80%;
    top:55%;
    width:10%;
    height:20%;
}





/* 探索メッセージ */
#searchMessage {
    position: fixed;
    left: 50%;
    bottom: 30px;
    transform: translateX(-50%);

    width: 70%;
    padding: 15px;

    background: rgba(0, 0, 0, 0.8);
    color: #fff;

    border-radius: 10px;
    text-align: center;
    font-size: 18px;

    z-index: 3100;
    display: none;
}

#searchMessage.show {
    display: block;
}

/* =================================
   行き先選択マップ
================================= */

#travelMapScreen {

    position: fixed;

    top:0;
    left:0;

    width:100%;
    height:100%;

    background:rgba(0,0,0,0.6);

    display:flex;

    justify-content:center;

    align-items:center;

    z-index:2500;
}


#travelMapScreen.hidden {

    display:none;

}



.travelMapWindow {

    background:white;

    padding:30px;

    width:500px;

    border-radius:12px;

    text-align:center;

}


.travelMapArea {

    position:relative;

}


#travelMapImage {

    width:100%;

    border-radius:8px;

}


/* 場所ボタン */

.travelPoint {

    position:absolute;

    left:30%;

    top:40%;


    padding:10px 20px;

    border:none;

    border-radius:20px;

    background:#4a90e2;

    color:white;

    cursor:pointer;

}


/* 古い街角 */
#travelOldTown {

    left:25%;
    top:35%;

}


/* 河川敷 */
#travelRiver {

    left:60%;
    top:55%;

}

/* 校門 */
#travelSchool {

    left:65%;
    top: 30%;

}

/* 商店街 */
#travelshopping {

    left:10%;
    top: 65%;

}

/* 廃工場 */
#travelfactory {

    left:40%;
    top: 25%;

}

.riverPoint,
.oldtownPoint,
.schoolPoint,
.shoppingPoint,
.factoryPoint {
    display:none;
}

/* =================================
   最後の写真撮影場所選択マップ
================================= */

#finalPhotoMapScreen {

    position: fixed;

    top:0;
    left:0;

    width:100%;
    height:100%;

    background:rgba(0,0,0,0.6);

    display:flex;

    justify-content:center;

    align-items:center;

    z-index:2500;

}


#finalPhotoMapScreen.hidden {

    display:none;

}


#finalPhotoMapImage {

    width:100%;

    border-radius:8px;

}

/* =================================
   最後の写真場所選択
================================= */


#finalObservatory {

    left:25%;
    top:25%;

}


#finalCherry {

    left:55%;
    top:35%;

}


#finalPark {

    left:30%;
    top:65%;

}


#finalBeach {

    left:70%;
    top:60%;

}

/* =================================
   最後の写真 撮影画面
================================= */

#cameraScreen {
    position: fixed;
    inset: 0;
    background: #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    z-index: 2600;
}

#cameraScreen.hidden {
    display: none;
}

/* ファインダー */
#cameraView {
    position: relative;
    width: min(88vw, calc(68vh * 1.5));
    aspect-ratio: 3 / 2;
    overflow: hidden;
    border-radius: 4px;
}

#cameraImage {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transform: scale(1.04);
}

/* 周辺を少し暗くしてファインダーらしく */
#cameraView::after {
    content: "";
    position: absolute;
    inset: 0;
    box-shadow: inset 0 0 120px rgba(0, 0, 0, 0.55);
    pointer-events: none;
}

.finderCorner {
    position: absolute;
    width: 28px;
    height: 28px;
    border: 0 solid rgba(255, 255, 255, 0.85);
    z-index: 1;
}

.finderCorner.topLeft     { top: 16px;    left: 16px;  border-top-width: 2px;    border-left-width: 2px; }
.finderCorner.topRight    { top: 16px;    right: 16px; border-top-width: 2px;    border-right-width: 2px; }
.finderCorner.bottomLeft  { bottom: 16px; left: 16px;  border-bottom-width: 2px; border-left-width: 2px; }
.finderCorner.bottomRight { bottom: 16px; right: 16px; border-bottom-width: 2px; border-right-width: 2px; }

#cameraFocus {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 44px;
    height: 44px;
    margin: -22px 0 0 -22px;
    border: 1px solid rgba(255, 255, 255, 0.7);
    z-index: 1;
}

#cameraLocation {
    position: absolute;
    left: 56px;
    top: 20px;
    color: rgba(255, 255, 255, 0.9);
    font-size: 14px;
    letter-spacing: 0.08em;
    z-index: 1;
}

#cameraHint {
    margin: 0;
    color: rgba(255, 255, 255, 0.75);
    font-size: 15px;
}

/* シャッターボタン */
#shutterButton {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: 4px solid #fff;
    background: radial-gradient(circle, #f2f2f2 0 58%, transparent 60%);
    cursor: pointer;
    transition: transform 0.08s;
}

#shutterButton:active {
    transform: scale(0.92);
}

#shutterButton:focus-visible,
#cameraContinue:focus-visible {
    outline: 2px solid #8fc1ff;
    outline-offset: 4px;
}

#shutterButton:disabled {
    opacity: 0.4;
    cursor: default;
}

/* シャッターの光 */
#cameraFlash {
    position: fixed;
    inset: 0;
    background: #fff;
    opacity: 0;
    pointer-events: none;
    z-index: 2;
}

#cameraFlash.flash {
    animation: cameraFlash 0.6s ease-out;
}

@keyframes cameraFlash {
    0%   { opacity: 0.95; }
    100% { opacity: 0; }
}

/* 撮れた写真 */
#cameraResult {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    z-index: 3;
}

#cameraResult.hidden {
    display: none;
}

.printPhoto {
    background: #fbfaf7;
    padding: 14px 14px 10px;
    width: min(70vw, 460px);
    transform: rotate(-2deg);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
}

#cameraResultImage {
    width: 100%;
    aspect-ratio: 3 / 2;
    object-fit: cover;
    display: block;
    animation: developPhoto 2.4s ease-out;
}

/* 写真がじわっと浮かび上がる */
@keyframes developPhoto {
    0%   { filter: brightness(2.2) saturate(0) blur(2px); }
    100% { filter: brightness(1) saturate(1) blur(0); }
}

#cameraResultMessage {
    margin: 10px 0 0;
    color: #333;
    font-size: 15px;
    text-align: center;
}

.cameraResultNote {
    margin: 0;
    color: #fff;
    font-size: 16px;
}

#cameraContinue {
    padding: 10px 36px;
    border: 1px solid #fff;
    border-radius: 20px;
    background: transparent;
    color: #fff;
    font-size: 16px;
    cursor: pointer;
}

/* セルフタイマーの数字 */
#cameraCountdown {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: clamp(64px, 14vw, 140px);
    font-weight: 300;
    text-shadow: 0 2px 16px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    z-index: 1;
}

#cameraCountdown.tick {
    animation: countdownTick 0.9s ease-out;
}

@keyframes countdownTick {
    0%   { opacity: 0; transform: scale(1.3); }
    20%  { opacity: 1; transform: scale(1); }
    100% { opacity: 0.2; transform: scale(0.95); }
}

@media (prefers-reduced-motion: reduce) {
    #cameraCountdown.tick,
    #cameraFlash.flash,
    #cameraResultImage {
        animation: none;
    }
}


/* =================================
   エンディング
================================= */

#endingScreen {
    position: fixed;
    inset: 0;
    background: #000;
    overflow: hidden;
    z-index: 2800;
}

#endingScreen.hidden {
    display: none;
}

/* 奥の層 */
.endingLayer {
    position: absolute;
    inset: -4%;
    opacity: 0;
    transition: opacity 1.4s ease;
}

.endingLayer.visible {
    opacity: 1;
}

.endingBg {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    /* 写真を読みやすくするため、少し暗く・ぼかす */
    filter: brightness(0.55) blur(2px);
}

/* 二人のレイヤー（ending_○○_chara.png） */
.endingChara {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
    filter: brightness(0.75);
}

/* ゆっくり動く（背景と二人で速さを変えて奥行きを出す） */
.endingLayer.drift .endingBg        { animation: endingDriftBg 9s linear forwards; }
.endingLayer.drift .endingChara     { animation: endingDriftChara 9s linear forwards; }
.endingLayer.driftReverse .endingBg    { animation: endingDriftBg 9s linear reverse forwards; }
.endingLayer.driftReverse .endingChara { animation: endingDriftChara 9s linear reverse forwards; }

@keyframes endingDriftBg {
    from { transform: scale(1.02) translateX(-1.2%); }
    to   { transform: scale(1.08) translateX(1.2%); }
}

@keyframes endingDriftChara {
    from { transform: scale(1.02) translateX(-2.4%); }
    to   { transform: scale(1.08) translateX(2.4%); }
}

/* 写真カード（.printPhoto の見た目を使う） */
.endingCard {
    position: absolute;
    top: 46%;
    left: 50%;
    width: min(42vw, 440px);
    opacity: 0;
    transform: translate(-50%, -46%) rotate(-3deg) translateY(16px);
    transition: opacity 0.9s ease, transform 0.9s ease;
}

.endingCard img {
    width: 100%;
    aspect-ratio: 3 / 2;
    object-fit: cover;
    display: block;
}

.endingCard p {
    margin: 10px 0 0;
    color: #333;
    font-size: 15px;
    text-align: center;
}

/* 写真がまだないとき */
.endingCard.noImage img {
    visibility: hidden;
    background: #d9d6cf;
}

#endingCard.show {
    opacity: 1;
    transform: translate(-50%, -46%) rotate(-3deg);
}

#endingCard.tiltRight,
#endingCard.tiltRight.show {
    rotate: 5deg;
}

/* 最後の一枚 → ツーショット */
#endingFinal .endingCard {
    width: min(40vw, 420px);
}

/* ツーショットは、並ぶ位置で下からふわっと現れる */
#endingSelfie {
    transform: translate(4%, -46%) rotate(3deg) translateY(24px);
}

#endingFinal.stageLast #endingLast {
    opacity: 1;
    transform: translate(-50%, -46%) rotate(-2deg);
}

#endingFinal.stageBoth #endingLast {
    transform: translate(-104%, -46%) rotate(-4deg);
}

#endingFinal.stageBoth #endingSelfie {
    opacity: 1;
    transform: translate(4%, -46%) rotate(3deg);
}

#endingText {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 10%;
    margin: 0;
    padding: 0 24px;
    color: #fff;
    font-size: clamp(16px, 2.2vw, 22px);
    letter-spacing: 0.06em;
    text-align: center;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
    opacity: 0;
    transition: opacity 1.6s ease;
}

#endingText.show {
    opacity: 1;
}

/* 暗転 */
#endingFade {
    position: absolute;
    inset: 0;
    background: #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 28px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 2.4s ease;
    z-index: 5;
}

#endingFade.show {
    opacity: 1;
    pointer-events: auto;
}

#endingFin,
#endingBack {
    opacity: 0;
    transition: opacity 1.4s ease;
}

#endingFade.finished #endingFin,
#endingFade.finished #endingBack {
    opacity: 1;
}

#endingFin {
    margin: 0;
    color: #fff;
    font-size: 22px;
    letter-spacing: 0.4em;
}

#endingBack {
    padding: 10px 32px;
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: 20px;
    background: transparent;
    color: #fff;
    font-size: 15px;
    cursor: pointer;
}

#endingSkip {
    position: absolute;
    top: 16px;
    right: 16px;
    padding: 6px 14px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 14px;
    background: rgba(0, 0, 0, 0.3);
    color: rgba(255, 255, 255, 0.8);
    font-size: 13px;
    cursor: pointer;
    z-index: 4;
}

#endingSkip.hidden {
    display: none;
}

#endingSkip:focus-visible,
#endingBack:focus-visible {
    outline: 2px solid #8fc1ff;
    outline-offset: 3px;
}

@media (prefers-reduced-motion: reduce) {
    .endingLayer .endingBg,
    .endingLayer .endingChara {
        animation: none !important;
    }
}


/* =================================
   タイトル画面
================================= */

#titleScreen {
    position: fixed;
    inset: 0;
    background: #000;          /* 黒い幕は最初から不透明（後ろのゲーム画面を見せない） */
    overflow: hidden;
    z-index: 2900;
}

/* 中身だけをフェードイン */
#titleScreen #titleBg,
#titleScreen #titleContent {
    opacity: 0;
}

#titleScreen.ready #titleBg,
#titleScreen.ready #titleContent {
    opacity: 1;
    transition: opacity 1.2s ease;
}

#titleScreen.hidden {
    display: none;
}

@keyframes titleFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

#titleBg {
    position: absolute;
    inset: -3%;
    background-size: cover;
    background-position: center;
    animation: titleDrift 24s ease-in-out infinite alternate;
}

/* 文字を読みやすくするため、左下を暗くする */
#titleBg::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(100deg, rgba(0, 0, 0, 0.75) 0%, rgba(0, 0, 0, 0.35) 50%, rgba(0, 0, 0, 0.1) 100%);
}

@keyframes titleDrift {
    from { transform: scale(1.0); }
    to   { transform: scale(1.06) translateX(-1%); }
}

#titleContent {
    position: absolute;
    left: 8%;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 48px;
}

#titleLogo {
    display: none;
    max-width: min(60vw, 560px);
}

#titleText {
    margin: 0;
    color: #fff;
    font-size: clamp(40px, 7vw, 76px);
    font-weight: 300;
    letter-spacing: 0.18em;
    text-shadow: 0 2px 18px rgba(0, 0, 0, 0.45);
}

#titleMenu {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.titleBtn {
    min-width: 200px;
    padding: 10px 0 10px 4px;
    border: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.35);
    background: transparent;
    color: #fff;
    font-size: 18px;
    letter-spacing: 0.12em;
    text-align: left;
    text-shadow: 0 1px 8px rgba(0, 0, 0, 0.6);
    cursor: pointer;
    transition: padding-left 0.2s ease, border-color 0.2s ease;
}

.titleBtn:hover:not(:disabled) {
    padding-left: 14px;
    border-color: #fff;
}

.titleBtn:focus-visible {
    outline: 2px solid #8fc1ff;
    outline-offset: 4px;
}

.titleBtn:disabled {
    color: rgba(255, 255, 255, 0.35);
    border-color: rgba(255, 255, 255, 0.15);
    cursor: default;
}

/* タイトルから開いたセーブ画面は読み込み専用 */
#saveMenu.fromTitle #newSave,
#saveMenu.fromTitle .slotOverwrite {
    display: none;
}

@media (prefers-reduced-motion: reduce) {
    #titleBg { animation: none; }
}


/* =================================
   キャラクター表示
================================= */

#charaLayer {
    position: fixed;
    inset: 0;
    z-index: 5;            /* 背景より前、テキスト欄より後ろ */
    pointer-events: none;
    overflow: hidden;
}

.charaSlot {
    position: absolute;
    bottom: 0;
    height: 88vh;
    width: min(46vw, 64vh);
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity 0.45s ease, left 0.5s ease, filter 0.3s ease;
}

#charaLeft  { left: 28%; }
#charaRight { left: 72%; }

/* 1人だけのときは中央 */
#charaLayer.single .charaSlot {
    left: 50%;
}

.charaSlot.show {
    opacity: 1;
}

/* 話していない方を少し暗く */
.charaSlot.dim {
    filter: brightness(0.62);
}

.charaImg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: bottom center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.charaImg.active {
    opacity: 1;
}

/* ロード直後などはアニメーションなし */
#charaLayer.instant,
#charaLayer.instant * {
    transition: none !important;
}

/* 名前欄 */
#nameBox {
    position: absolute;
    top: -20px;
    left: 24px;
    padding: 4px 20px;
    background: rgba(28, 32, 38, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 6px;
    font-size: 17px;
    line-height: 1.5;
    letter-spacing: 0.08em;
}

#nameBox:empty {
    display: none;
}

@media (prefers-reduced-motion: reduce) {
    .charaSlot,
    .charaImg {
        transition: none;
    }
}


/* =================================
   本文・文字送り
================================= */

/* 管理画面で入れた改行をそのまま表示 */
#textBody {
    white-space: pre-wrap;
    word-break: break-word;
}

/* クリック待ちの ▼ */
#textNext {
    position: absolute;
    right: 18px;
    bottom: 10px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
    opacity: 0;
    pointer-events: none;
}

#textNext.show {
    opacity: 1;
    animation: textNextBlink 1.1s ease-in-out infinite;
}

@keyframes textNextBlink {
    0%, 100% { transform: translateY(0);   opacity: 1; }
    50%      { transform: translateY(3px); opacity: 0.4; }
}

/* スマホでダブルタップ拡大が起きないように */
body {
    touch-action: manipulation;
}

@media (prefers-reduced-motion: reduce) {
    #textNext.show { animation: none; }
}


/* =================================
   設定画面
================================= */

#settingsScreen {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2950;   /* メニュー・タイトルより手前 */
}

#settingsScreen.hidden {
    display: none;
}

.settingsWindow {
    width: min(86vw, 420px);
    text-align: left;
    box-sizing: border-box;
}

.settingsWindow h2 {
    text-align: center;
}

.settingItem label {
    display: block;
    font-size: 16px;
    margin-bottom: 8px;
}

#textSpeedRange {
    width: 100%;
    accent-color: #4a90e2;
}

.rangeEnds {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: #777;
    margin-top: 2px;
}

#textSpeedSample {
    margin: 14px 0 20px;
    padding: 12px 14px;
    min-height: 3.2em;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.78);
    color: #fff;
    font-size: 15px;
    line-height: 1.6;
    white-space: pre-wrap;
}

.settingsWindow .menuClose {
    display: block;
    margin: 0 auto;
}


/* =================================
   起動画面（最初の1クリック）
================================= */

#startScreen {
    position: fixed;
    inset: 0;
    background: #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    z-index: 3200;
    cursor: pointer;
}

#startScreen.hidden {
    display: none;
}

#startHint {
    margin: 0;
    color: #fff;
    font-size: 17px;
    letter-spacing: 0.12em;
    animation: startBlink 2s ease-in-out infinite;
}

#startNote {
    margin: 0;
    color: rgba(255, 255, 255, 0.5);
    font-size: 13px;
}

@keyframes startBlink {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.35; }
}

@media (prefers-reduced-motion: reduce) {
    #startHint { animation: none; }
}

.settingItem + .settingItem {
    margin-top: 14px;
}
