* { margin: 0; padding: 0; box-sizing: border-box; }

html, body, canvas, #ui-overlay, #interaction-overlay, #transition-overlay, #mobile-controls {
    touch-action: none !important;
}

@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=VT323&display=swap');

.hidden { display: none !important; }
body {
    background: linear-gradient(135deg, #0f0c29, #302b63, #24243e);
    background-size: 400% 400%;
    animation: gradientBG 15s ease infinite;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100dvh;
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: 'Press Start 2P', monospace;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    background-color: #000;
}

@keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 100vw;
    max-height: 100dvh;
    aspect-ratio: 16 / 9;
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

#gameCanvas {
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
    image-rendering: pixelated;
    -ms-interpolation-mode: nearest-neighbor;
    display: block;
}

#gameCanvas:focus { outline: none; }

.title-glow {
    position: absolute;
    top: -60px;
    color: #FFD700;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.8), 0 0 20px rgba(255, 215, 0, 0.5);
    font-size: 24px;
    letter-spacing: 2px;
}

#ui-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    z-index: 10;
}

#intro-ui {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: black;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
}

.intro-skip {
    position: absolute;
    top: 20px; right: 30px;
    color: #FFF;
    font-size: 24px;
    font-family: 'VT323', 'Courier New', monospace;
}

.intro-dialog-box {
    width: 80%;
    max-width: 800px;
    padding: 30px;
    background: #111;
    border: 4px solid #FFF;
    border-radius: 10px;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

#intro-text {
    color: #FFF;
    font-family: 'VT323', 'Courier New', monospace;
    font-size: 32px;
    line-height: 1.5;
    text-align: left;
    margin: 0;
}

.blinking {
    animation: blink 1s infinite;
}

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

#intro-prompt {
    color: #FFD700;
    text-align: right;
    font-size: 24px;
    margin-top: 20px;
    font-family: 'VT323', 'Courier New', monospace;
}

#trivia-ui {
    position: absolute;
    top: 10%;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 800px;
    background: rgba(0, 0, 0, 0.85);
    border: 4px solid #AAAAAA;
    padding: 20px;
    text-align: center;
}

#trivia-ui.master-scroll {
    border-color: #FFD700;
}

#trivia-title {
    font-family: 'VT323', 'Courier New', monospace;
    font-size: 32px;
    margin-bottom: 15px;
    color: #AAAAAA;
}

#trivia-ui.master-scroll #trivia-title {
    color: #FFD700;
}

#trivia-text {
    font-family: 'VT323', 'Courier New', monospace;
    font-size: 28px;
    color: #FFF;
    line-height: 1.4;
    margin: 0;
}

#editor-ui {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    pointer-events: auto;
    display: flex;
    justify-content: center;
    background: rgba(0, 0, 0, 0.85);
    padding: 10px;
    border-top: 2px solid #555;
    z-index: 1000;
}

.editor-toolbar {
    display: flex;
    gap: 10px;
}

.editor-btn {
    background: #333;
    color: #FFF;
    border: 2px solid #555;
    padding: 8px 15px;
    font-family: 'VT323', 'Courier New', monospace;
    font-size: 20px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.editor-btn:hover {
    background: #444;
}

.editor-btn.active {
    background: #FFD700;
    color: #000;
    border-color: #FFF;
}

.editor-btn.export-btn {
    background: #2D6A4F;
    border-color: #0F0;
}

.editor-btn.export-btn:hover {
    background: #40916c;
}

#toast {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #2D6A4F;
    color: #FFF;
    font-family: 'VT323', 'Courier New', monospace;
    font-size: 24px;
    padding: 10px 20px;
    border: 2px solid #0F0;
    border-radius: 4px;
    z-index: 2000;
    pointer-events: none;
    box-shadow: 0 4px 6px rgba(0,0,0,0.5);
}

#mobile-controls {
    position: absolute;
    bottom: 0; left: 0; right: 0; top: 0;
    pointer-events: none;
    z-index: 500;
    box-sizing: border-box;
    width: 100vw;
    overflow-x: hidden;
}

#mobile-controls:not(.hidden) {
    display: block;
}

.dpad {
    position: absolute;
    bottom: 20px;
    left: 20px;
    padding-left: env(safe-area-inset-left, 20px);
    display: flex;
    align-items: center;
    gap: 15px;
    pointer-events: auto;
}

.action-pad {
    position: absolute;
    bottom: 20px;
    right: 20px;
    padding-right: env(safe-area-inset-right, 20px);
    display: flex;
    align-items: center;
    gap: 15px;
    pointer-events: auto;
}

.touch-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(200, 200, 200, 0.3);
    border: 2px solid rgba(255, 255, 255, 0.5);
    color: rgba(255, 255, 255, 0.7);
    font-family: 'VT323', 'Courier New', monospace;
    font-size: 20px;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
}

.touch-btn:active {
    background: rgba(255, 215, 0, 0.5);
    border-color: rgba(255, 215, 0, 0.8);
    color: #FFF;
}

#transition-overlay {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    pointer-events: none;
    z-index: 9999;
    background-color: transparent;
    box-shadow: 0 0 0 200vmax #000;
    width: 250vmax;
    height: 250vmax;
    transition: width 1s ease-in-out, height 1s ease-in-out;
}

#interaction-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    pointer-events: auto;
    transition: opacity 0.5s ease-out;
    cursor: pointer;
}

.interaction-text {
    color: #FFD700;
    font-size: 32px;
    font-family: 'Press Start 2P', monospace;
    text-shadow: 0 0 15px rgba(255, 215, 0, 0.8), 0 0 30px rgba(255, 215, 0, 0.5);
}

#chapter-select-menu {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    pointer-events: auto;
    z-index: 50;
}

#level-select-menu {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    pointer-events: auto;
    z-index: 60;
}

.chapter-menu-title {
    color: #FFD700;
    font-family: 'Press Start 2P', monospace;
    font-size: 24px;
    margin-bottom: 20px;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.8);
}

#chapter-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 80%;
    max-width: 600px;
    flex-grow: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 10px;
    margin-bottom: 20px;
}

#chapter-list::-webkit-scrollbar {
    display: none;
}

#level-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 80%;
    max-width: 600px;
    flex-grow: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 10px;
    margin-bottom: 20px;
}

#level-list::-webkit-scrollbar {
    display: none;
}

.chapter-btn {
    background: #111;
    border: 3px solid #555;
    color: #FFF;
    padding: 15px 20px;
    font-family: 'VT323', 'Courier New', monospace;
    font-size: 24px;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
    text-align: left;
}

.chapter-btn:hover:not(:disabled) {
    background: #222;
    border-color: #FFD700;
    transform: scale(1.02);
}

.chapter-btn:active:not(:disabled) {
    background: #333;
    transform: scale(0.98);
}

.chapter-btn:disabled {
    color: #555;
    border-color: #333;
    cursor: not-allowed;
    background: #0a0a0a;
}

.chapter-back-btn {
    background: #500;
    border: 3px solid #F00;
    color: #FFF;
    padding: 15px 30px;
    font-family: 'Press Start 2P', monospace;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
}

.chapter-back-btn:hover {
    background: #800;
}
