/* ============================== */
/* リセット & 基本設定 */
/* ============================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body { 
    width: 100%; 
    height: 100%; 
    overflow: hidden; 
    font-family: 'Hiragino Kaku Gothic ProN', 'Yu Gothic', sans-serif; 
    user-select: none; 
    touch-action: manipulation;
    background: #000;
    position: fixed;
}

/* ============================== */
/* エフェクト用キャンバス */
/* ============================== */
#starfield {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
    filter: brightness(1.8) contrast(1.4) saturate(1.2);
    opacity: 0.95;
}

#starfield::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(
        circle at 50% 50%, 
        rgba(255, 215, 0, 0.1) 0%, 
        transparent 60%
    );
    pointer-events: none;
}

/* ============================== */
/* メインコンテナ */
/* ============================== */
.app-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    z-index: 3;
    cursor: pointer;
}

/* ============================== */
/* 背景画像（最下層） */
/* ============================== */
.background-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
}

.background-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    opacity: 0.7;
}

/* ============================== */
/* 上部ナビゲーション（中央配置） */
/* ============================== */
.top-nav {
    position: absolute;
    top: 15px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    z-index: 20;
    padding-top: max(0px, env(safe-area-inset-top));
}

.nav-btn { 
    position: relative;
    display: flex; 
    align-items: center; 
    gap: 8px; 
    padding: 16px 24px;
    background: rgba(0, 0, 0, 0.8); 
    border: 2px solid #FFD700; 
    border-radius: 30px; 
    color: #fff; 
    font-size: 14px; 
    font-weight: 600; 
    cursor: pointer; 
    transition: all 0.3s ease; 
    backdrop-filter: blur(15px); 
    min-height: 52px;
    min-width: 100px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    pointer-events: auto;
    z-index: 21;
}

.nav-btn::before {
    content: '';
    position: absolute;
    top: -10px;
    left: -10px;
    right: -10px;
    bottom: -10px;
    z-index: -1;
}

.nav-btn:hover, .nav-btn:active { 
    background: rgba(255, 215, 0, 0.2); 
    border-color: #FFA500; 
    transform: scale(1.05); 
}

.nav-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.nav-icon {
    font-size: 16px;
    font-weight: bold;
}

.nav-text {
    font-size: 14px;
}

/* ============================== */
/* 音声ダイアログ */
/* ============================== */
.audio-dialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.audio-dialog.show {
    opacity: 1;
    visibility: visible;
}

.dialog-overlay { 
    position: absolute; 
    top: 0; 
    left: 0; 
    right: 0; 
    bottom: 0; 
    background: rgba(0, 0, 0, 0.8); 
    backdrop-filter: blur(5px); 
}

.dialog-content {
    position: relative;
    background: linear-gradient(135deg, #1a1a1a, #2a2a2a);
    border: 2px solid #FFD700;
    border-radius: 20px;
    padding: 30px 25px;
    margin: 20px;
    text-align: center;
    max-width: 320px;
    color: #fff;
    z-index: 1001;
}

.audio-icon {
    font-size: 40px;
    margin-bottom: 15px;
    animation: pulse 2s infinite;
}

.dialog-content h3 {
    font-size: 18px;
    color: #FFD700;
    margin-bottom: 10px;
}

.dialog-content p {
    font-size: 14px;
    color: #ccc;
    margin-bottom: 25px;
    line-height: 1.5;
}

.dialog-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.dialog-btn {
    padding: 12px 20px;
    border: none;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 44px;
    pointer-events: auto;
    z-index: 1002;
}

.dialog-btn.primary {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    color: #000;
}

.dialog-btn.secondary { 
    background: rgba(255, 255, 255, 0.1); 
    color: #fff; 
    border: 1px solid rgba(255, 255, 255, 0.3); 
}

/* ============================== */
/* メインコンテンツ */
/* ============================== */
.content-area {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 70px 20px 140px 20px;
    z-index: 3;
}

/* ============================== */
/* スクリーンショット表示 */
/* ============================== */
.screenshot-container {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 90%;
    max-height: 85%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3;
    transform: translateY(-10px);
}

.screenshot-img {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    border-radius: 16px;
    box-shadow: 
        0 15px 50px rgba(0, 0, 0, 0.7),
        0 0 30px rgba(255, 215, 0, 0.4);
    transition: all 0.5s ease;
    object-fit: contain;
    opacity: 1;
    transform: scale(1);
    border: 3px solid rgba(255, 215, 0, 0.6);
    background: rgba(0, 0, 0, 0.2);
}

.screenshot-img.show {
    opacity: 1;
    transform: scale(1);
}

.screenshot-img.fade-out {
    opacity: 0;
    transform: scale(0.92);
}

.screenshot-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0) 0%,
        rgba(0, 0, 0, 0.1) 70%,
        rgba(0, 0, 0, 0.3) 100%
    );
    border-radius: 16px;
    pointer-events: none;
}

/* ============================== */
/* メッセージエリア */
/* ============================== */
.message-area {
    position: absolute;
    bottom: 85px;
    left: 20px;
    right: 20px;
    display: flex;
    align-items: flex-end;
    gap: 15px;
    z-index: 15;
    pointer-events: auto;
}

/* ============================== */
/* キャラクター */
/* ============================== */
.character-container {
    flex-shrink: 0;
    width: 80px;
    height: 80px;
    position: relative;
    animation: float 3s ease-in-out infinite;
    z-index: 15;
    pointer-events: none;
}

.character-img { 
    width: 100%; 
    height: 100%; 
    object-fit: contain; 
    filter: drop-shadow(0 4px 12px rgba(255, 215, 0, 0.4)); 
    transition: all 0.3s ease; 
    pointer-events: none;
}

/* ============================== */
/* 吹き出し */
/* ============================== */
.speech-bubble { 
    flex: 1; 
    position: relative; 
    background: rgba(255, 255, 255, 0.96); 
    border: 3px solid #FFD700; 
    border-radius: 20px; 
    padding: 20px; 
    box-shadow: 
        0 10px 40px rgba(0, 0, 0, 0.5),
        0 0 20px rgba(255, 215, 0, 0.3); 
    backdrop-filter: blur(15px); 
    transition: all 0.2s ease; 
    min-height: 80px;
    z-index: 15;
    pointer-events: auto;
}

.bubble-arrow { 
    position: absolute; 
    left: -12px; 
    bottom: 30px; 
    width: 0; 
    height: 0; 
    border-top: 12px solid transparent; 
    border-bottom: 12px solid transparent; 
    border-right: 12px solid rgba(255, 255, 255, 0.96);
    pointer-events: none;
}

.bubble-arrow::before {
    content: '';
    position: absolute;
    left: 3px;
    top: -15px;
    width: 0;
    height: 0;
    border-top: 15px solid transparent;
    border-bottom: 15px solid transparent;
    border-right: 15px solid #FFD700;
    pointer-events: none;
}

/* ============================== */
/* 吹き出し内容 */
/* ============================== */
.bubble-content {
    position: relative;
    z-index: 1;
    pointer-events: none;
}

.bubble-text {
    color: #333;
    font-size: 16px;
    line-height: 1.6;
    margin: 0;
    word-wrap: break-word;
    white-space: pre-wrap;
    font-weight: 500;
    pointer-events: none;
}

/* ============================== */
/* リンクスタイル */
/* ============================== */
.bubble-text a,
.bubble-text .story-link {
    color: #FFD700 !important;
    text-decoration: underline !important;
    font-weight: bold !important;
    cursor: pointer !important;
    display: inline-block !important;
    padding: 6px 12px !important;
    margin: 2px 4px !important;
    border-radius: 8px !important;
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.2), rgba(255, 165, 0, 0.15)) !important;
    border: 2px solid rgba(255, 215, 0, 0.5) !important;
    box-shadow: 0 2px 8px rgba(255, 215, 0, 0.3) !important;
    transition: all 0.3s ease !important;
    transform: scale(1) !important;
    pointer-events: auto !important;
    position: relative !important;
    z-index: 1000 !important;
    min-width: 44px !important;
    min-height: 44px !important;
    text-align: center !important;
    -webkit-tap-highlight-color: rgba(255, 215, 0, 0.3) !important;
    -webkit-touch-callout: default !important;
}

.bubble-text a:hover,
.bubble-text .story-link:hover,
.bubble-text a:active,
.bubble-text .story-link:active {
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.4), rgba(255, 165, 0, 0.3)) !important;
    border-color: rgba(255, 215, 0, 0.8) !important;
    box-shadow: 0 4px 16px rgba(255, 215, 0, 0.5) !important;
    transform: scale(1.05) !important;
    text-decoration: none !important;
}

.bubble-text a::before,
.bubble-text .story-link::before {
    content: '' !important;
    position: absolute !important;
    top: -10px !important;
    left: -10px !important;
    right: -10px !important;
    bottom: -10px !important;
    z-index: -1 !important;
}

/* ============================== */
/* タップインジケーター */
/* ============================== */
.tap-indicator {
    position: absolute;
    bottom: 8px;
    right: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #FFD700;
    font-size: 12px;
    pointer-events: none;
}

.tap-text {
    opacity: 0;
    animation: fadeInOut 2s infinite;
    font-weight: 600;
}

.tap-pulse {
    width: 12px;
    height: 12px;
    background: #FFD700;
    border-radius: 50%;
    animation: pulse 1.5s infinite;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.6);
}

/* ============================== */
/* プログレスエリア */
/* ============================== */
.progress-area {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    z-index: 20;
    pointer-events: none;
}

.progress-info { 
    color: #fff; 
    font-size: 14px; 
    font-weight: 600; 
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.8);
    background: rgba(0, 0, 0, 0.7);
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid rgba(255, 215, 0, 0.4);
    backdrop-filter: blur(10px);
}

.progress-bar-bg { 
    width: 200px; 
    height: 6px; 
    background: rgba(255, 255, 255, 0.3); 
    border-radius: 3px; 
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.3);
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #FFD700, #FFA500, #FFD700);
    border-radius: 3px;
    transition: width 0.5s ease;
    width: 20%;
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.6);
    animation: progressGlow 2s ease-in-out infinite;
}

/* ============================== */
/* アニメーション */
/* ============================== */
@keyframes float { 
    0%, 100% { transform: translateY(0px); } 
    50% { transform: translateY(-8px); } 
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.2);
        opacity: 0.7;
    }
}

@keyframes fadeInOut { 
    0%, 100% { opacity: 0; } 
    50% { opacity: 1; } 
}

@keyframes progressGlow {
    0%, 100% { box-shadow: 0 0 10px rgba(255, 215, 0, 0.6); }
    50% { box-shadow: 0 0 20px rgba(255, 215, 0, 0.9); }
}

/* ============================== */
/* レスポンシブ */
/* ============================== */
@media (max-width: 375px) {
    .character-container {
        width: 70px;
        height: 70px;
    }
    
    .speech-bubble {
        padding: 16px;
    }
    
    .bubble-text {
        font-size: 15px;
    }
    
    .bubble-text a,
    .bubble-text .story-link {
        padding: 8px 10px !important;
        margin: 2px 2px !important;
        font-size: 14px !important;
        min-width: 40px !important;
        min-height: 40px !important;
    }
    
    .content-area {
        padding: 65px 15px 135px 15px;
    }
    
    .nav-btn {
        min-width: 80px;
        padding: 14px 20px;
    }
    
    .screenshot-container {
        max-height: 80%;
        transform: translateY(-15px);
    }
}

@media (max-height: 667px) {
    .message-area {
        bottom: 70px;
    }
    
    .content-area {
        padding: 65px 20px 130px 20px;
    }
    
    .screenshot-container {
        max-height: 75%;
        transform: translateY(-20px);
    }
}

@media (orientation: landscape) and (max-height: 500px) {
    .content-area {
        padding: 55px 20px 110px 20px;
    }
    
    .message-area {
        bottom: 60px;
    }
    
    .character-container {
        width: 60px;
        height: 60px;
    }
    
    .speech-bubble {
        padding: 15px;
    }
    
    .bubble-text {
        font-size: 14px;
        line-height: 1.4;
    }
    
    .bubble-text a,
    .bubble-text .story-link {
        padding: 6px 8px !important;
        font-size: 13px !important;
    }
    
    .top-nav {
        top: 10px;
    }
    
    .screenshot-container {
        max-height: 70%;
        transform: translateY(-25px);
    }
}

/* ============================== */
/* iOS対応 */
/* ============================== */
@supports (-webkit-appearance: none) {
    .app-container {
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    
    .nav-btn,
    .dialog-btn {
        -webkit-appearance: none;
        -webkit-tap-highlight-color: transparent;
    }
    
    .bubble-text a,
    .bubble-text .story-link {
        -webkit-appearance: none !important;
        -webkit-user-select: none !important;
    }
}

/* ============================== */
/* 安全領域対応 */
/* ============================== */
@supports (padding: max(0px)) {
    .top-nav {
        padding-top: max(15px, env(safe-area-inset-top));
    }
    
    .progress-area {
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }
}
