/* ========================================
   CODE QUEST — Mario-Inspired Adventure UI
   Bright, warm, pixel-art style
   ======================================== */

:root {
    --pixel-font: 'Press Start 2P', monospace;
    --ui-font: 'Inter', sans-serif;
    --bg-warm: #1a1a2e;
    --bg-cream: #fff8e1;
    --accent-green: #4caf50;
    --accent-brown: #8d6e63;
    --accent-gold: #ffc107;
    --accent-red: #e53935;
    --accent-blue: #42a5f5;
    --accent-orange: #ff9800;
    --text-dark: #3e2723;
    --text-brown: #5d4037;
    --text-white: #fff;
    --text-dim: #8d6e63;
    --panel-bg: rgba(255, 248, 225, 0.97);
    --panel-border: #c4722a;
    --shadow-warm: 0 4px 20px rgba(139, 69, 19, 0.3);
    --shadow-gold: 0 0 20px rgba(255, 193, 7, 0.4);
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #42a5f5;
    font-family: var(--ui-font);
    color: var(--text-dark);
    user-select: none;
    -webkit-user-select: none;
}

canvas#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.hidden {
    display: none !important;
}

/* ========================================
   Loading Screen — Warm adventure style
   ======================================== */
#loading-screen {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: linear-gradient(180deg, #4fc3f7 0%, #81d4fa 60%, #c8e6c9 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.loader-content {
    text-align: center;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    padding: 50px 60px;
    border-radius: 24px;
    border: 3px solid rgba(255, 255, 255, 0.4);
}

/* Animated stickman loader */
.loader-stickman {
    position: relative;
    width: 60px;
    height: 100px;
    margin: 0 auto 30px;
}

.stick-head {
    width: 22px;
    height: 22px;
    border: 3px solid var(--accent-brown);
    border-radius: 50%;
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    background: #ffe0b2;
}

.stick-body {
    width: 3px;
    height: 30px;
    background: var(--accent-brown);
    position: absolute;
    top: 22px;
    left: 50%;
    transform: translateX(-50%);
}

.stick-arm-l, .stick-arm-r {
    width: 3px;
    height: 22px;
    background: var(--accent-brown);
    position: absolute;
    top: 28px;
    transform-origin: top center;
}

.stick-arm-l {
    left: 10px;
    transform: rotate(-40deg);
    animation: armSwingL 0.5s ease-in-out infinite alternate;
}

.stick-arm-r {
    right: 10px;
    transform: rotate(40deg);
    animation: armSwingR 0.5s ease-in-out infinite alternate;
}

.stick-leg-l, .stick-leg-r {
    width: 3px;
    height: 28px;
    background: var(--accent-brown);
    position: absolute;
    top: 52px;
    transform-origin: top center;
}

.stick-leg-l {
    left: 20px;
    transform: rotate(-20deg);
    animation: legSwingL 0.5s ease-in-out infinite alternate;
}

.stick-leg-r {
    right: 20px;
    transform: rotate(20deg);
    animation: legSwingR 0.5s ease-in-out infinite alternate;
}

@keyframes armSwingL { to { transform: rotate(40deg); } }
@keyframes armSwingR { to { transform: rotate(-40deg); } }
@keyframes legSwingL { to { transform: rotate(20deg); } }
@keyframes legSwingR { to { transform: rotate(-20deg); } }

.loader-title {
    font-family: var(--pixel-font);
    font-size: 32px;
    color: var(--text-dark);
    text-shadow:
        3px 3px 0 var(--accent-gold),
        -1px -1px 0 rgba(255,255,255,0.5);
    margin-bottom: 8px;
    letter-spacing: 4px;
}

.loader-sub {
    font-family: var(--pixel-font);
    font-size: 10px;
    color: var(--accent-brown);
    margin-bottom: 30px;
    letter-spacing: 2px;
}

.loader-bar {
    width: 280px;
    height: 12px;
    background: rgba(255, 255, 255, 0.5);
    border: 3px solid var(--accent-brown);
    margin: 0 auto 15px;
    border-radius: 6px;
    overflow: hidden;
}

.loader-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--accent-green), var(--accent-gold));
    transition: width 0.3s;
    border-radius: 4px;
}

.loader-hint {
    font-family: var(--pixel-font);
    font-size: 8px;
    color: var(--text-brown);
    animation: blink 1s step-end infinite;
}

@keyframes blink {
    50% { opacity: 0; }
}

/* ========================================
   Start Screen — Adventure title card
   ======================================== */
#start-screen {
    position: fixed;
    inset: 0;
    z-index: 900;
    background: linear-gradient(180deg, #4fc3f7 0%, #81d4fa 50%, #c8e6c9 85%, #a5d6a7 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.stars-bg {
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(3px 3px at 50px 80px, rgba(255,255,255,0.6), transparent),
        radial-gradient(2px 2px at 150px 40px, rgba(255,255,255,0.5), transparent),
        radial-gradient(3px 3px at 250px 120px, rgba(255,255,255,0.4), transparent),
        radial-gradient(2px 2px at 320px 60px, rgba(255,255,255,0.5), transparent);
    background-size: 400px 200px;
    animation: cloudDrift 30s linear infinite;
    opacity: 0.3;
}

@keyframes cloudDrift {
    to { background-position: 400px 0; }
}

.start-content {
    position: relative;
    z-index: 2;
    text-align: center;
    max-width: 640px;
    padding: 50px;
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(10px);
    border-radius: 24px;
    border: 3px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.game-title {
    font-family: var(--pixel-font);
    font-size: 48px;
    color: var(--text-dark);
    text-shadow:
        4px 4px 0 var(--accent-gold),
        -2px -2px 0 rgba(255,255,255,0.6),
        0 0 30px rgba(255, 193, 7, 0.3);
    margin-bottom: 10px;
    letter-spacing: 6px;
    animation: titleBounce 2s ease-in-out infinite;
}

@keyframes titleBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

.game-subtitle {
    font-family: var(--pixel-font);
    font-size: 12px;
    color: var(--accent-brown);
    margin-bottom: 30px;
    letter-spacing: 3px;
}

.story-intro {
    background: rgba(255, 248, 225, 0.7);
    border: 2px solid var(--accent-brown);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 30px;
}

.story-intro p {
    font-size: 14px;
    line-height: 1.8;
    color: var(--text-dark);
    margin-bottom: 5px;
}

.btn-pixel {
    font-family: var(--pixel-font);
    font-size: 14px;
    color: var(--text-white);
    background: linear-gradient(180deg, #66bb6a, #43a047);
    border: none;
    padding: 18px 44px;
    cursor: pointer;
    letter-spacing: 2px;
    transition: all 0.2s;
    box-shadow: 0 5px 0 #2e7d32, 0 8px 20px rgba(46, 125, 50, 0.3);
    border-radius: 8px;
    margin-bottom: 25px;
    border: 2px solid #2e7d32;
}

.btn-pixel:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 0 #2e7d32, 0 12px 30px rgba(46, 125, 50, 0.4);
    background: linear-gradient(180deg, #81c784, #66bb6a);
}

.btn-pixel:active {
    transform: translateY(3px);
    box-shadow: 0 2px 0 #2e7d32, 0 4px 10px rgba(46, 125, 50, 0.2);
}

.controls-hint {
    display: flex;
    gap: 20px;
    justify-content: center;
    font-family: var(--pixel-font);
    font-size: 9px;
    color: var(--text-brown);
}

.controls-hint span {
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ========================================
   Zone Transition — Bright & bold
   ======================================== */
#zone-transition {
    position: fixed;
    inset: 0;
    z-index: 800;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.transition-bg {
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, #4fc3f7, #81d4fa);
    opacity: 0;
    transition: opacity 0.5s;
}

#zone-transition.active .transition-bg {
    opacity: 1;
}

#transition-zone-name {
    position: relative;
    z-index: 2;
    font-family: var(--pixel-font);
    font-size: 32px;
    color: var(--text-dark);
    text-shadow: 3px 3px 0 var(--accent-gold);
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.5s 0.3s;
}

#transition-zone-desc {
    position: relative;
    z-index: 2;
    font-family: var(--pixel-font);
    font-size: 10px;
    color: var(--accent-brown);
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.5s 0.5s;
    margin-top: 10px;
}

#zone-transition.active #transition-zone-name,
#zone-transition.active #transition-zone-desc {
    opacity: 1;
    transform: translateY(0);
}

/* ========================================
   Pause Menu — Warm adventure card
   ======================================== */
.pause-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(62, 39, 35, 0.5);
    backdrop-filter: blur(6px);
}

#pause-menu {
    position: fixed;
    inset: 0;
    z-index: 850;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pause-window {
    position: relative;
    z-index: 2;
    text-align: center;
    background: var(--panel-bg);
    border: 3px solid var(--panel-border);
    border-radius: 16px;
    padding: 40px 60px;
    box-shadow: var(--shadow-warm);
}

.pause-window h2 {
    font-family: var(--pixel-font);
    font-size: 28px;
    color: var(--text-dark);
    text-shadow: 2px 2px 0 var(--accent-gold);
    margin-bottom: 30px;
    letter-spacing: 6px;
}

.pause-window .btn-pixel {
    display: block;
    width: 100%;
    margin-bottom: 12px;
    font-size: 11px;
}

/* ========================================
   Portrait Orientation Overlay
   ======================================== */
#rotate-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.rotate-content {
    text-align: center;
    padding: 40px 30px;
}

.rotate-icon {
    font-size: 64px;
    display: block;
    margin-bottom: 10px;
    animation: rotatePhone 2s ease-in-out infinite;
    transform-origin: center;
}

@keyframes rotatePhone {
    0%, 100% { transform: rotate(0deg); }
    30%      { transform: rotate(-90deg); }
    70%      { transform: rotate(-90deg); }
}

.rotate-arrow {
    font-size: 48px;
    color: var(--accent-gold);
    display: block;
    margin-bottom: 20px;
    animation: spinArrow 2s ease-in-out infinite;
}

@keyframes spinArrow {
    0%, 100% { transform: rotate(0deg); opacity: 0.4; }
    50%      { transform: rotate(360deg); opacity: 1; }
}

.rotate-title {
    font-family: var(--pixel-font);
    font-size: 16px;
    color: var(--text-white);
    letter-spacing: 3px;
    margin-bottom: 14px;
    text-shadow: 0 0 20px var(--accent-gold);
}

.rotate-sub {
    font-family: var(--pixel-font);
    font-size: 8px;
    color: var(--accent-gold);
    letter-spacing: 1px;
    line-height: 1.8;
}

/* Show overlay in portrait on mobile/tablet */
@media (max-width: 900px) and (orientation: portrait) {
    #rotate-overlay {
        display: flex;
    }
}

/* ========================================
   Mobile Touch Controls
   ======================================== */
#mobile-controls {
    position: fixed;
    inset: 0;
    z-index: 200;
    pointer-events: none;
}

.mobile-btn {
    position: absolute;
    pointer-events: auto;
    background: rgba(255, 248, 225, 0.18);
    border: 3px solid rgba(255, 248, 225, 0.5);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.9);
    font-size: 28px;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
    transition: background 0.1s, transform 0.1s;
    backdrop-filter: blur(4px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255,255,255,0.15);
}

.mobile-btn:active,
.mobile-btn.pressed {
    background: rgba(255, 193, 7, 0.35);
    border-color: var(--accent-gold);
    transform: scale(0.92);
    color: var(--accent-gold);
}

/* Left arrow — bottom-left */
.mobile-btn-left {
    bottom: 30px;
    left: 24px;
    width: 80px;
    height: 80px;
}

/* Right arrow — next to left arrow */
.mobile-btn-right {
    bottom: 30px;
    left: 116px;
    width: 80px;
    height: 80px;
}

/* Up/Down arrows — stacked at bottom-right */
.mobile-btn-up {
    bottom: 120px;
    right: 24px;
    width: 80px;
    height: 80px;
}

.mobile-btn-down {
    bottom: 30px;
    right: 24px;
    width: 80px;
    height: 80px;
}

/* Only show on touch/mobile devices */
#mobile-controls {
    display: none !important;
}

@media (max-width: 1024px) {
    #mobile-controls {
        display: block !important;
    }
}

/* ========================================
   Mobile / Tablet Responsive Overrides
   ======================================== */
@media (max-width: 900px) and (orientation: landscape) {
    /* Start screen smaller */
    .start-content {
        padding: 24px 28px;
        max-width: 90vw;
    }

    .game-title {
        font-size: 28px;
        letter-spacing: 3px;
    }

    .game-subtitle {
        font-size: 8px;
        margin-bottom: 14px;
    }

    .story-intro {
        padding: 12px;
        margin-bottom: 16px;
    }

    .story-intro p {
        font-size: 11px;
    }

    .btn-pixel {
        font-size: 10px;
        padding: 12px 28px;
        margin-bottom: 14px;
    }

    .controls-hint {
        font-size: 7px;
        gap: 12px;
    }

    .mobile-controls-hint {
        display: flex !important;
        margin-top: 8px;
        color: var(--accent-brown);
        opacity: 0.8;
    }

    /* HUD adjustments */
    #hud-top {
        padding: 8px 12px;
    }

    #hud-zone, #hud-quest {
        padding: 6px 10px;
        border-width: 2px;
    }

    #zone-name {
        font-size: 8px;
    }

    #quest-text {
        font-size: 6px;
    }

    .quest-icon, .zone-icon {
        font-size: 16px;
    }

    #hud-bottom {
        padding: 8px 12px;
        bottom: 120px;
    }

    #hud-controls {
        display: none;
    }

    #hud-progress {
        padding: 6px 10px;
    }

    .dot {
        width: 22px;
        height: 22px;
        font-size: 6px;
    }

    /* Interact prompt above mobile buttons */
    #interact-prompt {
        bottom: 215px;
    }

    /* Loading screen */
    .loader-content {
        padding: 30px 24px;
    }

    .loader-title {
        font-size: 22px;
    }

    .loader-sub {
        font-size: 8px;
    }

    .loader-bar {
        width: 220px;
    }

    /* Pause menu */
    .pause-window {
        padding: 28px 36px;
    }

    .pause-window h2 {
        font-size: 20px;
        margin-bottom: 20px;
    }

    /* Zone transition */
    #transition-zone-name {
        font-size: 22px;
    }

    #transition-zone-desc {
        font-size: 8px;
    }
}

/* Very small landscape (phone) */
@media (max-width: 600px) and (orientation: landscape) {
    .start-content {
        padding: 14px 18px;
    }

    .game-title {
        font-size: 20px;
        margin-bottom: 6px;
    }

    .story-intro {
        display: none;
    }

    .btn-pixel {
        padding: 10px 22px;
        font-size: 9px;
        margin-bottom: 10px;
    }

    #hud-top {
        padding: 4px 8px;
        gap: 6px;
    }

    #hud-quest {
        max-width: 200px;
    }

    #hud-bottom {
        bottom: 100px;
    }

    #interact-prompt {
        bottom: 190px;
    }

    .mobile-btn-left {
        bottom: 16px;
        left: 14px;
        width: 64px;
        height: 64px;
        font-size: 22px;
    }

    .mobile-btn-right {
        bottom: 16px;
        left: 88px;
        width: 64px;
        height: 64px;
        font-size: 22px;
    }

    .mobile-btn-up {
        bottom: 88px;
        right: 14px;
        width: 64px;
        height: 64px;
        font-size: 22px;
    }

    .mobile-btn-down {
        bottom: 16px;
        right: 14px;
        width: 64px;
        height: 64px;
        font-size: 22px;
    }
}

/* Hidden on desktop */
.mobile-controls-hint {
    display: none;
}

/* Mobile interact button (E) */
.mobile-btn-interact {
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    width: 70px;
    height: 70px;
    font-family: var(--pixel-font);
    font-size: 22px;
    font-weight: bold;
    background: rgba(255, 193, 7, 0.25);
    border-color: var(--accent-gold);
    color: var(--accent-gold);
    text-shadow: 0 0 10px rgba(255, 193, 7, 0.5);
    box-shadow: 0 4px 16px rgba(255, 193, 7, 0.3), inset 0 1px 0 rgba(255,255,255,0.15);
}

.mobile-btn-interact:active,
.mobile-btn-interact.pressed {
    background: rgba(255, 193, 7, 0.5);
    transform: translateX(-50%) scale(0.92);
}

/* Dialogue continue hints - show/hide based on device */
.dialogue-continue-mobile {
    display: none;
}

@media (max-width: 1024px) {
    .dialogue-continue-desktop {
        display: none;
    }
    .dialogue-continue-mobile {
        display: inline;
    }
}

/* Very small landscape - adjust interact button */
@media (max-width: 600px) and (orientation: landscape) {
    .mobile-btn-interact {
        width: 56px;
        height: 56px;
        font-size: 18px;
        bottom: 16px;
    }
}