/* Base Styles */
* {
    box-sizing: border-box;
    /* Prevent text selection on game elements */
    -webkit-user-select: none;
    user-select: none;
    /* Prevent touch callouts on iOS */
    -webkit-touch-callout: none;
}

body, html {
    padding: 0;
    margin: 0;
    background-color: #000000;
    overflow: hidden;
    height: 100%;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Courier New', Courier, monospace;
    /* iOS safe area support */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    /* Prevent overscroll bounce on iOS */
    overscroll-behavior: none;
    /* Prevent pull-to-refresh */
    touch-action: manipulation;
    /* Smooth font rendering on iOS */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.game-wrapper {
    position: relative;
    margin: 0;
    height: 100%;
    width: 100%;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Loading Screen */
#loadingScreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #0a0a0f 0%, #1a1a2e 50%, #0a0a0f 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.5s ease;
}

#loadingScreen.hidden {
    opacity: 0;
    pointer-events: none;
}

.loadingContent {
    text-align: center;
    color: white;
}

.loadingTitle {
    font-size: 48px;
    font-weight: bold;
    color: #21FF06;
    text-shadow: 0 0 20px rgba(33, 255, 6, 0.5);
    margin-bottom: 10px;
    letter-spacing: 8px;
}

.loadingSubtitle {
    font-size: 18px;
    color: #aaaaaa;
    margin-bottom: 30px;
}

.loadingBarContainer {
    width: 300px;
    height: 20px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    overflow: hidden;
    margin: 0 auto 15px auto;
    border: 1px solid rgba(33, 255, 6, 0.3);
}

.loadingBar {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #21FF06, #4AB009);
    border-radius: 10px;
    transition: width 0.1s ease;
    box-shadow: 0 0 10px rgba(33, 255, 6, 0.5);
}

.loadingPercent {
    font-size: 24px;
    color: #21FF06;
    font-weight: bold;
}

@keyframes loadingPulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

.loadingSubtitle {
    animation: loadingPulse 1.5s ease-in-out infinite;
}

.canvas-container {
    position: relative;
    text-align: center;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    width: calc(100% - 200px); /* Leave space for right panel */
    margin: 0;
    margin-right: 200px; /* Space for control panel */
    background: #000;
    /* Hardware acceleration for container */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
}

canvas {
    background: #000;
    display: block;
    /* Size controlled by JavaScript for proper aspect ratio */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: pixelated;
    /* Hardware acceleration for smoother rendering */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: transform;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* Game HUD - Top bar */
#gameHUD {
    position: absolute;
    top: 0;
    left: 0;
    right: 200px; /* Don't overlap control panel */
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: linear-gradient(180deg, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0) 100%);
    z-index: 200;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#gameHUD.visible {
    opacity: 1;
}

#scoreDisplay {
    color: #21FF06;
    font-size: 24px;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    letter-spacing: 2px;
}

#scoreValue {
    color: #ffffff;
    min-width: 60px;
    display: inline-block;
}

#controlsHint {
    color: #ffffff;
    font-size: 14px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
    animation: pulse 2s ease-in-out infinite;
}

.control-key {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 4px;
    padding: 3px 8px;
    margin: 0 2px;
    font-weight: bold;
    font-size: 12px;
}

@keyframes pulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

/* Right Side Control Panel */
#controlPanel {
    position: fixed;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    width: 200px;
    height: auto;
    max-height: 90vh;
    background: linear-gradient(180deg, rgba(15, 15, 20, 0.95) 0%, rgba(10, 10, 15, 0.98) 100%);
    padding: 20px 12px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 18px;
    overflow-y: auto;
    border-left: 1px solid rgba(33, 255, 6, 0.2);
    border-radius: 10px 0 0 10px;
}

.panelSection {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.panelSectionTitle {
    color: #21FF06;
    font-size: 13px;
    font-weight: bold;
    text-transform: uppercase;
}

/* Panel Footer with DNSai link */
.panelFooter {
    margin-top: auto;
    padding-top: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
}

.dnsaiLink {
    color: rgba(255, 255, 255, 0.5);
    text-decoration: none;
    font-size: 12px;
    font-family: 'Courier New', Courier, monospace;
    transition: all 0.3s ease;
}

.dnsaiLink:hover {
    color: #21FF06;
    text-shadow: 0 0 8px rgba(33, 255, 6, 0.5);
}

/* Panel Buttons */
#controlPanel button {
    width: 100%;
    padding: 12px 10px;
    font-size: 14px;
    font-family: 'Courier New', Courier, monospace;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    /* iOS touch optimization */
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    /* Minimum touch target for accessibility */
    min-height: 44px;
}

/* Start/Pause Button */
#controlPanel #startPauseBtn {
    background: linear-gradient(135deg, #4AB009, #3a8a07);
    color: white;
    font-weight: bold;
    font-size: 18px;
    padding: 14px 8px;
}

#controlPanel #startPauseBtn:hover {
    background: linear-gradient(135deg, #5cc40b, #4AB009);
    transform: scale(1.02);
}

/* Mute and Reset Buttons */
#controlPanel #muteButton,
#controlPanel #resetButton {
    background-color: #3a3a45;
    color: #ffffff;
}

#controlPanel #muteButton:hover,
#controlPanel #resetButton:hover {
    background-color: #4a4a55;
}

/* Security Buttons */
#controlPanel .securityBtn {
    background-color: #2a2a35;
    color: #cccccc;
    font-size: 18px;
    padding: 14px 8px;
}

#controlPanel .securityBtn:hover {
    background-color: #3a3a45;
    color: #ffffff;
}

#controlPanel .securityBtn.active {
    background: linear-gradient(135deg, #4AB009, #3a8a07);
    color: white;
    font-size: 18px;
}

/* Splash Screen */
#splashScreen {
    position: absolute;
    top: 0;
    left: 0;
    right: 200px; /* Don't cover control panel */
    height: 100%;
    background: url('GoPhish_Splash3.png') no-repeat center center;
    background-size: cover;
    z-index: 100;
    cursor: pointer;
}

.splashTitle {
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-shadow: 3px 3px 6px #000000;
    color: white;
    font-size: 36px;
    font-family: 'Courier New', Courier, monospace;
    text-align: center;
    width: 80%;
    max-width: 600px;
    line-height: 1.3;
}

.splashInstructions {
    position: absolute;
    top: 70%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #ffffff;
    font-size: 16px;
    font-weight: bold;
    font-family: 'Courier New', Courier, monospace;
    text-align: center;
    text-shadow: 2px 2px 6px rgba(0, 0, 0, 0.8);
    width: 85%;
    max-width: 500px;
    line-height: 1.8;
    background: rgba(0, 0, 0, 0.7);
    padding: 20px 25px;
    border-radius: 15px;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

/* Milestone Notification */
@keyframes fadeInOut {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
    10% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
    20% { transform: translate(-50%, -50%) scale(1); }
    80% { opacity: 1; }
    100% { opacity: 0; }
}

#milestoneText {
    position: absolute;
    top: 25%;
    left: calc(50% - 100px); /* Offset for panel */
    transform: translate(-50%, -50%);
    width: 450px;
    max-width: 80%;
    padding: 20px 25px;
    background: linear-gradient(135deg, rgba(0, 20, 0, 0.95), rgba(0, 40, 0, 0.95));
    color: #21FF06;
    font-family: 'Courier New', Courier, monospace;
    font-size: 18px;
    text-align: center;
    line-height: 1.5;
    border: 3px solid #21FF06;
    border-radius: 12px;
    z-index: 250;
    box-shadow: 0 0 30px rgba(33, 255, 6, 0.3);
}

#milestoneText.active {
    animation: fadeInOut 4s forwards;
}

.hidden {
    display: none !important;
}

/* Pause Overlay */
#pauseOverlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 200px; /* Don't cover control panel */
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 500;
    cursor: pointer;
    transition: opacity 0.3s ease;
}

#pauseOverlay.hidden {
    display: none !important;
}

.pauseText {
    color: #ffffff;
    font-size: 72px;
    font-weight: bold;
    font-family: 'Courier New', Courier, monospace;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.5);
    letter-spacing: 10px;
    animation: pausePulse 2s ease-in-out infinite;
}

.pauseSubtext {
    color: #aaaaaa;
    font-size: 20px;
    font-family: 'Courier New', Courier, monospace;
    margin-top: 20px;
}

@keyframes pausePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* Fullscreen Button - Bottom Left of canvas */
#fullscreenButton {
    position: absolute;
    bottom: 15px;
    left: 15px;
    width: 40px;
    height: 40px;
    z-index: 290;
    cursor: pointer;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 8px;
    padding: 8px;
    transition: all 0.3s ease;
}

#fullscreenButton:hover {
    background: rgba(74, 176, 9, 0.8);
    transform: scale(1.1);
}

#fullscreenButton img {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

/* Overlay - hidden by default */
.overlay {
    display: none;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 200px;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 160;
}

/* Legacy drawer - hidden */
#drawer {
    display: none;
}

/* ============ RESPONSIVE STYLES ============ */

/* Large screens */
@media (min-width: 1400px) {
    #controlPanel {
        width: 240px;
        padding: 25px 15px;
    }

    .canvas-container {
        width: calc(100% - 240px);
        margin-right: 240px;
    }

    #gameHUD {
        right: 240px;
    }

    #splashScreen {
        right: 240px;
    }

    #controlPanel button {
        font-size: 15px;
        padding: 14px 12px;
    }

    #controlPanel #startPauseBtn {
        font-size: 18px;
        padding: 16px 12px;
    }

    .panelSectionTitle {
        font-size: 14px;
    }
}

/* Medium screens */
@media (max-width: 1200px) {
    #controlPanel {
        width: 190px;
        padding: 18px 10px;
    }

    .canvas-container {
        width: calc(100% - 190px);
        margin-right: 190px;
    }

    #gameHUD {
        right: 190px;
    }

    #splashScreen {
        right: 190px;
    }

    #controlPanel button {
        font-size: 13px;
        padding: 11px 8px;
    }

    #controlPanel #startPauseBtn {
        font-size: 15px;
        padding: 13px 8px;
    }

    .panelSectionTitle {
        font-size: 12px;
    }

    #scoreDisplay {
        font-size: 20px;
    }

    #controlsHint {
        font-size: 12px;
    }
}

/* ============ iOS LANDSCAPE OPTIMIZATIONS ============ */

/* iOS devices in landscape - uses aspect ratio and height detection */
/* iPhone SE, iPhone 8 landscape (667px width) */
@media (max-width: 900px) and (orientation: landscape) {
    #controlPanel {
        width: 140px;
        padding: 8px 6px;
        gap: 6px;
        max-height: 100vh;
        /* Account for iOS safe areas (notch) */
        padding-right: calc(6px + env(safe-area-inset-right));
    }

    .canvas-container {
        width: calc(100% - 140px - env(safe-area-inset-right));
        margin-right: calc(140px + env(safe-area-inset-right));
        /* Account for left safe area (notch when rotated) */
        padding-left: env(safe-area-inset-left);
    }

    #gameHUD {
        right: calc(140px + env(safe-area-inset-right));
        padding: 6px 10px;
        padding-left: calc(10px + env(safe-area-inset-left));
    }

    #splashScreen {
        right: calc(140px + env(safe-area-inset-right));
        padding-left: env(safe-area-inset-left);
    }

    #pauseOverlay {
        right: calc(140px + env(safe-area-inset-right));
        padding-left: env(safe-area-inset-left);
    }

    .panelSection {
        gap: 4px;
    }

    .panelSectionTitle {
        font-size: 9px;
        padding-bottom: 2px;
        margin-bottom: 2px;
    }

    /* Touch-optimized buttons for iOS - minimum 44px touch target */
    #controlPanel button {
        font-size: 11px;
        padding: 8px 4px;
        min-height: 36px;
        border-radius: 6px;
    }

    #controlPanel #startPauseBtn {
        font-size: 13px;
        padding: 10px 4px;
        min-height: 40px;
    }

    #controlPanel .securityBtn {
        font-size: 10px;
        padding: 6px 4px;
        min-height: 34px;
    }

    #scoreDisplay {
        font-size: 16px;
    }

    #controlsHint {
        display: none;
    }

    .splashTitle {
        font-size: 24px;
        top: 35%;
    }

    .splashInstructions {
        font-size: 12px;
        padding: 12px 15px;
        top: 68%;
        line-height: 1.5;
    }

    .pauseText {
        font-size: 48px;
    }

    .pauseSubtext {
        font-size: 14px;
    }

    #milestoneText {
        font-size: 12px;
        padding: 10px 15px;
        width: 70%;
        top: 20%;
    }

    #fullscreenButton {
        width: 36px;
        height: 36px;
        padding: 6px;
        bottom: 8px;
        left: calc(8px + env(safe-area-inset-left));
    }

    .panelFooter {
        padding-top: 8px;
        margin-top: 4px;
    }

    .dnsaiLink {
        font-size: 10px;
    }
}

/* iPhone Pro/Pro Max landscape (932px width typically) */
@media (max-width: 950px) and (min-width: 901px) and (orientation: landscape) {
    #controlPanel {
        width: 160px;
        padding: 10px 8px;
        gap: 8px;
        padding-right: calc(8px + env(safe-area-inset-right));
    }

    .canvas-container {
        width: calc(100% - 160px - env(safe-area-inset-right));
        margin-right: calc(160px + env(safe-area-inset-right));
        padding-left: env(safe-area-inset-left);
    }

    #gameHUD {
        right: calc(160px + env(safe-area-inset-right));
        padding-left: calc(12px + env(safe-area-inset-left));
    }

    #splashScreen {
        right: calc(160px + env(safe-area-inset-right));
    }

    #pauseOverlay {
        right: calc(160px + env(safe-area-inset-right));
    }

    #controlPanel button {
        font-size: 12px;
        padding: 10px 6px;
        min-height: 40px;
    }

    #controlPanel #startPauseBtn {
        font-size: 14px;
        min-height: 44px;
    }

    #controlPanel .securityBtn {
        font-size: 11px;
        min-height: 38px;
    }

    .panelSectionTitle {
        font-size: 10px;
    }

    #scoreDisplay {
        font-size: 18px;
    }

    .splashTitle {
        font-size: 28px;
    }

    .splashInstructions {
        font-size: 13px;
    }
}

/* Very small landscape (older/smaller iPhones) */
@media (max-height: 400px) and (orientation: landscape) {
    #controlPanel {
        width: 120px;
        padding: 4px 4px;
        gap: 3px;
        padding-right: calc(4px + env(safe-area-inset-right));
    }

    .canvas-container {
        width: calc(100% - 120px - env(safe-area-inset-right));
        margin-right: calc(120px + env(safe-area-inset-right));
    }

    #gameHUD {
        right: calc(120px + env(safe-area-inset-right));
        padding: 4px 8px;
    }

    #splashScreen {
        right: calc(120px + env(safe-area-inset-right));
    }

    #pauseOverlay {
        right: calc(120px + env(safe-area-inset-right));
    }

    .panelSection {
        gap: 2px;
    }

    .panelSectionTitle {
        font-size: 8px;
        padding-bottom: 1px;
    }

    #controlPanel button {
        font-size: 9px;
        padding: 5px 3px;
        min-height: 28px;
        border-radius: 4px;
    }

    #controlPanel #startPauseBtn {
        font-size: 11px;
        padding: 6px 3px;
        min-height: 32px;
    }

    #controlPanel .securityBtn {
        font-size: 8px;
        padding: 4px 2px;
        min-height: 26px;
    }

    #scoreDisplay {
        font-size: 14px;
    }

    .splashTitle {
        font-size: 20px;
        top: 30%;
    }

    .splashInstructions {
        font-size: 10px;
        padding: 8px 10px;
        top: 65%;
        line-height: 1.4;
    }

    .pauseText {
        font-size: 36px;
        letter-spacing: 5px;
    }

    .pauseSubtext {
        font-size: 12px;
        margin-top: 10px;
    }

    #milestoneText {
        font-size: 10px;
        padding: 8px 10px;
    }

    #fullscreenButton {
        width: 28px;
        height: 28px;
        padding: 4px;
    }

    #fullscreenButton img {
        width: 20px;
        height: 20px;
    }

    .panelFooter {
        padding-top: 4px;
        display: none; /* Hide footer on very small screens */
    }

    .loadingTitle {
        font-size: 32px;
    }

    .loadingSubtitle {
        font-size: 14px;
    }

    .loadingBarContainer {
        width: 200px;
        height: 15px;
    }
}

/* iPad landscape */
@media (min-width: 1024px) and (max-width: 1366px) and (orientation: landscape) {
    #controlPanel {
        width: 200px;
        padding: 15px 12px;
    }

    .canvas-container {
        width: calc(100% - 200px);
        margin-right: 200px;
    }

    #gameHUD {
        right: 200px;
    }

    #splashScreen {
        right: 200px;
    }

    #controlPanel button {
        font-size: 14px;
        padding: 12px 10px;
        min-height: 48px;
    }

    #controlPanel #startPauseBtn {
        font-size: 16px;
        min-height: 52px;
    }
}

/* Portrait mode warning/adjustment for mobile */
@media (max-width: 900px) and (orientation: portrait) {
    #controlPanel {
        width: 100%;
        height: auto;
        max-height: none;
        position: fixed;
        bottom: 0;
        top: auto;
        left: 0;
        right: 0;
        transform: none;
        border-radius: 15px 15px 0 0;
        border-left: none;
        border-top: 1px solid rgba(33, 255, 6, 0.2);
        padding: 10px 15px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
        justify-content: center;
    }

    .canvas-container {
        width: 100%;
        margin-right: 0;
        height: calc(100% - 180px);
        margin-bottom: 180px;
    }

    #gameHUD {
        right: 0;
        padding-top: calc(10px + env(safe-area-inset-top));
    }

    #splashScreen {
        right: 0;
        bottom: 180px;
        height: calc(100% - 180px);
    }

    #pauseOverlay {
        right: 0;
        bottom: 180px;
    }

    .panelSection {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
        justify-content: center;
        width: 100%;
    }

    .panelSectionTitle {
        width: 100%;
        text-align: center;
        font-size: 10px;
    }

    #controlPanel button {
        width: auto;
        min-width: 80px;
        flex: 0 1 auto;
        font-size: 11px;
        padding: 10px 12px;
        min-height: 44px;
    }

    #controlPanel #startPauseBtn {
        min-width: 100px;
        font-size: 14px;
    }

    .panelFooter {
        width: 100%;
        padding-top: 6px;
        border-top: none;
    }

    .splashTitle {
        font-size: 28px;
        top: 25%;
    }

    .splashInstructions {
        font-size: 14px;
        top: 55%;
        width: 90%;
    }
}

/* Standard non-mobile small screens */
@media (max-width: 900px) and (min-height: 500px) and (orientation: portrait) {
    .canvas-container {
        height: calc(100% - 200px);
        margin-bottom: 200px;
    }

    #splashScreen {
        bottom: 200px;
        height: calc(100% - 200px);
    }
}

/* Extra small portrait screens */
@media (max-width: 500px) and (orientation: portrait) {
    #controlPanel {
        padding: 8px 10px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
    }

    #controlPanel button {
        font-size: 10px;
        padding: 8px 10px;
        min-width: 70px;
    }

    #controlPanel #startPauseBtn {
        font-size: 12px;
        min-width: 90px;
    }

    .panelSectionTitle {
        font-size: 9px;
    }

    .splashTitle {
        font-size: 22px;
    }

    .splashInstructions {
        font-size: 12px;
        padding: 12px;
    }
}
