:root {
    /* Colors - Millionaire X1 Theme */
    --bg-dark: #010614;
    --bg-light: #0d214a;
    --primary: #ffcc00;
    /* Gold */
    --secondary: #00ccff;
    /* Bright Blue */
    --text: #ffffff;
    --card-bg: rgba(5, 22, 48, 0.85);
    --border: rgba(255, 204, 0, 0.4);
    --ans-bg: rgba(0, 0, 0, 0.6);
    --ans-border: rgba(0, 204, 255, 0.3);

    /* Responsive Tokens */
    --root-padding: 2vmin;
    --app-gap: 2vmin;
    --main-radius: 2vmin;
    --home-size: 8vmin;
}

/* --- SAFETY OVERLAY --- */
#size-warning {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    background: rgba(1, 6, 20, 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);
}

/* --- LOGIN SCREEN --- */
#login-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    background: radial-gradient(circle at center, var(--bg-light) 0%, var(--bg-dark) 100%);
    z-index: 9000;
    display: flex;
    justify-content: center;
    align-items: center;
}

#login-screen.hidden {
    display: none;
}

.login-box {
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 3vmin;
    padding: 5vmin 6vmin;
    width: min(90vw, 420px);
    box-shadow: 0 0 6vmin rgba(255, 204, 0, 0.15);
    display: flex;
    flex-direction: column;
    gap: 2.5vmin;
}

.login-logo {
    font-size: clamp(1.8rem, 6vmin, 3rem);
    font-weight: 900;
    color: var(--primary);
    text-shadow: 0 0 2vmin var(--primary);
    letter-spacing: 4px;
    text-align: center;
}

.login-subtitle {
    margin: 0;
    text-align: center;
    color: rgba(255, 255, 255, 0.55);
    font-size: clamp(0.8rem, 2vmin, 1rem);
}

.login-field {
    display: flex;
    flex-direction: column;
    gap: 0.8vmin;
}

.login-field label {
    font-size: clamp(0.75rem, 1.8vmin, 0.92rem);
    color: var(--secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.login-field input {
    background: var(--ans-bg);
    border: 1.5px solid var(--ans-border);
    color: white;
    font-size: clamp(0.9rem, 2.2vmin, 1.1rem);
    padding: 1.5vmin 2vmin;
    border-radius: 10px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

.login-field input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 1.5vmin rgba(255, 204, 0, 0.25);
}

.login-field input::placeholder {
    color: rgba(255, 255, 255, 0.25);
}

.login-error {
    background: rgba(213, 0, 0, 0.15);
    border: 1px solid #ff5252;
    color: #ff5252;
    border-radius: 8px;
    padding: 1.2vmin 2vmin;
    font-size: clamp(0.8rem, 1.9vmin, 0.95rem);
    text-align: center;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    20% {
        transform: translateX(-8px);
    }

    40% {
        transform: translateX(8px);
    }

    60% {
        transform: translateX(-5px);
    }

    80% {
        transform: translateX(5px);
    }
}

.login-box.shake {
    animation: shake 0.4s ease;
}

/* Base Resets */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

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: 'Segoe UI', Tahoma, Geneva, Verdana, 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;
}

/* Header */
#top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.5);
    padding: 1.5vmin 3vmin;
    border-radius: var(--main-radius);
    border-bottom: 2px solid var(--primary);
}

.lifelines {
    display: flex;
    gap: 1.5vmin;
}

.lifeline {
    width: 7vmin;
    height: 4.5vmin;
    background: var(--ans-bg);
    border: 1.5px solid var(--secondary);
    border-radius: 50%;
    color: var(--secondary);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    cursor: pointer;
    font-size: 2vmin;
    box-shadow: 0 0 1vmin rgba(0, 204, 255, 0.2);
}

.lifeline.used {
    opacity: 0.2;
    filter: grayscale(1);
    cursor: not-allowed;
}

.game-logo {
    font-size: clamp(1.2rem, 5vmin, 2.5rem);
    font-weight: 900;
    color: var(--primary);
    text-shadow: 0 0 1.5vmin var(--primary);
    letter-spacing: 2px;
}

#current-prize-display {
    font-size: 3.5vmin;
    color: var(--primary);
    font-weight: 800;
}

.nav-btn-rect {
    background: transparent;
    border: 1.5px solid var(--primary);
    color: var(--primary);
    padding: 0.8vmin 2vmin;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    font-size: 2vmin;
    margin-left: 2vmin;
}

/* Main Content */
#main-content {
    flex: 1;
    display: flex;
    gap: var(--app-gap);
    overflow: hidden;
}

/* LADDER (RIGHT SIDE on Wide) */
#ladder-aside {
    width: 280px;
    background: var(--card-bg);
    border-radius: var(--main-radius);
    display: flex;
    flex-direction: column;
    padding: 2vmin;
    border: 1px solid var(--border);
    box-shadow: inset 0 0 3vmin rgba(0, 0, 0, 0.5);
}

.ladder-header {
    text-align: center;
    color: var(--primary);
    font-weight: 800;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1vmin;
    margin-bottom: 1vmin;
    font-size: 1.8vmin;
}

#money-ladder-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
}

.ladder-step {
    padding: 0.4vmin 1.5vmin;
    border-radius: 4px;
    font-size: 2vmin;
    color: var(--primary);
    text-align: right;
    display: flex;
    justify-content: space-between;
}

.ladder-step.milestone {
    color: white;
    font-weight: 800;
}

.ladder-step.active {
    background: var(--primary);
    color: black;
    box-shadow: 0 0 1.5vmin var(--primary);
}

/* GAME AREA (Center/Left) */
#game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4vmin;
}

#question-container {
    background: var(--ans-bg);
    border: 2px solid var(--secondary);
    border-radius: 40px;
    padding: 3vmin 5vmin;
    text-align: center;
    font-size: clamp(1.1rem, 3.5vmin, 2rem);
    position: relative;
    box-shadow: 0 0 2vmin rgba(0, 204, 255, 0.2);
}

#answers-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2vmin;
}

.answer-btn {
    background: var(--ans-bg);
    border: 2px solid var(--ans-border);
    border-radius: 30px;
    padding: 2vmin 4vmin;
    font-size: clamp(0.9rem, 2.8vmin, 1.4rem);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
}

@media (hover: hover) {
    .answer-btn:hover {
        border-color: var(--primary);
        background: rgba(255, 204, 0, 0.1);
    }
}

.answer-btn.selected {
    background: var(--primary) !important;
    color: black !important;
    border-color: white !important;
}

.answer-btn.correct {
    background: #00c853 !important;
    color: white !important;
    border-color: #69f0ae !important;
    animation: flash 0.5s infinite alternate;
}

.answer-btn.wrong {
    background: #d50000 !important;
    color: white !important;
}

.answer-btn .letter {
    color: var(--primary);
    font-weight: 900;
    margin-right: 2vmin;
}

.answer-btn.selected .letter {
    color: black;
}

/* UI Layer */
.ui-layer {
    position: absolute;
    z-index: 1000;
}

.home-btn {
    width: var(--home-size);
    height: var(--home-size);
    background: var(--primary);
    border: 0.6vmin solid white;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    text-decoration: none;
    font-size: calc(var(--home-size) * 0.5);
    box-shadow: 0 1vmin 2vmin rgba(0, 0, 0, 0.3);
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(8px);
}

.modal-content {
    background: var(--bg-light);
    padding: 5vmin;
    border-radius: 3vmin;
    text-align: center;
    border: 2px solid var(--primary);
    max-width: 80%;
}

.action-btn {
    background: var(--primary);
    color: black;
    border: none;
    padding: 1.5vmin 4vmin;
    font-weight: 800;
    border-radius: 12px;
    cursor: pointer;
    font-size: 2.5vmin;
    margin-top: 2vmin;
}

#input-modal-field {
    background: var(--ans-bg);
    border: 2px solid var(--secondary);
    color: var(--primary);
    font-size: 3vmin;
    padding: 1.5vmin;
    border-radius: 12px;
    width: 80%;
    outline: none;
    transition: all 0.3s ease;
}

#input-modal-field:focus {
    box-shadow: 0 0 2vmin rgba(0, 204, 255, 0.4);
    border-color: var(--primary);
}

/* =========================================
   ASPECT RATIO SPECIFIC LAYOUTS
   ========================================= */

/* --- 1. WIDE/COMPACT (Ladder is visible) --- */
.layout-wide #main-content,
.layout-compact #main-content {
    flex-direction: row;
}

.layout-wide .ui-layer,
.layout-compact .ui-layer {
    top: var(--root-padding);
    right: var(--root-padding);
}

.layout-wide #ladder-toggle-btn,
.layout-compact #ladder-toggle-btn {
    display: none;
}

/* --- 3. SQUARE/PORTRAIT (Ladder is hidden by default) --- */
.layout-square #main-content,
.layout-portrait #main-content {
    flex-direction: column;
}

.layout-square #ladder-aside,
.layout-portrait #ladder-aside {
    display: none;
}

.layout-square #ladder-toggle-btn,
.layout-portrait #ladder-toggle-btn {
    display: inline-block;
}

.layout-square .ui-layer,
.layout-portrait .ui-layer {
    top: 2vmin;
    right: 2vmin;
}

.layout-portrait #answers-grid {
    grid-template-columns: 1fr;
}

.layout-portrait #top-bar {
    padding: 1vmin 2vmin;
}

.layout-portrait .lifelines {
    gap: 1vmin;
}

@keyframes flash {
    from {
        box-shadow: 0 0 10px #00c853;
    }


    to {
        box-shadow: 0 0 25px #00c853;
    }
}

/* --- ADDITIONS FOR START SCREEN --- */
.start-content {
    width: 90%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    gap: 3vmin;
    background: var(--bg-light);
    /* Ensure solid background */
}

.game-logo-large {
    font-size: 5vmin;
    color: var(--primary);
    text-shadow: 0 0 2vmin var(--primary);
    margin: 0 0 2vmin 0;
    text-transform: uppercase;
    letter-spacing: 4px;
}

.settings-group h3 {
    margin: 0 0 1vmin 0;
    color: var(--secondary);
    font-size: 2.2vmin;
    text-align: left;
    text-transform: uppercase;
}

.toggle-container {
    display: flex;
    background: var(--ans-bg);
    border-radius: 12px;
    padding: 0.5vmin;
    border: 1px solid var(--ans-border);
}

.mode-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    padding: 1.5vmin;
    font-weight: bold;
    cursor: pointer;
    border-radius: 8px;
    font-size: 2vmin;
    transition: all 0.2s;
}

.mode-btn.active {
    background: var(--secondary);
    color: black;
    box-shadow: 0 0 1vmin rgba(0, 204, 255, 0.4);
}

.settings-select {
    width: 100%;
    padding: 1.5vmin;
    background: var(--ans-bg);
    border: 1px solid var(--ans-border);
    color: white;
    border-radius: 8px;
    font-size: 2vmin;
    margin-bottom: 1vmin;
}

.import-controls {
    display: flex;
    gap: 1vmin;
}

.secondary-btn {
    flex: 1;
    background: transparent;
    border: 1px solid var(--secondary);
    color: var(--secondary);
    padding: 1vmin;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.8vmin;
    transition: all 0.2s;
}

.secondary-btn:hover {
    background: rgba(0, 204, 255, 0.1);
}

.big-start {
    font-size: 3vmin;
    padding: 2vmin;
    background: var(--primary);
    color: black;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-top: 2vmin;
    box-shadow: 0 0 3vmin rgba(255, 204, 0, 0.3);
}

.big-start:hover {
    box-shadow: 0 0 5vmin rgba(255, 204, 0, 0.6);
    transform: scale(1.02);
}

/* =========================================
   VALIDATION MODAL
   ========================================= */

.validation-modal-content {
    width: 90%;
    max-width: 560px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    gap: 2vmin;
    overflow: hidden;
    text-align: left;
}

.val-header {
    display: flex;
    align-items: center;
    gap: 2vmin;
    border-bottom: 1px solid var(--border);
    padding-bottom: 2vmin;
}

.val-icon {
    font-size: 4vmin;
    line-height: 1;
}

.val-header h2 {
    margin: 0;
    font-size: clamp(1rem, 3vmin, 1.5rem);
    color: var(--text);
}

.val-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1vmin;
}

.val-tag {
    font-size: clamp(0.7rem, 1.8vmin, 0.9rem);
    padding: 0.4vmin 1.5vmin;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--text);
}

.val-tag-blue {
    background: rgba(0, 204, 255, 0.12);
    border-color: var(--secondary);
    color: var(--secondary);
}

.val-tag-warn {
    background: rgba(255, 165, 0, 0.12);
    border-color: orange;
    color: orange;
}

.val-tag-ok {
    background: rgba(0, 200, 83, 0.12);
    border-color: #00c853;
    color: #00c853;
}

.val-tag-error {
    background: rgba(213, 0, 0, 0.12);
    border-color: #ff5252;
    color: #ff5252;
}

.val-summary {
    margin: 0;
    font-size: clamp(0.85rem, 2.2vmin, 1rem);
    color: rgba(255, 255, 255, 0.85);
    line-height: 1.5;
}

/* Scrollable body area */
.val-body {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.5vmin;
    padding-right: 0.5vmin;
}

.val-section {
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    overflow: hidden;
}

.val-toggle-btn {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: none;
    color: var(--text);
    padding: 1.5vmin 2vmin;
    font-size: clamp(0.8rem, 2vmin, 0.95rem);
    font-weight: bold;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s;
}

.val-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.val-collapsible {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    padding: 0 2vmin;
}

.val-collapsible.open {
    max-height: 300px;
    overflow-y: auto;
    padding: 1.5vmin 2vmin;
}

/* Error row */
.val-error-row {
    padding: 1vmin 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    font-size: clamp(0.75rem, 1.8vmin, 0.9rem);
}

.val-error-row:last-child {
    border-bottom: none;
}

.val-error-row .val-row-num {
    color: #ff5252;
    font-weight: bold;
    margin-right: 0.5em;
}

.val-error-row .val-row-text {
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.9em;
    display: block;
    margin-top: 0.3em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.val-error-row .val-row-reason {
    color: orange;
    font-size: 0.88em;
    display: block;
    margin-top: 0.2em;
}

/* Warning row */
.val-warning-row {
    padding: 0.8vmin 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    font-size: clamp(0.75rem, 1.8vmin, 0.9rem);
    color: rgba(255, 165, 0, 0.9);
}

.val-warning-row:last-child {
    border-bottom: none;
}

/* Preview card */
.val-preview-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(0, 204, 255, 0.15);
    border-radius: 8px;
    padding: 1.5vmin;
    margin-bottom: 1vmin;
}

.val-preview-card:last-child {
    margin-bottom: 0;
}

.val-preview-card .val-q-diff {
    font-size: 0.8em;
    color: var(--secondary);
    margin-bottom: 0.4em;
}

.val-preview-card .val-q-text {
    font-size: clamp(0.8rem, 1.9vmin, 0.95rem);
    font-weight: bold;
    margin-bottom: 0.6em;
}

.val-preview-card .val-q-answers {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5vmin;
    font-size: clamp(0.7rem, 1.7vmin, 0.85rem);
}

.val-preview-card .val-q-answers span {
    color: rgba(255, 255, 255, 0.65);
}

.val-preview-card .val-q-answers span.correct-ans {
    color: #69f0ae;
    font-weight: bold;
}

.val-actions {
    display: flex;
    justify-content: flex-end;
    gap: 2vmin;
    border-top: 1px solid var(--border);
    padding-top: 2vmin;
    margin-top: auto;
}

/* Set name input – visible on success */
.val-name-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.8vmin;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding-top: 2vmin;
}

.val-name-label {
    font-size: clamp(0.75rem, 1.8vmin, 0.9rem);
    color: var(--secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.val-name-input {
    background: var(--ans-bg);
    border: 1.5px solid var(--ans-border);
    color: white;
    font-size: clamp(0.9rem, 2.2vmin, 1.1rem);
    padding: 1.2vmin 1.8vmin;
    border-radius: 10px;
    outline: none;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    width: 100%;
}

/* --- LEADERBOARD & START ACTIONS --- */
.start-actions {
    display: flex;
    flex-direction: column;
    gap: 1.5vmin;
    margin-top: 1vmin;
}

.leaderboard-content {
    width: min(90%, 450px);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    gap: 3vmin;
}

.leaderboard-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1vmin;
    padding-right: 1vmin;
}

.leaderboard-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5vmin 2.5vmin;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 204, 0, 0.15);
    border-radius: 12px;
    font-size: 2.2vmin;
}

.leaderboard-item .rank {
    width: 4vmin;
    font-weight: 800;
    color: var(--secondary);
}

.leaderboard-item .name {
    flex: 1;
    padding: 0 2vmin;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.leaderboard-item .prize {
    font-weight: 800;
    color: var(--primary);
}

#take-money-btn:hover {
    background: rgba(0, 200, 83, 0.1);
    box-shadow: 0 0 1.5vmin rgba(0, 200, 83, 0.3);
}

.val-name-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 1.5vmin rgba(255, 204, 0, 0.2);
}

/* --- Extra Save Buttons --- */
#val-server-save-btn {
    border-color: #00c853 !important;
    color: #00c853 !important;
}

#val-server-save-btn:hover {
    background: rgba(0, 200, 83, 0.1) !important;
}

#val-local-save-btn {
    margin-right: auto;
    border-color: var(--secondary) !important;
    color: var(--secondary) !important;
}

#val-local-save-btn:hover {
    background: rgba(0, 204, 255, 0.1) !important;
}

.val-actions {
    display: flex;
    gap: 1.5vmin;
    padding-top: 2vmin;
    border-top: 1px solid var(--border);
    margin-top: auto;
}