/* ===========================================
   Tomo Game - Refined Mobile App UI
   =========================================== */

:root {
    /* Colors */
    --bg-primary: #0a1628;
    --bg-secondary: #0f2847;
    --surface: rgba(255, 255, 255, 0.06);
    --surface-border: rgba(255, 255, 255, 0.1);
    --accent-cyan: #00d4ff;
    --accent-pink: #ff6b9d;
    --accent-orange: #ff8c42;
    --accent-gold: #ffd700;
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.5);
    --danger-red: #ff3366;

    /* Game Sizes */
    --game-width: 440px;
    --game-height: 700px;
    --header-height: 48px;
    --next-height: 44px;
    --evo-height: 36px;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: radial-gradient(ellipse at top, #1a3a5c 0%, #0f2847 30%, #0a1628 60%, #050d18 100%);
    height: 100vh;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0;
    margin: 0;
    overflow: hidden;
    touch-action: none;
    user-select: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    -webkit-font-smoothing: antialiased;
}

/* Stars background */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image:
        radial-gradient(2px 2px at 20px 30px, rgba(255, 255, 255, 0.8), transparent),
        radial-gradient(2px 2px at 40px 70px, rgba(255, 255, 255, 0.5), transparent),
        radial-gradient(1px 1px at 90px 40px, rgba(255, 255, 255, 0.6), transparent),
        radial-gradient(2px 2px at 130px 80px, rgba(255, 255, 255, 0.4), transparent),
        radial-gradient(1px 1px at 160px 120px, rgba(255, 255, 255, 0.7), transparent),
        radial-gradient(2px 2px at 200px 50px, rgba(255, 255, 255, 0.5), transparent),
        radial-gradient(1px 1px at 250px 100px, rgba(255, 255, 255, 0.6), transparent),
        radial-gradient(2px 2px at 300px 30px, rgba(255, 255, 255, 0.4), transparent),
        radial-gradient(1px 1px at 350px 80px, rgba(255, 255, 255, 0.8), transparent),
        radial-gradient(2px 2px at 400px 120px, rgba(255, 255, 255, 0.5), transparent);
    background-size: 450px 150px;
    animation: twinkle 4s ease-in-out infinite alternate;
    pointer-events: none;
    z-index: 0;
}

@keyframes twinkle {

    0%,
    100% {
        opacity: 0.8;
    }

    50% {
        opacity: 0.4;
    }
}

/* ===========================================
   Title Screen
   =========================================== */
#title-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 200;
    animation: fadeIn 0.8s ease;
    background: radial-gradient(ellipse at center, rgba(0, 100, 150, 0.2) 0%, transparent 60%);
    padding: env(safe-area-inset-top, 20px) env(safe-area-inset-right, 16px) env(safe-area-inset-bottom, 20px) env(safe-area-inset-left, 16px);
    overflow-y: auto;
}

#title-screen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url('./assets/title.png');
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.3;
    /* 薄く表示 */
    z-index: -1;
    pointer-events: none;
}

#title-screen.hidden {
    display: none;
}

.title-content {
    text-align: center;
    width: 100%;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 40px;
    padding: 24px 16px;
}

.title-logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.title-main {
    display: flex;
    align-items: baseline;
    gap: 12px;
    line-height: 1;
    white-space: nowrap;
}

.title-tomo {
    font-family: 'Zen Maru Gothic', sans-serif;
    font-size: 4.5rem;
    font-weight: 900;
    color: #ff8c42;
    letter-spacing: -3px;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6), 0 0 30px rgba(255, 140, 66, 0.4);
}

.title-game {
    font-family: 'Inter', sans-serif;
    font-size: 1.8rem;
    font-weight: 800;
    color: #00d4ff;
    letter-spacing: 6px;
    text-transform: uppercase;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5), 0 0 20px rgba(0, 212, 255, 0.3);
}

.title-tagline {
    font-family: 'Inter', sans-serif;
    font-size: 0.7rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.6);
    letter-spacing: 6px;
    text-transform: uppercase;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

/* Music Box */
.music-box {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.music-box-header {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--accent-pink);
    letter-spacing: 5px;
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.music-box-header::before {
    content: '🎵';
    font-size: 1rem;
}

.music-box-selector {
    display: flex;
    align-items: center;
    gap: 12px;
}

.music-nav-btn {
    width: 44px;
    height: 44px;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 50%;
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.music-nav-btn:active {
    transform: scale(0.9);
    background: rgba(255, 255, 255, 0.12);
}

.music-info {
    flex: 1;
    text-align: center;
    min-width: 0;
}

.music-name {
    font-size: 0.9rem;
    font-weight: 800;
    color: var(--text-primary);
    white-space: normal;
    word-break: break-word;
    line-height: 1.3;
}

.music-counter {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Start Button */
#start-btn {
    width: 100%;
    padding: 18px 32px;
    font-size: 1rem;
    font-family: 'Inter', sans-serif;
    font-weight: 800;
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.2s ease;
    letter-spacing: 8px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

#start-btn:active {
    transform: scale(0.97);
    background: rgba(255, 255, 255, 0.15);
}

/* ===========================================
   Game Container
   =========================================== */
#game-container {
    width: 100%;
    max-width: var(--game-width);
    height: var(--game-height);
    max-height: var(--game-height);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    position: relative;
    z-index: 1;
    padding: 0;
    overflow: hidden;
}

#game-container.hidden {
    display: none;
}

/* ===========================================
   Header
   =========================================== */
#game-header {
    width: 100%;
    height: var(--header-height);
    flex-shrink: 0;
    background: rgba(10, 20, 40, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--surface-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 12px;
}

.header-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    /* 余白を埋める */
    min-width: 0;
    /* 縮小許可 */
    margin-right: 4px;
    /* 右側との間隔確保 */
    justify-content: center;
}

.title {
    font-size: 0.8rem;
    font-weight: 900;
    color: var(--text-primary);
    letter-spacing: -0.5px;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.title-sub {
    font-size: 0.4rem;
    font-weight: 600;
    color: var(--accent-cyan);
    letter-spacing: 0.5px;
    font-style: italic;
    opacity: 0.8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-right {
    display: flex;
    gap: 6px;
    /* 間隔少し狭める */
    flex-shrink: 0;
    /* 右側は縮小させない */
    align-items: center;
}

.score-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-sm);
    padding: 2px 6px;
    min-width: 44px;
    justify-content: center;
}

.score-label {
    font-size: 0.4rem;
    font-weight: 700;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    line-height: 1;
    white-space: nowrap;
}

.score-value {
    font-size: 0.95rem;
    font-weight: 900;
    color: var(--text-primary);
    line-height: 1.1;
    transition: transform 0.1s ease;
    white-space: nowrap;
}

.score-card.best .score-value {
    font-size: 0.85rem;
    color: var(--accent-gold);
}

.score-card.max-lv {
    min-width: 36px;
}

.score-card.max-lv .score-value {
    font-size: 0.85rem;
    color: var(--accent-cyan);
}

/* Combo Badge */
/* Combo Badge (Updated Position) */
.combo-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 200;
    margin-top: 0;
    transform: none;

    background: var(--accent-pink);
    color: white;
    font-size: 0.8rem;
    font-weight: 800;
    font-family: 'Inter', sans-serif;
    padding: 2px 6px;
    border-radius: 10px;
    letter-spacing: 0.5px;
    animation: comboPulse 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    white-space: nowrap;
}

.header-right {
    position: relative;
    /* 基準点にする */
    display: flex;
    gap: 6px;
    flex-shrink: 0;
    align-items: center;
}

.combo-badge.hidden {
    display: none;
}

.combo-badge.combo-active {
    animation: comboPulse 0.15s ease;
}

@keyframes comboPulse {
    0% {
        transform: translateX(-50%) scale(0.8);
        /* translateXを維持 */
        opacity: 0;
    }

    50% {
        transform: translateX(-50%) scale(1.1);
        opacity: 1;
    }

    100% {
        transform: translateX(-50%) scale(1);
        opacity: 1;
    }
}

/* Combo Pop Effect */
.combo-pop {
    position: absolute;
    pointer-events: none;
    z-index: 26;
    font-size: 1.2rem;
    font-weight: 900;
    font-family: 'Inter', sans-serif;
    color: var(--accent-pink);
    text-shadow: 0 0 12px rgba(255, 107, 157, 0.6);
    animation: comboPop 1s ease-out forwards;
}

@keyframes comboPop {
    0% {
        transform: translate(-50%, 0) scale(0.8);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -80px) scale(1.3);
        opacity: 0;
    }
}

/* Fever Time */
#game-area.fever-active {
    box-shadow: inset 0 0 30px rgba(255, 215, 0, 0.3), 0 0 20px rgba(255, 215, 0, 0.2);
    animation: feverGlow 0.8s ease-in-out infinite alternate;
}

@keyframes feverGlow {
    0% { box-shadow: inset 0 0 30px rgba(255, 215, 0, 0.2), 0 0 15px rgba(255, 215, 0, 0.15); }
    100% { box-shadow: inset 0 0 40px rgba(255, 107, 157, 0.3), 0 0 25px rgba(255, 107, 157, 0.2); }
}

.combo-badge.fever {
    background: linear-gradient(135deg, #ffd700, #ff6b9d);
    color: #fff;
    text-shadow: 0 0 8px rgba(255, 215, 0, 0.8);
    animation: feverBadgePulse 0.5s ease-in-out infinite alternate;
}

@keyframes feverBadgePulse {
    0% { transform: scale(1); }
    100% { transform: scale(1.1); }
}

.fever-announce {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 300;
    font-size: 2rem;
    font-weight: 900;
    font-family: 'Inter', sans-serif;
    color: #ffd700;
    text-shadow: 0 0 20px rgba(255, 215, 0, 0.8), 0 0 40px rgba(255, 107, 157, 0.5);
    pointer-events: none;
    animation: feverAnnounce 1.5s ease-out forwards;
}

@keyframes feverAnnounce {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    20% { transform: translate(-50%, -50%) scale(1.3); opacity: 1; }
    50% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    100% { transform: translate(-50%, -50%) scale(1.2); opacity: 0; }
}

/* Max Level Value in Game Over */
.result-value.max-lv-value {
    font-size: 1rem;
    color: var(--accent-cyan);
}

/* Settings Button */
.settings-btn {
    width: 44px;
    height: 44px;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    margin-left: 4px;
    flex-shrink: 0;
}

.settings-btn:active {
    transform: scale(0.9);
    color: var(--text-primary);
}

/* Settings Panel */
#settings-panel {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(5, 10, 20, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 90;
    animation: fadeIn 0.2s ease;
}

#settings-panel.hidden {
    display: none;
}

.settings-content {
    width: 320px;
    max-width: 88vw;
    background: rgba(15, 25, 45, 0.95);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-lg);
    padding: 28px 24px;
    box-sizing: border-box;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.settings-title {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--text-secondary);
    letter-spacing: 4px;
}

.settings-close-btn {
    width: 44px;
    height: 44px;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 50%;
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.settings-close-btn:active {
    transform: scale(0.9);
    background: rgba(255, 255, 255, 0.12);
}

.settings-section {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-md);
    padding: 16px;
}

/* Cast Button */
.cast-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 1.2rem;
}

.cast-btn:hover {
    background: var(--surface);
    color: var(--text-primary);
}

.cast-btn:active {
    transform: scale(0.9);
}

/* Cast Panel */
#cast-panel {
    position: fixed;
    /* absolute -> fixed に変更 */
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 10, 20, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    /* 最前面に */
    animation: fadeIn 0.2s ease;
    touch-action: pan-y;
    /* bodyのtouch-action:noneを上書きしてスクロール有効化 */
    overscroll-behavior: contain;
    /* スクロールがページ全体に伝播しないように */
}

#cast-panel.hidden {
    display: none;
}

.cast-content {
    width: 450px;
    max-width: 90%;
    max-height: 85vh;
    max-height: 85dvh;
    /* dvh: Androidアドレスバーを考慮した実際の表示領域 */
    background: rgba(15, 25, 45, 0.95);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* はみ出し防止 */
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.cast-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-shrink: 0;
}

.cast-title {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--text-secondary);
    letter-spacing: 4px;
}

.cast-close-btn {
    width: 44px;
    height: 44px;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 50%;
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.cast-close-btn:active {
    transform: scale(0.9);
    background: rgba(255, 255, 255, 0.12);
}

.cast-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-right: 4px;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    overscroll-behavior: contain;
}

.cast-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-md);
    padding: 12px 8px;
    transition: all 0.2s ease;
    cursor: pointer;
    text-decoration: none;
}

.cast-item:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent-cyan);
    transform: translateY(-2px);
}

.cast-image {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    background: rgba(0, 0, 0, 0.2);
    border: 2px solid transparent;
}

.cast-name {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.5px;
    text-align: center;
}

.cast-level {
    font-size: 0.55rem;
    color: var(--accent-cyan);
    opacity: 0.8;
}

/* Scrollbar for cast list */
.cast-list::-webkit-scrollbar {
    width: 4px;
}

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

.cast-list::-webkit-scrollbar-thumb {
    background: var(--surface-border);
    border-radius: 4px;
}

/* Cast Detail View */
.cast-nav-btn {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--accent-cyan);
    background: transparent;
    border: none;
    cursor: pointer;
    letter-spacing: 1px;
    padding: 4px 8px;
    margin-left: -8px;
    transition: all 0.2s ease;
}

.cast-nav-btn:hover {
    color: var(--text-primary);
}

.cast-detail-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    flex: 1;
    overflow-y: auto;
    padding-right: 4px;
    padding-bottom: 10px;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    overscroll-behavior: contain;
}

.detail-image {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    border: 4px solid var(--surface-border);
    object-fit: cover;
    background: rgba(0, 0, 0, 0.2);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 3rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.detail-info-box {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.detail-name {
    font-size: 1.4rem;
    font-weight: 900;
    color: var(--text-primary);
    text-align: center;
}

.detail-level {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--accent-gold);
    background: rgba(255, 215, 0, 0.1);
    padding: 4px 12px;
    border-radius: 12px;
    margin-bottom: 8px;
}

.detail-desc {
    font-size: 0.8rem;
    line-height: 1.6;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 20px;
    padding: 0 10px;
}

.detail-links {
    display: flex;
    gap: 12px;
    width: 100%;
    justify-content: center;
}

.detail-link-btn {
    padding: 10px 20px;
    border-radius: 30px;
    text-decoration: none;
    font-size: 0.75rem;
    font-weight: 700;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.detail-link-btn.twitter {
    background: #000;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.detail-link-btn.instagram {
    background: linear-gradient(45deg, #f09433 0%, #e6683c 25%, #dc2743 50%, #cc2366 75%, #bc1888 100%);
    color: #fff;
    border: none;
}

.detail-link-btn.youtube {
    background: #ff0000;
    color: #fff;
    border: none;
}

.detail-link-btn.map {
    background: #34a853;
    color: #fff;
    border: none;
}

.detail-link-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    opacity: 0.9;
}

/* ===========================================
   Cast Detail Modal (全画面)
   =========================================== */
#cast-detail-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 10, 20, 0.98);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    animation: fadeIn 0.2s ease;
    padding: 20px;
    padding: env(safe-area-inset-top, 20px) env(safe-area-inset-right, 20px) env(safe-area-inset-bottom, 20px) env(safe-area-inset-left, 20px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

#cast-detail-modal.hidden {
    display: none;
}

.detail-modal-content {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 20px;
    position: relative;
}

.detail-modal-close-btn {
    position: absolute;
    top: 0;
    right: 0;
    width: 44px;
    height: 44px;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 50%;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.detail-modal-close-btn:active {
    transform: scale(0.9);
    background: rgba(255, 255, 255, 0.12);
}

#cast-detail-modal .detail-image {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    border: 4px solid var(--accent-pink);
    background: rgba(0, 0, 0, 0.2);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 4rem;
    box-shadow: 0 8px 32px rgba(255, 107, 157, 0.3);
    margin-top: 20px;
}

#cast-detail-modal .detail-name {
    font-size: 1.8rem;
    font-weight: 900;
    color: var(--text-primary);
    text-align: center;
}

#cast-detail-modal .detail-level {
    font-size: 1rem;
    font-weight: 700;
    padding: 6px 16px;
    border-radius: 16px;
}

#cast-detail-modal .detail-desc {
    font-size: 1rem;
    line-height: 1.8;
    color: var(--text-secondary);
    text-align: center;
    margin: 16px 0;
}

#cast-detail-modal .detail-links {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 280px;
}

#cast-detail-modal .detail-link-btn {
    width: 100%;
    justify-content: center;
    padding: 14px 24px;
    font-size: 0.9rem;
}

/* ===========================================
   Next Preview
   =========================================== */
#next-preview {
    width: 100%;
    height: var(--next-height);
    flex-shrink: 0;
    background: rgba(10, 20, 40, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--surface-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
}

.next-inner {
    display: flex;
    align-items: center;
    gap: 12px;
}

.next-label {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-secondary);
    letter-spacing: 3px;
}

.next-cat {
    width: 36px;
    height: 36px;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    overflow: hidden;
}

/* Hold feature */
.hold-inner {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hold-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    min-width: 90px;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.hold-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent-cyan);
}

.hold-btn:active {
    transform: scale(0.95);
}

.hold-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.hold-label {
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--text-secondary);
    letter-spacing: 2px;
}

.hold-cat {
    width: 24px;
    height: 24px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px dashed var(--surface-border);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.85rem;
    overflow: hidden;
}

.hold-cat.has-cat {
    border-style: solid;
    background: var(--surface);
}

.hold-count {
    font-size: 0.7rem;
    font-weight: 800;
    color: var(--accent-cyan);
    min-width: 16px;
    text-align: center;
}

.hold-count.exhausted {
    color: var(--text-secondary);
}

/* Reroll feature */
.reroll-inner {
    display: flex;
    align-items: center;
    gap: 8px;
}

.reroll-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    min-width: 90px;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.reroll-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent-pink);
}

.reroll-btn:hover .reroll-icon {
    transform: rotate(180deg);
}

.reroll-btn:active {
    transform: scale(0.95);
}

.reroll-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.reroll-label {
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--text-secondary);
    letter-spacing: 2px;
}

.reroll-icon {
    width: 24px;
    height: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.85rem;
    transition: transform 0.3s ease;
}

.reroll-count {
    font-size: 0.7rem;
    font-weight: 800;
    color: var(--accent-pink);
    min-width: 16px;
    text-align: center;
}

.reroll-count.exhausted {
    color: var(--text-secondary);
}


/* Bomb skip button */
.skip-bomb-btn {
    padding: 6px 16px;
    font-size: 0.7rem;
    font-family: 'Inter', sans-serif;
    font-weight: 800;
    background: var(--accent-orange);
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.15s ease;
    letter-spacing: 1px;
}

.skip-bomb-btn:active {
    transform: scale(0.95);
    opacity: 0.8;
}

.skip-bomb-btn.hidden {
    display: none;
}

/* Bomb mode */
#next-preview.bomb-mode {
    background: rgba(255, 100, 50, 0.15);
    border-color: rgba(255, 140, 66, 0.4);
}

/* Shake animation */
@keyframes shake {
    0% {
        transform: translate(0, 0) rotate(0deg);
    }

    5% {
        transform: translate(-30px, -12px) rotate(-5deg);
    }

    10% {
        transform: translate(30px, 10px) rotate(5deg);
    }

    15% {
        transform: translate(-28px, -10px) rotate(-4.5deg);
    }

    20% {
        transform: translate(28px, 12px) rotate(4.5deg);
    }

    25% {
        transform: translate(-25px, -8px) rotate(-4deg);
    }

    30% {
        transform: translate(25px, 8px) rotate(4deg);
    }

    35% {
        transform: translate(-22px, -10px) rotate(-3.5deg);
    }

    40% {
        transform: translate(22px, 10px) rotate(3.5deg);
    }

    45% {
        transform: translate(-18px, -6px) rotate(-3deg);
    }

    50% {
        transform: translate(18px, 6px) rotate(3deg);
    }

    55% {
        transform: translate(-15px, -5px) rotate(-2deg);
    }

    60% {
        transform: translate(15px, 5px) rotate(2deg);
    }

    65% {
        transform: translate(-12px, -4px) rotate(-1.5deg);
    }

    70% {
        transform: translate(12px, 4px) rotate(1.5deg);
    }

    75% {
        transform: translate(-8px, -2px) rotate(-1deg);
    }

    80% {
        transform: translate(8px, 2px) rotate(1deg);
    }

    85% {
        transform: translate(-5px, -1px) rotate(-0.5deg);
    }

    90% {
        transform: translate(5px, 1px) rotate(0.5deg);
    }

    95% {
        transform: translate(-2px, 0) rotate(0deg);
    }

    100% {
        transform: translate(0, 0) rotate(0deg);
    }
}

.shaking {
    animation: shake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

/* ===========================================
   Game Area
   =========================================== */
#game-area {
    position: relative;
    width: 100%;
    flex: 1;
    min-height: 0;
    margin-bottom: 0;
    background:
        linear-gradient(180deg,
            rgba(6, 16, 32, 0.7) 0%,
            rgba(10, 22, 40, 0.5) 50%,
            rgba(15, 30, 50, 0.3) 100%),
        url('./assets/beach_night_bg.png');
    background-size: cover;
    background-position: center bottom;
    overflow: hidden;
    box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.4);
}

/* Wall textures */
#game-area::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 15px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.06) 0%, transparent 100%);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 2;
}

#game-area::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 15px;
    background: linear-gradient(270deg, rgba(255, 255, 255, 0.06) 0%, transparent 100%);
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 2;
}

/* Danger line */
#danger-line {
    position: absolute;
    top: 100px;
    left: 15px;
    right: 15px;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--danger-red), transparent);
    opacity: 0.6;
    z-index: 10;
    animation: dangerPulse 2s ease-in-out infinite;
}

#danger-line::before,
#danger-line::after {
    content: '';
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 6px;
    height: 6px;
    background: var(--danger-red);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--danger-red);
}

#danger-line::before {
    left: 0;
}

#danger-line::after {
    right: 0;
}

@keyframes dangerPulse {

    0%,
    100% {
        opacity: 0.4;
    }

    50% {
        opacity: 0.8;
    }
}

#game-canvas {
    display: block;
    position: relative;
    z-index: 1;
}

/* (Evolution Guide styles moved to single block below) */

/* Skip Bomb Button (Highlight) */
.skip-bomb-btn {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #ff4d4d, #cc0000);
    color: white;
    border: 2px solid #ffcccc;
    padding: 12px 32px;
    border-radius: 30px;
    font-weight: 900;
    font-size: 1.2rem;
    letter-spacing: 2px;
    box-shadow: 0 4px 15px rgba(255, 0, 0, 0.6);
    cursor: pointer;
    z-index: 1000;
    animation: pulseBtn 1s infinite alternate;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.skip-bomb-btn::before {
    content: '💣';
    font-size: 1.4rem;
}

.skip-bomb-btn:active {
    transform: translateX(-50%) scale(0.95);
    background: #aa0000;
}

@keyframes pulseBtn {
    0% {
        transform: translateX(-50%) scale(1);
        box-shadow: 0 4px 15px rgba(255, 0, 0, 0.6);
    }

    100% {
        transform: translateX(-50%) scale(1.05);
        box-shadow: 0 0 25px rgba(255, 50, 50, 0.8);
    }
}

/* ===========================================
   Game Over Overlay
   =========================================== */
#game-over {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(5, 10, 20, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    animation: fadeIn 0.3s ease;
}

#game-over.hidden {
    display: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.game-over-content {
    text-align: center;
    padding: 40px 36px;
    background: rgba(15, 25, 45, 0.95);
    border: 1px solid var(--surface-border);
    border-radius: 24px;
    width: 340px;
    max-width: 90vw;
    animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
    from {
        transform: translateY(30px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.gameover-icon {
    font-size: 1.6rem;
    font-weight: 900;
    color: var(--text-primary);
    letter-spacing: 3px;
    margin-bottom: 6px;
}

.game-over-content .subtitle {
    font-family: 'Zen Maru Gothic', sans-serif;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.result-card {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-md);
    padding: 20px 24px;
    margin-bottom: 24px;
}

.result-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
}

.result-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-secondary);
    letter-spacing: 2px;
}

.result-value {
    font-size: 2rem;
    font-weight: 900;
    color: var(--text-primary);
    line-height: 1;
}

.result-value.best {
    font-size: 1.3rem;
    color: var(--accent-gold);
}

.result-divider {
    height: 1px;
    background: var(--surface-border);
    margin: 10px 0;
}

.new-record {
    font-size: 0.8rem;
    font-weight: 800;
    color: var(--accent-gold);
    letter-spacing: 3px;
    margin-top: 12px;
    animation: recordPulse 1s ease-in-out infinite alternate;
}

.new-record.hidden {
    display: none;
}

@keyframes recordPulse {
    from {
        opacity: 0.7;
    }

    to {
        opacity: 1;
    }
}

.share-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-bottom: 16px;
}

.share-btn {
    padding: 10px 20px;
    font-size: 0.8rem;
    font-family: 'Inter', sans-serif;
    font-weight: 700;
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--surface);
    color: var(--text-primary);
}

.share-btn:active {
    transform: scale(0.96);
    opacity: 0.8;
}

.share-btn.twitter {
    background: rgba(255, 255, 255, 0.08);
}

.share-btn.line {
    background: rgba(0, 185, 0, 0.15);
    border-color: rgba(0, 185, 0, 0.3);
    color: #4dff4d;
}

/* Continue Button */
/* Continue Button */
.continue-btn {
    width: 100%;
    padding: 14px 20px;
    font-size: 0.95rem;
    font-family: 'Inter', sans-serif;
    font-weight: 800;
    background: linear-gradient(135deg, #ff8c42 0%, #ff6b9d 100%);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    letter-spacing: 1px;
    margin-bottom: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(255, 140, 66, 0.3);
    white-space: nowrap;
}

.continue-btn .icon {
    font-size: 1.2rem;
}

.continue-btn:active {
    transform: scale(0.96);
    opacity: 0.9;
}

.continue-btn.hidden {
    display: none;
}

/* Ad Loading Countdown */
#countdown-area {
    width: 100%;
    padding: 20px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

#countdown-area.hidden {
    display: none;
}

#countdown-area p {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 1px;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--accent-cyan);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

#restart-btn {
    width: 100%;
    padding: 16px;
    font-size: 1rem;
    font-family: 'Inter', sans-serif;
    font-weight: 800;
    background: var(--accent-cyan);
    color: #001a2e;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s ease;
    letter-spacing: 2px;
}

#restart-btn:active {
    transform: scale(0.97);
    opacity: 0.85;
}

/* ===========================================
   Evolution Guide - Rebuilt
   =========================================== */
#evolution-guide {
    width: 100%;
    flex-shrink: 0;
    background: rgba(10, 20, 35, 0.92);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    padding: 6px 8px 8px;
    margin: 0;
    position: relative;
    z-index: 10;
}

.guide-title {
    font-size: 0.5rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 4px;
    letter-spacing: 3px;
    line-height: 1;
}

#evolution-chart {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: nowrap;
    gap: 0;
    width: 100%;
}

.evo-item {
    width: 30px;
    height: 30px;
    min-width: 30px;
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.8rem;
    background: var(--surface);
    border: 1.5px solid rgba(255, 255, 255, 0.12);
    border-radius: 50%;
    overflow: hidden;
    background-size: cover;
    background-position: center;
    position: relative;
}

.evo-arrow {
    color: rgba(255, 255, 255, 0.25);
    font-size: 0.45rem;
    flex-shrink: 0;
    width: 8px;
    text-align: center;
    line-height: 1;
}

/* Level badge under each item */
.evo-level {
    display: none;
}

/* Responsive: scale items to always fit */
@media (max-width: 440px) {
    #evolution-guide {
        padding: 5px 4px 6px;
    }

    .evo-item {
        width: 26px;
        height: 26px;
        min-width: 26px;
    }

    .evo-arrow {
        width: 6px;
        font-size: 0.4rem;
    }
}

@media (max-width: 360px) {
    #evolution-guide {
        padding: 4px 2px 5px;
    }

    .evo-item {
        width: 23px;
        height: 23px;
        min-width: 23px;
    }

    .evo-arrow {
        width: 5px;
        font-size: 0.35rem;
    }

    .guide-title {
        font-size: 0.4rem;
        letter-spacing: 2px;
        margin-bottom: 3px;
    }
}

@media (max-width: 320px) {
    .evo-item {
        width: 20px;
        height: 20px;
        min-width: 20px;
    }

    .evo-arrow {
        width: 4px;
        font-size: 0.3rem;
    }
}

/* ===========================================
   Merge Effect
   =========================================== */
.merge-effect {
    position: absolute;
    pointer-events: none;
    z-index: 20;
    animation: mergeExpand 0.5s ease-out forwards;
}

@keyframes mergeExpand {
    0% {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 1;
    }

    50% {
        transform: translate(-50%, -50%) scale(1.5);
        opacity: 0.8;
    }

    100% {
        transform: translate(-50%, -50%) scale(2.5);
        opacity: 0;
    }
}

/* Score pop */
.score-pop {
    position: absolute;
    pointer-events: none;
    z-index: 25;
    font-size: 1rem;
    font-weight: 900;
    font-family: 'Inter', sans-serif;
    color: var(--accent-gold);
    text-shadow: 0 0 12px rgba(255, 215, 0, 0.6);
    animation: scorePop 0.8s ease-out forwards;
}

@keyframes scorePop {
    0% {
        transform: translate(-50%, 0) scale(0.5);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -60px) scale(1.2);
        opacity: 0;
    }
}

/* ===========================================
   Skill Effect
   =========================================== */
.skill-announce {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3rem;
    font-weight: 900;
    font-family: 'Inter', sans-serif;
    color: var(--accent-cyan);
    text-shadow: 0 0 20px rgba(0, 212, 255, 0.8), 0 0 40px rgba(0, 212, 255, 0.4);
    letter-spacing: 8px;
    z-index: 30;
    pointer-events: none;
    animation: skillAnnounce 1.2s ease-out forwards;
}

@keyframes skillAnnounce {
    0% {
        transform: translate(-50%, -50%) scale(0.5);
        opacity: 0;
    }

    20% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 1;
    }

    50% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -50%) scale(1.5);
        opacity: 0;
    }
}

.skill-sparkle {
    position: absolute;
    pointer-events: none;
    z-index: 25;
    font-size: 2rem;
    animation: skillSparkle 0.6s ease-out forwards;
}

@keyframes skillSparkle {
    0% {
        transform: translate(-50%, -50%) scale(0.5) rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -50%) scale(2) rotate(180deg);
        opacity: 0;
    }
}

/* ===========================================
   Responsive
   =========================================== */

/* Mobile: align game to top, full-screen */
@media (max-width: 460px) {
    body {
        align-items: flex-start;
        padding: 0;
    }

    :root {
        --game-width: 100vw;
        --game-height: 100dvh;
    }

    #game-container {
        height: 100dvh;
        max-height: 100dvh;
        padding: 0 0 env(safe-area-inset-bottom, 0px) 0;
        border-radius: 0;
    }

    #game-header {
        border-radius: 0;
    }

    #evolution-guide {
        border-radius: 0;
    }
}

/* Tablet: full-screen height, width constrained by aspect ratio */
@media (min-width: 461px) and (max-width: 1024px) {
    body {
        align-items: center;
        padding: 0;
    }

    :root {
        --game-height: 100dvh;
    }

    #game-container {
        height: 100dvh;
        max-height: 100dvh;
        width: min(100vw, calc(100dvh * 440 / 700));
        max-width: min(100vw, calc(100dvh * 440 / 700));
        padding: 0;
        border-radius: 0;
    }

    #game-header {
        border-radius: 0;
    }

    #evolution-guide {
        border-radius: 0;
    }
}

/* PC (large screens): keep centered with fixed aspect ratio */
@media (min-width: 1025px) {
    body {
        align-items: center;
        padding: 16px;
    }

    #game-container {
        /* 高さは画面高さ - padding分に制限、幅はアスペクト比440:700で自動計算 */
        height: min(var(--game-height), calc(100dvh - 32px));
        max-height: min(var(--game-height), calc(100dvh - 32px));
        max-width: min(var(--game-width), calc((100dvh - 32px) * 440 / 700));
    }
}

@media (max-width: 460px) {
    .title {
        font-size: 0.75rem;
    }

    .score-value {
        font-size: 1.2rem;
    }

    .score-card {
        min-width: 60px;
        padding: 5px 10px;
    }

    .game-over-content {
        padding: 32px 24px;
    }
}

/* ===========================================
   Android App Optimized Styles
   =========================================== */

/* Small phones (height < 700px) */
@media (max-height: 700px) {
    .title-content {
        gap: 24px;
    }

    .title-tomo {
        font-size: 3rem;
    }

    .title-game {
        font-size: 1.2rem;
    }

    .title-tagline {
        font-size: 0.6rem;
        letter-spacing: 4px;
    }

    .music-box {
        padding: 16px;
    }

    #start-btn {
        padding: 14px 24px;
        font-size: 0.9rem;
    }
}

/* Medium phones (height 700-850px) */
@media (min-height: 700px) and (max-height: 850px) {
    .title-content {
        gap: 32px;
    }

    .title-tomo {
        font-size: 3.8rem;
    }

    .title-game {
        font-size: 1.5rem;
    }
}

/* Large phones & tablets (height > 850px) */
@media (min-height: 850px) {
    .title-content {
        gap: 44px;
    }

    .title-tomo {
        font-size: 5rem;
    }

    .title-game {
        font-size: 2rem;
    }
}

/* Landscape mode adjustments */
@media (orientation: landscape) and (max-height: 500px) {
    .title-content {
        gap: 16px;
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: center;
        max-width: 90vw;
    }

    .title-logo {
        width: 100%;
    }

    .title-tomo {
        font-size: 2.5rem;
    }

    .title-game {
        font-size: 1rem;
    }

    .title-tagline {
        font-size: 0.55rem;
    }

    .music-box {
        width: auto;
        flex: 1;
        min-width: 200px;
    }

    #start-btn {
        flex: 1;
        min-width: 150px;
        padding: 14px 20px;
    }
}

/* Mobile Responsiveness for Cast Panel */
@media (max-width: 480px) {
    .cast-content {
        width: 92%;
        max-height: 80vh;
        max-height: 80dvh;
        padding: 16px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        /* ノッチ付き端末の下部セーフエリア対応 */
    }

    .cast-header {
        margin-bottom: 12px;
    }

    .cast-list {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .detail-image {
        width: 100px;
        height: 100px;
        font-size: 2.5rem;
    }

    .detail-name {
        font-size: 1.2rem;
    }

    .detail-link-btn {
        padding: 8px 16px;
        font-size: 0.7rem;
    }

    .detail-links {
        flex-direction: column;
        gap: 8px;
        width: 100%;
        align-items: center;
    }

    .detail-link-btn {
        width: 100%;
        justify-content: center;
        max-width: 200px;
    }
}

/* 小型Android端末向け (Galaxy A系, Pixel 4aなど 360px幅) */
@media (max-width: 380px) {
    .cast-content {
        width: 95%;
        max-height: 78dvh;
        padding: 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }

    .cast-list {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
    }

    .cast-item {
        padding: 8px 6px;
    }

    .cast-image {
        width: 40px;
        height: 40px;
    }

    .cast-name {
        font-size: 0.6rem;
    }

    .detail-image {
        width: 80px;
        height: 80px;
        font-size: 2rem;
    }

    .detail-name {
        font-size: 1rem;
    }

    .detail-desc {
        font-size: 0.7rem;
        padding: 0 4px;
    }

    .detail-link-btn {
        padding: 6px 12px;
        font-size: 0.65rem;
    }
}

/* ===========================================
   小型Android端末向け ゲームUI調整 (360px以下)
   Galaxy A系, Pixel 4a, AQUOS sense 等
   =========================================== */
@media (max-width: 360px) {
    :root {
        --game-width: 100vw;
    }

    body {
        padding: 0;
    }

    /* ヘッダー */
    #game-header {
        padding: 0 8px;
    }

    .title {
        font-size: 0.7rem;
    }

    .title-sub {
        display: none;
    }

    .score-card {
        min-width: 48px;
        padding: 4px 6px;
    }

    .score-value {
        font-size: 1rem;
    }

    .score-label {
        font-size: 0.45rem;
    }

    .header-right {
        gap: 4px;
    }

    /* 設定・キャストボタン */
    .settings-btn,
    .cast-btn {
        width: 40px;
        height: 40px;
    }

    /* 設定パネル */
    .settings-content {
        max-width: 92vw;
        padding: 20px 16px;
    }

    /* Next/Hold/Reroll エリア */
    .next-preview {
        padding: 6px 8px;
    }

    .next-cat {
        width: 32px;
        height: 32px;
    }

    /* タイトル画面 */
    .title-content {
        max-width: 95vw;
        padding: 0 8px;
    }

    .title-tomo {
        font-size: 2.5rem;
    }

    .title-game {
        font-size: 1rem;
    }

    .music-box {
        padding: 12px;
    }

    #start-btn {
        padding: 14px 20px;
        font-size: 0.9rem;
    }

    /* ゲームオーバー */
    .game-over-content {
        padding: 24px 16px;
        max-width: 92vw;
    }
}

/* 超小型端末 (320px以下) */
@media (max-width: 320px) {
    :root {
        --game-width: 100vw;
        --header-height: 48px;
    }

    .title {
        font-size: 0.65rem;
    }

    .score-card {
        min-width: 42px;
        padding: 3px 5px;
    }

    .score-value {
        font-size: 0.9rem;
    }

    .settings-btn,
    .cast-btn {
        width: 36px;
        height: 36px;
    }

    .title-tomo {
        font-size: 2rem;
    }

    .title-game {
        font-size: 0.9rem;
    }
}

/* Skill feature */
.skill-inner {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 8px;
    display: none;
    /* Initially hidden */
}

.skill-inner.visible {
    display: flex;
    /* Show only when ready */
    animation: popIn 0.3s ease;
}

@keyframes popIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }

    80% {
        transform: scale(1.1);
        opacity: 1;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.skill-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    min-width: 90px;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.15s ease;
    color: var(--text-primary);
}

.skill-btn:hover:not(:disabled) {
    background: rgba(255, 215, 0, 0.1);
    border-color: var(--accent-gold);
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.2);
}

.skill-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.skill-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    filter: grayscale(100%);
}

.skill-btn.active {
    background: var(--accent-gold);
    color: #000;
    border-color: var(--accent-gold);
    animation: skillPulse 1s infinite alternate;
}

@keyframes skillPulse {
    from {
        box-shadow: 0 0 5px var(--accent-gold);
    }

    to {
        box-shadow: 0 0 15px var(--accent-gold);
    }
}

.skill-label {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 2px;
}

.skill-icon {
    font-size: 1rem;
}

.skill-count {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-secondary);
    min-width: 24px;
    text-align: center;
}

.skill-count.ready {
    color: var(--accent-gold);
}

/* ===========================================
   Skill Video Overlay (game-area内)
   =========================================== */
#skill-video-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 500;
    display: flex;
    justify-content: center;
    align-items: center;
}

#skill-video-overlay.hidden {
    display: none;
}

#skill-video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.skill-video-skip-btn {
    position: absolute;
    bottom: 16px;
    right: 12px;
    padding: 14px 28px;
    font-size: 0.85rem;
    font-family: 'Inter', sans-serif;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
    border: 2px solid rgba(255, 255, 255, 0.6);
    border-radius: 30px;
    cursor: pointer;
    z-index: 9999;
    letter-spacing: 2px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: all 0.2s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

.skill-video-skip-btn:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.3);
}