/* --- デザインシステム & CSS変数 --- */
:root {
    --bg-dark: #0a0616;
    --primary-indigo: #160e33;
    --text-color: #f5f4f8;
    --text-muted: #b7b2ca;
    
    /* グラスモルフィズム用カラー */
    --glass-bg: rgba(22, 14, 46, 0.65);
    --glass-bg-accent: rgba(255, 209, 102, 0.1);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-border-hover: rgba(255, 255, 255, 0.2);
    
    /* アクセントカラー */
    --accent-amber: #ffd166;
    --accent-amber-hover: #ffc03d;
    --accent-violet: #8e7dff;
    --danger-red: #ef476f;
    
    /* シャドウとブラー */
    --shadow-premium: 0 12px 40px 0 rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 15px rgba(255, 209, 102, 0.35);
    --blur-strength: 12px;
}

/* 全体のリセット */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none; /* テキスト選択を無効化（ゲーム操作性向上） */
}

body {
    background-color: var(--bg-dark);
    color: var(--text-color);
    font-family: 'Inter', 'Noto Serif JP', serif;
    overflow: hidden;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* --- メインゲームコンテナ --- */
#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 1920px;
    max-height: 1080px;
    background-color: #000;
    overflow: hidden;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.8);
    aspect-ratio: 16/9;
}

@media (max-aspect-ratio: 16/9) {
    #game-container {
        width: 100%;
        height: auto;
    }
}

@media (min-aspect-ratio: 16/9) {
    #game-container {
        height: 100%;
        width: auto;
    }
}

/* 画面レイアウトのベースクラス */
.screen, .screen-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* 汎用的な非表示クラス */
.hidden {
    display: none !important;
    opacity: 0;
    pointer-events: none;
}

/* --- タイトル画面 --- */
#title-screen {
    background: #090518;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    transition: opacity 0.8s ease-in-out;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

#title-screen.fade-out {
    opacity: 0;
    pointer-events: none;
}

#title-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

.title-content {
    position: relative;
    z-index: 10;
    text-align: center;
    animation: fadeInDown 1.5s cubic-bezier(0.19, 1, 0.22, 1) both;
    padding: 3rem;
    border-radius: 24px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(var(--blur-strength));
    box-shadow: var(--shadow-premium);
    max-width: 600px;
    width: 90%;
}

.main-title {
    font-family: 'Noto Serif JP', serif;
    font-size: 3.5rem;
    font-weight: 900;
    letter-spacing: 0.2em;
    margin-bottom: 0.5rem;
    background: linear-gradient(to right, #ffffff, var(--accent-amber), #ffffff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.1);
}

.subtitle {
    font-size: 1.1rem;
    letter-spacing: 0.4em;
    text-transform: uppercase;
    color: var(--accent-violet);
    margin-bottom: 1.5rem;
    font-weight: 300;
}

.description {
    font-size: 0.95rem;
    line-height: 1.8;
    color: var(--text-muted);
    margin-bottom: 2.5rem;
    font-weight: 300;
}

.title-menu {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: 100%;
}

/* ボタンの基本スタイル */
.menu-btn {
    padding: 0.9rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    letter-spacing: 0.1em;
    font-family: 'Noto Serif JP', serif;
}

.primary-btn {
    background: linear-gradient(135deg, var(--accent-amber), #ffb703);
    color: var(--bg-dark);
    border: none;
    box-shadow: 0 4px 15px rgba(255, 209, 102, 0.4);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 209, 102, 0.6);
    background: linear-gradient(135deg, #ffdb85, var(--accent-amber));
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-color);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(5px);
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--glass-border-hover);
    transform: translateY(-2px);
}

.title-footer {
    position: absolute;
    bottom: 2rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    letter-spacing: 0.1em;
}

/* --- ゲームステージ --- */
#game-stage {
    width: 100%;
    height: 100%;
    position: relative;
}

/* 背景画像レイヤー */
.bg-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

.bg-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    transition: opacity 1s cubic-bezier(0.4, 0, 0.2, 1);
}

.bg-image.fade-out {
    opacity: 0;
}

/* キャラクター立ち絵レイヤー */
.char-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    z-index: 2;
    padding-bottom: 120px; /* メッセージウィンドウの上に配置 */
    pointer-events: none; /* 下の要素のクリックを妨げない */
}

/* プレミアムな立ち絵フレーム（ガラスの額縁のようなデザイン） */
.char-card {
    width: 320px;
    height: 480px;
    border-radius: 20px;
    overflow: hidden;
    border: 1px solid var(--glass-border);
    background: rgba(10, 6, 22, 0.3);
    box-shadow: var(--shadow-premium), 0 0 30px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    opacity: 0;
    transform: translateY(30px) scale(0.95);
    animation: float 6s ease-in-out infinite;
}

.char-card:not(.hidden) {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.char-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
}

/* --- テキストウィンドウ（メッセージボックス） --- */
.text-window {
    position: absolute;
    bottom: 2.5rem;
    left: 5%;
    width: 90%;
    min-height: 180px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    backdrop-filter: blur(var(--blur-strength));
    box-shadow: var(--shadow-premium);
    z-index: 5;
    padding: 1.5rem 2rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.text-window:hover {
    box-shadow: var(--shadow-premium), 0 0 15px rgba(255, 255, 255, 0.05);
}

.text-window-header {
    height: 30px;
    display: flex;
    align-items: center;
    margin-bottom: 0.5rem;
}

.char-name {
    font-family: 'Noto Serif JP', serif;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--accent-amber);
    letter-spacing: 0.1em;
    border-left: 4px solid var(--accent-amber);
    padding-left: 0.8rem;
    text-shadow: 0 0 10px rgba(255, 209, 102, 0.2);
}

.text-window-body {
    flex-grow: 1;
    position: relative;
}

.char-text {
    font-size: 1.05rem;
    line-height: 1.8;
    color: var(--text-color);
    letter-spacing: 0.06em;
    white-space: pre-wrap;
}

/* テキスト送り待ちのインジケーター */
.next-indicator {
    position: absolute;
    bottom: -5px;
    right: 0;
    width: 14px;
    height: 14px;
    background-color: var(--accent-amber);
    clip-path: polygon(0 0, 100% 0, 50% 100%);
    animation: bounce 1.2s infinite;
}

/* メニューボタンバー */
.system-menu {
    display: flex;
    justify-content: flex-end;
    gap: 0.8rem;
    margin-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding-top: 0.8rem;
}

.sys-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.08em;
    padding: 2px 8px;
    border-radius: 4px;
}

.sys-btn:hover {
    color: var(--accent-amber);
    background: rgba(255, 255, 255, 0.05);
}

.sys-btn.active-sys {
    color: var(--accent-amber) !important;
    background: rgba(255, 209, 102, 0.15);
    text-shadow: 0 0 8px rgba(255, 209, 102, 0.5);
}

/* --- 選択肢メニュー --- */
.choices-container {
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80%;
    max-width: 560px;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    z-index: 10;
    animation: fadeInUp 0.5s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.choice-btn {
    padding: 1.1rem 2rem;
    font-size: 1.05rem;
    font-family: 'Noto Serif JP', serif;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-color);
    border-radius: 14px;
    cursor: pointer;
    text-align: center;
    backdrop-filter: blur(var(--blur-strength));
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.choice-btn:hover {
    border-color: var(--accent-amber);
    background: rgba(255, 209, 102, 0.12);
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow), var(--shadow-premium);
    color: var(--accent-amber);
}

/* --- グラスモルフィズム・ドロワー (Log, Save, Settings) --- */
.drawer-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    justify-content: flex-end;
    transition: opacity 0.4s ease;
}

.drawer-content {
    width: 450px;
    height: 100%;
    background: var(--glass-bg);
    border-left: 1px solid var(--glass-border);
    backdrop-filter: blur(20px);
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    animation: slideInRight 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.drawer-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.drawer-header h2 {
    font-family: 'Noto Serif JP', serif;
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--accent-amber);
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.close-btn:hover {
    color: var(--danger-red);
}

.drawer-body {
    flex-grow: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

/* 履歴（Log）表示用のスタイル */
#log-body {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.log-entry {
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    padding-bottom: 1rem;
}

.log-entry-name {
    font-family: 'Noto Serif JP', serif;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--accent-violet);
    margin-bottom: 0.3rem;
}

.log-entry-name.speaker-aoi {
    color: var(--accent-amber);
}

.log-entry-text {
    font-size: 0.98rem;
    line-height: 1.6;
    color: var(--text-color);
}

/* セーブ・ロード用のスタイル */
.save-slots {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.save-slot {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    transition: all 0.2s;
}

.save-slot:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--glass-border-hover);
}

.slot-number {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-violet);
    text-transform: uppercase;
}

.slot-info {
    min-height: 60px;
}

.slot-empty {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.9rem;
}

.slot-date {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}

.slot-preview {
    font-size: 0.9rem;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.slot-actions {
    display: flex;
    gap: 0.8rem;
}

.slot-btn {
    flex-grow: 1;
    padding: 0.5rem;
    font-size: 0.85rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-action-save {
    background: rgba(142, 125, 255, 0.2);
    color: #e0dbff;
    border: 1px solid rgba(142, 125, 255, 0.3);
}

.btn-action-save:hover {
    background: rgba(142, 125, 255, 0.4);
}

.btn-action-load {
    background: rgba(255, 209, 102, 0.2);
    color: #ffeed1;
    border: 1px solid rgba(255, 209, 102, 0.3);
}

.btn-action-load:hover:not(:disabled) {
    background: rgba(255, 209, 102, 0.4);
}

.btn-action-load:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* 設定画面のスタイル */
.settings-body {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.settings-section {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1.2rem;
}

.settings-section h3 {
    font-family: 'Noto Serif JP', serif;
    font-size: 1.05rem;
    margin-bottom: 1rem;
    color: var(--accent-amber);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 0.5rem;
}

.slider-container {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.slider-container input[type="range"] {
    flex-grow: 1;
    accent-color: var(--accent-amber);
    cursor: pointer;
}

.credits-section ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    font-size: 0.9rem;
}

.credits-section li strong {
    color: var(--accent-violet);
}

.danger-btn {
    width: 100%;
    padding: 0.8rem;
    background: rgba(239, 71, 111, 0.15);
    border: 1px solid var(--danger-red);
    color: #ffdce5;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.danger-btn:hover {
    background: var(--danger-red);
    color: #fff;
    box-shadow: 0 0 10px rgba(239, 71, 111, 0.4);
}

/* --- スクロールバーのカスタマイズ --- */
.drawer-body::-webkit-scrollbar {
    width: 6px;
}

.drawer-body::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

.drawer-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.drawer-body::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* --- アニメーションのキーフレーム --- */

@keyframes float {
    0% {
        transform: translateY(0) scale(1);
    }
    50% {
        transform: translateY(-8px) scale(1.01);
    }
    100% {
        transform: translateY(0) scale(1);
    }
}

@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    50% {
        transform: translateY(4px);
        opacity: 1;
    }
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-150%);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translate(-50%, -40%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
    }
    to {
        transform: translateX(0);
    }
}
