:root {
    /* Colors - Counts X1 Theme (Night Flight - Same as Alphabet) */
    --bg-dark: #020b1c;
    --bg-light: #0d2d5e;
    --primary: #ff9d00;
    /* Neon Orange */
    --secondary: #00e5ff;
    /* Cyan */
    --text: #ffffff;
    --card-bg: rgba(5, 22, 48, 0.7);
    --border: rgba(0, 229, 255, 0.3);
    --header-bg: rgba(0, 0, 0, 0.4);
    --success: #00ff88;

    /* Responsive Tokens */
    --root-padding: 2vmin;
    --app-gap: 2vmin;
    --main-radius: 2.5vmin;
    --wagon-size: 11vmin;
    /* Adapted for numbers */
    --train-gap: 0.8vmin;
    --home-size: 8vmin;
}


/* --- ORIENTATION LOCK --- */
#orientation-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--bg-dark);
    z-index: 9999;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 5vmin;
    color: white;
}

#orientation-overlay .rotate-icon {
    font-size: 15vmin;
    margin-bottom: 5vmin;
    animation: rotateForever 2s linear infinite;
}

@keyframes rotateForever {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

@media screen and (orientation: portrait) {
    #orientation-overlay {
        display: flex;
    }

    #app-root,
    .overlay {
        display: none !important;
    }
}

/* --- SAFETY OVERLAY --- */
#size-warning {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    background: rgba(2, 11, 28, 0.98);
    z-index: 10000;
    display: none;
    justify-content: center;
    align-items: center;
    color: white;
    padding: 10vw;
    text-align: center;
}

.warning-box {
    background: #051630;
    padding: 6vmin;
    border-radius: 4vmin;
    border: 2px solid var(--primary);
    box-shadow: 0 0 5vmin var(--primary);
}

.warning-icon {
    font-size: 12vmin;
    display: block;
    margin-bottom: 2vmin;
}

/* Base Resets */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: radial-gradient(circle at center, var(--bg-light) 0%, var(--bg-dark) 100%);
    font-family: 'Outfit', 'Segoe UI', sans-serif;
    color: var(--text);
}

#app-root {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100dvh;
    padding: var(--root-padding);
    gap: var(--app-gap);
    position: relative;
    opacity: 0;
    animation: fadeIn 0.5s forwards;
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

/* Header */
#top-bar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    background: var(--header-bg);
    padding: 1.5vmin 3.5vmin;
    border-radius: var(--main-radius);
    border-bottom: 2px solid var(--secondary);
    backdrop-filter: blur(10px);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 2vmin;
}

.app-title {
    font-weight: 800;
    letter-spacing: 0.2rem;
    color: var(--primary);
    font-size: clamp(1rem, 4.5vmin, 2rem);
    text-shadow: 0 0 15px var(--primary);
    text-align: center;
}

.level-indicator {
    display: flex;
    gap: 1.2vmin;
}

.lvl-btn {
    width: 7.5vmin;
    height: 7.5vmin;
    border-radius: 50%;
    border: 2px solid var(--secondary);
    background: transparent;
    color: var(--secondary);
    font-weight: 800;
    font-size: 3.5vmin;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
    box-shadow: inset 0 0 10px rgba(0, 229, 255, 0.1);
}

.lvl-btn.active {
    background: var(--secondary);
    color: var(--bg-dark);
    box-shadow: 0 0 15px var(--secondary);
    transform: scale(1.1);
}

.lvl-btn:active {
    transform: scale(0.9);
}

#narrator-bubble {
    display: flex;
    align-items: center;
    gap: 2vmin;
    background: rgba(255, 255, 255, 0.08);
    padding: 1.2vmin 2.5vmin;
    border-radius: 6vmin;
    justify-self: end;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

#instruction-text {
    font-weight: bold;
    color: var(--secondary);
    font-size: 3vmin;
    max-width: 50vw;
    /* Increased from 25vw */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.icon-btn {
    background: var(--primary);
    border: none;
    border-radius: 50%;
    width: 8vmin;
    height: 8vmin;
    cursor: pointer;
    font-size: 4vmin;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #000;
    box-shadow: 0 4px 10px rgba(255, 157, 0, 0.3);
    transition: transform 0.2s;
}

.icon-btn:active {
    transform: scale(0.9);
}

/* Main Content Area */
#main-content {
    flex: 1;
    display: flex;
    gap: var(--app-gap);
    overflow: hidden;
}

/* Left: Game Scene (The Train) */
#game-scene {
    flex: 2;
    background: var(--card-bg);
    border-radius: var(--main-radius);
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.5);
}

#train-track {
    width: 100%;
    height: 100%;
    position: relative;
    background: linear-gradient(transparent 83.2%, rgba(0, 229, 255, 0.1) 83.33%, transparent 83.5%);
}

#train-track::after {
    content: '';
    position: absolute;
    bottom: 16.67%;
    left: 0;
    right: 0;
    height: 2px;
    background: rgba(0, 229, 255, 0.2);
    box-shadow: 0 0 10px rgba(0, 229, 255, 0.4);
}

#train-group {
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    position: absolute;
    bottom: 16.67%;
    transition: transform 1.8s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
    transform-origin: left bottom;
    transform: translateX(0) scale(var(--train-scale, 1));
}

#train-group.off-right {
    transform: translateX(120vw) scale(var(--train-scale, 1));
    transition: none !important;
}

#train-group.arrive {
    transform: translateX(0) scale(var(--train-scale, 1));
}

#train-group.depart {
    transform: translateX(-220vw) scale(var(--train-scale, 1));
}

/* Progress Counter Pill */
#progress-counter {
    position: absolute;
    top: -4vmin;
    left: 2vmin;
    background: rgba(255, 255, 255, 0.15);
    padding: 0.6vmin 2vmin;
    border-radius: 4vmin;
    font-size: 2.8vmin;
    font-weight: 800;
    color: var(--primary);
    border: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(5px);
    white-space: nowrap;
}

#train-engine {
    font-size: 13vmin;
    margin-left: 1.5vmin;
    filter: drop-shadow(0 0 15px rgba(255, 157, 0, 0.6));
    line-height: 1;
}

#wagon-slots {
    display: flex;
    gap: var(--train-gap);
}



.wagon {
    width: var(--wagon-size);
    height: calc(var(--wagon-size) * 0.85);
    background: var(--primary);
    border: 0.5vmin solid white;
    border-radius: 1.8vmin;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 6vmin;
    font-weight: 800;
    color: #000;
    box-shadow: 0 0.8vmin 1.5vmin rgba(0, 0, 0, 0.4);
    position: relative;
    transition: transform 0.3s;
}

.wagon::after {
    content: '';
    position: absolute;
    bottom: -1.2vmin;
    left: 15%;
    right: 15%;
    height: 0.6vmin;
    background: #111;
    border-radius: 1vmin;
}

.wagon.error-wagon {
    background: #ff4d4d;
    color: white;
    border-color: #ffcccc;
}

.wagon.entering {
    animation: wagonIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.1);
}

.wagon.recap-active {
    transform: translateY(-4vmin) scale(1.15);
    box-shadow: 0 3vmin 5vmin rgba(0, 229, 255, 0.6);
    border-color: var(--secondary);
    z-index: 10;
}

@keyframes wagonIn {
    from {
        transform: translateX(50vw) scale(0.5);
        opacity: 0;
    }

    to {
        transform: translateX(0) scale(1);
        opacity: 1;
    }
}

/* Sidebar Interaction Area */
#ui-layer {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: var(--app-gap);
    background: rgba(0, 0, 0, 0.2);
    padding: 2vmin;
    border-radius: var(--main-radius);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

#options-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 2.5vmin;
}

.option-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--main-radius);
    height: 22vmin;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 9vmin;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(8px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.option-card:hover {
    transform: translateY(-0.8vmin);
    border-color: var(--secondary);
    box-shadow: 0 15px 35px rgba(0, 229, 255, 0.25);
}

.option-card:active {
    transform: scale(0.92);
}

.option-card.wrong {
    border-color: #ff4d4d;
    color: #ff4d4d;
    animation: shake 0.4s;
    background: rgba(255, 77, 77, 0.15);
    box-shadow: 0 0 20px rgba(255, 77, 77, 0.3);
}

/* Overlays */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.88);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 5000;
    backdrop-filter: blur(12px);
}

.glass-card {
    background: linear-gradient(135deg, var(--bg-light), var(--bg-dark));
    padding: 8vmin;
    border-radius: 5vmin;
    text-align: center;
    border: 2px solid var(--primary);
    max-width: 85%;
    box-shadow: 0 0 60px rgba(255, 157, 0, 0.2);
}

.card-icon {
    font-size: 15vmin;
    margin-bottom: 2vmin;
}

.glass-card h1 {
    font-size: 8vmin;
    margin: 2vmin 0;
    color: var(--primary);
    text-shadow: 0 0 20px var(--primary);
}

.glass-card p {
    font-size: 4vmin;
    color: var(--secondary);
    margin-bottom: 5vmin;
}

.action-btn-large {
    background: var(--primary);
    color: #000;
    border: none;
    padding: 3vmin 8vmin;
    font-weight: 800;
    border-radius: 2.5vmin;
    cursor: pointer;
    font-size: 5vmin;
    box-shadow: 0 1.5vmin 0 #cc7a00, 0 2vmin 40px rgba(255, 157, 0, 0.3);
    transition: all 0.1s;
}

.action-btn-large:active {
    transform: translateY(1vmin);
    box-shadow: 0 0.5vmin 0 #cc7a00, 0 1vmin 20px rgba(255, 157, 0, 0.2);
}

.secondary-btn {
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 2.5vmin 5vmin;
    border-radius: 2vmin;
    font-size: 3.5vmin;
    margin-top: 3vmin;
    cursor: pointer;
    transition: all 0.2s;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: white;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    20% {
        transform: translateX(-1.5vmin);
    }

    40% {
        transform: translateX(1.5vmin);
    }

    60% {
        transform: translateX(-1vmin);
    }

    80% {
        transform: translateX(1vmin);
    }
}

/* Audio Lock State */
.audio-locked .option-card,
.audio-locked #repeat-btn {
    pointer-events: none;
    opacity: 0.6;
    filter: grayscale(0.5);
}

/* --- Responsive Adjustments (Layout Manager) --- */
.layout-portrait #main-content {
    flex-direction: column;
}

.layout-portrait #game-scene {
    height: 35%;
    flex: none;
}

.layout-portrait #ui-layer {
    flex: 1;
}

.layout-portrait .option-card {
    height: 18vmin;
    font-size: 10vmin;
}

.layout-compact .option-card {
    height: 25vmin;
}

/* Wide screens: More grid columns for more options */
.layout-wide #options-container {
    grid-template-columns: repeat(2, 1fr);
}

/* Home Button Specific */
.home-btn {
    width: var(--home-size);
    height: var(--home-size);
    flex-shrink: 0;
    /* Prevent squashing */
    aspect-ratio: 1;
    /* Force square/circle */
    background: var(--primary);
    border: 0.6vmin solid white;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    text-decoration: none;
    font-size: 4.5vmin;
    box-shadow: 0 1vmin 2.5vmin rgba(0, 0, 0, 0.4);
    transition: transform 0.2s;
    color: #000;
}

.home-btn:hover {
    transform: scale(1.1) rotate(-5deg);
}

.home-btn:active {
    transform: scale(0.9);
}