* {
            margin: 0; padding: 0; box-sizing: border-box;
            user-select: none; -webkit-tap-highlight-color: transparent;
            touch-action: manipulation;
            image-rendering: pixelated; image-rendering: -moz-crisp-edges; image-rendering: crisp-edges;
        }
        :root {
            --gb-darkest: #0f380f; --gb-dark: #306230; --gb-light: #8bac0f; --gb-lightest: #9bbc0f;
            --gb-background: #c3dd84; --gb-case: #d3d0c8; --gb-case-dark: #8b8b83; --gb-case-shadow: #6b6b63;
            --gb-button-a: #ab3e41; --gb-button-b: #ab3e41; --gb-button-dark: #433634; --gb-screen-frame: #403934;
            --button-size: clamp(50px, 15vw, 80px); --dpad-size: clamp(140px, 30vw, 200px);
            --action-button-size: clamp(60px, 13vw, 80px); --menu-button-width: clamp(60px, 15vw, 100px);
            --menu-button-height: clamp(20px, 4vw, 30px);
            --controls-spacing: clamp(20px, 5vw, 40px);
            --hc-mode: 0; --hc-dark: #000000; --hc-light: #ffffff;
        }
        .high-contrast {
            --gb-darkest: var(--hc-dark); --gb-dark: var(--hc-dark); --gb-light: var(--hc-light);
            --gb-lightest: var(--hc-light); --gb-background: var(--hc-light); --hc-mode: 1;
             --gb-button-a: var(--hc-dark); --gb-button-b: var(--hc-dark); --gb-button-dark: var(--hc-light);
             --gb-case: var(--hc-dark); --gb-screen-frame: var(--hc-dark); --gb-case-shadow: var(--hc-dark);
        }
        @font-face {
            font-family: 'PressStart2P';
            src: url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');
            font-display: swap;
        }
        body {
            background-color: #333;
            font-family: 'PressStart2P', monospace, sans-serif;
            display: flex; flex-direction: column; justify-content: center; align-items: center;
            min-height: 100vh;
             height: 100vh;
             overflow: hidden; position: fixed; width: 100%; touch-action: none;
        }
        #game-wrapper { width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 10px; }
        #gameboy-container { width: 100%; max-width: 500px; max-height: 100%; display: flex; flex-direction: column; align-items: center; }
        #screen-container {
            width: 100%; position: relative; aspect-ratio: 10/9; margin-bottom: var(--controls-spacing);
            border-radius: 12px 12px 50px 12px; overflow: hidden; background-color: var(--gb-case);
            box-shadow: inset -3px -3px 5px var(--gb-case-shadow), inset 3px 3px 5px rgba(255, 255, 255, 0.3), 0 10px 20px rgba(0, 0, 0, 0.4);
        }
        .gameboy-mode #screen-container { padding: 35px 25px 60px 25px; background-image: radial-gradient(circle at 10% 10%, rgba(255,255,255,0.1) 10%, transparent 10.5%), radial-gradient(circle at 90% 5%, rgba(255,255,255,0.1) 10%, transparent 10.5%), linear-gradient(45deg, rgba(0,0,0,0.05) 0%, transparent 100%); }
        .canvas-mode #screen-container { background-color: var(--gb-darkest); padding: 5px; border-radius: 10px; box-shadow: none; aspect-ratio: 160/144; }
        #game-screen {
            background-color: var(--gb-lightest); border: 10px solid var(--gb-screen-frame); border-radius: 5px;
            margin-bottom: 10px; position: relative; width: 100%; height: 100%; overflow: hidden;
            box-shadow: inset 0 0 10px rgba(0,0,0,0.4);
        }
        .high-contrast #game-screen { background-color: var(--hc-light); border-color: var(--hc-dark); }        .canvas-mode #game-screen { border: 2px solid var(--gb-dark); margin-bottom: 0; }
        .high-contrast.canvas-mode #game-screen { border-color: var(--hc-dark); }
        #game-canvas {
            position: absolute; top: 0; left: 0; width: 100%; height: 100%;
            background-color: transparent;
            display: none;
        }
        .nintendo-logo { color: #8b0000; text-align: center; font-weight: bold; font-style: italic; margin-bottom: 8px; font-size: min(2vw, 12px); letter-spacing: -0.3px; position: relative; font-family: monospace; }
        .nintendo-logo::after { content: "®"; position: absolute; font-size: 50%; top: 0; margin-left: 2px; }
        .high-contrast .nintendo-logo { color: var(--hc-dark); }
        .gameboy-text { text-align: center; font-weight: bold; font-size: min(5vw, 20px); color: #5a0000; margin-bottom: 15px; letter-spacing: -1px; text-transform: uppercase; font-family: monospace, Arial, sans-serif; text-shadow: 1px 1px 0 rgba(255,255,255,0.5); }
        .high-contrast .gameboy-text { color: var(--hc-dark); text-shadow: none; }
        .canvas-mode .nintendo-logo, .canvas-mode .gameboy-text { display: none; }
        #controls { display: flex; flex-direction: column; align-items: center; width: 100%; max-width: 600px; gap: var(--controls-spacing); }
        #main-controls { display: flex; justify-content: space-between; width: 100%; align-items: center; padding: 0 10px; }
        #d-pad {
            position: relative;
            width: var(--dpad-size); height: var(--dpad-size);
        }
        .gameboy-mode #d-pad { background-color: rgba(0,0,0,0.05); border-radius: 50%; }
        .d-button {
            position: absolute;
            background-color: #333;
            box-shadow: 0 4px 8px rgba(0,0,0,0.5), inset -2px -2px 3px rgba(0,0,0,0.5), inset 2px 2px 3px rgba(255,255,255,0.1);
            display: flex; justify-content: center; align-items: center;
            color: #666; font-weight: bold; font-size: calc(var(--dpad-size) * 0.15);
            -webkit-user-select: none; user-select: none;
            border: none; transition: all 0.05s ease;
            z-index: 1;
        }
        #btn-up { top: 0; left: calc(50% - 16.66%); width: 33.33%; height: 40%; border-radius: 5px 5px 0 0; padding-bottom: 5%; }
        #btn-down { bottom: 0; left: calc(50% - 16.66%); width: 33.33%; height: 40%; border-radius: 0 0 5px 5px; padding-top: 5%; }
        #btn-left { top: calc(50% - 16.66%); left: 0; width: 40%; height: 33.33%; border-radius: 5px 0 0 5px; padding-right: 5%; }
        #btn-right { top: calc(50% - 16.66%); right: 0; width: 40%; height: 33.33%; border-radius: 0 5px 5px 0; padding-left: 5%; }
        #dpad-center {
            position: absolute;
            top: calc(50% - 16.66%); left: calc(50% - 16.66%);
            width: 33.33%; height: 33.33%;
            background-color: #333;
            box-shadow: inset 1px 1px 3px rgba(0,0,0,0.5);
            border-radius: 50%;
            z-index: 0;
        }
        #action-buttons { display: flex; gap: calc(var(--action-button-size) * 0.5); }
        .action-button {
            background-color: var(--gb-button-a); color: var(--gb-button-dark);
            width: var(--action-button-size); height: var(--action-button-size); border-radius: 50%;
            display: flex; justify-content: center; align-items: center; font-weight: bold;
            font-size: calc(var(--action-button-size) * 0.4); border: none;
            box-shadow: 0 4px 8px rgba(0,0,0,0.5), inset -3px -3px 5px rgba(0,0,0,0.3), inset 3px 3px 5px rgba(255,255,255,0.2);            text-shadow: 1px 1px 1px rgba(0,0,0,0.5); transition: all 0.05s ease; position: relative;
        }
        .gameboy-mode .action-button::after {
            content: ""; position: absolute; width: 90%; height: 90%; border-radius: 50%;
            background: radial-gradient(circle at 70% 70%, rgba(255,255,255,0.2) 0%, transparent 60%);
        }
        .high-contrast .action-button::after { display: none; }
        #menu-buttons { display: flex; justify-content: center; width: 100%; gap: calc(var(--menu-button-width) * 0.5); }
        .menu-container { display: flex; flex-direction: column; align-items: center; gap: 5px; }
        .menu-button {
            background-color: #555; width: var(--menu-button-width); height: var(--menu-button-height);
            border-radius: 10px; transform: rotate(-25deg);
            box-shadow: 0 3px 5px rgba(0,0,0,0.5), inset -2px -2px 3px rgba(0,0,0,0.3), inset 2px 2px 3px rgba(255,255,255,0.1);
            border: none; transition: all 0.05s ease;
        }
        .button-label { font-size: min(2.5vw, 10px); text-align: center; font-weight: bold; font-family: monospace; text-transform: uppercase; }
        .gameboy-mode .button-label {
            color: var(--gb-case-shadow); text-shadow: 0.5px 0.5px 0 rgba(255,255,255,0.5); transform: rotate(-15deg);
        }
        .canvas-mode .d-button, .high-contrast .d-button,
        .canvas-mode #dpad-center, .high-contrast #dpad-center,
        .canvas-mode .action-button, .high-contrast .action-button,
        .canvas-mode .menu-button, .high-contrast .menu-button {
            background-color: var(--gb-dark);
            color: var(--gb-lightest);
            box-shadow: 0 2px 4px rgba(0,0,0,0.3);
            text-shadow: none;
            transform: none;
            border-radius: 4px;
        }
        .canvas-mode .action-button, .high-contrast .action-button { border-radius: 50%; }
        .canvas-mode #dpad-center, .high-contrast #dpad-center { border-radius: 50%; }
        .canvas-mode #btn-up { border-radius: 4px 4px 0 0; }
        .canvas-mode #btn-down { border-radius: 0 0 4px 4px; }
        .canvas-mode #btn-left { border-radius: 4px 0 0 4px; }
        .canvas-mode #btn-right { border-radius: 0 4px 4px 0; }
        .canvas-mode .button-label, .high-contrast .button-label {
            transform: none; color: var(--gb-lightest); text-shadow: none;
        }
        #a11y-controls { position: absolute; top: 10px; right: 10px; display: flex; gap: 10px; z-index: 100; }
        .a11y-button { width: 40px; height: 40px; border-radius: 50%; background-color: rgba(255,255,255,0.2); border: 2px solid #fff; color: #fff; font-size: 20px; display: flex; justify-content: center; align-items: center; cursor: pointer; transition: background-color 0.2s ease; font-family: sans-serif; }
        .a11y-button:hover { background-color: rgba(255,255,255,0.3); }
        #start-screen, #game-over-screen, #pause-screen, #game-selection-screen {
            position: absolute; top: 0; left: 0; width: 100%; height: 100%;
            display: flex; flex-direction: column; justify-content: center; align-items: center;
            background-color: var(--gb-lightest); z-index: 10; text-align: center; padding: 20px;
            font-family: 'PressStart2P', monospace, sans-serif;
        }
        .high-contrast #start-screen, .high-contrast #game-over-screen, .high-contrast #pause-screen, .high-contrast #game-selection-screen { background-color: var(--hc-light); }
        #start-screen { display: flex; }        #game-over-screen, #pause-screen, #game-selection-screen { display: none; }
        .screen-title { font-size: min(6vw, 18px); color: var(--gb-darkest); margin-bottom: 20px; text-transform: uppercase; letter-spacing: -1px; text-shadow: 1px 1px 0 var(--gb-light); }
        .high-contrast .screen-title { color: var(--hc-dark); text-shadow: none; }
        .screen-text { font-size: min(4vw, 12px); color: var(--gb-darkest); margin-bottom: 15px; font-family: monospace, sans-serif; }
        .high-contrast .screen-text { color: var(--hc-dark); }
        .blink { animation: blink 1s infinite; }
        @keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
        #game-list { list-style: none; padding: 0; margin: 20px 0; font-size: min(5vw, 16px); color: var(--gb-darkest); font-family: monospace, sans-serif; }
        .high-contrast #game-list { color: var(--hc-dark); }
        .game-option { margin: 10px 0; padding: 5px 10px; cursor: pointer; transition: background-color 0.1s; border: 2px solid transparent; text-transform: uppercase; }
        .game-option.selected { background-color: var(--gb-dark); color: var(--gb-lightest); border: 2px dashed var(--gb-lightest); }
        .game-option.selected::before { content: '▶ '; font-weight: normal; display: inline-block; width: 1.2em; text-align: right; margin-right: 3px; }
        .high-contrast .game-option.selected { background-color: var(--hc-dark); color: var(--hc-light); border-color: var(--hc-light); }
        .high-contrast .game-option.selected::before { color: var(--hc-light); }
        .active { filter: brightness(0.8); transform: scale(0.95); }
        .key-hints { position: absolute; bottom: 5px; left: 5px; font-size: 9px; color: var(--gb-darkest); background-color: rgba(139, 172, 15, 0.7); padding: 3px 5px; border-radius: 4px; font-family: monospace, sans-serif; z-index: 5; }
        .high-contrast .key-hints { color: var(--hc-dark); background-color: rgba(255, 255, 255, 0.5); }
        #view-toggle { position: absolute; top: 10px; left: 10px; z-index: 100; background-color: rgba(255,255,255,0.2); border: 2px solid #fff; color: #fff; padding: 5px 10px; border-radius: 20px; font-size: 11px; cursor: pointer; transition: background-color 0.2s ease; font-family: monospace, sans-serif; }
        #view-toggle:hover { background-color: rgba(255,255,255,0.3); }
        .large-text .screen-title { font-size: min(8vw, 24px); }
        .large-text .screen-text, .large-text #game-list { font-size: min(6vw, 18px); }
        .large-text .button-label { font-size: min(4vw, 14px); }
        #toast-container { position: fixed; bottom: 20px; left: 0; right: 0; display: flex; flex-direction: column; align-items: center; pointer-events: none; z-index: 1000; }
        .toast { background-color: rgba(15, 56, 15, 0.85); color: var(--gb-lightest); border: 1px solid var(--gb-light); padding: 8px 15px; border-radius: 5px; margin: 5px; opacity: 0; transition: opacity 0.3s ease-out, transform 0.3s ease-out; font-family: monospace, sans-serif; font-size: 11px; transform: translateY(20px); }
        .toast.show { opacity: 1; transform: translateY(0); }
        .high-contrast .toast { background-color: rgba(0,0,0,0.85); color: #fff; border-color: #fff;}
        .gameboy-details { position: absolute; width: 100%; height: 100%; pointer-events: none; }
        .gameboy-speaker { position: absolute; bottom: 15%; right: 10%; width: 25%; height: 8%; display: flex; flex-wrap: wrap; justify-content: space-between; align-content: space-between; transform: rotate(-15deg); }
        .speaker-hole { width: 10%; padding-bottom: 10%; height: 0; background-color: var(--gb-case-shadow); border-radius: 50%; opacity: 0.7; }
        .high-contrast .speaker-hole { background-color: var(--hc-dark); }
        .gameboy-power { position: absolute; top: 20px; left: 20px; width: 8px; height: 8px; border-radius: 50%; background-color: #a00; box-shadow: 0 0 3px rgba(0,0,0,0.5); transition: background-color 0.3s, box-shadow 0.3s; }
        .gameboy-power.on { background-color: #f00; box-shadow: 0 0 5px 2px rgba(255,0,0,0.5); }
        .gameboy-power::after { content: "POWER"; position: absolute; font-size: 7px; color: var(--gb-case-shadow); top: 10px; left: 50%; transform: translateX(-50%); white-space: nowrap; font-family: monospace, sans-serif; }
        .high-contrast .gameboy-power::after { color: var(--hc-dark); }
        .canvas-mode .gameboy-details { display: none; }
        @media (max-width: 767px) {
             :root { --dpad-size: clamp(140px, 38vw, 180px); --action-button-size: clamp(60px, 18vw, 80px); --menu-button-width: clamp(60px, 20vw, 100px); }
             #controls { gap: 15px; }
        }
        @media (min-width: 768px) and (max-width: 1024px) {
              :root { --dpad-size: clamp(160px, 25vw, 200px); --action-button-size: clamp(70px, 14vw, 90px); }
        }
        @media (max-height: 500px) and (orientation: landscape) {
             #game-wrapper { flex-direction: row; gap: 10px; padding: 5px; }
             #gameboy-container { width: 50%; max-width: none; }
             #controls { width: 45%; gap: 10px; }
             :root { --dpad-size: clamp(110px, 22vh, 140px); --action-button-size: clamp(45px, 10vh, 60px); --menu-button-width: clamp(45px, 10vh, 65px); --menu-button-height: clamp(15px, 3.5vh, 20px); --controls-spacing: 10px;}
             #main-controls { flex-direction: column; align-items: center; gap: 15px; padding: 0; }
             #menu-buttons { flex-direction: row; gap: 15px; margin-top: 10px;}
             .menu-button, .button-label { transform: none; }             .gameboy-mode .menu-button { transform: rotate(-25deg); }
             .gameboy-mode .button-label { transform: rotate(-15deg); }
             .canvas-mode .menu-button, .canvas-mode .button-label { transform: none; }
        }
        #loading-placeholder {
            position: absolute; inset: 0; background: var(--gb-lightest); color: var(--gb-darkest);
            display: none; justify-content: center; align-items: center; font-family: monospace, sans-serif;
            font-size: 14px; z-index: 11; text-align: center; padding: 10px;
        }
        .high-contrast #loading-placeholder { background: var(--hc-light); color: var(--hc-dark); }
        .tetris-grid-line { stroke: var(--gb-light); stroke-width: 0.5; }
        .high-contrast .tetris-grid-line { stroke: var(--hc-dark); }