﻿/* --- CSS: デザインとレイアウト --- */
        :root {
            --bg-color: #050510;
            --grid-line: #1a1a3d;
            --neon-blue: #00f3ff;
            --neon-pink: #ff00ff;
            --neon-green: #00ff41;
            --neon-yellow: #ffee00;
            --neon-purple: #bc13fe;
            --panel-bg: rgba(0, 0, 0, 0.6);
        }

        body {
            background-color: var(--bg-color);
            color: var(--neon-blue);
            font-family: 'Orbitron', sans-serif;
            margin: 0;
            height: 100vh;
            height: 100dvh; 
            display: flex;
            justify-content: center;
            align-items: center;
            overflow: hidden;
            background-image: 
                linear-gradient(var(--grid-line) 1px, transparent 1px),
                linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
            background-size: 40px 40px;
            touch-action: none; 
        }

        .main-container {
            display: flex;
            align-items: flex-start;
            justify-content: center;
            gap: 20px;
            padding: 20px;
            max-width: 1200px;
            width: 100%;
            height: 100%;
            box-sizing: border-box;
        }

        .side-panel {
            flex: 1;
            background: var(--panel-bg);
            border: 1px solid rgba(0, 243, 255, 0.3);
            border-radius: 8px;
            padding: 20px;
            box-shadow: 0 0 15px rgba(0, 243, 255, 0.1);
            backdrop-filter: blur(5px);
            display: flex;
            flex-direction: column;
            gap: 20px;
            min-width: 200px;
            max-width: 300px;
            height: 740px; 
            position: relative;
            transition: all 0.3s ease;
        }

        .left-panel { text-align: left; }
        .right-panel { text-align: right; }

        .game-title {
            font-size: 2.5rem;
            font-weight: 900;
            line-height: 1;
            margin: 0 0 10px 0;
            color: var(--neon-pink);
            text-shadow: 0 0 15px var(--neon-pink);
            font-style: italic;
            border-bottom: 2px solid var(--neon-pink);
            padding-bottom: 15px;
        }

        .game-title span {
            display: inline-block;
            margin-top: 8px;
            font-size: 1.35rem;
            color: var(--neon-blue);
            text-shadow: 0 0 12px var(--neon-blue);
            font-style: normal;
        }

        .story-text {
            font-size: 0.8rem;
            color: #aaa;
            line-height: 1.5;
            margin-bottom: 20px;
        }

        .controls-box h3 {
            color: var(--neon-yellow);
            margin: 0 0 10px 0;
            text-shadow: 0 0 5px var(--neon-yellow);
        }

        .control-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 8px;
            font-size: 0.9rem;
            color: #ddd;
        }

        .key-badge {
            display: inline-block;
            border: 1px solid var(--neon-blue);
            background: rgba(0, 243, 255, 0.1);
            padding: 2px 8px;
            border-radius: 4px;
            color: var(--neon-blue);
            font-size: 0.8rem;
            box-shadow: 0 0 5px var(--neon-blue);
            min-width: 20px;
            text-align: center;
        }

        .sub-canvas-container {
            display: flex;
            flex-direction: column;
            align-items: center;
            margin-top: 20px;
            background: rgba(0,0,0,0.3);
            padding: 10px;
            border-radius: 5px;
            border: 1px solid #333;
        }
        
        .sub-canvas-label {
            font-size: 1rem;
            color: var(--neon-yellow);
            margin-bottom: 5px;
            text-shadow: 0 0 5px var(--neon-yellow);
        }

        canvas.sub-canvas {
            background-color: #000;
            border: 1px solid #333;
            box-shadow: inset 0 0 20px rgba(0,0,0,1);
        }

        .game-wrapper {
            position: relative;
            padding: 5px;
            border: 2px solid var(--neon-blue);
            border-radius: 4px;
            box-shadow: 0 0 30px rgba(0, 243, 255, 0.2);
            background: #000;
            transition: transform 0.1s;
        }

        body.puyo-mode .game-wrapper {
            border-color: var(--neon-green);
            box-shadow: 0 0 30px rgba(0, 255, 65, 0.2);
        }

        canvas#tetris {
            display: block;
            background-color: #020205;
            box-shadow: inset 0 0 50px rgba(0,0,0,1);
        }

        .status-block { margin-bottom: 20px; }

        .status-label {
            font-size: 1rem;
            color: #888;
            margin-bottom: 5px;
            text-transform: uppercase;
            letter-spacing: 1px;
        }

        .status-value {
            font-size: 2.5rem;
            font-weight: 700;
            color: var(--neon-green);
            text-shadow: 0 0 10px var(--neon-green);
        }

        .status-value.level { color: var(--neon-yellow); text-shadow: 0 0 10px var(--neon-yellow); }
        .status-value.lines { color: var(--neon-purple); text-shadow: 0 0 10px var(--neon-purple); }

        #overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.85);
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            z-index: 999;
        }

        /* --- 追加: 複数画面用のコンテナ設定 --- */
        .overlay-screen {
            flex-direction: column;
            justify-content: center;
            align-items: center;
            width: 100%;
        }

        .overlay-screen h2 {
            font-size: 3rem;
            color: var(--neon-pink);
            text-shadow: 0 0 20px var(--neon-pink);
            margin-bottom: 34px;
        }

        /* --- 追加: リザルト詳細 --- */

        .title-screen {
            padding: 24px;
            box-sizing: border-box;
        }

        .title-panel,
        .help-panel {
            position: relative;
            width: min(90vw, 520px);
            background: rgba(0, 0, 0, 0.72);
            border: 1px solid rgba(0, 243, 255, 0.45);
            border-radius: 8px;
            box-shadow: 0 0 28px rgba(0, 243, 255, 0.2), inset 0 0 30px rgba(0, 0, 0, 0.65);
            backdrop-filter: blur(6px);
            padding: 34px 42px;
            box-sizing: border-box;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        .title-brand {
            text-align: center;
            margin-bottom: 24px;
        }

        .title-brand h1 {
            margin: 0;
            font-size: 3.7rem;
            line-height: 1;
            color: var(--neon-pink);
            text-shadow: 0 0 18px var(--neon-pink);
            font-style: italic;
        }

        .title-brand p {
            margin: 10px 0 0;
            color: var(--neon-yellow);
            font-size: 0.85rem;
            letter-spacing: 2px;
            text-shadow: 0 0 10px var(--neon-yellow);
        }

        .menu-title {
            font-size: 1.35rem !important;
            color: var(--neon-blue) !important;
            text-shadow: 0 0 14px var(--neon-blue) !important;
            margin: 0 0 22px !important;
        }

        .audio-hint {
            margin-top: 18px;
            font-size: 0.72rem;
            color: #888;
        }

        .help-btn {
            position: absolute;
            top: 14px;
            right: 14px;
            width: 42px !important;
            height: 42px;
            min-width: 0 !important;
            padding: 0 !important;
            border-radius: 50%;
            font-size: 1.35rem !important;
            color: var(--neon-yellow) !important;
            border-color: var(--neon-yellow) !important;
            box-shadow: 0 0 14px rgba(255, 238, 0, 0.35) !important;
        }

        .help-panel {
            width: min(92vw, 680px);
            max-height: 86vh;
            padding: 28px 34px;
        }

        .help-panel h2 {
            font-size: 2.3rem;
            margin: 0 0 20px;
            color: var(--neon-yellow);
            text-shadow: 0 0 18px var(--neon-yellow);
        }

        .help-content {
            width: 100%;
            max-height: 52vh;
            overflow-y: auto;
            color: #ddd;
            font-family: sans-serif;
            line-height: 1.65;
            padding: 18px 20px;
            margin-bottom: 22px;
            background: rgba(0, 0, 0, 0.45);
            border: 1px solid rgba(0, 243, 255, 0.25);
            border-radius: 8px;
            box-sizing: border-box;
        }

        .help-content p { margin: 0 0 16px; }

        .help-section-title {
            margin: 16px 0 8px;
            color: var(--neon-blue);
            font-family: 'Orbitron', sans-serif;
            font-size: 0.9rem;
            text-shadow: 0 0 8px var(--neon-blue);
        }

        .help-content ul {
            margin: 0 0 12px;
            padding-left: 1.2rem;
        }

        .help-content li { margin: 4px 0; }
        .help-tabs { margin: -6px 0 18px; }
        .result-details {
            background: rgba(0, 0, 0, 0.7);
            border: 1px solid var(--neon-blue);
            padding: 20px 40px;
            border-radius: 8px;
            margin-bottom: 30px;
            text-align: left;
            box-shadow: 0 0 15px rgba(0, 243, 255, 0.2);
            font-size: 1.5rem;
            min-width: 250px;
        }
        
        .result-details p {
            margin: 15px 0;
            display: flex;
            justify-content: space-between;
            color: #fff;
            text-shadow: 0 0 5px rgba(255,255,255,0.5);
        }

        /* --- 追加: ランキングリスト --- */
        .ranking-list {
            list-style: none;
            padding: 0;
            margin: 0 0 30px 0;
            width: min(88%, 440px);
            max-width: 440px;
            background: rgba(0, 0, 0, 0.7);
            border: 1px solid var(--neon-yellow);
            border-radius: 8px;
            box-shadow: 0 0 15px rgba(255, 238, 0, 0.2);
        }

        .ranking-list li {
            display: grid;
            grid-template-columns: 48px 1fr 92px;
            align-items: center;
            gap: 12px;
            font-size: 1.5rem;
            padding: 15px 20px;
            border-bottom: 1px solid rgba(255, 238, 0, 0.3);
            color: #fff;
        }
        .ranking-list li:last-child { border-bottom: none; }
        .ranking-list li .rank { color: var(--neon-pink); font-weight: bold; }
        .ranking-list li .score-val { color: var(--neon-green); font-weight: bold; text-shadow: 0 0 10px var(--neon-green); text-align: right;}
        .ranking-list li .mode-label {
            color: var(--neon-blue);
            font-size: 0.75rem;
            text-align: right;
            text-shadow: 0 0 8px var(--neon-blue);
        }

        /* 共通ボタン設定 */
        .mode-buttons {
            display: flex;
            flex-direction: column;
            gap: 20px;
            align-items: center;
        }

        .mode-buttons button {
            width: 260px;
            text-align: center;
        }

        .ranking-tabs {
            display: flex;
            justify-content: center;
            gap: 10px;
            margin: -14px 0 18px;
            flex-wrap: wrap;
        }

        .ranking-tabs button {
            min-width: 104px;
            font-size: 0.9rem !important;
            padding: 8px 14px !important;
            box-shadow: 0 0 10px rgba(0, 243, 255, 0.45) !important;
        }

        .ranking-tabs button.active {
            background: var(--neon-blue) !important;
            color: #000 !important;
            box-shadow: 0 0 24px var(--neon-blue) !important;
        }

        #overlay button {
            background: transparent;
            color: var(--neon-blue);
            font-family: 'Orbitron', sans-serif;
            font-size: 1.5rem;
            padding: 10px 30px;
            border: 2px solid var(--neon-blue);
            cursor: pointer;
            box-shadow: 0 0 15px var(--neon-blue);
            transition: all 0.2s;
        }

        #overlay button:hover {
            background: var(--neon-blue);
            color: #000;
            box-shadow: 0 0 30px var(--neon-blue);
        }

        .sound-control {
            margin-top: auto;
            display: flex;
            align-items: center;
            justify-content: flex-end;
            gap: 10px;
            cursor: pointer;
            color: #888;
        }
        .sound-icon { font-size: 1.5rem; }
        .sound-active { color: var(--neon-blue); text-shadow: 0 0 5px var(--neon-blue); }
        
        .mobile-controls {
            display: none;
            z-index: 20;
        }

        .d-pad-row {
            display: flex;
            justify-content: center;
            gap: 15px;
            margin-bottom: 10px;
            pointer-events: auto;
        }

        .ctrl-btn {
            width: 60px;
            height: 60px;
            background: rgba(0, 243, 255, 0.1);
            border: 2px solid var(--neon-blue);
            border-radius: 50%;
            color: var(--neon-blue);
            display: flex;
            justify-content: center;
            align-items: center;
            font-size: 1.5rem;
            backdrop-filter: blur(4px);
            user-select: none;
            -webkit-user-select: none;
            -webkit-touch-callout: none;
            touch-action: manipulation;
            box-shadow: 0 0 10px rgba(0, 243, 255, 0.2);
        }

        .ctrl-btn:active {
            background: var(--neon-blue);
            color: #000;
        }

        .ctrl-btn.large {
            width: 70px;
            height: 70px;
            border-color: var(--neon-pink);
            color: var(--neon-pink);
            box-shadow: 0 0 10px rgba(255, 0, 255, 0.2);
        }
        .ctrl-btn.large:active {
            background: var(--neon-pink);
            color: #000;
        }


        #mobile-left,
        #mobile-right {
            border-color: var(--neon-blue);
            color: var(--neon-blue);
            box-shadow: 0 0 12px rgba(0, 243, 255, 0.35);
        }

        #mobile-rotate {
            border-color: var(--neon-yellow);
            color: var(--neon-yellow);
            box-shadow: 0 0 12px rgba(255, 238, 0, 0.35);
        }

        #mobile-hold {
            border-color: var(--neon-purple);
            color: var(--neon-purple);
            box-shadow: 0 0 12px rgba(188, 19, 254, 0.35);
        }

        #mobile-drop {
            border-color: var(--neon-pink);
            color: var(--neon-pink);
            box-shadow: 0 0 14px rgba(255, 0, 255, 0.42);
        }

        #mobile-left:active,
        #mobile-right:active {
            background: var(--neon-blue);
            color: #000;
        }

        #mobile-rotate:active {
            background: var(--neon-yellow);
            color: #000;
        }

        #mobile-hold:active {
            background: var(--neon-purple);
            color: #000;
        }
        .shake { animation: shake 0.3s cubic-bezier(.36,.07,.19,.97) both; }
        @keyframes shake {
            10%, 90% { transform: translate3d(-1px, 0, 0); }
            20%, 80% { transform: translate3d(2px, 0, 0); }
            30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
            40%, 60% { transform: translate3d(4px, 0, 0); }
        }

        /* =========================================
           レスポンシブ対応
           ========================================= */
        @media (max-width: 900px) {
            body { 
                flex-direction: column; 
                justify-content: center; 
                padding: env(safe-area-inset-top, 10px) 0 env(safe-area-inset-bottom, 15px) 0;
                box-sizing: border-box;
            }
            
            .main-container {
                flex-direction: column;
                align-items: center; 
                justify-content: center;
                flex: none;      
                height: auto;    
                padding: 0;      
                gap: 8px;
                margin: 0;       
            }
            
            .left-panel { display: none; }
            
            .right-panel {
                order: 1; 
                display: grid;
                grid-template-columns: repeat(5, 1fr); 
                align-items: center; 
                justify-items: center; 
                height: auto;
                padding: 5px; 
                flex: none;
                gap: 0; 
                width: 95%; 
                max-width: 360px;
                box-sizing: border-box; 
            }
            
            .right-panel > div:not(.sub-canvas-container):not(.sound-control) {
                display: contents !important; 
            }
            
            .status-block { 
                margin-bottom: 0; 
                width: 100%;
                display: flex;
                flex-direction: column;
                align-items: center !important; 
                justify-content: center;
            }
            .status-label { font-size: 0.5rem; margin-bottom: 2px; text-align: center; } 
            .status-value { font-size: 1.0rem; line-height: 1; text-align: center; } 
            
            .sub-canvas-container { 
                margin-top: 0; 
                padding: 0; 
                flex-direction: column; 
                gap: 2px; 
                border: none; 
                background: none; 
                width: 100%;
                align-items: center !important; 
                justify-content: center !important;
            }
            .sub-canvas-label { font-size: 0.5rem; margin-bottom: 0; text-align: center; }
            canvas.sub-canvas { width: 30px !important; height: 30px !important; display: block; margin: 0 auto; } 
            
            .sound-control { 
                margin-top: 0; 
                font-size: 0.5rem; 
                gap: 2px; 
                flex-direction: column; 
                padding-bottom: 0; 
                width: 100%;
                align-items: center !important; 
                justify-content: center !important;
                text-align: center;
            }
            .sound-icon { font-size: 1.0rem; line-height: 1; text-align: center; } 
            
            .game-wrapper {
                order: 2;
                flex: none; 
                height: min(73vh, calc(100vh - 155px));   
                height: min(73dvh, calc(100dvh - 155px)); 
                align-self: center; 
                aspect-ratio: 1 / 2; 
                max-width: 100%; 
                display: flex;
                justify-content: center;
                align-items: center;
                padding: 2px;
                margin: 0; 
            }
            
            body.puyo-mode .game-wrapper {
            border-color: var(--neon-green);
            box-shadow: 0 0 30px rgba(0, 255, 65, 0.2);
        }

        canvas#tetris {
                width: 100%;
                height: 100%;
                display: block;
            }
            
            .mobile-controls {
                display: flex;
                flex-direction: row;
                justify-content: center;
                align-items: center;
                gap: 0;
                position: relative;
                width: 98%;
                max-width: 380px;
                flex: none;
                margin-top: 14px;
                padding: 0;
                box-sizing: border-box;
                background-color: transparent;
            }
            
            .d-pad-row {
                display: flex;
                justify-content: center;
                align-items: center;
                gap: 8px;
                margin-bottom: 0;
            }
            
            .ctrl-btn { width: 50px; height: 50px; font-size: 1.05rem; border-width: 1px; flex: 0 0 auto; } 
            .ctrl-btn.large { width: 72px; height: 50px; border-radius: 25px; font-size: 0.78rem; flex: 0 0 auto; } 
            /* スマホ用のリザルト＆ランキングのサイズ調整 */
            .overlay-screen h2 { font-size: 2rem; margin-bottom: 26px; }
            .title-screen { padding: 14px; }
            .title-panel { width: 92vw; padding: 24px 22px 22px; }
            .title-brand { margin-bottom: 18px; }
            .title-brand h1 { font-size: clamp(2rem, 11vw, 2.45rem); }
            .title-brand p { font-size: 0.58rem; letter-spacing: 1.4px; }
            .menu-title { font-size: 1rem !important; margin-bottom: 16px !important; }
            .help-btn { top: 10px; right: 10px; width: 38px !important; height: 38px; font-size: 1.1rem !important; }
            .audio-hint { margin-top: 12px; font-size: 0.62rem; }
            .result-details { padding: 15px 25px; font-size: 1.2rem; min-width: 200px; }
            .ranking-list { width: 92%; max-width: 340px; }
            .ranking-list li { grid-template-columns: 34px 1fr 58px; gap: 8px; font-size: 1.0rem; padding: 10px 12px; }
            .ranking-list li .mode-label { font-size: 0.55rem; }
            .mode-buttons { gap: 13px; }
            .mode-buttons button { width: min(76vw, 240px); min-width: 0; }
            .ranking-tabs { gap: 8px; margin: -8px 0 16px; width: 92%; }
            .ranking-tabs button { min-width: 86px; flex: 1 1 86px; font-size: 0.72rem !important; padding: 8px 6px !important; }
            .help-panel { width: 92vw; max-height: 86vh; padding: 22px 18px; }
            .help-panel h2 { font-size: 1.55rem; margin-bottom: 16px; }
            .help-content { max-height: min(48vh, 360px); max-height: min(48dvh, 360px); padding: 14px 15px; font-size: 0.9rem; }
            .help-section-title { font-size: 0.78rem; }
            #overlay button { font-size: 1.05rem; padding: 8px 18px; }
        }




