/* ==========================================================================
   GARAGE -- 2D Side-Scroller Platformer Styles
   ========================================================================== */

/* --- RESET & BASE --- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

@font-face {
    font-family: 'PixelFont';
    src: local('Press Start 2P'), local('Courier New');
}

:root {
    --bg: #0a0a0f;
    --panel: #111827;
    --panel-dark: #0d1117;
    --accent: #3b82f6;
    --accent2: #8b5cf6;
    --gold: #fbbf24;
    --green: #22c55e;
    --red: #ef4444;
    --text: #e5e7eb;
    --muted: #6b7280;
    --radius: 8px;
    --font: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
}

html,
body {
    width: 100%;
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    background: var(--bg);
    font-family: var(--font);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* --- SCREENS --- */
.screen {
    position: fixed;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.screen.active {
    display: flex;
}

/* --- AUTH SCREENS (LOGIN / REGISTER) --- */
.auth-bg {
    position: absolute;
    inset: 0;
    z-index: 0;
    overflow: hidden;
}

.auth-bg-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center 30%;
    filter: brightness(0.35) blur(2px);
}

.auth-bg-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg,
            rgba(10, 10, 15, 0.7) 0%,
            rgba(10, 10, 15, 0.85) 60%,
            rgba(10, 10, 15, 0.95) 100%);
}

.auth-container {
    position: relative;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    height: 100dvh;
    padding: 16px;
    overflow-y: auto;
}

.auth-card {
    background: rgba(17, 24, 39, 0.92);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 16px;
    padding: 40px 36px;
    width: 100%;
    max-width: 420px;
    backdrop-filter: blur(16px);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5),
        0 0 60px rgba(59, 130, 246, 0.08);
}

.auth-logo {
    font-family: var(--font);
    font-size: 2rem;
    font-weight: 900;
    color: var(--green);
    text-align: center;
    letter-spacing: 4px;
    margin-bottom: 4px;
}

.auth-logo span {
    color: var(--gold);
    text-shadow: 0 0 10px rgba(251, 191, 36, 0.4);
}

.auth-subtitle {
    text-align: center;
    color: var(--muted);
    font-size: 0.75rem;
    margin-bottom: 28px;
    letter-spacing: 1px;
}

.auth-field {
    margin-bottom: 16px;
}

.auth-field label {
    display: block;
    font-size: 0.65rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 6px;
}

.auth-field input,
.auth-field select {
    width: 100%;
    padding: 12px 14px;
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid #374151;
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.85rem;
    transition: border-color 0.2s;
    -webkit-appearance: none;
}

.auth-field input:focus,
.auth-field select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.auth-field input::placeholder {
    color: #4b5563;
}

.auth-field select {
    cursor: pointer;
}

.auth-field select option {
    background: #111827;
    color: var(--text);
}

.auth-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--red);
    font-size: 0.75rem;
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    text-align: center;
}

.auth-success {
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.3);
    color: var(--green);
    font-size: 0.75rem;
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    text-align: center;
}

/* OTP verification input boxes */
.otp-box {
    width: 46px;
    height: 56px;
    text-align: center;
    font-size: 1.5rem;
    font-weight: 700;
    font-family: var(--font);
    background: #0f172a;
    border: 2px solid #334155;
    border-radius: 8px;
    color: #fbbf24;
    caret-color: #fbbf24;
    outline: none;
    transition: border-color 0.15s;
}

.otp-box:focus {
    border-color: #fbbf24;
    box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.2);
}

.otp-box.filled {
    border-color: #4ade80;
}

.auth-btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 3px;
    cursor: pointer;
    transition: all 0.2s;
    touch-action: manipulation;
    min-height: 48px;
}

.auth-btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.auth-btn-primary:hover {
    filter: brightness(1.15);
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(59, 130, 246, 0.3);
}

.auth-btn-primary:active {
    transform: translateY(0);
}

.auth-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: none;
    transform: none;
}

.auth-switch {
    text-align: center;
    margin-top: 20px;
    font-size: 0.7rem;
    color: var(--muted);
}

.auth-switch a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 700;
}

.auth-switch a:hover {
    text-decoration: underline;
}

/* Auth responsive -- phones */
@media (max-width: 480px) {
    .auth-card {
        padding: 28px 20px;
        border-radius: 12px;
    }

    .auth-logo {
        font-size: 1.5rem;
        letter-spacing: 2px;
    }

    .auth-subtitle {
        font-size: 0.65rem;
        margin-bottom: 20px;
    }

    .auth-field input,
    .auth-field select {
        font-size: 16px;
        padding: 12px 12px;
        min-height: 48px;
    }

    .auth-field label {
        font-size: 0.6rem;
    }

    .auth-btn {
        font-size: 0.8rem;
        min-height: 50px;
    }
}

/* Auth responsive -- landscape phone */
@media (max-height: 500px) and (orientation: landscape) {
    .auth-container {
        align-items: flex-start;
        padding-top: 8px;
    }

    .auth-card {
        padding: 16px 20px;
        max-height: 95vh;
        overflow-y: auto;
    }

    .auth-field {
        margin-bottom: 8px;
    }

    .auth-logo {
        font-size: 1.2rem;
        margin-bottom: 2px;
    }

    .auth-subtitle {
        margin-bottom: 10px;
    }
}

/* --- TITLE SCREEN (ARCADE RETRO 80s/90s) --- */
#screen-title {
    background: #000;
    position: relative;
    overflow: hidden;
}

#screen-title::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse at center, rgba(20, 0, 80, 0.8) 0%, rgba(0, 0, 0, 0.95) 70%);
    z-index: 0;
}

.arcade-scanlines {
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(0deg,
            transparent,
            transparent 2px,
            rgba(0, 0, 0, 0.15) 2px,
            rgba(0, 0, 0, 0.15) 4px);
    pointer-events: none;
    z-index: 100;
}

.arcade-container {
    position: relative;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    box-sizing: border-box;
    padding: 0 16px;
    overflow-y: auto;
    overflow-x: hidden;
}

.arcade-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    flex: 1;
    justify-content: center;
    padding: 16px 0;
    width: 100%;
}

.arcade-top-text {
    font-size: clamp(0.5rem, 1.5vw, 0.75rem);
    color: #00ffff;
    letter-spacing: 6px;
    text-transform: uppercase;
    text-shadow: 0 0 8px #00ffff, 0 0 20px rgba(0, 255, 255, 0.3);
    animation: arcadeFlicker 4s ease-in-out infinite;
}

.arcade-logo {
    font-size: clamp(2rem, 8vw, 7rem);
    font-weight: 900;
    color: #fbbf24;
    letter-spacing: clamp(2px, 0.8vw, 12px);
    text-shadow:
        0 0 10px #fbbf24,
        0 0 30px rgba(251, 191, 36, 0.5),
        0 0 60px rgba(251, 191, 36, 0.3),
        4px 4px 0 #92400e,
        6px 6px 0 #451a03;
    line-height: 1.15;
    margin: 10px auto;
    white-space: nowrap;
    display: inline-block;
    text-align: center;
    animation: arcadeLogoGlow 2s ease-in-out infinite alternate;
}

.arcade-logo-bracket {
    color: #22c55e;
    text-shadow: 0 0 15px #22c55e, 0 0 40px rgba(34, 197, 94, 0.4);
    display: inline;
    letter-spacing: 0;
}

.arcade-logo-bracket:first-child {
    margin-right: 0.2em;
}

.arcade-logo-bracket:last-child {
    margin-left: 0.2em;
}

@keyframes arcadeLogoGlow {
    from {
        text-shadow: 0 0 10px #fbbf24, 0 0 30px rgba(251, 191, 36, 0.5), 0 0 60px rgba(251, 191, 36, 0.3), 4px 4px 0 #92400e, 6px 6px 0 #451a03;
    }

    to {
        text-shadow: 0 0 20px #fbbf24, 0 0 50px rgba(251, 191, 36, 0.7), 0 0 80px rgba(251, 191, 36, 0.4), 4px 4px 0 #92400e, 6px 6px 0 #451a03;
    }
}

.arcade-tagline {
    font-size: clamp(0.55rem, 1.8vw, 0.85rem);
    color: #a78bfa;
    letter-spacing: 4px;
    text-shadow: 0 0 8px #a78bfa;
}

.arcade-divider {
    color: #374151;
    font-size: 0.7rem;
    letter-spacing: 2px;
    margin: 6px 0;
    overflow: hidden;
    max-width: 90vw;
}

.arcade-description {
    font-size: clamp(0.5rem, 1.4vw, 0.7rem);
    color: #9ca3af;
    letter-spacing: 2px;
    line-height: 1.8;
    max-width: 600px;
}

.arcade-insert {
    font-size: clamp(0.7rem, 2vw, 1rem);
    color: #fbbf24;
    letter-spacing: 4px;
    margin: 20px 0 10px;
    text-shadow: 0 0 10px #fbbf24;
}

.arcade-insert.blink {
    animation: arcadeBlink 1s step-start infinite;
}

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

@keyframes arcadeFlicker {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.7;
    }
}

.arcade-btn {
    display: block;
    width: min(280px, 85vw);
    padding: 14px 24px;
    margin: 6px 0;
    background: transparent;
    border: 2px solid #3b82f6;
    color: #3b82f6;
    font-family: var(--font);
    font-size: 0.85rem;
    letter-spacing: 3px;
    cursor: pointer;
    transition: all 0.15s;
    text-transform: uppercase;
    position: relative;
    overflow: hidden;
    touch-action: manipulation;
    min-height: 48px;
}

.arcade-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(59, 130, 246, 0.1), transparent);
    transform: translateX(-100%);
    transition: transform 0.4s;
}

.arcade-btn:hover {
    background: rgba(59, 130, 246, 0.15);
    border-color: #60a5fa;
    color: #fff;
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.3), inset 0 0 20px rgba(59, 130, 246, 0.1);
    text-shadow: 0 0 8px #60a5fa;
}

.arcade-btn:hover::before {
    transform: translateX(100%);
}

.arcade-btn-alt {
    border-color: #6b7280;
    color: #6b7280;
}

.arcade-btn-alt:hover {
    border-color: #9ca3af;
    color: #e5e7eb;
    box-shadow: 0 0 15px rgba(156, 163, 175, 0.2);
    background: rgba(156, 163, 175, 0.1);
}

.arcade-btn-icon {
    margin-right: 8px;
    font-size: 0.7rem;
}

.arcade-btn-logout {
    border-color: var(--red);
    color: var(--red);
    font-size: 0.6rem;
    padding: 8px 24px;
    margin-top: 4px;
    letter-spacing: 3px;
    min-height: auto;
}

.arcade-btn-logout:hover {
    border-color: #f87171;
    color: #fca5a5;
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.2);
    background: rgba(239, 68, 68, 0.08);
}

.arcade-credits {
    margin-top: 24px;
    font-size: 0.6rem;
    color: #4b5563;
    letter-spacing: 2px;
    line-height: 2;
}

.arcade-footer {
    padding: 16px 0;
    font-size: 0.62rem;
    color: #ffffff;
    letter-spacing: 2px;
    line-height: 2;
    text-align: center;
    flex-shrink: 0;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
    font-weight: 700;
}

/* --- ONBOARDING / CHARACTER SELECT --- */
#screen-onboarding {
    background: var(--panel-dark);
    padding: 30px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.onboard-title {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--gold);
}

.form-row {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
    max-width: 600px;
}

.form-row input,
.form-row select {
    flex: 1;
    min-width: 200px;
    padding: 10px 14px;
    background: #1f2937;
    border: 1px solid #374151;
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.85rem;
}

.form-row input:focus,
.form-row select:focus {
    border-color: var(--accent);
    outline: none;
}

/* --- AVATAR SELECTION (Boy + Girl) --- */
.avatar-selection {
    display: flex;
    flex-direction: row;
    justify-content: center;
    gap: 16px;
    margin: 16px auto;
    width: 100%;
}

.avatar-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px;
    background: #1f2937;
    border: 2px solid #374151;
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
    flex: 0 1 140px;
    touch-action: manipulation;
}

.avatar-card:hover {
    border-color: #6b7280;
}

.avatar-card.selected {
    border-color: var(--gold);
    box-shadow: 0 0 16px rgba(251, 191, 36, 0.25);
    transform: scale(1.03);
}

.avatar-card canvas {
    image-rendering: pixelated;
    width: 120px;
    height: 180px;
    pointer-events: none;
}

.avatar-card-name {
    font-size: 0.75rem;
    color: var(--gold);
    font-weight: 700;
    letter-spacing: 2px;
    margin-top: 10px;
    text-transform: uppercase;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.avatar-card.selected .avatar-card-name {
    opacity: 1;
}

.btn-primary {
    padding: 12px 40px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 0.9rem;
    cursor: pointer;
    margin-top: 16px;
    letter-spacing: 1px;
    transition: all 0.2s;
    touch-action: manipulation;
}

.btn-primary:hover {
    background: #2563eb;
    box-shadow: 0 0 16px rgba(59, 130, 246, 0.3);
}

/* --- GAME WORLD --- */
#screen-world {
    z-index: 0;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
}

/* --- HUD (ARCADE RETRO) --- */
.hud {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0;
    padding: 0;
    background: linear-gradient(180deg, #0a0a1a 0%, #111827 50%, #0a0a1a 100%);
    border-bottom: 3px solid #fbbf24;
    box-shadow: 0 3px 15px rgba(251, 191, 36, 0.2), inset 0 -1px 0 #92400e;
    z-index: 10;
    pointer-events: none;
    height: 52px;
}

.hud-block {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 16px;
    height: 100%;
}

.hud-sep {
    color: #374151;
    font-size: 1.2rem;
    line-height: 52px;
    user-select: none;
}

.hud-icon {
    font-size: 1rem;
    color: #fbbf24;
    text-shadow: 0 0 6px rgba(251, 191, 36, 0.5);
    line-height: 1;
}

.hud-icon-red {
    color: #ef4444;
    text-shadow: 0 0 6px rgba(239, 68, 68, 0.5);
}

.hud-icon-book {
    color: #a78bfa;
    text-shadow: 0 0 6px rgba(167, 139, 250, 0.5);
}

.hud-label {
    font-size: 0.5rem;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 2px;
    line-height: 1;
    margin-bottom: 2px;
}

.hud-value {
    font-size: 0.85rem;
    font-weight: 700;
    color: #fbbf24;
    text-shadow: 0 0 4px rgba(251, 191, 36, 0.3);
    line-height: 1;
}

.hud-stage {
    color: #22c55e;
    text-shadow: 0 0 4px rgba(34, 197, 94, 0.3);
}

.hud-score {
    color: #fbbf24;
}

#hudErrors {
    color: #ef4444;
    text-shadow: 0 0 4px rgba(239, 68, 68, 0.3);
}

.hud-books {
    color: #a78bfa;
    text-shadow: 0 0 4px rgba(167, 139, 250, 0.3);
}

.hud-icon-company {
    color: #60a5fa;
    text-shadow: 0 0 6px rgba(96, 165, 250, 0.5);
}

.hud-companies {
    color: #60a5fa;
    text-shadow: 0 0 4px rgba(96, 165, 250, 0.3);
}

.hud-block-btn:hover {
    background: rgba(96, 165, 250, 0.1);
    border-radius: 4px;
}

/* --- METRICS PANEL --- */
.metrics-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 100;
    display: none;
    justify-content: center;
    align-items: center;
    font-family: 'JetBrains Mono', monospace;
}

.metrics-overlay.visible {
    display: flex;
}

.metrics-panel {
    background: linear-gradient(145deg, #0f172a, #1e293b);
    border: 2px solid #fbbf24;
    border-radius: 12px;
    width: 90%;
    max-width: 900px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 40px rgba(251, 191, 36, 0.15);
}

.metrics-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #334155;
}

.metrics-header h2 {
    font-size: 0.9rem;
    color: #fbbf24;
    letter-spacing: 3px;
    margin: 0;
}

.metrics-tabs {
    display: flex;
    gap: 4px;
}

.metrics-tab {
    background: transparent;
    border: 1px solid #475569;
    color: #94a3b8;
    padding: 6px 16px;
    font-size: 0.7rem;
    font-family: 'JetBrains Mono', monospace;
    cursor: pointer;
    border-radius: 4px;
    letter-spacing: 1px;
    transition: all 0.2s;
}

.metrics-tab:hover {
    border-color: #fbbf24;
    color: #fbbf24;
}

.metrics-tab.active {
    background: #fbbf24;
    color: #0f172a;
    border-color: #fbbf24;
    font-weight: 700;
}

.metrics-close {
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 8px;
    line-height: 1;
}

.metrics-close:hover {
    color: #ef4444;
}

.metrics-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.metrics-tab-content {
    display: none;
}

.metrics-tab-content.active {
    display: block;
}

/* Company grid */
.metrics-company-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
}

.metrics-company-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid #334155;
    background: rgba(15, 23, 42, 0.6);
    transition: all 0.2s;
}

.metrics-company-card.completed {
    border-color: #22c55e;
    background: rgba(34, 197, 94, 0.08);
}

.metrics-company-card.locked {
    border-color: #475569;
    opacity: 0.5;
}

.metrics-company-logo {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    flex-shrink: 0;
    border: 2px solid;
}

.metrics-company-info {
    flex: 1;
    min-width: 0;
}

.metrics-company-name {
    font-size: 0.7rem;
    font-weight: 700;
    color: #f1f5f9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.metrics-company-stage {
    font-size: 0.55rem;
    color: #64748b;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.metrics-company-status {
    font-size: 0.7rem;
    flex-shrink: 0;
}

/* Book grid */
.metrics-book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 8px;
}

.metrics-book-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid #334155;
    background: rgba(15, 23, 42, 0.6);
}

.metrics-book-card.collected {
    border-color: #a78bfa;
    background: rgba(167, 139, 250, 0.08);
}

.metrics-book-card.missing {
    opacity: 0.4;
}

.metrics-book-icon {
    width: 28px;
    height: 36px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.metrics-book-info {
    flex: 1;
    min-width: 0;
}

.metrics-book-title {
    font-size: 0.65rem;
    font-weight: 700;
    color: #f1f5f9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.metrics-book-author {
    font-size: 0.55rem;
    color: #64748b;
}

.metrics-book-status {
    font-size: 0.7rem;
    flex-shrink: 0;
}

.metrics-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    border-top: 1px solid #334155;
    font-size: 0.65rem;
    color: #64748b;
}

.metrics-hint {
    color: #475569;
    font-style: italic;
}

/* --- INTERACTION HINT --- */
.interact-hint {
    position: fixed;
    bottom: 140px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(0, 0, 0, 0.85);
    color: var(--gold);
    padding: 10px 24px;
    border-radius: 6px;
    border: 1px solid var(--gold);
    font-size: 0.75rem;
    letter-spacing: 1px;
    opacity: 0;
    transition: all 0.3s;
    z-index: 15;
    pointer-events: none;
    text-align: center;
}

.interact-hint.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* --- MOBILE CONTROLS --- */
.mobile-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: none;
    padding: 14px 18px 28px;
    z-index: 20;
    pointer-events: none;
    /* Stronger gradient so controls stand out against any background */
    background: linear-gradient(to top, rgba(0, 0, 0, 0.72) 0%, rgba(0, 0, 0, 0.35) 80%, transparent 100%);
    align-items: flex-end;
}

@media (max-width: 768px),
(pointer: coarse) {
    .mobile-controls {
        display: flex;
        justify-content: space-between;
    }

    .interact-hint {
        display: none;
    }

    .key-cap {
        display: none;
    }
}

.ctrl-group {
    display: flex;
    gap: 8px;
    pointer-events: auto;
}

.ctrl-btn {
    width: 62px;
    height: 62px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    background: rgba(10, 10, 30, 0.72);
    color: #fff;
    font-size: 1.35rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    /* Explicit pointer-events:auto — parent has pointer-events:none */
    pointer-events: auto;
    /* manipulation: allows fast tap, prevents double-tap zoom */
    touch-action: manipulation;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition: background 0.08s, transform 0.08s, border-color 0.08s;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.12);
    -webkit-tap-highlight-color: transparent;
    outline: none;
    /* Slightly larger actual tap area via padding trick */
    padding: 0;
}

.ctrl-btn:active,
.ctrl-btn.pressed {
    background: rgba(59, 130, 246, 0.75);
    border-color: #60a5fa;
    transform: scale(0.88);
    box-shadow: 0 0 14px rgba(59, 130, 246, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.ctrl-btn.action {
    width: 70px;
    height: 70px;
    background: rgba(251, 191, 36, 0.22);
    border-color: var(--gold);
    border-width: 2.5px;
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    box-shadow: 0 2px 12px rgba(251, 191, 36, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.ctrl-btn.action:active,
.ctrl-btn.action.pressed {
    background: rgba(251, 191, 36, 0.55);
    border-color: #fde68a;
    transform: scale(0.88);
    box-shadow: 0 0 16px rgba(251, 191, 36, 0.5);
}

/* --- DIALOG BOX --- */
.dialog-box {
    position: fixed;
    bottom: 100px;
    /* desktop: resting position when open */
    left: 50%;
    /* HIDDEN STATE: slide entire box below viewport (own height + 200px margin) */
    transform: translateX(-50%) translateY(calc(100% + 200px));
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    width: min(92vw, 700px);
    background: var(--panel);
    border: 2px solid #374151;
    border-radius: 12px;
    padding: 20px;
    z-index: 30;
    /* animate transform & opacity; visibility delay matches slide-out duration */
    transition: transform 0.4s ease, opacity 0.4s ease, visibility 0s linear 0.4s;
    /* flex column keeps CONTINUAR button always visible at bottom */
    display: flex;
    flex-direction: column;
    max-height: min(80vh, 520px);
}

.dialog-box.open {
    transform: translateX(-50%) translateY(0);
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    /* slide-IN: visibility becomes visible instantly */
    transition: transform 0.4s ease, opacity 0.4s ease, visibility 0s linear 0s;
}

@media (max-width: 768px),
(pointer: coarse) {
    .dialog-box {
        bottom: 160px;
        max-height: calc(100vh - 200px);
    }
}

.dialog-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 12px;
    flex-shrink: 0;
}

.dialog-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #374151;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--gold);
    border: 2px solid var(--accent);
    flex-shrink: 0;
}

.dialog-name {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--gold);
}

.dialog-role {
    font-size: 0.65rem;
    color: var(--muted);
}

.dialog-content {
    font-size: 0.8rem;
    line-height: 1.6;
    color: #d1d5db;
    margin-bottom: 12px;
    white-space: pre-line;
    flex: 1 1 auto;
    max-height: 40vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.dialog-close-hint {
    font-size: 0.6rem;
    color: var(--muted);
    text-align: right;
}

/* --- CHALLENGE OVERLAY --- */
.challenge-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 40;
    padding: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.challenge-overlay.visible {
    display: flex;
}

.challenge-panel {
    background: var(--panel);
    border: 1px solid #374151;
    border-radius: 12px;
    padding: 28px;
    width: min(95vw, 700px);
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.challenge-mentor {
    font-size: 0.7rem;
    color: var(--accent2);
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 6px;
}

.challenge-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--gold);
    margin-bottom: 4px;
}

.challenge-region {
    font-size: 0.65rem;
    color: var(--muted);
    margin-bottom: 14px;
}

.challenge-desc {
    font-size: 0.8rem;
    line-height: 1.6;
    color: #d1d5db;
    margin-bottom: 14px;
}

.challenge-code {
    background: #0d1117;
    border: 1px solid #21262d;
    border-radius: 6px;
    padding: 14px;
    font-family: var(--font);
    font-size: 0.75rem;
    color: #7ee787;
    white-space: pre-wrap;
    word-break: break-all;
    margin-bottom: 16px;
    max-height: 200px;
    overflow-y: auto;
}

.options-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}

.option-btn {
    padding: 12px 16px;
    background: #1f2937;
    border: 1px solid #374151;
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.78rem;
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
    line-height: 1.5;
    touch-action: manipulation;
    min-height: 44px;
}

.option-btn:hover:not(:disabled) {
    border-color: var(--accent);
    background: #1e293b;
}

.option-btn:disabled {
    cursor: default;
    opacity: 0.6;
}

.option-btn.correct {
    border-color: var(--green);
    background: rgba(34, 197, 94, 0.15);
}

.option-btn.wrong {
    border-color: var(--red);
    background: rgba(239, 68, 68, 0.15);
}

.feedback-box {
    padding: 14px;
    border-radius: var(--radius);
    font-size: 0.78rem;
    line-height: 1.6;
    margin-top: 10px;
}

.feedback-box.correct {
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid var(--green);
    color: #bbf7d0;
}

.feedback-box.wrong {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--red);
    color: #fecaca;
}

.challenge-actions {
    display: none;
    gap: 10px;
    margin-top: 14px;
    justify-content: center;
}

.ch-btn {
    padding: 10px 28px;
    border: 1px solid #374151;
    border-radius: var(--radius);
    background: #1f2937;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s;
}

.ch-btn:hover {
    border-color: var(--accent);
    background: #1e293b;
}

.ch-btn.primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.ch-btn.primary:hover {
    background: #2563eb;
}

/* --- PROMOTION OVERLAY --- */
.promotion-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 45;
    text-align: center;
}

.promotion-title {
    font-size: 1.6rem;
    font-weight: 900;
    color: var(--gold);
    margin-bottom: 12px;
    letter-spacing: 4px;
    text-shadow: 0 0 20px rgba(251, 191, 36, 0.4);
    animation: promoPulse 1.5s ease-in-out infinite;
}

@keyframes promoPulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.08);
    }
}

.promotion-stage {
    font-size: 2.2rem;
    font-weight: 900;
    color: #fff;
    margin-bottom: 10px;
}

.promotion-msg {
    font-size: 0.85rem;
    color: #d1d5db;
    max-width: 400px;
    line-height: 1.6;
    margin-bottom: 24px;
}

/* --- LEARNING PREP OVERLAY --- */
.learning-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.94);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 47;
    padding: 20px;
}

.learning-card {
    width: min(980px, 96vw);
    max-height: 92vh;
    overflow-y: auto;
    background: linear-gradient(160deg, #0f172a 0%, #111827 55%, #0b1222 100%);
    border: 1px solid rgba(59, 130, 246, 0.35);
    box-shadow: 0 20px 50px rgba(2, 6, 23, 0.65);
    border-radius: 14px;
    padding: 18px 18px 16px;
}

.learning-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.learning-chip {
    font-size: 0.62rem;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: #93c5fd;
    border: 1px solid rgba(59, 130, 246, 0.45);
    background: rgba(37, 99, 235, 0.18);
    border-radius: 999px;
    padding: 4px 10px;
}

.learning-stage-label {
    font-size: 0.7rem;
    color: #fbbf24;
    letter-spacing: 1px;
    text-transform: uppercase;
    font-weight: 700;
}

.learning-card h2 {
    color: #e2e8f0;
    font-size: 1.15rem;
    margin: 0 0 6px;
    letter-spacing: 0.3px;
}

.learning-subtitle {
    color: #cbd5e1;
    font-size: 0.78rem;
    line-height: 1.5;
    margin: 0 0 14px;
}

.learning-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.learning-section {
    background: rgba(15, 23, 42, 0.72);
    border: 1px solid rgba(148, 163, 184, 0.24);
    border-radius: 10px;
    padding: 12px;
}

.learning-section h3 {
    margin: 0 0 8px;
    color: #93c5fd;
    font-size: 0.74rem;
    letter-spacing: 0.7px;
    text-transform: uppercase;
}

.learning-section ul {
    margin: 0;
    padding-left: 16px;
    color: #e2e8f0;
    font-size: 0.74rem;
    line-height: 1.5;
}

.learning-section li {
    margin-bottom: 6px;
}

.learning-warmup {
    margin-top: 12px;
    padding: 11px 12px;
    border-radius: 10px;
    border: 1px solid rgba(245, 158, 11, 0.4);
    background: rgba(245, 158, 11, 0.08);
}

.learning-warmup-title {
    font-size: 0.68rem;
    letter-spacing: 1.1px;
    text-transform: uppercase;
    color: #fbbf24;
    margin-bottom: 6px;
}

.learning-warmup p {
    margin: 0;
    color: #fde68a;
    font-size: 0.75rem;
    line-height: 1.48;
}

.learning-actions {
    margin-top: 14px;
    display: flex;
    justify-content: flex-end;
}

/* --- GAME OVER & VICTORY --- */
#screen-gameover {
    background: linear-gradient(135deg, #1a0000 0%, #0a0a0f 100%);
}

.gameover-title {
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--red);
    letter-spacing: 6px;
    margin-bottom: 20px;
    text-shadow: 0 0 30px rgba(239, 68, 68, 0.5);
}

.gameover-stats {
    font-size: 0.85rem;
    line-height: 2;
    color: #d1d5db;
    margin-bottom: 30px;
    text-align: center;
}

.victory-title {
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--gold);
    letter-spacing: 6px;
    margin-bottom: 10px;
    text-shadow: 0 0 30px rgba(251, 191, 36, 0.5);
    animation: promoPulse 2s ease-in-out infinite;
}

.victory-sub {
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 24px;
}

.victory-stats {
    font-size: 0.85rem;
    line-height: 2;
    color: #d1d5db;
    margin-bottom: 30px;
    text-align: center;
}

/* --- SCROLLBAR --- */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #374151;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #4b5563;
}

/* --- ADDITIONAL ELEMENTS --- */

.title-container {
    text-align: center;
}

.title-subtitle {
    font-size: clamp(0.65rem, 1.5vw, 0.85rem);
    color: var(--muted);
    letter-spacing: 4px;
    margin-bottom: 20px;
}

.title-description {
    font-size: 0.78rem;
    color: #9ca3af;
    line-height: 1.7;
    margin-bottom: 30px;
    max-width: 500px;
}

.btn-secondary {
    padding: 12px 36px;
    background: transparent;
    border: 1px solid #4b5563;
    color: var(--muted);
    font-family: var(--font);
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: var(--radius);
    margin-top: 10px;
    transition: all 0.2s;
}

.btn-secondary:hover {
    border-color: var(--accent);
    color: var(--text);
}

.onboarding-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 600px;
    width: 100%;
    padding: 30px;
}

.onboarding-panel h2 {
    font-size: 1.4rem;
    color: var(--gold);
    margin-bottom: 6px;
}

.onboarding-panel .subtitle {
    font-size: 0.75rem;
    color: var(--muted);
    margin-bottom: 20px;
}

.onboarding-panel label {
    font-size: 0.7rem;
    color: var(--accent);
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 8px;
    margin-top: 14px;
    align-self: flex-start;
}

.onboarding-panel .hint {
    font-size: 0.65rem;
    color: var(--muted);
    margin-bottom: 8px;
    align-self: flex-start;
}

.onboarding-panel input,
.onboarding-panel select {
    width: 100%;
    padding: 10px 14px;
    background: #1f2937;
    border: 1px solid #374151;
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.85rem;
    margin-bottom: 6px;
}

.onboarding-panel input:focus,
.onboarding-panel select:focus {
    border-color: var(--accent);
    outline: none;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    flex-shrink: 0;
    padding-top: 4px;
}

.btn-dialog {
    padding: 10px 24px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-family: var(--font);
    font-size: 0.72rem;
    cursor: pointer;
    transition: all 0.15s;
    min-height: 44px;
    touch-action: manipulation;
}

.btn-dialog:hover {
    background: #2563eb;
}

.key-cap {
    display: inline-block;
    padding: 2px 8px;
    background: #374151;
    border: 1px solid #555;
    border-radius: 4px;
    font-size: 0.6rem;
    color: #fff;
    margin-right: 4px;
}

.mobile-left,
.mobile-right {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    pointer-events: auto;
    /* Prevent accidental text selection on long press */
    -webkit-user-select: none;
    user-select: none;
}

.ctrl-jump,
.ctrl-down,
.ctrl-action {
    font-size: 0.58rem;
    font-weight: 800;
    letter-spacing: 0.03em;
}

/* Jump button: amber ring to distinguish from d-pad */
.ctrl-jump {
    border-color: rgba(251, 191, 36, 0.55);
    color: #fbbf24;
}

/* Pause button: smaller, muted */
.ctrl-pause {
    width: 46px !important;
    height: 46px !important;
    font-size: 0.9rem !important;
    border-color: rgba(255, 255, 255, 0.2);
    opacity: 0.75;
}

.challenge-description {
    font-size: 0.8rem;
    line-height: 1.6;
    color: #d1d5db;
    margin-bottom: 14px;
}

.gameover-panel {
    text-align: center;
    max-width: 500px;
    padding: 30px;
}

/* Victory screen with canvas celebration */
#screen-victory {
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    background: #0a0e1a;
    overflow: hidden;
    padding-bottom: 3%;
    /* garante que o card nunca encoste na borda */
}

#victoryCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    z-index: 0;
}

.victory-overlay-ui {
    position: relative;
    z-index: 2;
    text-align: center;
    width: 70%;
    max-width: 300px;
    padding: 10px 16px 12px;
    background: rgba(10, 14, 26, 0.93);
    border: 1px solid rgba(251, 191, 36, 0.35);
    border-radius: 14px;
    margin-bottom: 2.5%;
    backdrop-filter: blur(12px);
    box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.6);
}

.victory-overlay-ui h1 {
    font-size: 0.72rem;
    font-weight: 900;
    color: var(--gold);
    letter-spacing: 3px;
    margin-bottom: 4px;
    text-shadow: 0 0 30px rgba(251, 191, 36, 0.5);
    animation: promoPulse 2s ease-in-out infinite;
}

.victory-overlay-ui p {
    font-size: 0.58rem;
    color: #9ca3af;
    line-height: 1.4;
    margin-bottom: 6px;
    max-width: 280px;
    margin-left: auto;
    margin-right: auto;
}

.victory-overlay-ui .victory-stats {
    font-size: 0.62rem;
    line-height: 1.7;
    margin-bottom: 8px;
}

.victory-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

.gameover-panel h1 {
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--red);
    letter-spacing: 6px;
    margin-bottom: 16px;
    text-shadow: 0 0 30px rgba(239, 68, 68, 0.5);
}

.gameover-panel p {
    font-size: 0.8rem;
    color: #9ca3af;
    line-height: 1.7;
    margin-bottom: 10px;
}

.promotion-card {
    text-align: center;
    max-width: 420px;
    padding: 30px;
}

.promotion-card h2 {
    font-size: 1.6rem;
    font-weight: 900;
    color: var(--gold);
    letter-spacing: 4px;
    margin-bottom: 16px;
    text-shadow: 0 0 20px rgba(251, 191, 36, 0.4);
    animation: promoPulse 1.5s ease-in-out infinite;
}

.promotion-card p {
    font-size: 0.85rem;
    color: #d1d5db;
    line-height: 1.6;
    margin-bottom: 12px;
}

.challenge-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}

.challenge-header {
    margin-bottom: 10px;
}

.challenge-body {
    margin-bottom: 16px;
}

/* --- BOOK POPUP --- */
.book-popup {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 55;
    animation: bookFadeIn 0.3s ease;
}

.book-popup.visible {
    display: flex;
}

@keyframes bookFadeIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.book-popup-card {
    background: linear-gradient(145deg, #1e293b, #0f172a);
    border: 2px solid var(--gold);
    border-radius: 16px;
    padding: 32px 28px;
    max-width: 480px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    text-align: center;
    box-shadow: 0 0 40px rgba(251, 191, 36, 0.15);
}

.book-icon-large {
    font-size: 3.5rem;
    margin-bottom: 12px;
    filter: drop-shadow(0 0 10px rgba(251, 191, 36, 0.4));
}

.book-popup-title {
    font-size: 1.1rem;
    font-weight: 900;
    color: var(--gold);
    margin-bottom: 4px;
    letter-spacing: 1px;
}

.book-popup-author {
    font-size: 0.75rem;
    color: var(--muted);
    margin-bottom: 16px;
    font-style: italic;
}

.book-popup-summary {
    font-size: 0.8rem;
    color: var(--text);
    line-height: 1.7;
    margin-bottom: 14px;
    text-align: left;
}

.book-popup-lesson {
    font-size: 0.78rem;
    color: var(--green);
    font-weight: 700;
    padding: 10px 14px;
    background: rgba(34, 197, 94, 0.08);
    border-left: 3px solid var(--green);
    border-radius: 0 6px 6px 0;
    text-align: left;
    margin-bottom: 18px;
}

/* ==========================================================================
   PAUSE OVERLAY
   ========================================================================== */
.pause-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(4px);
    animation: pauseFadeIn 0.2s ease;
}

.pause-overlay.active {
    display: flex;
}

@keyframes pauseFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.pause-card {
    background: linear-gradient(145deg, #1e293b, #0f172a);
    border: 2px solid var(--gold);
    border-radius: 16px;
    padding: 40px 48px;
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow: 0 0 60px rgba(251, 191, 36, 0.2);
}

.pause-title {
    font-size: 2rem;
    font-weight: 900;
    color: var(--gold);
    letter-spacing: 3px;
    margin-bottom: 12px;
    text-transform: uppercase;
}

.pause-hint {
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 28px;
}

.pause-hint strong {
    color: var(--text);
}

.pause-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* HUD pause button — always visible */
#btnPauseHud {
    pointer-events: auto;
    cursor: pointer;
}

/* Mobile pause button */
.ctrl-pause {
    font-size: 1.1rem;
    letter-spacing: 2px;
    color: #facc15;
    background: rgba(250, 204, 21, 0.15);
    border-color: rgba(250, 204, 21, 0.4);
}

.ctrl-pause:active {
    background: rgba(250, 204, 21, 0.3);
}

/* ==========================================================================
   STUDY CHAT SIDEBAR (IDE RIGHT)
   ========================================================================== */
.study-chat-overlay {
    width: 360px;
    min-width: 320px;
    max-width: 420px;
    height: 100%;
    border-left: 1px solid #1e293b;
    background: #0f172a;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.study-chat-overlay.visible {
    display: flex;
}

.study-chat-card {
    width: 100%;
    height: 100%;
    background: #0f172a;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.study-chat-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid #1e293b;
    background: linear-gradient(180deg, #0b1224 0%, #0f172a 100%);
}

.study-chat-header h3 {
    margin: 0;
    font-size: 0.9rem;
    letter-spacing: 1px;
    color: #e2e8f0;
}

.study-chat-header p {
    margin: 4px 0 0;
    color: #94a3b8;
    font-size: 0.72rem;
}

/* Dots animados no cabeçalho enquanto a IA processa */
.chat-header-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 5px;
}

.chat-header-dots span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #22d3ee;
    animation: garageDotWave 1s ease-in-out infinite;
}

.chat-header-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-header-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

.study-chat-close {
    border: 1px solid #334155;
    border-radius: 8px;
    background: #0b1220;
    color: #cbd5e1;
    width: 36px;
    height: 36px;
    font-size: 1.2rem;
    cursor: pointer;
}

.study-chat-close:hover {
    border-color: #22d3ee;
    color: #22d3ee;
}

.study-chat-messages {
    flex: 1;
    min-height: 120px;
    overflow-y: auto;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #0b1220;
}

.study-msg {
    border: 1px solid #1f2937;
    border-radius: 10px;
    padding: 10px 12px;
    line-height: 1.45;
    font-size: 0.8rem;
}

.study-msg-user {
    white-space: pre-wrap;
}

.study-msg-user {
    align-self: flex-end;
    background: #111827;
    border-color: #334155;
    color: #e2e8f0;
    max-width: 90%;
}

.study-msg-assistant {
    align-self: stretch;
    background: #0f172a;
    border-color: #1e293b;
    color: #cbd5e1;
}

.study-msg-meta {
    display: block;
    margin-bottom: 5px;
    font-size: 0.67rem;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: #67e8f9;
}

.study-chat-composer {
    border-top: 1px solid #1e293b;
    padding: 12px;
    background: #0f172a;
}

.study-chat-composer textarea {
    width: 100%;
    min-height: 86px;
    resize: vertical;
    border: 1px solid #334155;
    border-radius: 8px;
    background: #020617;
    color: #e2e8f0;
    padding: 10px 12px;
    font-family: var(--font);
    font-size: 0.78rem;
    line-height: 1.45;
}

.study-chat-composer textarea:focus {
    outline: none;
    border-color: #22d3ee;
    box-shadow: 0 0 0 2px rgba(34, 211, 238, 0.15);
}

.study-chat-actions {
    margin-top: 8px;
    display: flex;
    justify-content: flex-end;
}

.study-chat-actions .btn-primary {
    min-width: 130px;
}

/* === Garage A.I — animated dots (header loading indicator) === */
@keyframes garageDotWave {

    0%,
    100% {
        transform: translateY(0);
        opacity: 0.3;
    }

    50% {
        transform: translateY(-5px);
        opacity: 1;
    }
}

/* === AI typing bubble — aparece enquanto aguarda resposta === */
.ai-typing-bubble {
    align-self: flex-start;
    display: flex;
    flex-direction: column;
    gap: 5px;
    background: #0f172a;
    border: 1px solid #1e293b;
    border-radius: 10px;
    padding: 8px 14px;
}

.ai-typing-bubble-meta {
    font-size: 0.67rem;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: #67e8f9;
}

.ai-typing-dots {
    display: flex;
    align-items: center;
    gap: 5px;
    height: 14px;
}

.ai-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #22d3ee;
    animation: garageDotWave 1s ease-in-out infinite;
}

.ai-typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes garageIdlePulse {

    0%,
    100% {
        opacity: 0.15;
        transform: scale(0.85);
    }

    50% {
        opacity: 0.55;
        transform: scale(1.15);
    }
}


/* === Typing indicator — bolinha no chat quando o usuario digita === */
.study-msg-typing {
    min-height: 38px;
}

.study-typing-body {
    display: flex !important;
    align-items: center;
    gap: 6px;
    padding: 4px 0 2px;
}

.study-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22d3ee;
    opacity: 0.35;
    animation: garageDotWave 1s ease-in-out infinite;
}

.study-typing-dot:nth-child(2) {
    animation-delay: 0.22s;
}

.study-typing-dot:nth-child(3) {
    animation-delay: 0.44s;
}

/* === Thinking button: spinning ring + stop icon === */
@keyframes garageSpinRing {
    to {
        transform: rotate(360deg);
    }
}

.garage-send-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    width: 100%;
    pointer-events: none;
}

.garage-send-ring {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2.5px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    animation: garageSpinRing 0.7s linear infinite;
    flex-shrink: 0;
}

.garage-stop-icon {
    width: 9px;
    height: 9px;
    background: #fff;
    border-radius: 2px;
    flex-shrink: 0;
}

.garage-stop-label {
    font-size: 0.62rem;
    letter-spacing: 1.2px;
    color: #fff;
    opacity: 0.9;
}

/* --- Study Chat Markdown Rendering ---------------------------------------- */
.study-msg-body p.study-p {
    margin: 2px 0 4px;
}

.study-msg-body .study-code-block {
    position: relative;
    background: #020817;
    border: 1px solid #22d3ee33;
    border-radius: 8px;
    padding: 30px 14px 12px 14px;
    /* top padding = room for header row */
    margin: 8px 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    box-sizing: border-box;
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 0.75rem;
    line-height: 1.6;
    color: #7dd3fc;
    white-space: pre;
    tab-size: 4;
}

.study-msg-body .study-code-block code {
    display: block;
    white-space: pre;
    word-break: normal;
    overflow-wrap: normal;
}

.study-msg-body .study-code-lang {
    position: absolute;
    top: 7px;
    left: 12px;
    font-size: 0.58rem;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: #22d3ee;
    opacity: 0.75;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
}

/* ---- Copy button ---- */
.study-code-copy {
    position: absolute;
    top: 5px;
    right: 8px;
    background: transparent;
    border: 1px solid #22d3ee44;
    border-radius: 4px;
    color: #22d3ee;
    font-family: var(--font, 'Courier New', monospace);
    font-size: 0.58rem;
    letter-spacing: 0.8px;
    padding: 2px 9px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    line-height: 1.6;
    white-space: nowrap;
    /* Critical: button text must NOT be selected when user selects code */
    user-select: none;
    -webkit-user-select: none;
}

.study-code-copy:hover {
    background: #22d3ee18;
    border-color: #22d3ee88;
}

.study-code-copy.study-code-copy--ok {
    background: #22d3ee22;
    border-color: #22d3ee;
    color: #6ee7b7;
}

.study-msg-body .study-inline-code {
    background: #0f2845;
    border: 1px solid #1e4d8080;
    border-radius: 4px;
    padding: 1px 5px;
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 0.78em;
    color: #7dd3fc;
}

.study-msg-body strong {
    color: #f0feff;
    font-weight: 700;
}

.study-msg-body em {
    color: #93c5fd;
    font-style: italic;
}

.study-msg-body .study-list {
    margin: 4px 0 4px 16px;
    padding-left: 8px;
}

.study-msg-body .study-list li {
    margin: 2px 0;
    line-height: 1.5;
}

.study-msg-body .study-heading {
    color: #22d3ee;
    font-size: 0.82rem;
    margin: 8px 0 4px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.study-msg-body .study-hr {
    border: none;
    border-top: 1px solid #1e293b;
    margin: 8px 0;
}

/* Streaming typing cursor */
@keyframes studyCursorBlink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

/* ── Pensando... (waiting for complete response) ── */
@keyframes pensandoPulse {
    0% {
        opacity: 1;
        letter-spacing: 2px;
    }

    50% {
        opacity: 0.4;
        letter-spacing: 6px;
    }

    100% {
        opacity: 1;
        letter-spacing: 2px;
    }
}

.study-pensando {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #58a6ff;
    font-size: 0.82rem;
    font-family: 'Courier New', monospace;
    letter-spacing: 2px;
    animation: pensandoPulse 1.4s ease-in-out infinite;
    padding: 4px 0;
}


/* ==========================================================================
   IDE CODING CHALLENGE OVERLAY
   ========================================================================== */
.ide-overlay {
    position: fixed;
    inset: 0;
    background: #0d1117;
    display: none;
    flex-direction: column;
    z-index: 50;
}

.ide-overlay.visible {
    display: flex;
}

.ide-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
}

.ide-container.keyboard-open .ide-terminal {
    height: 80px;
    min-height: 60px;
}

.ide-container.keyboard-open .ide-bottombar {
    display: none !important;
}

/* --- Top Bar (VS Code style) --- */
.ide-topbar {
    display: flex;
    align-items: center;
    background: #161b22;
    border-bottom: 1px solid #21262d;
    padding: 6px 14px;
    height: 36px;
    min-height: 36px;
}

.ide-topbar-dots {
    display: flex;
    gap: 6px;
    margin-right: 14px;
}

.ide-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.ide-dot-red {
    background: #ff5f56;
}

.ide-dot-yellow {
    background: #ffbd2e;
}

.ide-dot-green {
    background: #27c93f;
}

.ide-topbar-title {
    color: #8b949e;
    font-family: var(--font);
    font-size: 0.78rem;
    flex: 1;
}

.ide-topbar-right {
    display: flex;
    align-items: center;
}

.ide-stage-badge {
    background: var(--accent);
    color: #000;
    font-family: var(--font);
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 10px;
    border-radius: 10px;
    letter-spacing: 1px;
}

/* --- Main Area (sidebar + editor) --- */
.ide-main {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Sidebar */
.ide-sidebar {
    width: 220px;
    min-width: 220px;
    background: #0d1117;
    border-right: 1px solid #21262d;
    padding: 10px 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.ide-sidebar-header {
    color: #8b949e;
    font-family: var(--font);
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 2px;
    padding: 6px 14px;
    text-transform: uppercase;
}

.ide-file {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 14px 4px 20px;
    color: #c9d1d9;
    font-family: var(--font);
    font-size: 0.75rem;
    cursor: default;
}

.ide-file.active {
    background: #1f2937;
}

.ide-file-icon {
    color: #f97316;
    font-size: 0.55rem;
}

.ide-sidebar-section {
    color: #8b949e;
    font-family: var(--font);
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 2px;
    padding: 14px 14px 4px;
    text-transform: uppercase;
    border-top: 1px solid #21262d;
    margin-top: 8px;
}

.ide-challenge-info {
    padding: 6px 14px;
}

.ide-challenge-title {
    color: #58a6ff;
    font-family: var(--font);
    font-size: 0.78rem;
    font-weight: 700;
    margin-bottom: 6px;
}

.ide-challenge-desc {
    color: #8b949e;
    font-family: var(--font);
    font-size: 0.68rem;
    line-height: 1.5;
}

.ide-concept-tag {
    margin: 6px 14px;
    display: inline-block;
    background: rgba(88, 166, 255, 0.12);
    color: #58a6ff;
    font-family: var(--font);
    font-size: 0.65rem;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 4px;
}

/* Editor Area */
.ide-editor-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ide-editor {
    flex: 1;
    display: flex;
    background: #0d1117;
    overflow: hidden;
    position: relative;
}

.ide-line-numbers {
    display: flex;
    flex-direction: column;
    padding: 14px 0;
    min-width: 44px;
    text-align: right;
    padding-right: 12px;
    background: #0d1117;
    border-right: 1px solid #21262d;
    user-select: none;
    overflow: hidden;
    /* scroll sync via JS — no visible scrollbar */
    flex-shrink: 0;
}

.ide-line-numbers span {
    color: #484f58;
    font-family: var(--font);
    font-size: 0.82rem;
    /* MUST match .ide-code-input font-size for pixel-perfect row alignment */
    line-height: 1.65;
    padding-right: 4px;
    display: block;
}

.ide-code-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #c9d1d9;
    font-family: var(--font);
    font-size: 0.82rem;
    line-height: 1.65;
    padding: 14px 16px;
    resize: none;
    tab-size: 4;
    white-space: pre;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.ide-code-input::placeholder {
    color: #484f58;
}

.ide-code-input:focus {
    box-shadow: none;
}

/* Terminal */
.ide-terminal {
    height: 140px;
    min-height: 100px;
    background: #161b22;
    border-top: 1px solid #21262d;
    display: flex;
    flex-direction: column;
}

.ide-terminal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 14px;
    color: #8b949e;
    font-family: var(--font);
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 1px;
    border-bottom: 1px solid #21262d;
}

.ide-terminal-status {
    color: #27c93f;
}

.ide-terminal-status.error {
    color: #ff5f56;
}

.ide-terminal-output {
    flex: 1;
    padding: 8px 14px;
    font-family: var(--font);
    font-size: 0.75rem;
    color: #8b949e;
    overflow-y: auto;
    white-space: pre-wrap;
    line-height: 1.5;
}

.ide-prompt {
    color: #27c93f;
}

.ide-term-success {
    color: #27c93f;
}

.ide-term-error {
    color: #ff5f56;
}

.ide-term-info {
    color: #58a6ff;
}

.ide-term-warn {
    color: #ffbd2e;
}

/* Real JVM stdout — neutral white, like a real terminal */
.ide-term-output {
    color: #e6edf3;
}

/* Bottom Bar */
.ide-bottombar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    background: #161b22;
    border-top: 1px solid #21262d;
    padding: 8px 20px;
    min-height: 90px;
}

/* Characters in IDE */
.ide-char {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.ide-char canvas {
    image-rendering: pixelated;
}

.ide-char-name {
    color: #c9d1d9;
    font-family: var(--font);
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 1px;
    text-align: center;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Action Buttons */
.ide-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.ide-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border: 1px solid #374151;
    border-radius: 6px;
    font-family: var(--font);
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    letter-spacing: 0.5px;
    touch-action: manipulation;
    min-height: 44px;
}

.ide-btn-icon {
    font-size: 0.9rem;
}

.ide-btn-run {
    background: #238636;
    border-color: #2ea043;
    color: #fff;
}

.ide-btn-run:hover {
    background: #2ea043;
}

.ide-btn-help {
    background: #1f2937;
    border-color: #374151;
    color: #58a6ff;
}

.ide-btn-help:hover {
    background: #293548;
    border-color: #58a6ff;
}

.ide-btn-chat {
    background: #0f172a;
    border-color: #334155;
    color: #22d3ee;
}

.ide-btn-chat:hover {
    background: #12243a;
    border-color: #22d3ee;
}

.ide-btn-chat.active {
    background: #0e2a3b;
    border-color: #22d3ee;
    color: #67e8f9;
}

.ide-btn-skip {
    background: #1f2937;
    border-color: #374151;
    color: #8b949e;
}

.ide-btn-skip:hover {
    background: #293548;
}

.ide-btn-exit {
    background: #1f2937;
    border-color: #374151;
    color: #f87171;
}

.ide-btn-exit:hover {
    background: #2a1515;
    border-color: #ef4444;
}

/* Help Overlay */
.ide-help-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 55;
    padding: 16px;
    overflow-y: auto;
}

.ide-help-card {
    background: #161b22;
    border: 1px solid #58a6ff;
    border-radius: 10px;
    padding: 24px;
    max-width: 500px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.ide-help-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    flex-shrink: 0;
}

.ide-help-icon {
    font-size: 1.4rem;
}

.ide-help-mentor {
    color: #58a6ff;
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 700;
}

.ide-help-content {
    color: #c9d1d9;
    font-family: var(--font);
    font-size: 0.78rem;
    line-height: 1.7;
    white-space: pre-wrap;
    margin-bottom: 18px;
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
}

.ide-help-card .ide-btn {
    flex-shrink: 0;
}

/* ---- responsive: tablets (max-width 768px) ---- */
@media (max-width: 768px) {
    .hud {
        height: 44px;
        flex-wrap: nowrap;
        overflow: hidden;
        gap: 0;
        padding: 0 4px;
        justify-content: flex-start;
    }

    /* PAUSA e SAIR sempre visíveis no mobile — ficam na frente via order */
    #btnPauseHud {
        order: -2;
        flex-shrink: 0;
    }

    #hudBtnSair {
        order: -1;
        flex-shrink: 0;
    }

    .hud-block {
        padding: 2px 6px;
        flex-shrink: 1;
        min-width: 0;
    }

    .hud-sep {
        display: none;
    }

    .hud-label {
        font-size: 0.38rem;
        letter-spacing: 1px;
    }

    .hud-value {
        font-size: 0.68rem;
    }

    .challenge-overlay {
        padding: 10px;
    }

    .challenge-panel {
        padding: 18px 14px;
        width: 98vw;
        max-height: 92vh;
    }

    .challenge-code {
        font-size: 0.65rem;
        padding: 10px;
    }

    .option-btn {
        padding: 14px 14px;
        font-size: 0.78rem;
        min-height: 48px;
    }

    .onboarding-panel {
        padding: 20px 16px;
    }

    .book-popup-card {
        padding: 24px 18px;
        width: 94%;
        max-height: 90vh;
        overflow-y: auto;
    }

    .dialog-box {
        width: min(96vw, 600px);
    }

    .btn-dialog {
        padding: 12px 24px;
        font-size: 0.78rem;
        min-height: 44px;
    }
}

/* ---- responsive: phones (max-width 480px) ---- */
@media (max-width: 480px) {

    /* title screen */
    .arcade-top-text {
        font-size: 0.45rem;
        letter-spacing: 3px;
    }

    .arcade-description {
        font-size: 0.5rem;
        letter-spacing: 1px;
        line-height: 1.6;
        padding: 0 8px;
    }

    .arcade-insert {
        font-size: 0.65rem;
        margin: 10px 0 6px;
    }

    .arcade-btn {
        width: 90vw;
        padding: 16px 16px;
        font-size: 0.75rem;
        min-height: 50px;
    }

    .arcade-credits {
        margin-top: 12px;
        font-size: 0.5rem;
    }

    .arcade-footer {
        font-size: 0.55rem;
        padding: 10px 8px;
        line-height: 1.8;
    }

    /* HUD */
    .hud {
        flex-wrap: wrap;
        justify-content: space-around;
        padding: 4px;
        gap: 2px;
    }

    .hud-block {
        padding: 2px 6px;
        gap: 4px;
    }

    .hud-icon {
        font-size: 0.75rem;
    }

    .hud-label {
        font-size: 0.35rem;
        letter-spacing: 1px;
    }

    .hud-value {
        font-size: 0.6rem;
    }

    /* dialog */
    .dialog-box {
        width: 96vw;
        padding: 14px;
        bottom: 150px;
        max-height: calc(100vh - 190px);
    }

    .dialog-avatar {
        width: 40px;
        height: 40px;
        font-size: 1.1rem;
    }

    .dialog-name {
        font-size: 0.75rem;
    }

    .dialog-content {
        font-size: 0.72rem;
        line-height: 1.5;
        max-height: 30vh;
    }

    .btn-dialog {
        padding: 12px 20px;
        font-size: 0.75rem;
        min-height: 44px;
    }

    .interact-hint {
        bottom: 200px;
        font-size: 0.65rem;
        padding: 8px 16px;
    }

    /* mobile controls -- bigger touch targets */
    .mobile-controls {
        padding: 10px 14px 24px;
    }

    .ctrl-btn {
        width: 52px;
        height: 52px;
        font-size: 1.1rem;
    }

    .ctrl-btn.action {
        width: 60px;
        height: 60px;
        font-size: 0.6rem;
    }

    .mobile-left,
    .mobile-right {
        gap: 8px;
    }

    /* challenge */
    .challenge-overlay {
        padding: 8px;
    }

    .challenge-panel {
        padding: 16px 12px;
        border-radius: 8px;
        width: 100vw;
        max-height: 95vh;
        border-radius: 12px 12px 0 0;
    }

    .challenge-title {
        font-size: 0.95rem;
    }

    .challenge-description {
        font-size: 0.72rem;
    }

    .challenge-code {
        font-size: 0.6rem;
        max-height: 150px;
    }

    .option-btn {
        padding: 14px 12px;
        font-size: 0.72rem;
        min-height: 48px;
    }

    .feedback-box {
        font-size: 0.7rem;
        padding: 10px;
    }

    .challenge-actions {
        flex-direction: column;
        gap: 8px;
    }

    .challenge-actions .btn-primary,
    .challenge-actions .btn-secondary {
        width: 100%;
        min-height: 48px;
    }

    /* learning prep */
    .learning-overlay {
        padding: 10px;
    }

    .learning-card {
        width: 100%;
        max-height: 95vh;
        padding: 14px 12px;
    }

    .learning-card h2 {
        font-size: 0.98rem;
    }

    .learning-subtitle {
        font-size: 0.7rem;
    }

    .learning-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .learning-section {
        padding: 10px;
    }

    .learning-section h3 {
        font-size: 0.66rem;
    }

    .learning-section ul {
        font-size: 0.7rem;
    }

    .learning-actions .btn-primary {
        width: 100%;
        min-height: 48px;
    }

    /* onboarding */
    .onboarding-panel h2 {
        font-size: 1.1rem;
    }

    .avatar-selection {
        gap: 10px;
    }

    .avatar-card {
        padding: 12px 8px;
        flex: 0 1 120px;
    }

    .avatar-card canvas {
        width: 80px;
        height: 134px;
    }

    .avatar-card-name {
        font-size: 0.65rem;
        letter-spacing: 1px;
    }

    .onboarding-panel label {
        font-size: 0.6rem;
    }

    .onboarding-panel input,
    .onboarding-panel select {
        font-size: 16px;
        padding: 12px 12px;
        min-height: 48px;
    }

    .btn-primary {
        width: 100%;
        padding: 14px 20px;
        font-size: 0.82rem;
        min-height: 50px;
    }

    .btn-secondary {
        width: 100%;
        min-height: 48px;
    }

    /* game over / victory */
    .gameover-panel {
        padding: 24px 16px;
        max-width: 95vw;
    }

    .gameover-panel h1 {
        font-size: 1.8rem;
        letter-spacing: 4px;
    }

    .gameover-panel p {
        font-size: 0.72rem;
    }

    .victory-overlay-ui {
        padding: 8px 10px 10px;
        max-width: 80vw;
        margin-bottom: 1.5%;
    }

    .victory-overlay-ui h1 {
        font-size: 0.65rem;
        letter-spacing: 2px;
    }

    .victory-overlay-ui p {
        font-size: 0.52rem;
    }

    .victory-overlay-ui .victory-stats {
        font-size: 0.56rem;
        line-height: 1.6;
    }

    /* promotion */
    .promotion-card {
        padding: 24px 16px;
        max-width: 90vw;
    }

    .promotion-card h2 {
        font-size: 1.2rem;
    }

    .promotion-card p {
        font-size: 0.75rem;
    }

    /* book popup */
    .book-popup-card {
        padding: 20px 16px;
        width: 94%;
        max-height: 90vh;
        overflow-y: auto;
    }

    .book-icon-large {
        font-size: 2.5rem;
    }

    .book-popup-title {
        font-size: 0.95rem;
    }

    .book-popup-summary {
        font-size: 0.72rem;
    }

    .book-popup-lesson {
        font-size: 0.7rem;
    }

    .study-chat-overlay {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        min-width: 0;
        max-width: none;
        border-left: none;
        border-top: 1px solid #1e293b;
        z-index: 56;
    }

    .study-chat-card {
        width: 100%;
        height: 100%;
    }

    .study-chat-messages {
        min-height: 0;
    }

    .study-chat-composer textarea {
        min-height: 94px;
        font-size: 16px;
    }

    .study-chat-actions .btn-primary {
        width: 100%;
    }

    .study-msg-body .study-code-block {
        font-size: 0.7rem;
        padding: 28px 10px 10px 10px;
    }

    .study-code-copy {
        font-size: 0.6rem;
        padding: 3px 10px;
        min-height: 24px;
    }
}

/* ---- responsive: IDE on phones ---- */
@media (max-width: 700px) {
    .study-chat-overlay {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        min-width: 0;
        max-width: none;
        border-left: none;
        border-top: 1px solid #1e293b;
        z-index: 56;
    }

    .study-chat-card {
        height: 100%;
    }

    .study-msg-body .study-code-block {
        font-size: 0.65rem;
        padding: 26px 8px 8px 8px;
    }

    .study-code-copy {
        font-size: 0.58rem;
        padding: 3px 8px;
        top: 4px;
        right: 6px;
    }

    .ide-sidebar {
        display: none;
    }

    .ide-topbar {
        padding: 4px 10px;
        height: 32px;
        min-height: 32px;
    }

    .ide-topbar-title {
        font-size: 0.68rem;
    }

    .ide-stage-badge {
        font-size: 0.55rem;
        padding: 2px 8px;
    }

    .ide-bottombar {
        padding: 6px 10px;
        min-height: 70px;
        flex-wrap: wrap;
        gap: 6px;
        justify-content: center;
    }

    .ide-actions {
        order: -1;
        width: 100%;
        justify-content: center;
    }

    .ide-btn {
        padding: 10px 14px;
        font-size: 0.72rem;
        min-height: 44px;
        flex: 1;
        justify-content: center;
    }

    .ide-char {
        display: none;
    }

    .ide-code-input {
        font-size: 16px;
        padding: 10px 12px;
        line-height: 1.5;
    }

    .ide-line-numbers {
        min-width: 32px;
        padding-right: 6px;
    }

    .ide-line-numbers span {
        font-size: 0.62rem;
    }

    .ide-terminal {
        height: 110px;
        min-height: 80px;
    }

    .ide-terminal-output {
        font-size: 0.68rem;
        -webkit-overflow-scrolling: touch;
    }

    .ide-help-card {
        padding: 16px;
        width: 95%;
        max-height: 80vh;
        overflow-y: auto;
    }

    .ide-help-content {
        font-size: 0.7rem;
        max-height: none;
    }

    .ide-help-card .ide-btn {
        width: 100%;
        min-height: 48px;
        flex-shrink: 0;
    }
}

/* ---- responsive: landscape on phones ---- */
@media (max-height: 500px) and (orientation: landscape) {
    .hud {
        height: auto;
        padding: 2px 6px;
    }

    .hud-block {
        padding: 1px 6px;
    }

    .hud-label {
        display: none;
    }

    .mobile-controls {
        padding: 6px 14px 10px;
    }

    .ctrl-btn {
        width: 42px;
        height: 42px;
        font-size: 0.9rem;
    }

    .ctrl-btn.action {
        width: 50px;
        height: 50px;
        font-size: 0.55rem;
    }

    .dialog-box {
        bottom: 120px;
    }

    .interact-hint {
        bottom: 130px;
    }

    .challenge-panel {
        max-height: 85vh;
        overflow-y: auto;
    }

    .ide-bottombar {
        min-height: 50px;
        padding: 4px 8px;
    }

    .ide-char canvas {
        width: 28px;
        height: 48px;
    }

    .ide-terminal {
        height: 70px;
        min-height: 50px;
    }

    .ide-help-overlay {
        padding: 8px;
    }

    .ide-help-card {
        max-height: 90vh;
        padding: 12px;
    }

    .ide-help-content {
        font-size: 0.68rem;
        line-height: 1.5;
    }

    .ide-help-card .ide-btn {
        min-height: 40px;
        padding: 6px 14px;
    }
}
