/* Pinball Game Styles v2.1 - 3D Cabinet & UI Refinement */
:root {
    --bg-color: #1a1a2e;
    --accent-color: #e94560;
    --text-color: #ffffff;
    --canvas-bg: #16213e;
    --cabinet-body: #2c3e50;
    --cabinet-trim: #95a5a6;
    --flipper-color: #ff2a6d;
}

body {
    margin: 0;
    overflow: hidden;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Orbitron', 'Noto Sans JP', sans-serif;
    touch-action: none;
    height: 100vh;
}

.game-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    perspective: 1200px;
    background: url('retro_arcade_bg.png') no-repeat center center/cover;
    position: relative;
}

.game-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    /* Overlay to darken background */
    pointer-events: none;
    z-index: 0;
}

/* 3D Scene Container */
#game-scene {
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.5s;
    transform: rotateX(25deg) scale(0.9);
}

/* The Cabinet Box */
#cabinet {
    position: relative;
    width: 450px;
    height: 800px;
    background: #000;
    border-radius: 10px;
    transform-style: preserve-3d;
    box-shadow:
        0 50px 100px rgba(0, 0, 0, 0.8),
        0 0 0 15px var(--cabinet-body);
}

/* Main Playing Surface Frame */
.cabinet-frame {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 20px solid var(--cabinet-body);
    border-bottom-width: 80px;
    box-sizing: border-box;
    background: #000;
    overflow: hidden;
    border-radius: 8px;
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.8);
    transform: translateZ(2px);
}

canvas {
    display: block;
    background-color: var(--canvas-bg);
}

/* Glass Reflection Effect */
#glass-reflection {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 30%, transparent 50%);
    pointer-events: none;
    z-index: 50;
    mix-blend-mode: overlay;
}

/* Cabinet Sides (Pseudo-3D) */
.cabinet-side {
    position: absolute;
    top: 0;
    width: 40px;
    height: 100%;
    background: #202020;
    transform-origin: top;
}

.side-left {
    left: -40px;
    transform: rotateY(-90deg);
    transform-origin: right;
    background: linear-gradient(to bottom, #444, #222);
    border-right: 1px solid #555;
}

.side-right {
    right: -40px;
    transform: rotateY(90deg);
    transform-origin: left;
    background: linear-gradient(to bottom, #444, #222);
    border-left: 1px solid #555;
}

.cabinet-front {
    position: absolute;
    bottom: -60px;
    left: 0;
    width: 100%;
    height: 60px;
    background: #333;
    transform: rotateX(-90deg);
    transform-origin: top;
    display: flex;
    justify-content: center;
    align-items: center;
    border-top: 1px solid #555;
}

.plunger-button {
    width: 80px;
    height: 40px;
    background: #e74c3c;
    border-radius: 50px;
    color: white;
    text-align: center;
    line-height: 40px;
    font-weight: bold;
    font-family: 'Press Start 2P', cursive;
    font-size: 0.8rem;
    box-shadow: 0 5px 0 #c0392b;
    cursor: pointer;
    transition: transform 0.1s;
    user-select: none;
}

.plunger-button:active {
    transform: translateY(3px);
    box-shadow: 0 2px 0 #c0392b;
}

/* UI Elements */
#game-ui {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

#score-display,
#high-score-display {
    position: absolute;
    top: 70px;
    font-family: 'Press Start 2P', cursive;
    font-size: 1.2rem;
    color: white;
    text-shadow: 2px 2px 0 #000;
    z-index: 10;
    background: rgba(0, 0, 0, 0.5);
    padding: 10px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

#score-display {
    right: 20px;
}

#in-game-reset {
    position: absolute;
    top: 70px;
    left: 50%;
    transform: translateX(-50%) translateZ(60px);
    background: rgba(233, 69, 96, 0.8);
    border: 2px solid #fff;
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    z-index: 1001;
    pointer-events: auto;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    transition: all 0.2s;
}

#in-game-reset:hover {
    background: rgba(233, 69, 96, 1);
    transform: translateX(-50%) translateZ(65px) scale(1.1);
}

#in-game-reset:active {
    transform: translateX(-50%) translateZ(55px) scale(0.9);
}

#high-score-display {
    left: 20px;
    font-size: 0.8rem;
    color: #ffd700;
}

/* 週間ランキングパネル（手書き風の白いアーチ） */
#ranking-panel {
    position: absolute;
    top: -220px;
    left: 50%;
    transform: translateX(-50%) translateZ(20px);
    /* 手前に浮かせる */
    transform-style: preserve-3d;
    background: rgba(0, 0, 0, 0.6);
    border: 8px solid #fff;
    /* 線をさらに太く */
    border-bottom: none;
    border-radius: 200px 200px 0 0;
    padding: 80px 40px 20px 40px;
    width: 420px;
    height: 240px;
    text-align: center;
    z-index: 1000;
    font-family: 'Press Start 2P', 'Noto Sans JP', cursive;
    color: #fff;
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    pointer-events: none;
    /* ゲームの邪魔をしない */
}

#ranking-panel ol {
    margin: 0;
    padding: 0;
    list-style: none;
    width: 100%;
}

#ranking-panel li {
    font-size: 0.9rem;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    border-bottom: 2px solid #fff;
    /* 下線をスケッチ通りに追加 */
    padding-bottom: 5px;
    align-items: baseline;
}

.rank-label {
    min-width: 50px;
    text-align: left;
    color: #fff;
}

.rank-name {
    flex: 1;
    text-align: center;
    color: #fff;
    font-size: 0.9rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    padding: 0 4px;
}

.rank-score {
    min-width: 80px;
    text-align: right;
    color: #ffd700;
    /* スコアは目立つ色に */
}

/* Overlays */
.overlay {
    position: absolute;
    top: 45%;
    left: 50%;
    transform: translate(-50%, -50%) translateZ(40px);
    background: rgba(0, 0, 0, 0.9);
    padding: 30px;
    border-radius: 12px;
    text-align: center;
    border: 2px solid var(--accent-color);
    display: none;
    z-index: 3000;
    min-width: 320px;
    backdrop-filter: blur(10px);
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.8), 0 0 20px var(--accent-color);
    pointer-events: auto;
}

.overlay.active {
    display: block;
    animation: bounceIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes bounceIn {
    from {
        opacity: 0;
        transform: translate(-50%, -45%) translateZ(40px) scale(0.8);
    }

    to {
        opacity: 1;
        transform: translate(-50%, -50%) translateZ(40px) scale(1);
    }
}

.game-title {
    font-family: 'Press Start 2P', cursive;
    font-size: 2rem;
    color: #f1c40f;
    margin-bottom: 25px;
    text-shadow: 3px 3px 0 #d35400, 0 0 15px rgba(241, 196, 15, 0.5);
}

.instruction {
    margin-bottom: 20px;
    font-size: 1rem;
    color: #eee;
}

/* Buttons */
.theme-selector {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 25px;
}

.btn--primary,
.btn--secondary,
.theme-btn {
    padding: 15px 25px;
    border: none;
    border-radius: 8px;
    color: white;
    font-weight: bold;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    text-transform: uppercase;
    font-family: 'Orbitron', sans-serif;
    letter-spacing: 1px;
    display: block;
    width: 100%;
    box-sizing: border-box;
}

.btn--primary,
.theme-btn {
    background: var(--accent-color);
    box-shadow: 0 4px 0 #c0392b;
}

.btn--primary:hover,
.theme-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #c0392b;
}

.btn--primary:active,
.theme-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #c0392b;
}

.btn--secondary {
    background: #444;
    box-shadow: 0 4px 0 #222;
    margin-top: 10px;
}

.btn--secondary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #222;
}

.btn--secondary:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #222;
}

.controls-info {
    font-size: 0.8rem;
    color: #aaa;
    margin-top: 20px;
    background: rgba(255, 255, 255, 0.05);
    padding: 10px;
}

/* Touch Controls */
.touch-controls {
    position: fixed;
    bottom: 30px;
    /* Adjusted to be closer to the bottom/visible area */
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    /* Align to bottom */
    padding: 0 50px;
    /* Increased padding */
    box-sizing: border-box;
    z-index: 2000;
    pointer-events: none;
}

.touch-btn-group-right {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
    pointer-events: none;
}

.touch-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.15);
    color: white;
    font-size: 1.5rem;
    pointer-events: auto;
    backdrop-filter: blur(8px);
    transition: all 0.1s;
    user-select: none;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.touch-btn:active {
    background: rgba(255, 255, 255, 0.4);
    transform: scale(0.9);
    border-color: rgba(255, 255, 255, 0.6);
}

#plunger-touch-btn {
    width: 70px;
    height: 70px;
    font-size: 1.2rem;
    margin-bottom: 5px;
}

/* Theme overrides */
body[data-theme="retro"] #cabinet {
    --cabinet-body: #8e44ad;
}

body[data-theme="neon"] #cabinet {
    --cabinet-body: #1abc9c;
}

/* Responsive */
@media (max-width: 600px) {
    #game-scene {
        transform: rotateX(10deg) scale(0.65);
    }

    .game-container {
        align-items: flex-start;
        padding-top: 50px;
    }

    .touch-controls {
        bottom: 20px;
        padding: 0 20px;
    }

    .score-display,
    .high-score-display {
        font-size: 1rem;
    }
}

/* iPad / Landscape Adjustments */
@media (orientation: landscape) and (max-height: 900px) {
    .touch-controls {
        bottom: 50px;
        /* Adjusted for better visibility */
        padding: 0 100px;
    }

    .touch-btn-group-right {
        transform: translateY(-57px);
    }

    .touch-btn {
        width: 97px;
        height: 97px;
    }

    #plunger-touch-btn {
        width: 85px;
        height: 85px;
    }
}

/* Success Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    backdrop-filter: blur(5px);
    pointer-events: auto;
    cursor: pointer;
}

.modal-overlay.active {
    display: flex;
}

.modal-content {
    background: #2c3e50;
    border: 3px solid var(--accent-color);
    padding: 30px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.8), 0 0 20px var(--accent-color);
    animation: bounceIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    max-width: 90%;
    pointer-events: auto;
}

.modal-content h2 {
    color: #f1c40f;
    font-family: 'Press Start 2P', cursive;
    margin-top: 0;
    font-size: 1.2rem;
    text-shadow: 2px 2px 0 #d35400;
    margin-bottom: 20px;
}

.modal-content p {
    color: #fff;
    margin: 0 0 25px 0;
    font-size: 1rem;
}

#success-ok-btn {
    padding: 12px 30px;
    background: var(--accent-color);
    border: none;
    color: white;
    font-family: 'Press Start 2P', cursive;
    font-size: 0.9rem;
    cursor: pointer;
    box-shadow: 0 4px 0 #c0392b;
    border-radius: 6px;
    transition: all 0.1s;
}

#success-ok-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #c0392b;
}

#success-ok-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #c0392b;
}

/* Ranking Interaction */
.ranking-board-btn {
    background: #444;
    color: #fff;
    border: 1px solid #666;
    padding: 12px 24px;
    font-family: 'Press Start 2P', cursive;
    font-size: 0.7rem;
    cursor: pointer;
    text-transform: uppercase;
    transition: 0.2s;
    border-radius: 8px;
    width: 100%;
    margin-top: 10px;
}

.ranking-board-btn:hover {
    background: #555;
    transform: translateY(-2px);
}

.ranking-board-btn:active {
    transform: translateY(1px);
}

/* Arcade Ranking Modal */
.arcade-ranking-container {
    background: #111;
    border: 2px solid #444;
    padding: 30px;
    width: 90%;
    max-width: 800px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    font-family: 'Press Start 2P', cursive;
    border-radius: 12px;
}

.arcade-title {
    color: #fff;
    font-size: 1.5rem;
    margin-bottom: 20px;
    text-align: center;
}

.ranking-table-wrapper {
    overflow-y: auto;
    margin-bottom: 20px;
    border: 2px solid #333;
    padding: 5px;
}

.ranking-table-wrapper::-webkit-scrollbar {
    width: 8px;
}

.ranking-table-wrapper::-webkit-scrollbar-thumb {
    background: #444;
}

.arcade-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.6rem;
    color: #eee;
}

.arcade-table th {
    background: #222;
    color: #fff;
    padding: 10px;
    text-align: left;
    border-bottom: 2px solid #444;
}

.arcade-table td {
    padding: 10px;
    border-bottom: 1px solid #333;
}

.arcade-table tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.05);
}

.arcade-table tr:hover {
    background: rgba(255, 255, 255, 0.1);
}

.arcade-table .rank-gold {
    color: #ffd700;
    font-weight: bold;
}

.arcade-table .rank-silver {
    color: #c0c0c0;
    font-weight: bold;
}

.arcade-table .rank-bronze {
    color: #cd7f32;
    font-weight: bold;
}

@media (max-width: 600px) {

    .arcade-table th:nth-child(3),
    .arcade-table td:nth-child(3) {
        display: none;
    }

    .arcade-ranking-container {
        padding: 15px;
    }

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