/* Enhanced VHS-Era Dystopian Styling for BARCODE: System Override */

/* Touch controls are DOM overlays. Native canvas fitting and game drawing stay
   with their existing owners; no filters, animation, or full-screen panels. */
.touch-controls {
    position: fixed;
    inset: 0;
    z-index: 100010;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
    color: #e4f3ef;
    font-family: Oxanium, system-ui, sans-serif;
    --touch-gap: 8px;
    --touch-edge: 12px;
    --touch-size: 48px;
    --touch-stick-width: 144px;
    --touch-tone: #a0ead2;
    --touch-tone-rgb: 160, 234, 210;
}
.touch-controls[hidden], .touch-controls [hidden] { display: none !important; }
.touch-actions, .touch-utilities, .touch-gears, .touch-tools, .touch-joystick {
    pointer-events: auto;
    touch-action: none;
}
.touch-actions {
    position: absolute;
    right: max(var(--touch-edge), env(safe-area-inset-right));
    bottom: max(var(--touch-edge), env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(3, minmax(64px, 1fr));
    gap: var(--touch-gap);
    width: min(300px, calc(100vw - 24px));
    pointer-events: none;
}
.touch-button {
    pointer-events: auto;
    min-width: 44px;
    min-height: var(--touch-size);
    position: relative;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 7px 9px;
    border: 1px solid rgba(var(--touch-tone-rgb), .38);
    border-radius: 14px;
    background: rgba(6, 17, 26, .72);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), 0 2px 0 rgba(0, 0, 0, .16);
    color: #d9eae5;
    font: 600 12px/1.2 Oxanium, system-ui, sans-serif;
    touch-action: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.touch-icon, .touch-label, .touch-status { pointer-events: none; }
.touch-status:empty { display: none; }
.touch-status {
    position: absolute;
    top: -3px;
    right: -4px;
    padding: 2px 4px;
    border-radius: 6px;
    background: #152a30;
    color: #e4f3ef;
    font-size: 9px;
    line-height: 1;
}
.touch-icon { font-size: 22px; line-height: 1; color: var(--touch-tone); }
.touch-label { font-size: 11px; line-height: 1.15; text-align: center; }
.touch-button[data-tone="a"] { --touch-tone: #a0ead2; --touch-tone-rgb: 160, 234, 210; }
.touch-button[data-tone="b"] { --touch-tone: #f2c38b; --touch-tone-rgb: 242, 195, 139; }
.touch-button[data-tone="x"] { --touch-tone: #a4d4e9; --touch-tone-rgb: 164, 212, 233; }
.touch-button[data-tone="y"] { --touch-tone: #e6d993; --touch-tone-rgb: 230, 217, 147; }
.touch-button[data-tone="neutral"] { --touch-tone: #b5c6c9; --touch-tone-rgb: 181, 198, 201; }
.touch-button.is-held, .touch-button.is-latched, .touch-button.is-selected,
.touch-button[aria-pressed="true"] {
    border-color: rgba(var(--touch-tone-rgb), .88);
    background: rgba(var(--touch-tone-rgb), .18);
    color: #f1fff8;
    box-shadow: inset 0 0 0 1px rgba(var(--touch-tone-rgb), .2);
}
.touch-button:disabled { opacity: .5; cursor: default; }
.touch-button[data-active="true"] { opacity: .85; border-color: rgba(var(--touch-tone-rgb), .8); }
.touch-button:focus-visible { outline: 2px solid #f2c38b; outline-offset: 3px; }
.touch-icon-only .touch-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}
.touch-gameplay .touch-actions {
    width: 112px;
    grid-template-columns: repeat(2, 52px);
    grid-template-rows: 52px 52px 64px;
    justify-content: end;
    align-items: end;
}
.touch-gameplay .touch-actions > .touch-button {
    width: 52px;
    height: 52px;
    min-height: 52px;
    border-radius: 50%;
    padding: 4px;
}
.touch-gameplay .touch-actions > .touch-primary,
.touch-gameplay .touch-actions > [data-kind="primary"] {
    grid-column: 1 / -1;
    justify-self: end;
    width: 64px;
    height: 64px;
    min-height: 64px;
    border-color: rgba(var(--touch-tone-rgb), .65);
    background: rgba(8, 24, 31, .68);
}
.touch-button[data-ready="true"] {
    border-color: rgba(var(--touch-tone-rgb), .96);
    background: rgba(var(--touch-tone-rgb), .28);
    color: #f1fff8;
    box-shadow: inset 0 0 0 1px rgba(var(--touch-tone-rgb), .32);
}
.touch-primary .touch-icon, [data-kind="primary"] .touch-icon { font-size: 26px; }
.touch-primary .touch-label, [data-kind="primary"] .touch-label { font-size: 11px; font-weight: 700; }
.touch-road .touch-actions { width: 112px; grid-template-columns: 48px 58px; grid-template-rows: 44px 44px 64px; gap: 6px; }
.touch-road .touch-actions > .touch-button { width: 44px; height: 44px; min-height: 44px; justify-self: end; }
.touch-road .touch-actions > [data-touch-action="road:beat"] { grid-row: 3; grid-column: 1 / -1; width: 64px; height: 64px; min-height: 64px; }
.touch-road .touch-actions > [data-touch-action="road_attack"] { grid-row: 2; grid-column: 1; }
.touch-road .touch-actions > [data-touch-action="road_defend"] { grid-row: 2; grid-column: 2; }
.touch-road .touch-actions > [data-touch-action="road_turbo"] { grid-row: 1; grid-column: 1; }
.touch-road .touch-actions > [data-touch-action="road_disrupt"],
.touch-road .touch-actions > [data-touch-action="road_echo"] { grid-row: 1; grid-column: 2; }
.touch-road .touch-actions .touch-icon { font-size: 18px; }
.touch-road .touch-actions .touch-label { font-size: 10px; }
.touch-road .touch-actions > [data-touch-action="road:beat"] .touch-icon { font-size: 26px; }
.touch-gameplay .touch-actions > [data-touch-action="jump"] { grid-row: 3; }
.touch-gameplay .touch-actions > [data-touch-action="primary"] { grid-row: 2; grid-column: 2; }
.touch-gameplay .touch-actions > [data-touch-action="rhythm_mode"] { grid-row: 2; grid-column: 1; }
.touch-gameplay .touch-actions > [data-touch-action="interact"] { grid-row: 1; grid-column: 2; }
.touch-gameplay .touch-actions > [data-touch-action="inspect"] { grid-row: 1; grid-column: 1; }
.touch-secondary .touch-icon, [data-kind="secondary"] .touch-icon { font-size: 20px; }
.touch-secondary .touch-label, [data-kind="secondary"] .touch-label { font-size: 10px; }
.touch-utilities {
    position: absolute;
    top: max(10px, env(safe-area-inset-top));
    right: max(var(--touch-edge), env(safe-area-inset-right));
    display: flex;
    gap: 8px;
}
.touch-utilities .touch-button {
    width: 46px;
    height: 46px;
    min-height: 46px;
    padding: 4px;
    border-radius: 50%;
    background: rgba(5, 15, 23, .56);
}
.touch-utilities .touch-label { font-size: 9px; }
.touch-utilities .touch-icon { font-size: 19px; }
.touch-gears {
    position: absolute;
    left: calc(max(var(--touch-edge), env(safe-area-inset-left)) + var(--touch-stick-width));
    bottom: calc(max(var(--touch-edge), env(safe-area-inset-bottom)) + 24px);
    display: grid;
    grid-template-columns: 44px;
    gap: 6px;
}
.touch-gears .touch-button {
    width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 3px;
    border-radius: 50%;
    background: rgba(5, 16, 24, .6);
}
.touch-gears .touch-icon { font-size: 21px; }
.touch-gears .touch-label { font-size: 9px; }
.touch-tools {
    position: absolute;
    right: max(var(--touch-edge), env(safe-area-inset-right));
    bottom: max(var(--touch-edge), env(safe-area-inset-bottom));
    display: grid;
    grid-template-columns: repeat(2, minmax(44px, 1fr));
    justify-items: center;
    gap: 6px;
    width: 136px;
    max-height: min(188px, calc(100vh - 96px));
    overflow-y: auto;
    padding: 6px;
    border: 1px solid rgba(181, 198, 201, .16);
    border-radius: 22px;
    background: rgba(4, 13, 21, .46);
    overscroll-behavior: contain;
}
.touch-tools .touch-button {
    width: 52px;
    height: 52px;
    min-height: 52px;
    border-radius: 50%;
    padding: 4px;
}
.touch-tools .touch-icon { font-size: 20px; }
.touch-tools .touch-label { font-size: 10px; }
.touch-tools-open .touch-actions { display: none; }
.touch-readout {
    position: absolute;
    right: max(var(--touch-edge), env(safe-area-inset-right));
    bottom: calc(max(var(--touch-edge), env(safe-area-inset-bottom)) + 124px);
    width: min(300px, calc(100vw - 24px));
    max-height: min(240px, calc(100vh - 210px));
    overflow-y: auto;
    padding: 12px 14px;
    border: 1px solid rgba(160, 234, 210, .25);
    border-radius: 16px;
    background: rgba(5, 15, 24, .86);
    font-size: 16px;
    line-height: 1.45;
    white-space: pre-line;
    overflow-wrap: anywhere;
    pointer-events: auto;
    touch-action: pan-y;
    user-select: text;
    -webkit-user-select: text;
}
.touch-joystick {
    position: absolute;
    left: max(var(--touch-edge), env(safe-area-inset-left));
    bottom: max(var(--touch-edge), env(safe-area-inset-bottom));
    width: var(--touch-stick-width);
    height: 144px;
    background: transparent;
}
.touch-stick-base {
    position: absolute;
    left: 50%; top: 50%;
    width: 108px; height: 108px;
    transform: translate(-50%, -50%);
    border: 1px solid rgba(160, 234, 210, .32);
    border-radius: 50%;
    background: rgba(6, 17, 25, .3);
    pointer-events: none;
}
.touch-stick-thumb {
    position: absolute;
    left: 50%; top: 50%;
    width: 48px; height: 48px;
    transform: translate(-50%, -50%);
    border: 1px solid rgba(176, 236, 216, .65);
    border-radius: 50%;
    background: rgba(69, 117, 103, .5);
}
.touch-joystick.is-held .touch-stick-base { border-color: rgba(160, 234, 210, .54); }
.touch-joystick.is-held .touch-stick-thumb { background: rgba(91, 154, 133, .62); }
.touch-stick-label {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    text-align: center;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .1em;
    color: #b8d5ca;
    pointer-events: none;
}
.touch-hint {
    position: absolute;
    bottom: max(5px, env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    line-height: 1.2;
    text-align: center;
    color: #b8ccc7;
    pointer-events: none;
}
.touch-keypad .touch-actions { grid-template-columns: repeat(3, 1fr); width: 228px; }
.touch-keypad .touch-button { font-size: 19px; min-height: 48px; }
.touch-keypad .touch-label { font-size: 16px; }
@media (orientation: portrait) {
    .touch-actions { left: 12px; right: 12px; width: auto; grid-template-columns: repeat(3, 1fr); }
    .touch-gameplay .touch-actions { left: auto; right: max(var(--touch-edge), env(safe-area-inset-right)); width: 112px; }
    .touch-road .touch-actions { width: 112px; }
    .touch-readout { left: 12px; right: 12px; width: auto; }
    .touch-keypad .touch-actions { left: 50%; right: auto; transform: translateX(-50%); width: min(276px, calc(100vw - 24px)); }
    .touch-hint { bottom: calc(max(var(--touch-edge), env(safe-area-inset-bottom)) + 154px); left: 84px; width: 144px; }
}
@media (orientation: landscape) {
    .touch-utilities { flex-direction: column; }
}
@media (orientation: landscape) and (max-aspect-ratio: 21/10) {
    /* With no wide side gutter, Pause sits above the left-hand gear pair,
       clear of the native HUD and the active right-thumb skill cluster. */
    .touch-road .touch-utilities {
        top: auto;
        right: auto;
        left: calc(max(var(--touch-edge), env(safe-area-inset-left)) + var(--touch-stick-width));
        bottom: calc(max(var(--touch-edge), env(safe-area-inset-bottom)) + 124px);
    }
}
@media (max-height: 450px) and (orientation: landscape) {
    .touch-controls { --touch-size: 44px; }
    .touch-actions { bottom: max(8px, env(safe-area-inset-bottom)); }
    .touch-joystick { height: 136px; }
    .touch-hint { display: none; }
    .touch-readout { bottom: calc(max(8px, env(safe-area-inset-bottom)) + 106px); font-size: 14px; padding: 8px 10px; max-height: calc(100vh - 172px); }
    .touch-button { font-size: 11px; padding: 5px; }
}
@media (max-width: 360px) and (orientation: portrait) {
    .touch-controls { --touch-stick-width: 128px; --touch-edge: 10px; }
    .touch-gameplay .touch-actions { right: max(10px, env(safe-area-inset-right)); }
    .touch-gears { left: calc(max(10px, env(safe-area-inset-left)) + var(--touch-stick-width)); }
    .touch-readout { left: 10px; right: 10px; }
}
@media (orientation: portrait) and (max-height: 700px) {
    .touch-hint { display: none; }
    .touch-tools { max-height: 166px; }
    .touch-tools .touch-button { width: 44px; height: 44px; min-height: 44px; }
    .touch-tools .touch-icon { font-size: 17px; }
    .touch-tools .touch-label { font-size: 9px; }
}

/* Full viewport game container - CRITICAL FIX for both modes */
.game-container {
    width: 100vw;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    background: #000;
    overflow: hidden;
}

/* Canvas maximization - CRITICAL FIX for proper scaling */
#gameCanvas {
    display: block;
    flex: 1;
    width: 100%;
    height: 100%;
    
    /* CRITICAL: Use max dimensions for aspect ratio */
    max-width: 100vw;
    max-height: calc(100vh - 120px); /* Account for topbar + hint (60px + 60px) */
    
    /* Center the canvas within its container */
    margin: 0 auto;
    
    /* Maintain aspect ratio */
    object-fit: contain;
    
    /* High quality rendering */
    image-rendering: auto;
    image-rendering: smooth;
    image-rendering: -webkit-optimize-contrast;
    
    /* Prevent stretching */
    background: #000;
    
    /* Ensure proper sizing in flex container */
    min-height: 0;
}

/* Glitch Text Effects */
.glitch-text {
    position: relative;
    color: #00ffff;
    font-weight: 900;
    text-shadow: 
        2px 2px 0 #ff00ff,
        -2px -2px 0 #00ffff;
    animation: glitch-text 2s infinite;
}

@keyframes glitch-text {
    0% { transform: translate(0); }
    20% { transform: translate(-2px, 2px); }
    40% { transform: translate(-2px, -2px); }
    60% { transform: translate(2px, 2px); }
    80% { transform: translate(2px, -2px); }
    100% { transform: translate(0); }
}

/* Holographic Menu Styles */
.hologram {
    background: linear-gradient(45deg, 
        rgba(0,255,255,0.1) 0%, 
        rgba(255,0,255,0.1) 50%, 
        rgba(0,255,255,0.1) 100%);
    border: 2px solid transparent;
    border-image: linear-gradient(45deg, #00ffff, #ff00ff, #00ffff) 1;
    backdrop-filter: blur(10px);
    box-shadow: 
        0 0 20px rgba(0,255,255,0.5),
        inset 0 0 20px rgba(255,0,255,0.1);
}

/* Data Stream Animation */
.data-stream {
    position: fixed;
    top: -100px;
    font-family: 'Share Tech Mono', monospace;
    font-size: 12px;
    color: #00ff00;
    text-shadow: 0 0 5px #00ff00;
    animation: data-fall 3s linear infinite;
    pointer-events: none;
    z-index: 999;
}

@keyframes data-fall {
    0% { top: -100px; opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { top: 100vh; opacity: 0; }
}

/* Boss Intro Animation */
.boss-intro {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2000;
    text-align: center;
    animation: boss-zoom 2s ease-out;
}

@keyframes boss-zoom {
    0% { 
        transform: translate(-50%, -50%) scale(0.1);
        opacity: 0;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

.boss-name {
    font-size: 4rem;
    font-weight: 900;
    color: #ff00ff;
    text-shadow: 0 0 20px #ff00ff, 0 0 40px #ff00ff;
    letter-spacing: 4px;
    text-transform: uppercase;
}

.boss-title {
    font-size: 1.5rem;
    color: #00ffff;
    margin-top: 10px;
    letter-spacing: 6px;
}

/* Mixtape Collectible Effect */
.mixtape-collect {
    position: fixed;
    bottom: 100px;
    right: -300px;
    background: linear-gradient(135deg, #ff00ff, #00ffff);
    padding: 20px 30px;
    border-radius: 10px;
    color: #fff;
    font-weight: bold;
    animation: mixtape-slide 3s ease-out;
    z-index: 1500;
}

@keyframes mixtape-slide {
    0% { right: -300px; }
    20% { right: 50px; }
    80% { right: 50px; }
    100% { right: -300px; opacity: 0; }
}

/* Terminal Style */
.terminal {
    background: #000;
    border: 2px solid #00ff00;
    font-family: 'Share Tech Mono', monospace;
    color: #00ff00;
    padding: 20px;
    text-shadow: 0 0 5px #00ff00;
}

.terminal-cursor {
    animation: cursor-blink 1s infinite;
}

@keyframes cursor-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Rhythm Combat UI */
.rhythm-track {
    display: flex;
    gap: 10px;
    padding: 20px;
    background: rgba(0,0,0,0.8);
    border: 2px solid #ff00ff;
    border-radius: 10px;
}

.rhythm-beat {
    width: 60px;
    height: 60px;
    border: 2px solid #00ffff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.1s;
}

.rhythm-beat.active {
    background: radial-gradient(circle, #ff00ff, #00ffff);
    transform: scale(1.2);
    box-shadow: 0 0 20px #ff00ff;
}

/* Dialogue System */
.dialogue-box {
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.9);
    border: 2px solid #00ffff;
    padding: 20px 30px;
    max-width: 800px;
    color: #fff;
    font-family: 'Share Tech Mono', monospace;
    font-size: 16px;
    z-index: 500;
}

.dialogue-choices {
    margin-top: 15px;
    display: flex;
    gap: 15px;
    justify-content: center;
}

.dialogue-choice {
    background: transparent;
    border: 1px solid #ff00ff;
    color: #ff00ff;
    padding: 8px 16px;
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.dialogue-choice:hover {
    background: rgba(255,0,255,0.2);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(255,0,255,0.5);
}

/* Loading Screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 3000;
}

.loading-barcode {
    font-size: 3rem;
    font-weight: 900;
    color: #00ffff;
    letter-spacing: 4px;
    margin-bottom: 30px;
    animation: barcode-scan 2s infinite;
}

@keyframes barcode-scan {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

.loading-progress {
    width: 300px;
    height: 4px;
    background: rgba(255,0,255,0.2);
    border: 1px solid #ff00ff;
    position: relative;
    overflow: hidden;
}

.loading-progress::after {
    content: "";
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, #00ffff, transparent);
    animation: progress-scan 1.5s infinite;
}

@keyframes progress-scan {
    0% { left: -100%; }
    100% { left: 100%; }
}
