:root {
    --bg-color: #060818;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --accent: #f43f5e;
    --text: #f1f5f9;
    --glass-bg: rgba(255, 255, 255, 0.06);
    --glass-border: rgba(255, 255, 255, 0.12);
    --neon-blue: #38bdf8;
    --neon-purple: #a78bfa;
}

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

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@400;700;900&display=swap');

body {
    background: radial-gradient(ellipse at 50% 0%, #1e1b4b 0%, #060818 60%);
    color: var(--text);
    font-family: 'Outfit', sans-serif;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    min-height: 100vh;
}

#game-container {
    position: relative;
    width: 800px;
    height: 600px;
    background: linear-gradient(160deg, #0d0d2b 0%, #0f172a 100%);
    border-radius: 20px;
    box-shadow:
        0 0 0 1px rgba(99, 102, 241, 0.25),
        0 0 60px rgba(99, 102, 241, 0.15),
        0 40px 80px rgba(0, 0, 0, 0.8);
    overflow: hidden;
    transition: background 1.2s ease;
}

/* Level Themes – canvas handles the backgrounds now, just the outer box glow changes */
#game-container.theme-level-1 {
    box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.3), 0 0 60px rgba(56, 189, 248, 0.12), 0 40px 80px rgba(0,0,0,0.8);
}
#game-container.theme-level-2 {
    box-shadow: 0 0 0 1px rgba(74, 222, 128, 0.3), 0 0 60px rgba(74, 222, 128, 0.12), 0 40px 80px rgba(0,0,0,0.8);
}
#game-container.theme-level-3 {
    box-shadow: 0 0 0 1px rgba(251, 191, 36, 0.3), 0 0 60px rgba(251, 191, 36, 0.1), 0 40px 80px rgba(0,0,0,0.8);
}
#game-container.theme-level-4 {
    box-shadow: 0 0 0 1px rgba(167, 139, 250, 0.3), 0 0 60px rgba(167, 139, 250, 0.12), 0 40px 80px rgba(0,0,0,0.8);
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* === UI OVERLAY LAYER === */
#ui-layer {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 100;
}

.screen {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(6, 8, 24, 0.88);
    backdrop-filter: blur(16px);
    pointer-events: auto;
    text-align: center;
    padding: 2rem;
    transition: opacity 0.4s ease;
}

.screen.hidden {
    opacity: 0;
    pointer-events: none;
}

h1 {
    font-size: 3.5rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--neon-blue) 0%, var(--neon-purple) 60%, #f472b6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
    letter-spacing: -1px;
    filter: drop-shadow(0 0 20px rgba(99,102,241,0.5));
}

.subtitle {
    font-size: 1.1rem;
    color: rgba(241, 245, 249, 0.6);
    margin-bottom: 2.5rem;
    max-width: 80%;
    line-height: 1.6;
}

h2 {
    font-size: 2.5rem;
    font-weight: 900;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--neon-blue), var(--neon-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

p {
    font-size: 1.1rem;
    margin-bottom: 2rem;
    max-width: 80%;
    line-height: 1.6;
    color: rgba(241, 245, 249, 0.7);
}

button {
    background: linear-gradient(135deg, var(--primary), var(--neon-purple));
    color: white;
    border: none;
    padding: 0.9rem 2.5rem;
    font-size: 1.1rem;
    font-weight: 700;
    border-radius: 9999px;
    cursor: pointer;
    transition: all 0.25s ease;
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.4), 0 4px 14px rgba(0,0,0,0.5);
    letter-spacing: 0.5px;
    font-family: 'Outfit', sans-serif;
}
/* Name Input on Start Screen */
.name-input-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 2rem;
}

.name-input-wrap label {
    font-size: 0.9rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: rgba(241,245,249,0.5);
}

#player-name-input {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 12px;
    padding: 0.75rem 1.5rem;
    font-size: 1.1rem;
    font-weight: 700;
    font-family: 'Outfit', sans-serif;
    color: #f1f5f9;
    text-align: center;
    outline: none;
    transition: all 0.2s ease;
    min-width: 260px;
}

#player-name-input::placeholder { color: rgba(241,245,249,0.3); }
#player-name-input:focus {
    border-color: rgba(99,102,241,0.7);
    box-shadow: 0 0 20px rgba(99,102,241,0.3);
    background: rgba(99,102,241,0.08);
}

/* Highscore Box on Win Screen */
.highscore-box {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 16px;
    padding: 1.5rem 2.5rem;
    margin: 1rem 0 2rem;
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
@keyframes error-shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-5px); }
    40%, 80% { transform: translateX(5px); }
}

.error-shake {
    animation: error-shake 0.4s ease;
}

.hs-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1rem;
    font-weight: 700;
}

.hs-label { color: rgba(241,245,249,0.7); }
.hs-value { color: var(--neon-blue); font-size: 1.2rem; }

.hs-total {
    border-top: 1px solid rgba(255,255,255,0.12);
    padding-top: 0.75rem;
    margin-top: 0.25rem;
}
.hs-total .hs-label { color: #fbbf24; }
.hs-total .hs-value { color: #fde68a; font-size: 1.5rem; }

.leaderboard-container {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    padding: 1rem;
    margin-top: 1.5rem;
    max-height: 200px;
    overflow-y: auto;
    text-align: left;
}

.leaderboard-container h3 {
    margin: 0 0 10px 0;
    font-size: 1.2rem;
    color: #38bdf8;
    text-align: center;
}

.leaderboard-container ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.leaderboard-container li {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    font-size: 0.95rem;
}
.leaderboard-container li:last-child {
    border-bottom: none;
}
.leaderboard-container .rank {
    font-weight: 700;
    color: #fbbf24;
    width: 25px;
}
.leaderboard-container .name {
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 10px;
}
.leaderboard-container .score {
    color: #10b981;
    font-weight: bold;
    min-width: 50px;
    text-align: right;
}
.leaderboard-container .time {
    color: #94a3b8;
    min-width: 60px;
    text-align: right;
    font-size: 0.85rem;
}

button:hover {
    transform: translateY(-3px) scale(1.04);
    box-shadow: 0 0 30px rgba(99, 102, 241, 0.6), 0 8px 20px rgba(0,0,0,0.5);
}

button:active {
    transform: translateY(-1px) scale(1.01);
}

/* Decorative grid background on menu */
#start-screen::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(99,102,241,0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(99,102,241,0.05) 1px, transparent 1px);
    background-size: 40px 40px;
    pointer-events: none;
}

/* === QUIZ === */
#quiz-options {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    width: 100%;
    max-width: 420px;
    margin-top: 0.5rem;
}

.quiz-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(8px);
    text-align: left;
    padding: 0.85rem 1.5rem;
    border-radius: 12px;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.quiz-btn:hover {
    background: rgba(99, 102, 241, 0.25);
    border-color: rgba(99, 102, 241, 0.5);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.2);
    transform: translateY(-1px) scale(1.01);
}

/* === HUD LAYER === */
#hud-layer {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    z-index: 50;
}

#hud-layer.hidden { display: none !important; }
.hidden { display: none !important; }

/* Score / Level - top right */
.hud-top {
    position: absolute;
    top: 1rem;
    right: 1.2rem;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.35rem;
}

.level-indicator,
.score-indicator {
    background: rgba(6, 8, 24, 0.7);
    border: 1px solid var(--glass-border);
    border-radius: 9999px;
    padding: 0.3rem 1rem;
    font-size: 0.95rem;
    font-weight: 700;
    backdrop-filter: blur(8px);
    letter-spacing: 0.5px;
}

.level-indicator span,
.score-indicator span {
    color: var(--neon-blue);
}

/* === MARTIN'S TROLL HUD (Top Left) === */
.martin-hud {
    position: absolute;
    top: 1rem;
    left: 1rem;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    background: rgba(6, 8, 24, 0.75);
    padding: 0.75rem 1rem 0.75rem 0.75rem;
    border-radius: 18px;
    border: 1px solid rgba(255,255,255,0.1);
    backdrop-filter: blur(12px);
    box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}

.troll-wrapper {
    position: relative;
    flex-shrink: 0;
}

/* Troll Face */
#troll-face {
    width: 58px;
    height: 58px;
    background: #4ade80;
    border-radius: 16px;
    position: relative;
    border: 2.5px solid #166534;
    transition: background 0.3s ease, border-color 0.3s ease;
    box-shadow: 0 0 12px rgba(74, 222, 128, 0.3);
    overflow: hidden;
}

.eyes {
    position: absolute;
    top: 18px;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-around;
    padding: 0 10px;
}

.eye {
    width: 10px;
    height: 10px;
    background: #111;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.mouth {
    position: absolute;
    bottom: 11px;
    left: 50%;
    transform: translateX(-50%);
    width: 22px;
    height: 7px;
    background: #111;
    border-radius: 10px;
    transition: all 0.3s ease;
}

/* Mood States */
.mood-calm { background: #4ade80 !important; border-color: #166534 !important; box-shadow: 0 0 12px rgba(74,222,128,0.3) !important; }

.mood-annoyed { background: #facc15 !important; border-color: #a16207 !important; box-shadow: 0 0 12px rgba(250,204,21,0.4) !important; }
.mood-annoyed .eye { height: 6px; border-radius: 2px; }
.mood-annoyed .mouth { width: 14px; height: 4px; }

.mood-angry { background: #f97316 !important; border-color: #c2410c !important; box-shadow: 0 0 16px rgba(249,115,22,0.5) !important; }
.mood-angry .eye { height: 4px; transform: rotate(12deg); }
.mood-angry .eye.right { transform: rotate(-12deg); }
.mood-angry .mouth { width: 26px; height: 11px; border-radius: 4px; background: #7f1d1d; }

.mood-furious { background: #ef4444 !important; border-color: #7f1d1d !important; box-shadow: 0 0 24px rgba(239,68,68,0.7) !important; animation: shake 0.25s infinite; }
.mood-furious .eye { height: 4px; background: #fef08a; transform: rotate(22deg); }
.mood-furious .eye.right { transform: rotate(-22deg); }
.mood-furious .mouth { width: 28px; height: 15px; border-radius: 3px; background: #111; border-top: 4px solid #fff; }

@keyframes shake {
    0%   { transform: translate(1px, 1px) rotate(0deg); }
    15%  { transform: translate(-2px, -1px) rotate(-1deg); }
    30%  { transform: translate(-2px, 1px) rotate(1deg); }
    45%  { transform: translate(2px, 1px) rotate(0deg); }
    60%  { transform: translate(1px, -1px) rotate(1deg); }
    75%  { transform: translate(-1px, 2px) rotate(-1deg); }
    100% { transform: translate(1px, -1px) rotate(0deg); }
}

/* Mood Bar */
.mood-container {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    width: 140px;
}

.mood-label {
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    font-size: 0.75rem;
    color: rgba(241,245,249,0.6);
}

.mood-bar-bg {
    width: 100%;
    height: 18px;
    background: rgba(0,0,0,0.5);
    border-radius: 9999px;
    border: 1px solid rgba(255,255,255,0.1);
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
}

#mood-bar-fill {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, #34d399, #fbbf24, #ef4444);
    transition: width 0.3s ease;
    border-radius: 9999px;
    box-shadow: 0 0 8px rgba(239,68,68,0.4);
}

/* === SPEECH BUBBLE === */
.dialog-box {
    position: absolute;
    top: 50%;
    left: calc(100% + 16px);
    transform: translateY(-50%);
    background: #fff;
    padding: 0.7rem 1rem;
    border-radius: 14px;
    border: 2px solid #e2e8f0;
    width: max-content;
    max-width: 220px;
    animation: popIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    z-index: 100;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.dialog-box::before {
    content: '';
    position: absolute;
    top: 50%;
    left: -9px;
    transform: translateY(-50%);
    border-width: 9px 9px 9px 0;
    border-style: solid;
    border-color: transparent #fff transparent transparent;
    z-index: 2;
}

.dialog-box::after {
    content: '';
    position: absolute;
    top: 50%;
    left: -12px;
    transform: translateY(-50%);
    border-width: 11px 11px 11px 0;
    border-style: solid;
    border-color: transparent #e2e8f0 transparent transparent;
    z-index: 1;
}

.dialog-text {
    font-size: 0.9rem;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.35;
}

@keyframes popIn {
    0%   { opacity: 0; transform: translateY(-50%) scale(0.7); }
    100% { opacity: 1; transform: translateY(-50%) scale(1); }
}
