/* --- 変数定義 --- */
:root {
    --main-pink: #fff0f5;
    --main-blue: #e0f7fa;
    --accent-pink: #ff9eb5;
    --accent-blue: #4fc3f7;
    --text-color: #5d5d5d;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --border-radius-main: 20px;
}

/* --- 全体設定 --- */
body {
    margin: 0;
    font-family: 'M PLUS Rounded 1c', sans-serif;
    background-color: var(--main-blue);
    color: var(--text-color);
    overflow-x: hidden;
    transition: background-color 2s ease;
}

body.time-day { background-color: #e0f7fa; }
body.time-evening { background-color: #fff3e0; }
body.time-night { background-color: #263238; color: #eceff1; }

/* --- ローディング画面 --- */
#loading-screen {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: #fff; z-index: 9999;
    display: flex; justify-content: center; align-items: center;
    transition: opacity 0.5s;
}
.loader-content { text-align: center; }
.loader-chisa { width: 100px; animation: bounce 0.5s infinite alternate; }
@keyframes bounce { from { transform: translateY(0); } to { transform: translateY(-20px); } }

/* --- ヘッダー --- */
.site-header {
    position: relative; z-index: 100;
    display: flex; justify-content: space-between; align-items: center;
    padding: 15px 40px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    border-radius: 0 0 20px 20px;
    max-width: 1160px; margin: 0 auto;
}
.site-header h1 { margin: 0; font-size: 26px; color: #ff8fa3; letter-spacing: 2px; }
.site-header nav a {
    margin-left: 25px; text-decoration: none; color: #78909c;
    font-weight: 700; transition: color 0.3s, transform 0.2s; display: inline-block;
}
.site-header nav a:hover { color: #ff8fa3; transform: translateY(-2px); }

/* --- リビングルーム (コンテナ) --- */
#living-room-container {
    width: 100%; max-width: 1200px; margin: 30px auto; padding: 0 20px; box-sizing: border-box;
}

/* --- リビングルーム (背景・空間) --- */
.living-room-bg {
    position: relative;
    width: 100%; height: 75vh; min-height: 600px;
    background: #fdf5e6;
    border: 12px solid #fff;
    border-radius: 30px;
    box-shadow: 
        0 20px 50px rgba(0,0,0,0.1),
        inset 0 0 100px rgba(0,0,0,0.05);
    overflow: hidden;
    perspective: 1000px;
}

/* 床 */
.living-room-bg::after {
    content: ''; position: absolute; bottom: 0; left: 0; width: 100%; height: 20%;
    background: #deb887;
    border-top: 5px solid #d2a679;
    z-index: 0;
}

/* 時間帯オーバーレイ */
#room-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; z-index: 50; transition: background-color 2s;
}
body.time-evening #room-overlay { background-color: rgba(255, 140, 0, 0.2); mix-blend-mode: overlay; }
body.time-night #room-overlay { background-color: rgba(10, 10, 40, 0.6); }

/* 木漏れ日 */
#sun-beams {
    position: absolute; top: -50%; left: -20%; width: 200%; height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.4) 0%, rgba(255,255,255,0) 60%);
    transform: rotate(-30deg);
    opacity: 0.6; pointer-events: none; z-index: 51;
    mix-blend-mode: overlay;
    transition: opacity 2s;
}
body.time-night #sun-beams { opacity: 0; }

/* パーティクル */
#particle-layer { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 52; }
.particle {
    position: absolute; background: #fff; border-radius: 50%;
    opacity: 0.8; animation: floatParticle linear infinite;
}
@keyframes floatParticle {
    0% { transform: translateY(0) translateX(0); opacity: 0; }
    20% { opacity: 0.8; }
    80% { opacity: 0.8; }
    100% { transform: translateY(-100px) translateX(50px); opacity: 0; }
}

/* --- キャラクターフィールド（重要修正） --- */
/* z-indexを削除し、内部のキャラクターが家具の手前に来れるようにする */
#character-field {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; 
    /* z-index: 20; を削除 */
}

.character-container {
    position: absolute; pointer-events: auto;
    transform-origin: bottom center;
    transition: left 0.1s linear, top 0.1s linear, transform 0.2s;
    will-change: left, top, transform;
    /* キャラクターのz-indexはJSで制御（100〜200程度になる） */
}
.character-container:hover { transform: scale(1.1); z-index: 1000 !important; }

/* 地面にいるキャラクター用の影 */
.character-container:not(.anim-float)::after {
    content: ''; position: absolute; bottom: 5px; left: 50%; transform: translateX(-50%);
    width: 60%; height: 10px; background: rgba(0, 0, 0, 0.2); border-radius: 50%; filter: blur(2px); z-index: -1;
}

.character-sprite img {
    width: 100%; height: auto; display: block; -webkit-user-drag: none;
}

/* エモーションバブル */
.emote-bubble {
    position: absolute; top: -40px; left: 50%; transform: translateX(-50%) scale(0);
    width: 40px; height: 40px; background: #fff; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 5px 15px rgba(0,0,0,0.15); font-size: 24px;
    z-index: 101; transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.emote-bubble::after { content: ''; position: absolute; bottom: -5px; left: 50%; transform: translateX(-50%) rotate(45deg); width: 10px; height: 10px; background: #fff; }
.character-container.showing-emote .emote-bubble { transform: translateX(-50%) scale(1); }

/* 名前ラベル */
.name-label {
    position: absolute; bottom: -25px; left: 50%; transform: translateX(-50%);
    background: rgba(255,255,255,0.8); padding: 2px 8px; border-radius: 10px;
    font-size: 12px; color: #555; opacity: 0; transition: opacity 0.3s;
    white-space: nowrap; pointer-events: none;
}
.character-container:hover .name-label { opacity: 1; }
.character-container.facing-left .character-sprite { transform: scaleX(-1); }

/* アニメーション */
.anim-float { animation: float 6s ease-in-out infinite; }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-20px); } }
.anim-spin { animation: spin 0.5s linear; }
@keyframes spin { 100% { transform: rotate(1080deg); } }
@keyframes popIn { from { transform: translateX(-50%) scale(0); } to { transform: translateX(-50%) scale(1); } }

/* --- 家具（重要修正：z-indexを低く固定） --- */
.interactive-object {
    position: absolute;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), filter 0.3s;
}
.interactive-object[data-clickable="true"] { cursor: pointer; }
.interactive-object[data-clickable="true"]:hover { transform: scale(1.05); filter: brightness(1.1); }

/* 冷蔵庫：z-indexを10に固定（キャラは100以上なので常にキャラが手前） */
#fridge { bottom: 15%; right: 5%; width: 130px; height: 240px; z-index: 10; perspective: 800px; }
.fridge-body { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; }
.fridge-door {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: #fff; border: 2px solid #ddd; border-radius: 15px;
    box-shadow: 5px 5px 15px rgba(0,0,0,0.1);
    transform-origin: right; transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 2;
}
.fridge-handle { position: absolute; top: 50%; left: 15px; width: 8px; height: 60px; background: #eee; border-radius: 4px; box-shadow: 1px 1px 3px rgba(0,0,0,0.1); }
.fridge-inside {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: #bbdefb; border-radius: 15px;
    display: flex; align-items: center; justify-content: center;
    box-shadow: inset 5px 5px 15px rgba(0,0,0,0.1);
}
.fridge-inside img { width: 90%; transform: scale(0.8); transition: transform 0.3s; }
#fridge.open .fridge-door { transform: rotateY(110deg); }

/* テレビ：z-indexを10に固定 */
#tv { bottom: 15%; left: 30%; width: 200px; height: 160px; z-index: 10; }
.tv-body {
    position: relative; width: 100%; height: 130px;
    background: #333; border-radius: 15px; padding: 10px; box-sizing: border-box;
    box-shadow: 0 10px 20px rgba(0,0,0,0.3);
}
.tv-screen { width: 100%; height: 100%; background: #111; border-radius: 5px; overflow: hidden; position: relative; }
.tv-screen::after { content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, transparent 50%); pointer-events: none; }
.tv-stand { position: absolute; bottom: -20px; left: 50%; transform: translateX(-50%); width: 80px; height: 20px; background: #222; border-radius: 0 0 10px 10px; }
#tv.on .tv-screen { background: #fff; }

/* 窓：z-index 5 */
#window {
    top: 10%; left: 10%; width: 240px; height: 160px;
    background: #87ceeb; border: 15px solid #fff; border-radius: 10px;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.2), 5px 5px 15px rgba(0,0,0,0.1);
    z-index: 5; overflow: hidden;
}
.window-view { width: 100%; height: 100%; background-size: cover; background-position: center; transition: background 2s; }
.window-frame-v { position: absolute; left: 50%; top: 0; width: 12px; height: 100%; background: #fff; transform: translateX(-50%); box-shadow: 2px 0 5px rgba(0,0,0,0.1); }
.window-frame-h { position: absolute; top: 60%; left: 0; width: 100%; height: 12px; background: #fff; transform: translateY(-50%); box-shadow: 0 2px 5px rgba(0,0,0,0.1); }

/* 時計：z-index 5 */
#wall-clock {
    top: 30px; right: 100px; width: 100px; height: 100px;
    background: #fff; border-radius: 50%; box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    border: 8px solid #8d6e63; z-index: 5;
}
.clock-face { position: relative; width: 100%; height: 100%; }
.clock-center { position: absolute; top: 50%; left: 50%; width: 10px; height: 10px; background: #555; border-radius: 50%; transform: translate(-50%, -50%); z-index: 5; }
.clock-hand { position: absolute; bottom: 50%; left: 50%; background: #333; transform-origin: bottom center; border-radius: 5px; }
.hour-hand { width: 6px; height: 25%; }
.minute-hand { width: 4px; height: 35%; }
.second-hand { width: 2px; height: 40%; background: #ff5252; }

/* 本棚：z-index 5 */
#bookshelf {
    bottom: 25%; left: 5%; width: 160px; height: 240px;
    background: #8d6e63; border-radius: 10px 10px 0 0;
    box-shadow: 5px 5px 15px rgba(0,0,0,0.2);
    z-index: 5;
    background-image: linear-gradient(#795548 10px, transparent 10px); background-size: 100% 60px;
}
#bookshelf::before { content: 'BOOKS'; position: absolute; top: -30px; left: 50%; transform: translateX(-50%); font-weight: bold; color: #8d6e63; }

/* 植木鉢：z-index 5 */
#plant { bottom: 25%; right: 280px; width: 80px; height: 120px; z-index: 5; }
.plant-pot { position: absolute; bottom: 0; width: 100%; height: 50px; background: #d87146; border-radius: 5px 5px 15px 15px; box-shadow: 2px 2px 5px rgba(0,0,0,0.2); }
.plant-growth { position: absolute; bottom: 40px; left: 50%; width: 8px; height: 0; background: #4caf50; border-radius: 5px; transform: translateX(-50%); transition: height 0.5s ease-out; }
.plant-growth::before, .plant-growth::after { content: ''; position: absolute; width: 15px; height: 15px; background: #4caf50; opacity: 0; transition: opacity 0.3s; }
.plant-growth::before { top: 0; left: -15px; border-radius: 0 100% 0 100%; transform: rotate(-45deg); }
.plant-growth::after { top: 5px; right: -15px; border-radius: 100% 0 100% 0; transform: rotate(-45deg); }
#plant[data-growth="1"] .plant-growth { height: 30px; }
#plant[data-growth="2"] .plant-growth { height: 60px; }
#plant[data-growth="2"] .plant-growth::before, #plant[data-growth="2"] .plant-growth::after { opacity: 1; }
#plant[data-growth="3"] .plant-growth { height: 80px; }
#plant[data-growth="3"] .plant-growth::before, #plant[data-growth="3"] .plant-growth::after { opacity: 1; top: 20px; }
#plant[data-growth="3"] .plant-pot::after { content: '🌺'; position: absolute; top: -90px; left: 50%; transform: translateX(-50%) scale(0); font-size: 40px; animation: popIn 0.5s forwards; }

/* --- コンテンツエリア --- */
.content-wrapper { padding: 40px 20px; }
.content-section { background: #fff; padding: 40px; border-radius: 30px; box-shadow: 0 10px 30px rgba(0,0,0,0.05); margin-bottom: 40px; border: 2px solid #f0f0f0; }
.content-section h2 { color: #333; font-size: 24px; margin-top: 0; border-bottom: 2px solid var(--accent-pink); display: inline-block; padding-bottom: 10px; margin-bottom: 20px; }
.content-section .icon { font-size: 28px; margin-right: 10px; }

/* --- リビングの手前テーブル --- */
#low-table {
    position: absolute; bottom: 10%; left: 50%; transform: translateX(-50%);
    width: 300px; height: 100px; z-index: 30; /* キャラより手前 */
}
.table-top {
    position: absolute; top: 0; left: 0; width: 100%; height: 20px;
    background: #8b4513; border-radius: 10px;
    box-shadow: 0 5px 10px rgba(0,0,0,0.2);
}
.table-leg {
    position: absolute; top: 20px; width: 10px; height: 60px; background: #5d4037;
}
.table-leg.left { left: 20px; transform: rotate(10deg); }
.table-leg.right { right: 20px; transform: rotate(-10deg); }

/* --- 日記帳 --- */
#diary-book {
    position: absolute; top: -15px; left: 50%; transform: translateX(-50%) rotate(-5deg);
    width: 60px; height: 80px; cursor: pointer; transition: transform 0.2s;
}
#diary-book:hover { transform: translateX(-50%) rotate(0deg) scale(1.1); }
.diary-cover {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: #ff69b4; border-radius: 2px 5px 5px 2px;
    color: white; font-size: 10px; text-align: center; padding-top: 10px;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.2); z-index: 2;
}
.diary-pages {
    position: absolute; top: 2px; left: 2px; width: 95%; height: 95%;
    background: #fff; border-radius: 2px 5px 5px 2px; z-index: 1;
}