/* ===== THEME VARS ===== */
:root {
    --bg-color: #0f172a;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;

    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);

    --accent-primary: #3b82f6;
    --accent-secondary: #8b5cf6;

    --machine-body: #334155;
    --machine-dark: #1e293b;
    --machine-accent: #f59e0b;
    --belt-color: #475569;
    --belt-dot: #64748b;

    --ball-a-bg: linear-gradient(135deg, #f97316, #ef4444);
    --ball-b-bg: linear-gradient(135deg, #06b6d4, #3b82f6);
    --ball-result-bg: linear-gradient(135deg, #10b981, #059669);

    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

:root.light-theme {
    --bg-color: #f1f5f9;
    --text-main: #0f172a;
    --text-muted: #475569;

    --glass-bg: rgba(255, 255, 255, 0.6);
    --glass-border: rgba(255, 255, 255, 0.8);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.05);

    --machine-body: #cbd5e1;
    --machine-dark: #94a3b8;
    --machine-accent: #f59e0b;
    --belt-color: #cbd5e1;
    --belt-dot: #94a3b8;
}

/* ===== RESET ===== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
    transition: background-color 0.5s ease;
}

/* ===== BG SHAPES ===== */
.background-shapes {
    position: fixed;
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    z-index: -1;
    overflow: hidden;
}

.shape {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.45;
    animation: float 20s infinite alternate;
}

.blob1 {
    top: -10%; left: -10%;
    width: 50vw; height: 50vw;
    background: radial-gradient(circle, var(--accent-secondary), transparent);
}

.blob2 {
    bottom: -20%; right: -10%;
    width: 60vw; height: 60vw;
    background: radial-gradient(circle, var(--accent-primary), transparent);
    animation-delay: -5s;
}

.blob3 {
    top: 40%; left: 30%;
    width: 40vw; height: 40vw;
    background: radial-gradient(circle, #0ea5e9, transparent);
    animation-delay: -10s;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(5%, 5%) scale(1.1); }
}

/* ===== TOP BAR ===== */
.top-bar {
    position: fixed;
    top: 0;
    left: 0; right: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
}

.back-btn {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(12px);
    border-radius: 14px;
    padding: 10px 20px;
    color: var(--text-main);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    transition: var(--transition);
}

.back-btn:hover {
    transform: translateX(-4px);
    background: rgba(59, 130, 246, 0.15);
}

.theme-toggle {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(12px);
    border-radius: 50%;
    width: 48px; height: 48px;
    cursor: pointer;
    display: flex;
    justify-content: center; align-items: center;
    font-size: 1.3rem;
    color: var(--text-main);
    transition: var(--transition);
}

.theme-toggle:hover {
    transform: scale(1.1) rotate(15deg);
}

.icon-sun { display: none; }
.icon-moon { display: block; }
:root.light-theme .icon-sun { display: block; }
:root.light-theme .icon-moon { display: none; }

.top-right-controls {
    display: flex;
    align-items: center;
    gap: 16px;
}

.daily-countdown {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(12px);
    border-radius: 14px;
    padding: 10px 18px;
    font-size: 1.15rem;
    color: var(--text-muted);
    font-family: 'Outfit', sans-serif;
    transition: var(--transition);
}

.daily-countdown span {
    font-family: 'Rubik', sans-serif;
    color: #3b82f6;
    font-weight: 700;
    margin-left: 6px;
    letter-spacing: 0.05em;
}

@media (max-width: 600px) {
    .daily-countdown {
        display: none; /* Hide on very small screens to save space */
    }
}

/* ===== PAGE LAYOUT ===== */
.page-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 100px 20px 60px;
    display: flex;
    flex-direction: column;
    gap: 50px;
}

.page-header {
    text-align: center;
    animation: fadeInDown 0.7s ease-out;
}

.page-header h1 {
    font-size: 2.8rem;
    font-weight: 800;
    margin-bottom: 8px;
}

.page-header h1 .gradient-text {
    background: linear-gradient(to right, #60a5fa, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.page-header p {
    font-size: 1.15rem;
    color: var(--text-muted);
}

/* ===== MACHINE SECTION ===== */
.machine-section {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(16px);
    border-radius: 28px;
    padding: 36px 28px;
    box-shadow: var(--glass-shadow);
    animation: fadeInUp 0.8s ease-out both;
}

.challenge-section {
    animation-delay: 0.2s;
}

.section-label {
    text-align: center;
    font-size: 1.4rem;
    font-family: 'Rubik', sans-serif;
    margin-bottom: 28px;
    color: var(--text-main);
    letter-spacing: 0.02em;
}

/* ===== TODAY'S FUZZLE BADGE ===== */
.today-fuzzle-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    width: max-content;
    margin: 0 auto 28px;
    background: linear-gradient(135deg, #ef4444, #f59e0b);
    color: white;
    padding: 8px 24px;
    border-radius: 30px;
    font-family: 'Rubik', sans-serif;
    font-weight: 800;
    font-size: 1.5rem;
    letter-spacing: 0.05em;
    box-shadow: 0 4px 20px rgba(239, 68, 68, 0.5);
    gap: 10px;
    transform-origin: center;
    animation: floatBadge 3s ease-in-out infinite;
    border: 3px solid rgba(255, 255, 255, 0.2);
}

.today-fuzzle-badge .badge-icon {
    font-size: 1.6rem;
    animation: pulseIcon 1s infinite alternate;
}

@keyframes floatBadge {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-8px) scale(1.03); }
}

@keyframes pulseIcon {
    0% { transform: scale(1) rotate(-5deg); }
    100% { transform: scale(1.3) rotate(5deg); }
}

/* ===== PAST FUZZLE BADGES ===== */
.yesterday-fuzzle-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    width: max-content;
    margin: 0 auto 28px;
    background: linear-gradient(135deg, #8b5cf6, #3b82f6);
    color: white;
    padding: 8px 24px;
    border-radius: 30px;
    font-family: 'Rubik', sans-serif;
    font-weight: 800;
    font-size: 1.5rem;
    letter-spacing: 0.05em;
    box-shadow: 0 4px 20px rgba(139, 92, 246, 0.5);
    border: 3px solid rgba(255, 255, 255, 0.2);
    gap: 10px;
}

.yesterday-fuzzle-badge .badge-icon {
    font-size: 1.6rem;
    animation: pulseIcon 1.5s infinite alternate;
}

.daybefore-fuzzle-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    width: max-content;
    margin: 0 auto 28px;
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    padding: 8px 24px;
    border-radius: 30px;
    font-family: 'Rubik', sans-serif;
    font-weight: 800;
    font-size: 1.5rem;
    letter-spacing: 0.05em;
    box-shadow: 0 4px 20px rgba(16, 185, 129, 0.5);
    border: 3px solid rgba(255, 255, 255, 0.2);
    gap: 10px;
}

.daybefore-fuzzle-badge .badge-icon {
    font-size: 1.6rem;
    animation: pulseIcon 2s infinite alternate;
}

/* ===== MACHINE STAGE ===== */
.machine-stage {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    position: relative;
    height: 260px;
    margin: 0 auto;
    max-width: 760px;
    overflow: hidden;
}

/* ===== CONVEYOR BELTS ===== */
.conveyor-left,
.conveyor-right {
    position: relative;
    flex: 1;
    height: 100%;
    display: flex;
    align-items: center;
}

.belt-track {
    position: absolute;
    bottom: 72px;
    left: 0; right: 0;
    height: 18px;
    background: var(--belt-color);
    border-radius: 9px;
    overflow: hidden;
}

.belt-dots {
    position: absolute;
    top: 0; left: 0;
    width: 200%;
    height: 100%;
    background: repeating-linear-gradient(
        90deg,
        transparent,
        transparent 16px,
        var(--belt-dot) 16px,
        var(--belt-dot) 20px
    );
    animation: beltScroll 1.5s linear infinite;
}

.conveyor-left .belt-dots {
    animation-direction: normal;
}

.conveyor-right .belt-dots {
    animation-direction: normal;
}

@keyframes beltScroll {
    0% { transform: translateX(0); }
    100% { transform: translateX(-50%); }
}

/* ===== NUMBER BALLS ===== */
.number-ball {
    position: absolute;
    bottom: 60px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Rubik', sans-serif;
    font-weight: 700;
    font-size: 1.5rem;
    color: white;
    box-shadow: 0 6px 20px rgba(0,0,0,0.35);
    z-index: 10;
    opacity: 0;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.ball-a {
    background: var(--ball-a-bg);
    left: -60px;
}

.ball-b {
    background: var(--ball-b-bg);
    left: -60px;
}

.ball-result {
    background: var(--ball-result-bg);
    right: 100%;
    left: auto;
}

.challenge-result {
    font-size: 1.6rem;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #a855f7, #ec4899);
}

/* ===== THE MACHINE ===== */
.machine-body {
    position: relative;
    width: 200px;
    min-width: 200px;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 5;
}

.machine-top {
    display: flex;
    align-items: flex-end;
    gap: 20px;
    height: 50px;
    margin-bottom: -4px;
    z-index: 6;
}

.chimney {
    width: 32px;
    height: 44px;
    background: var(--machine-dark);
    border-radius: 6px 6px 0 0;
    position: relative;
    border: 2px solid rgba(255,255,255,0.08);
    border-bottom: none;
}

.smoke {
    position: absolute;
    top: -10px;
    left: 50%;
    width: 14px;
    height: 14px;
    background: rgba(148, 163, 184, 0.5);
    border-radius: 50%;
    transform: translateX(-50%);
    opacity: 0;
    pointer-events: none;
}

.smoke.active {
    animation: smokeRise 1.8s ease-out forwards;
}

.smoke2 { left: 40%; }
.smoke3 { left: 60%; }

@keyframes smokeRise {
    0% {
        opacity: 0.8;
        transform: translateX(-50%) translateY(0) scale(0.5);
    }
    50% {
        opacity: 0.5;
    }
    100% {
        opacity: 0;
        transform: translateX(-50%) translateY(-60px) scale(2.5);
    }
}

.antenna {
    width: 8px;
    height: 36px;
    background: var(--machine-dark);
    border-radius: 4px;
    position: relative;
}

.antenna-light {
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #475569;
    box-shadow: none;
    transition: all 0.3s ease;
}

.antenna-light.active {
    background: #ef4444;
    box-shadow: 0 0 12px 4px rgba(239, 68, 68, 0.6);
    animation: blink 0.5s ease-in-out infinite alternate;
}

@keyframes blink {
    0% { opacity: 1; box-shadow: 0 0 12px 4px rgba(239, 68, 68, 0.6); }
    100% { opacity: 0.6; box-shadow: 0 0 20px 8px rgba(239, 68, 68, 0.4); }
}

.machine-main {
    width: 100%;
    height: 120px;
    background: var(--machine-body);
    border-radius: 16px;
    display: flex;
    align-items: center;
    position: relative;
    border: 2px solid rgba(255,255,255,0.08);
    box-shadow: 0 8px 30px rgba(0,0,0,0.25), inset 0 2px 0 rgba(255,255,255,0.05);
    overflow: visible;
}

.machine-input-slot,
.machine-output-slot {
    width: 28px;
    height: 50px;
    background: var(--machine-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    flex-shrink: 0;
}

.slot-arrow {
    color: var(--machine-accent);
    font-size: 0.9rem;
    animation: arrowPulse 1.5s ease-in-out infinite;
}

@keyframes arrowPulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

.machine-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    position: relative;
}

.gears {
    display: flex;
    gap: 4px;
}

.gear {
    font-size: 2rem;
    color: var(--machine-accent);
    opacity: 0.7;
    transition: all 0.3s ease;
}

.gear.spinning {
    animation: gearSpin 0.6s linear infinite;
    opacity: 1;
    color: #fbbf24;
}

.gear2.spinning {
    animation-direction: reverse;
}

@keyframes gearSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.machine-label {
    font-family: 'Rubik', sans-serif;
    font-size: 1.4rem;
    color: #fbbf24;
    font-weight: 800;
    letter-spacing: 0.15em;
    text-shadow: 0 0 12px rgba(251, 191, 36, 0.6);
}

.machine-display {
    background: rgba(0,0,0,0.5);
    padding: 4px 18px;
    border-radius: 6px;
    font-family: 'Rubik', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    min-width: 90px;
    text-align: center;
    border: 1px solid rgba(251, 191, 36, 0.2);
}

.display-dots {
    color: #fbbf24;
    letter-spacing: 2px;
    text-shadow: 0 0 8px rgba(251, 191, 36, 0.5);
}

.machine-display.processing .display-dots {
    animation: dotPulse 0.4s ease-in-out infinite;
}

@keyframes dotPulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

.machine-legs {
    display: flex;
    gap: 80px;
    margin-top: -2px;
}

.leg {
    width: 16px;
    height: 22px;
    background: var(--machine-dark);
    border-radius: 0 0 6px 6px;
    border: 2px solid rgba(255,255,255,0.06);
    border-top: none;
}

/* ===== PLAY BUTTON ===== */
.play-btn {
    display: block;
    margin: 28px auto 0;
    padding: 14px 36px;
    border: none;
    border-radius: 16px;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    color: white;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.3);
    letter-spacing: 0.02em;
}

.play-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 30px rgba(59, 130, 246, 0.45);
}

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

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

.fuzzle-btn {
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    box-shadow: 0 6px 20px rgba(245, 158, 11, 0.3);
}

.fuzzle-btn:hover {
    box-shadow: 0 10px 30px rgba(245, 158, 11, 0.45);
}

/* ===== ANSWER AREA ===== */
.answer-area {
    margin-top: 30px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.answer-prompt {
    font-size: 1.1rem;
    color: var(--text-muted);
}

.answer-prompt strong {
    color: var(--text-main);
    font-size: 1.2rem;
}

.answer-input-row {
    display: flex;
    gap: 12px;
    align-items: center;
}

.answer-input {
    width: 160px;
    padding: 14px 20px;
    border: 2px solid var(--glass-border);
    border-radius: 14px;
    background: rgba(255,255,255,0.05);
    color: var(--text-main);
    font-family: 'Rubik', sans-serif;
    font-size: 1.3rem;
    font-weight: 700;
    text-align: center;
    outline: none;
    transition: var(--transition);
    -moz-appearance: textfield;
}

.answer-input::-webkit-outer-spin-button,
.answer-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.answer-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
}

:root.light-theme .answer-input {
    background: rgba(255,255,255,0.7);
}

.submit-btn {
    padding: 14px 28px;
    border: none;
    border-radius: 14px;
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 1.05rem;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.3);
}

.submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(16, 185, 129, 0.4);
}

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

/* ===== FEEDBACK ===== */
.feedback {
    font-family: 'Rubik', sans-serif;
    font-size: 1.15rem;
    font-weight: 600;
    min-height: 36px;
    transition: var(--transition);
}

.feedback.correct {
    color: #10b981;
    animation: popIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.feedback.wrong {
    color: #ef4444;
    animation: shake 0.5s ease-in-out;
}

@keyframes popIn {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-10px); }
    40% { transform: translateX(10px); }
    60% { transform: translateX(-8px); }
    80% { transform: translateX(8px); }
}

/* ===== ANIMATIONS ===== */
@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-30px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== BALL ANIMATION CLASSES ===== */
/* Slide ball A onto belt from left and move to machine */
.ball-a.anim-enter {
    opacity: 1;
    animation: slideInBallA 1.5s ease-in-out forwards;
}

@keyframes slideInBallA {
    0% {
        left: -60px;
        opacity: 0;
    }
    15% {
        opacity: 1;
    }
    100% {
        left: calc(100% - 30px);
        opacity: 1;
    }
}

/* Slide ball B after A */
.ball-b.anim-enter {
    opacity: 1;
    animation: slideInBallB 1.5s ease-in-out forwards;
}

@keyframes slideInBallB {
    0% {
        left: -60px;
        opacity: 0;
    }
    15% {
        opacity: 1;
    }
    100% {
        left: calc(100% - 30px);
        opacity: 1;
    }
}

/* Ball disappears into machine */
.ball-a.anim-enter-machine,
.ball-b.anim-enter-machine {
    animation: enterMachine 0.5s ease-in forwards;
}

@keyframes enterMachine {
    0% {
        opacity: 1;
        transform: scale(1);
    }
    100% {
        opacity: 0;
        transform: scale(0.3);
    }
}

/* Ball result comes out */
.ball-result.anim-exit {
    opacity: 1;
    animation: slideOutResult 1.2s ease-out forwards;
}

@keyframes slideOutResult {
    0% {
        right: 100%;
        opacity: 0;
        transform: scale(0.4);
    }
    20% {
        opacity: 1;
        transform: scale(1);
    }
    100% {
        right: 20px;
        opacity: 1;
        transform: scale(1);
    }
}

/* Machine shake when processing */
.machine-body.processing {
    animation: machineShake 0.15s linear infinite;
}

@keyframes machineShake {
    0% { transform: translateX(0) translateY(0); }
    25% { transform: translateX(-2px) translateY(1px); }
    50% { transform: translateX(2px) translateY(-1px); }
    75% { transform: translateX(-1px) translateY(1px); }
    100% { transform: translateX(1px) translateY(0); }
}

/* Pulse attention on the "?" ball */
.ball-result.pulse-attention {
    animation: pulseGlow 1.5s ease-in-out infinite;
}

@keyframes pulseGlow {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 6px 20px rgba(0,0,0,0.35);
    }
    50% {
        transform: scale(1.15);
        box-shadow: 0 0 30px 8px rgba(168, 85, 247, 0.5), 0 6px 20px rgba(0,0,0,0.35);
    }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 700px) {
    .page-header h1 {
        font-size: 2rem;
    }
    
    .machine-stage {
        height: 220px;
        transform: scale(0.85);
        transform-origin: center;
    }
    
    .machine-section {
        padding: 24px 16px;
    }
    
    .answer-input-row {
        flex-direction: column;
    }
    
    .answer-input {
        width: 200px;
    }
}

@media (max-width: 480px) {
    .machine-stage {
        transform: scale(0.65);
    }
    
    .page-header h1 {
        font-size: 1.6rem;
    }
}
