/* ══════════════════════════════════════════════════════════════
   DESIGN TOKENS
══════════════════════════════════════════════════════════════ */
:root {
    --bg-color: #f8fafc;
    --surface-color: #ffffff;
    --surface-glass: rgba(255, 255, 255, 0.8);
    --accent-color: #1e293b;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --positive-color: #059669;
    --negative-color: #e11d48;
    --border-color: rgba(0, 0, 0, 0.06);
    --shadow-soft: 0 12px 30px rgba(0, 0, 0, 0.05);
    --transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);

    /* Escape theme */
    --escape-accent: #7c3aed;
    --escape-danger: #dc2626;
    --escape-bg: #0f0a1e;
    --escape-surface: rgba(124, 58, 237, 0.08);
    --escape-border: rgba(124, 58, 237, 0.2);
    --escape-glow: rgba(124, 58, 237, 0.4);
}

/* ══════════════════════════════════════════════════════════════
   RESET & BASE
══════════════════════════════════════════════════════════════ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    overflow: hidden;
}

/* ══════════════════════════════════════════════════════════════
   SCREEN SYSTEM
══════════════════════════════════════════════════════════════ */
.screen {
    position: fixed;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.23, 1, 0.32, 1);
    transform: scale(0.98);
    overflow-y: auto;
}

.screen.active {
    opacity: 1;
    pointer-events: all;
    transform: scale(1);
}

.screen.slide-out-left {
    opacity: 0;
    transform: translateX(-60px) scale(0.96);
    pointer-events: none;
}

.screen.slide-in-right {
    opacity: 0;
    transform: translateX(60px) scale(0.96);
    pointer-events: none;
}

/* ══════════════════════════════════════════════════════════════
   HOME SCREEN
══════════════════════════════════════════════════════════════ */
#home-screen {
    background: #ffffff;
    background-image: 
        radial-gradient(at 0% 0%, rgba(79, 70, 229, 0.03) 0px, transparent 50%),
        radial-gradient(at 100% 0%, rgba(124, 58, 237, 0.03) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(56, 189, 248, 0.03) 0px, transparent 50%),
        radial-gradient(at 0% 100%, rgba(20, 184, 166, 0.03) 0px, transparent 50%);
    flex-direction: column;
    overflow: hidden;
}

.home-bg {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

.home-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(120px);
    opacity: 0.05;
    animation: orb-float 12s ease-in-out infinite;
}

.orb1 {
    width: 600px;
    height: 600px;
    background: #818cf8;
    top: -200px;
    left: -150px;
}

.orb2 {
    width: 500px;
    height: 500px;
    background: #a78bfa;
    bottom: -150px;
    right: -100px;
    animation-delay: -4s;
}

.orb3 {
    width: 400px;
    height: 400px;
    background: #38bdf8;
    top: 60%;
    left: 40%;
    animation-delay: -8s;
}

@keyframes orb-float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(40px, -30px) scale(1.1); }
    66% { transform: translate(-30px, 20px) scale(0.9); }
}

.home-content {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 900px;
    padding: 4rem 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5rem;
}

.home-header {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.home-logo {
    font-size: 2.5rem;
    color: #4f46e5;
    opacity: 0.8;
    margin-bottom: 0.5rem;
}

.home-title {
    font-size: 2.25rem;
    font-weight: 300;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    color: var(--text-primary);
    margin: 0;
}

.home-title span {
    font-weight: 800;
    color: #4f46e5;
    background: none;
    -webkit-text-fill-color: initial;
}

.home-subtitle {
    color: var(--text-secondary);
    font-size: 0.8rem;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    opacity: 0.6;
}

/* ---- Game Cards ---- */
.game-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2.5rem;
    width: 100%;
}

.game-card {
    position: relative;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 2rem;
    padding: 3rem 2.5rem;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    overflow: hidden;
    transition: transform 0.4s cubic-bezier(0.2, 1, 0.3, 1), border-color 0.4s ease, box-shadow 0.4s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.02);
}

.game-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at top right, rgba(79, 70, 229, 0.05), transparent 70%);
    opacity: 0;
    transition: opacity 0.4s ease;
}

.game-card:hover {
    transform: translateY(-5px);
    border-color: rgba(79, 70, 229, 0.1);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.04);
}

.game-card:hover::before {
    opacity: 1;
}

.escape-card:hover {
    border-color: rgba(124, 58, 237, 0.1);
}

.escape-card::before {
    background: radial-gradient(circle at top right, rgba(124, 58, 237, 0.05), transparent 70%);
}

.card-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.1), rgba(79, 70, 229, 0.03));
    border: 1px solid rgba(79, 70, 229, 0.1);
    border-radius: 1rem;
}

.escape-card .card-icon {
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.12), rgba(124, 58, 237, 0.03));
    border-color: rgba(124, 58, 237, 0.12);
}

.card-icon-symbol {
    font-size: 2rem;
    color: #4f46e5;
}

.escape-card .card-icon-symbol {
    color: #7c3aed;
}

.card-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.card-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    background: #f1f5f9;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    width: fit-content;
}

.card-badge.danger {
    background: #fff1f2;
    color: #e11d48;
    border-color: #fecdd3;
}

.card-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.05em;
}

.card-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.7;
}

.card-desc strong {
    color: var(--text-primary);
    font-weight: 600;
}

.card-features {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-top: 0.5rem;
}

.card-features li {
    font-size: 0.8rem;
    color: var(--text-secondary);
    opacity: 0.8;
}

.card-action {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    transition: color 0.3s ease;
}

.game-card:hover .card-action {
    color: #4f46e5;
}

.escape-card:hover .card-action {
    color: #7c3aed;
}

.card-arrow {
    transition: transform 0.3s ease;
}

.game-card:hover .card-arrow {
    transform: translateX(6px);
}

/* ══════════════════════════════════════════════════════════════
   SHARED GAME HEADER
══════════════════════════════════════════════════════════════ */
.game-header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.back-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.4rem 1rem;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.75rem;
    cursor: pointer;
    transition: var(--transition);
    letter-spacing: 0.05em;
}

.back-btn:hover {
    background: var(--text-primary);
    color: var(--bg-color);
}

/* ══════════════════════════════════════════════════════════════
   MATH PUZZLE SCREEN
══════════════════════════════════════════════════════════════ */
#math-screen {
    background-color: var(--bg-color);
    align-items: center;
}

#math-game-container {
    padding: 2rem;
    max-width: 900px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    align-items: center;
}

header {
    text-align: center;
    width: 100%;
}

h1 {
    font-size: 1.5rem;
    font-weight: 300;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--text-primary);
    opacity: 0.9;
}

#settings-panel {
    display: flex;
    justify-content: center;
    gap: 3rem;
    margin-bottom: 2rem;
    padding: 0.5rem;
}

.setting-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.setting-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.btn-group {
    display: flex;
    gap: 0.5rem;
}

.size-btn, .escape-size-btn, .diff-btn {
    padding: 4px 12px;
    border-radius: 4px;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.size-btn.active, .escape-size-btn.active {
    background: var(--text-primary);
    color: var(--bg-color);
    border-color: var(--text-primary);
}

.diff-btn.active {
    background: var(--text-primary);
    color: var(--bg-color);
    border-color: var(--text-primary);
}

.toggle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
}

.slider {
    width: 32px;
    height: 16px;
    background: #e2e8f0;
    border-radius: 8px;
    position: relative;
    transition: var(--transition);
}

.slider:before {
    content: "";
    position: absolute;
    width: 10px;
    height: 10px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: var(--transition);
}

input:checked + .slider {
    background: var(--text-primary);
}

input:checked + .slider:before {
    transform: translateX(16px);
    background: var(--bg-color);
}

.toggle-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.stats-container {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
}

.escape-stats-container {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
}

.stat-box {
    background: var(--surface-glass);
    backdrop-filter: blur(12px);
    padding: 1.25rem 2.5rem;
    border-radius: 0.5rem;
    min-width: 160px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: var(--transition);
}

.stat-box.accent {
    border-color: rgba(255, 255, 255, 0.2);
}

.stat-box .label {
    font-size: 0.6rem;
    text-transform: uppercase;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.2em;
    margin-bottom: 0.5rem;
}

.stat-box .value {
    font-size: 2.25rem;
    font-weight: 300;
    color: var(--text-primary);
}

/* Escape stat boxes - smaller */
.stat-box.escape-stat {
    min-width: 120px;
    padding: 1rem 1.5rem;
}

.stat-box.escape-stat .value {
    font-size: 1.75rem;
}

main {
    position: relative;
    width: 100%;
    display: flex;
    justify-content: center;
}

#game-layout, #escape-game-layout {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
    justify-content: center;
    width: 100%;
}

#canvas-wrapper, #escape-canvas-wrapper {
    position: relative;
    padding: 2rem;
    background: radial-gradient(circle at center, rgba(0,0,0,0.01) 0%, transparent 70%);
    flex-shrink: 0;
}

#solution-guide {
    background: var(--surface-color);
    padding: 1.5rem;
    border-radius: 1.5rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: var(--shadow-soft);
    width: 250px;
    max-height: 620px;
    overflow-y: auto;
}

#solution-guide h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--accent-color);
}

.guide-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

#path-steps {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.path-step {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 0.5rem;
    font-size: 0.9rem;
}

.step-dir {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent-color);
    width: 24px;
    text-align: center;
}

.step-val { font-weight: 600; }
.step-val.pos { color: var(--positive-color); }
.step-val.neg { color: var(--negative-color); }

.step-coords {
    font-family: monospace;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-left: auto;
}

canvas {
    display: block;
    cursor: default;
    border-radius: 1rem;
}

/* ══════════════════════════════════════════════════════════════
   STATUS OVERLAY
══════════════════════════════════════════════════════════════ */
#status-overlay, #escape-status-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    transition: opacity 0.6s ease;
    border-radius: 1rem;
}

#status-overlay.hidden, #escape-status-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.overlay-content {
    text-align: center;
    padding: 3rem;
}

#status-title, #escape-status-title {
    font-size: 2.5rem;
    font-weight: 200;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    margin-bottom: 1.5rem;
}

#status-message, #escape-status-message {
    color: var(--text-secondary);
    margin-bottom: 3rem;
    font-size: 0.9rem;
    max-width: 320px;
    line-height: 1.8;
}

/* ══════════════════════════════════════════════════════════════
   BUTTONS
══════════════════════════════════════════════════════════════ */
button {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.75rem 2.5rem;
    border-radius: 2px;
    font-family: inherit;
    font-weight: 400;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.2em;
    cursor: pointer;
    transition: var(--transition);
}

button:hover {
    background: var(--text-primary);
    color: var(--bg-color);
    border-color: var(--text-primary);
}

.hint-action {
    border-radius: 20px;
    padding: 0.5rem 1.5rem;
    font-size: 0.65rem;
    border: 1px solid var(--border-color);
    margin-left: 1rem;
}

/* ══════════════════════════════════════════════════════════════
   ESCAPE PUZZLE SCREEN (light theme — same as Math Puzzle)
══════════════════════════════════════════════════════════════ */
#escape-screen {
    background: var(--bg-color);
}

#escape-game-container {
    padding: 2rem;
    max-width: 900px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    align-items: center;
}

#escape-game-container header {
    width: 100%;
}

.escape-title {
    font-size: 1.5rem;
    font-weight: 300;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--text-primary);
    opacity: 0.9;
}

#escape-settings-panel {
    display: flex;
    justify-content: center;
    gap: 3rem;
    margin-bottom: 1.5rem;
    padding: 0.5rem;
}

#escape-canvas-wrapper {
    background: radial-gradient(circle at center, rgba(0,0,0,0.01) 0%, transparent 70%);
}

#escape-status-overlay {
    background: rgba(255, 255, 255, 0.98);
}

#escape-screen footer {
    max-width: 500px;
    text-align: center;
}

#escape-screen footer p {
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

#escape-screen footer p strong {
    color: var(--negative-color);
}

/* ══════════════════════════════════════════════════════════════
   FOOTER
══════════════════════════════════════════════════════════════ */
#math-game-container footer {
    text-align: center;
    max-width: 500px;
}

.controls-hint {
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
}

.key {
    display: inline-block;
    background: #fff;
    padding: 2px 8px;
    border-radius: 4px;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    font-family: monospace;
    font-size: 0.9rem;
    margin: 0 2px;
}

#math-game-container footer p {
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* ══════════════════════════════════════════════════════════════
   ANIMATIONS
══════════════════════════════════════════════════════════════ */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.shake {
    animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes enemy-pulse {
    0%, 100% { opacity: 0.8; }
    50% { opacity: 1; }
}

/* ══════════════════════════════════════════════════════════════
   ESCAPE LEGEND
══════════════════════════════════════════════════════════════ */
.escape-legend {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.35);
}

.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ══════════════════════════════════════════════════════════════
   MOBILE RESPONSIVENESS
══════════════════════════════════════════════════════════════ */

/* Prevent browser default actions like scrolling when swiping on the canvas */
canvas {
    touch-action: none;
}

@media (max-width: 850px) {
    /* Home Screen layout adjustments */
    .home-content {
        padding: 2rem 1rem;
        gap: 2.5rem;
    }
    
    .home-title {
        font-size: 1.8rem;
    }
    
    .game-cards {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .game-card {
        padding: 2rem 1.5rem;
    }

    /* Math and Escape Screen layout adjustments */
    #math-game-container, #escape-game-container {
        padding: 1rem;
    }

    #game-layout, #escape-game-layout {
        flex-direction: column;
        align-items: center;
        gap: 1rem;
    }

    #canvas-wrapper, #escape-canvas-wrapper {
        padding: 0;
        width: 100%;
        display: flex;
        justify-content: center;
    }

    /* Keep canvas aspect ratio but scale it down */
    canvas {
        max-width: 100%;
        height: auto;
    }

    #settings-panel, #escape-settings-panel {
        flex-wrap: wrap;
        gap: 1rem;
        margin-bottom: 1rem;
    }

    .stats-container, .escape-stats-container {
        flex-wrap: wrap;
        gap: 1rem;
    }

    #solution-guide {
        width: 100%;
        max-width: 400px;
        max-height: 250px;
    }
    
    #status-title, #escape-status-title {
        font-size: 1.8rem;
    }
}
