/* Native App Feel */
* {
    -webkit-touch-callout: none;
    /* iOS Safari */
    -webkit-user-select: none;
    /* Safari */
    -khtml-user-select: none;
    /* Konqueror HTML */
    -moz-user-select: none;
    /* Old versions of Firefox */
    -ms-user-select: none;
    /* Internet Explorer/Edge */
    user-select: none;
    /* Non-prefixed version, currently
                                  supported by Chrome, Edge, Opera and Firefox */
    -webkit-tap-highlight-color: transparent;
    cursor: default;
}

/* Re-enable pointer events for interactive elements if not already handled */
/* Note: existing classes manage specific cursors, but this ensures defaults */

img,
canvas {
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
}

body {
    margin: 0;
    padding: 0;
    /* Safe-area insets for notched devices (iPhone X+) */
    padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0)
             env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
    box-sizing: border-box;
    background-color: #222;
    color: #eee;
    font-family: 'Courier New', Courier, monospace;
    display: flex;
    justify-content: center;
    align-items: center;
    /* 100vh is unreliable on mobile (ignores browser chrome).
       100dvh (dynamic) shrinks correctly when address bar appears.
       -webkit-fill-available is the fallback for older iOS Safari. */
    height: 100vh;
    height: 100dvh;
    min-height: -webkit-fill-available;
    overflow: hidden;
}

/* --- Orientation Overlay --- */
#orientation-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #2c3e50;
    z-index: 10000;
    /* Above everything */
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    font-family: 'Segoe UI Black', 'Arial Black', sans-serif;
}

.orientation-content {
    background: #ecf0f1;
    padding: 40px;
    border-radius: 24px;
    border: 6px solid #bdc3c7;
    box-shadow: 0 20px 0 #95a5a6;
    max-width: 80%;
}

.rotate-icon {
    font-size: 80px;
    margin-bottom: 20px;
    animation: rotatePhone 2s infinite ease-in-out;
}

.rotate-text {
    font-size: 38px;
    /* Increased for Chromebook */
    color: #e74c3c;
    margin-bottom: 10px;
    text-transform: uppercase;
}

.rotate-subtext {
    font-size: 24px;
    /* Increased for Chromebook */
    color: #34495e;
}

@keyframes rotatePhone {
    0% {
        transform: rotate(0deg);
    }

    50% {
        transform: rotate(90deg);
    }

    100% {
        transform: rotate(0deg);
    }
}

/* Orientation overlay: shown in portrait by CSS as a fallback, but also controlled by JS */
@media screen and (orientation: portrait) {
    #orientation-overlay {
        display: flex;
    }
}

#game-container {
    position: absolute;
    width: 1920px;
    /* Default, updated dynamically by JS */
    /* min-width removed: it prevented CSS scale from working on mobile */
    height: 1080px;
    background-color: #000;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    transform-origin: top left;
    font-size: clamp(28px, 2.8vw, 32px);
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    background-color: #111;
}

#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

#stats {
    position: absolute;
    top: 0;
    right: 0;
    width: 140px;
    /* Increased for Chromebook readability */
    height: 240px;
    /* Increased height */
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    /* Push text to bottom */
    gap: 5px;
    font-family: 'Segoe UI Black', 'Arial Black', sans-serif;
    font-size: 28px;
    /* Increased for Chromebook */
    background-color: #f1c40f;
    /* Yellow Top Header */
    border-bottom: 4px solid #f39c12;
    padding: 10px 0 15px 0;
    /* Add bottom padding */
    align-items: center;
    pointer-events: none;
    /* Text only */
    z-index: 20;
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.2);
    color: #c0392b;
    text-transform: uppercase;
    text-shadow: 1px 1px 0 rgba(255, 255, 255, 0.4);
}

#next-wave-btn {
    pointer-events: auto;
    /* Re-enable clicks for button */
    position: absolute;
    bottom: 20px;
    right: 20px;
    padding: 10px 20px;
    font-family: inherit;
    font-size: 16px;
    background-color: #4CAF50;
    color: white;
    border: none;
    cursor: pointer;
    border-radius: 4px;
}

#next-wave-btn:hover {
    background-color: #45a049;
}

#build-controls {
    position: absolute;
    top: 0;
    right: 0;
    width: 140px;
    /* Increased for Chromebook readability */
    height: 100%;
    /* Sidebar Background */
    background-color: #3498db;
    /* Blue Plastic Base */
    background-image:
        radial-gradient(rgba(0, 0, 0, 0.1) 20%, transparent 20%),
        radial-gradient(rgba(0, 0, 0, 0.1) 20%, transparent 20%);
    background-position: 0 0, 10px 10px;
    background-size: 20px 20px;

    border-left: 4px solid #2980b9;
    box-shadow: -4px 0 10px rgba(0, 0, 0, 0.3);

    display: flex;
    flex-direction: column;
    gap: 10px;
    /* Increased Gap */
    overflow-y: auto;
    /* Enable scrolling */
    align-items: center;
    padding-top: 280px;
    /* Stats + Pause (adjusted) */
    padding-bottom: 20px;
    pointer-events: auto;
    box-sizing: border-box;

    /* Scrollbar Styling */
    scrollbar-width: thin;
    scrollbar-color: #2980b9 #3498db;
}

#build-controls::-webkit-scrollbar {
    width: 8px;
}

#build-controls::-webkit-scrollbar-track {
    background: #3498db;
    border-left: 1px solid #2980b9;
}

#build-controls::-webkit-scrollbar-thumb {
    background-color: #ecf0f1;
    border-radius: 4px;
    border: 2px solid #3498db;
}

.tower-btn {
    pointer-events: auto;
    position: relative;
    width: 140px;
    height: 140px;
    /* Increased for Chromebook readability */
    background-color: #ecf0f1;
    border: none;
    border-radius: 6px;

    /* 3D Button Look */
    box-shadow:
        0 4px 0 #bdc3c7,
        0 6px 8px rgba(0, 0, 0, 0.2);

    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.1s;
    margin-bottom: 2px;

    font-family: 'Segoe UI', sans-serif;
    font-weight: bold;
    color: #000;
    text-transform: uppercase;
    font-size: 20px;
}



.tower-btn img {
    width: 90px;
    height: 90px;
    /* Increased for Chromebook readability */
    object-fit: contain;
    margin-bottom: 4px;
    image-rendering: pixelated;
    filter: drop-shadow(0 4px 0 rgba(0, 0, 0, 0.2));
    transition: transform 0.1s;
}

.tower-btn span {
    text-align: center;
    line-height: 1.2;
    background: rgba(255, 255, 255, 0.5);
    padding: 2px 8px;
    border-radius: 4px;
    width: 90%;
}

.tower-btn:hover {
    transform: translateY(-2px);
    box-shadow:
        0 8px 0 #bdc3c7,
        0 12px 15px rgba(0, 0, 0, 0.2);
}

.tower-btn:active {
    transform: translateY(4px);
    box-shadow:
        0 2px 0 #bdc3c7,
        0 2px 2px rgba(0, 0, 0, 0.2);
}

.tower-btn.selected {
    background-color: #2ecc71;
    /* Green Selection */
    box-shadow:
        0 6px 0 #27ae60,
        0 0 15px #2ecc71;
    border: 2px solid #fff;
}

.tower-btn.selected:hover {
    box-shadow:
        0 8px 0 #27ae60,
        0 0 20px #2ecc71;
}

/* --- Locked Tower --- */
.tower-btn.locked {
    background-color: #95a5a6;
    box-shadow: 0 6px 0 #7f8c8d;
    cursor: not-allowed;
    opacity: 0.8;
}

.tower-btn.locked img {
    opacity: 0.3;
    filter: grayscale(100%);
}

/* Tooltip Image */
.tooltip-img {
    width: 60px;
    height: 60px;
    object-fit: contain;
    image-rendering: pixelated;
    display: block;
    margin: 0 auto 10px auto;
    border: 1px solid #444;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    padding: 5px;
}

#controls-info {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    text-align: center;
    padding: 5px;
    font-size: 12px;
    color: #888;
    background-color: rgba(0, 0, 0, 0.8);
    pointer-events: none;
}

/* --- Base Screen --- */
#base-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.base-title {
    font-size: 80px;
    /* Increased for Chromebook */
    margin-bottom: 20px;
    text-shadow: 0 0 20px rgba(0, 255, 255, 0.5);
    background: linear-gradient(to right, #00c6ff, #0072ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.currency-display {
    font-size: 32px;
    margin-bottom: 50px;
    background: rgba(255, 255, 255, 0.1);
    padding: 15px 40px;
    border-radius: 50px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.base-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 30px;
    max-width: 800px;
}

.base-cell {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 30px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 200px;
    height: 150px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.base-cell:hover:not(.locked) {
    transform: translateY(-5px);
    background: rgba(255, 255, 255, 0.1);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3);
}

.battle-cell {
    background: linear-gradient(45deg, #8B0000, #ff4c4c);
    border: none;
    grid-column: span 2;
    /* Make it wide */
    width: auto;
}

.base-cell.locked {
    opacity: 0.5;
    cursor: not-allowed;
    background: #2b2b2b;
}

.base-cell .icon {
    font-size: 40px;
    margin-bottom: 10px;
}

.base-cell .label {
    font-size: 32px;
    font-weight: bold;
    letter-spacing: 1px;
}

.base-cell .sub {
    font-size: 14px;
    color: #aaa;
    margin-top: 5px;
}

/* --- Game Over Screen --- */
#game-over-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 5000;
    backdrop-filter: blur(12px);
    font-family: 'Segoe UI Black', 'Impact', sans-serif;
}

.result-box {
    background: #ecf0f1;
    padding: 40px;
    border-radius: 24px;
    border: 6px solid #bdc3c7;
    text-align: center;
    width: 900px;
    box-shadow:
        0 20px 0 #95a5a6,
        0 30px 60px rgba(0, 0, 0, 0.6);
    position: relative;
    overflow: hidden;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 48px;
    margin: 15px 0;
    background: #2c3e50;
    padding: 15px;
    border-radius: 12px;
    color: #ecf0f1;
    border: 2px solid #34495e;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.3);
    text-transform: uppercase;
    font-weight: 900;
}

.action-btn {
    margin-top: 10px;
    padding: 20px;
    font-size: 38px;
    font-weight: 900;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.1s;
    width: 100%;
    text-transform: uppercase;
    position: relative;
}

.action-btn:active {
    transform: translateY(4px);
    box-shadow: none !important;
}

/* --- Pause Button --- */
#pause-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 90px;
    height: 90px;
    background: #ecf0f1;
    border-radius: 12px;
    color: #2c3e50;
    font-size: 48px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    border: none;
    z-index: 3000;
}

#pause-btn:hover {
    transform: translateY(-2px);
}

#pause-btn:active {
    transform: translateY(4px);
    box-shadow:
        0 2px 0 #bdc3c7,
        0 2px 5px rgba(0, 0, 0, 0.2);
}

/* --- Pause Menu --- */
#pause-menu {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 4000;
    backdrop-filter: blur(12px);
    font-family: 'Segoe UI Black', 'Impact', sans-serif;
}

.pause-box {
    background: #ecf0f1;
    padding: 40px;
    border-radius: 24px;
    border: 6px solid #bdc3c7;
    width: 900px;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.pause-title {
    margin-top: 0;
    font-size: 64px;
    letter-spacing: -2px;
    background: linear-gradient(to bottom, #2ecc71, #27ae60);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 30px;
    text-transform: uppercase;
    filter: drop-shadow(0 4px 0 rgba(0, 0, 0, 0.2));
}

.pause-settings {
    text-align: left;
    margin-bottom: 35px;
    background: #2c3e50;
    padding: 25px;
    border-radius: 16px;
    border: 4px solid #34495e;
    box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.4);
}

.setting-row {
    margin-bottom: 20px;
}

.setting-row:last-child {
    margin-bottom: 0;
}

.setting-row label {
    display: block;
    margin-bottom: 10px;
    color: #ecf0f1;
    font-size: 42px;
    text-transform: uppercase;
    font-weight: 900;
    letter-spacing: 1px;
}

/* Custom Range Input */
.setting-row input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
}

.setting-row input[type=range]:focus {
    outline: none;
}

.setting-row input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 12px;
    cursor: pointer;
    background: #1a252f;
    border-radius: 6px;
    border: 2px solid #34495e;
}

.setting-row input[type=range]::-webkit-slider-thumb {
    height: 28px;
    width: 28px;
    border-radius: 8px;
    background: #2ecc71;
    cursor: pointer;
    -webkit-appearance: none;
    margin-top: -10px;
    box-shadow: 0 4px 0 #27ae60;
}

.pause-buttons {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.pause-btn {
    padding: 20px;
    font-size: 42px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 900;
    text-transform: uppercase;
    transition: all 0.1s;
    position: relative;
}

.pause-btn:active {
    transform: translateY(4px);
    box-shadow: none !important;
}

#btn-resume {
    background: #2ecc71;
    color: white;
    box-shadow: 0 8px 0 #27ae60;
}

#btn-resume:hover {
    background: #27ae60;
    transform: translateY(-2px);
    box-shadow: 0 10px 0 #1e8449;
}

.pause-btn.quit {
    background: #e74c3c;
    color: white;
    box-shadow: 0 8px 0 #c0392b;
}

.pause-btn.quit:hover {
    background: #c0392b;
    transform: translateY(-2px);
    box-shadow: 0 10px 0 #a93226;
}



/* --- Cases / Gacha --- */
#cases-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    background: radial-gradient(circle at center, #1a1a2e 0%, #000 100%);
    animation: none;
    display: flex;
    justify-content: center;
    align-items: center;
}

.cases-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 600px;
    height: 700px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 0 100px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
}

.cases-title {
    font-size: 64px;
    /* Increased for Chromebook */
    font-weight: 800;
    margin: 0 0 30px 0;
    background: linear-gradient(to right, #FFD700, #FDB931);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 30px rgba(255, 215, 0, 0.3);
    letter-spacing: 2px;
}

.cases-stats {
    display: flex;
    gap: 20px;
    margin-bottom: 50px;
    width: 100%;
    justify-content: center;
}

.stat-pill {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 10px 20px;
    border-radius: 50px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 120px;
}

.stat-pill .label {
    font-size: 18px;
    /* Increased for Chromebook */
    margin-bottom: 2px;
}

.stat-pill .val {
    font-size: 28px;
    /* Increased for Chromebook */
    font-weight: bold;
    color: #fff;
}

.stat-pill .val.price {
    color: #ffeb3b;
}

.stat-pill .val.balance {
    color: #4caf50;
}

.case-stage {
    position: relative;
    width: 300px;
    height: 300px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 30px;
}

.case-glow {
    position: absolute;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(255, 215, 0, 0.2) 0%, transparent 70%);
    animation: pulseGlow 3s infinite ease-in-out;
}

.case-box {
    font-size: 120px;
    z-index: 2;
    filter: drop-shadow(0 0 20px rgba(0, 0, 0, 0.5));
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.result-display {
    height: 60px;
    text-align: center;
    margin-bottom: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.result-display .placeholder {
    color: #444;
    font-style: italic;
    font-size: 14px;
}

.cases-actions {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    align-items: center;
}

.gacha-btn {
    background: linear-gradient(135deg, #FFD700 0%, #FDB931 100%);
    border: none;
    color: #000;
    padding: 15px 50px;
    font-size: 28px;
    /* Increased for Chromebook */
    font-weight: 800;
    border-radius: 8px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.2s;
    box-shadow: 0 5px 15px rgba(253, 185, 49, 0.3);
    width: 80%;
}

.gacha-btn:hover:not(.disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(253, 185, 49, 0.5);
    filter: brightness(1.1);
}

.gacha-btn:active:not(.disabled) {
    transform: translateY(1px);
}

.gacha-btn.disabled {
    background: #333;
    color: #555;
    cursor: not-allowed;
    box-shadow: none;
}

.back-link {
    background: transparent;
    border: none;
    color: #888;
    font-size: 20px;
    /* Increased for Chromebook */
    cursor: pointer;
    padding: 10px;
    transition: color 0.2s;
}

.back-link:hover {
    color: #fff;
    text-decoration: underline;
}

@keyframes pulseGlow {

    0%,
    100% {
        opacity: 0.5;
        transform: scale(0.9);
    }

    50% {
        opacity: 1;
        transform: scale(1.1);
    }
}

/* --- Tooltips --- */
.tooltip {
    position: absolute;
    background: #ecf0f1;
    border: 4px solid #bdc3c7;
    padding: 22px;
    border-radius: 12px;
    color: #2c3e50;
    pointer-events: none;
    z-index: 5000;
    width: 500px;
    /* Increased for Chromebook readability */
    box-shadow:
        0 8px 0 #95a5a6,
        0 15px 30px rgba(0, 0, 0, 0.4);
    font-family: 'Segoe UI Black', 'Impact', sans-serif;
    transform: translate(-50%, -100%);
    /* Center horizontally and move above */
}

.tooltip-title {
    color: #2c3e50;
    font-weight: 900;
    font-size: 30px;
    /* Increased for Chromebook readability */
    margin-bottom: 8px;
    text-transform: uppercase;
    text-align: center;
    border-bottom: 2px solid #bdc3c7;
    padding-bottom: 5px;
}

.tooltip-desc {
    font-size: 26px;
    /* Increased for Chromebook readability */
    margin-bottom: 12px;
    color: #7f8c8d;
    font-weight: bold;
    text-align: center;
}

.tooltip-stat {
    display: flex;
    justify-content: space-between;
    font-size: 30px;
    /* Increased for Chromebook readability */
    margin-bottom: 4px;
    background: #2c3e50;
    padding: 8px 15px;
    border-radius: 6px;
    color: #ecf0f1;
    font-family: monospace;
}

.tooltip-stat span.val {
    color: #2ecc71;
    font-weight: 900;
}

/* --- TUTORIAL UI --- */
#tutorial-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Let clicks pass through by default */
    z-index: 9000;
    display: none;
}

.tutorial-mask {
    /* Used to darken the background except for a specific spot */
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    pointer-events: auto;
    /* Block clicks on the dark area */
}

/* A "hole" in the mask to allow clicking specific elements */
.tutorial-highlight {
    position: absolute;
    border: 4px solid #f1c40f;
    border-radius: 8px;
    box-shadow: 0 0 20px #f1c40f, inset 0 0 20px #f1c40f;
    pointer-events: none;
    animation: pulse-border 1s infinite;
    /* transition: all 0.3s ease; Removed to prevent lag during resize tracking */
    z-index: 9002;
}

.tutorial-active-target {
    z-index: 9010 !important;
    /* Above overlay (9000) and highlight (9002) */
    pointer-events: auto !important;
    position: relative;
    /* Fallback if not absolute */
    box-shadow: 0 0 15px rgba(241, 196, 15, 0.5);
    /* Optional glow to emphasize lift */
    transition: box-shadow 0.3s ease;
}

@keyframes pulse-border {
    0% {
        transform: scale(1);
        border-color: rgba(241, 196, 15, 1);
        box-shadow: 0 0 20px rgba(241, 196, 15, 0.4), inset 0 0 10px rgba(241, 196, 15, 0.2);
    }

    50% {
        transform: scale(1.02);
        border-color: rgba(241, 196, 15, 0.6);
        box-shadow: 0 0 30px rgba(241, 196, 15, 0.6), inset 0 0 20px rgba(241, 196, 15, 0.4);
    }

    100% {
        transform: scale(1);
        border-color: rgba(241, 196, 15, 1);
        box-shadow: 0 0 20px rgba(241, 196, 15, 0.4), inset 0 0 10px rgba(241, 196, 15, 0.2);
    }
}

.tutorial-hole-mask {
    /* Huge shadow to dim everything OUTSIDE the box */
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.7) !important;
    pointer-events: none !important;
    z-index: 9002 !important;
}

.tutorial-dialog {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    max-width: 800px;
    background: #fff;
    border: 4px solid #333;
    border-radius: 12px;
    padding: 20px;
    display: flex;
    gap: 20px;
    align-items: center;
    box-shadow: 0 10px 0 rgba(0, 0, 0, 0.3);
    pointer-events: auto;
    z-index: 9005;
    font-family: 'Segoe UI Black', sans-serif;
    transition: bottom 0.3s ease, top 0.3s ease;
}

.tutorial-dialog.top {
    bottom: auto;
    top: 20px;
}

.tutorial-char {
    width: 128px;
    height: 128px;
    background: #ccc;
    /* Placeholder if image missing */
    border-radius: 50%;
    border: 4px solid #333;
    overflow: hidden;
    flex-shrink: 0;
}

.tutorial-char img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.tutorial-content {
    flex: 1;
}

.tutorial-text {
    font-size: 36px;
    /* Increased for Chromebook readability */
    line-height: 1.4;
    color: #333;
    margin-bottom: 15px;
}

.tutorial-btn {
    background: #2ecc71;
    border: none;
    border-bottom: 4px solid #27ae60;
    color: white;
    padding: 10px 20px;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    font-size: 40px;
    /* Increased for Chromebook readability */
    float: right;
}

.tutorial-btn:active {
    transform: translateY(4px);
    border-bottom: none;
}

/* --- END TUTORIAL UI --- */

/* --- Loading Screen --- */
/* --- Loading Screen --- */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: radial-gradient(circle, #2c3e50 0%, #000 100%);
    /* Deep dark plastic background */
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    pointer-events: all;
    /* Block clicks */
    transition: opacity 0.5s ease;
}

.loader-content {
    background: linear-gradient(135deg, #ecf0f1 0%, #bdc3c7 100%);
    padding: 40px;
    border-radius: 24px;
    border: 6px solid #95a5a6;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 650px;
    /* Increased for Chromebook readability */
    position: relative;
}

.loader-char-container {
    width: 120px;
    height: 120px;
    background: #fff;
    border: 4px solid #333;
    border-radius: 50%;
    overflow: hidden;
    margin-bottom: 20px;
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
    animation: bounce 0.5s infinite alternate;
}

.loader-char-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.loader-title {
    font-size: 48px;
    font-family: 'Segoe UI Black', Impact, sans-serif;
    margin-bottom: 20px;
    background: linear-gradient(to bottom, #f1c40f, #f39c12);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-transform: uppercase;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
    /* Simplified shadow for text-clip */
    filter: drop-shadow(0 2px 0 #d35400);
    animation: none;
    /* Removed pulse for clean gradient text */
}

.loader-bar-container {
    width: 100%;
    height: 30px;
    background: #2c3e50;
    border: 4px solid #34495e;
    border-radius: 15px;
    overflow: hidden;
    margin-bottom: 15px;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.5);
    position: relative;
}

#loader-bar-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(180deg, #2ecc71 0%, #27ae60 100%);
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.3);
    transition: width 0.2s cubic-bezier(0.25, 0.1, 0.25, 1);
}

#loader-text {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-weight: bold;
    font-size: 18px;
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: 1px;
    min-height: 24px;
    /* Prevent jump */
}

@keyframes bounce {
    from {
        transform: translateY(0);
    }

    to {
        transform: translateY(-10px);
    }
}

/* --- Custom Tutorial Language Selector for Upward Dropdown --- */
.lang-select-wrapper {
    position: relative;
    display: inline-block;
    vertical-align: middle;
    margin: 0 10px;
    font-family: inherit;
    font-size: 24px;
    /* Ensure good size */
    z-index: 10;
}

.lang-select-wrapper * {
    box-sizing: border-box;
    /* Vital for consistent sizing */
}

.lang-select-toggle {
    background: #fff;
    border: 2px solid #ccc;
    border-radius: 6px;
    padding: 5px 40px 5px 15px;
    cursor: pointer;
    min-width: 180px;
    position: relative;
    user-select: none;
    color: #333;
    font-weight: bold;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    white-space: nowrap;
}

.lang-select-toggle::after {
    content: '▼';
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    color: #666;
}

.lang-select-list {
    position: absolute;
    bottom: 110%;
    /* Opens UPWARDS with slight gap */
    left: 0;
    width: 100%;
    background: #fff;
    border: 2px solid #333;
    border-radius: 6px;
    box-shadow: 0 -10px 20px rgba(0, 0, 0, 0.3);
    max-height: 250px;
    overflow-y: auto;
    display: none;
    z-index: 9999;
}

.lang-select-item {
    padding: 12px 15px;
    cursor: pointer;
    border-bottom: 1px solid #eee;
    color: #333;
    transition: background 0.2s;
    font-size: 20px;
}

.lang-select-item:last-child {
    border-bottom: none;
}

.lang-select-item:hover {
    background: #2ecc71;
    /* Green hover */
    color: white;
}

.lang-select-wrapper.open .lang-select-list {
    display: block;
}