:root {
    --bg-dark: #0a0e17;
    --card-bg: rgba(16, 24, 40, 0.85);
    --cyan-glow: #00f0ff;
    --green-glow: #00ff88;
    --magenta-glow: #ff0077;
    --yellow-glow: #ffcc00;
    --purple-glow: #a855f7;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border-color: rgba(0, 240, 255, 0.3);
    --font-heading: 'Orbitron', sans-serif;
    --font-body: 'Rajdhani', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

body, html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-dark);
    font-family: var(--font-body);
    color: var(--text-main);
}

#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at center, #131d33 0%, #060911 100%);
}

#bg-canvas, #game-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#bg-canvas {
    z-index: 1;
    opacity: 0.7;
}

#game-canvas {
    z-index: 2;
    pointer-events: none;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    pointer-events: none;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    pointer-events: auto;
}

.screen.active {
    opacity: 1;
    visibility: visible;
}

.hidden {
    display: none !important;
}

/* TOP HUD BAR */
#top-bar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 70px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: rgba(10, 14, 23, 0.85);
    border-bottom: 2px solid var(--border-color);
    backdrop-filter: blur(8px);
    z-index: 10;
    pointer-events: auto;
    padding: 0 15px;
}

.hud-box {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.hud-label {
    font-family: var(--font-heading);
    font-size: 0.65rem;
    letter-spacing: 1px;
    color: var(--text-muted);
}

.hud-value {
    font-family: var(--font-heading);
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--cyan-glow);
    text-shadow: 0 0 8px rgba(0, 240, 255, 0.5);
}

.hud-lives {
    display: flex;
    gap: 4px;
    font-size: 1.2rem;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--border-color);
    color: #fff;
    font-size: 1.2rem;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: 0.2s;
}

.icon-btn:hover {
    background: rgba(0, 240, 255, 0.2);
}

/* MENU SCREEN */
.logo-container {
    text-align: center;
    margin-bottom: 30px;
}

.atom-icon {
    position: relative;
    width: 80px;
    height: 80px;
    margin: 0 auto 15px;
}

.nucleus {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    background: var(--cyan-glow);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    box-shadow: 0 0 15px var(--cyan-glow);
}

.orbit {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 2px solid rgba(0, 240, 255, 0.4);
    border-radius: 50%;
}

.orbit1 { transform: rotateX(60deg) rotateY(0deg); animation: spin 4s linear infinite; }
.orbit2 { transform: rotateX(60deg) rotateY(60deg); animation: spin 4s linear reverse infinite; }
.orbit3 { transform: rotateX(60deg) rotateY(120deg); animation: spin 3s linear infinite; }

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

.game-title {
    font-family: var(--font-heading);
    font-size: 2.2rem;
    font-weight: 900;
    letter-spacing: 2px;
    line-height: 1.1;
    text-shadow: 0 0 20px rgba(0, 240, 255, 0.4);
}

.game-title .highlight {
    color: var(--cyan-glow);
}

.subtitle {
    font-size: 1.1rem;
    color: var(--text-muted);
    margin-top: 8px;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    max-width: 360px;
}

.btn {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 14px 20px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-main);
    cursor: pointer;
    font-family: var(--font-body);
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

.btn-icon {
    font-size: 1.8rem;
}

.btn-text {
    display: flex;
    flex-direction: column;
    text-align: left;
}

.btn-text strong {
    font-family: var(--font-heading);
    font-size: 1rem;
    color: #fff;
}

.btn-text small {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.primary-btn { border-color: var(--cyan-glow); }
.primary-btn:hover { background: rgba(0, 240, 255, 0.2); transform: translateY(-2px); box-shadow: 0 0 20px rgba(0,240,255,0.4); }

.secondary-btn { border-color: var(--green-glow); }
.secondary-btn:hover { background: rgba(0, 255, 136, 0.2); transform: translateY(-2px); box-shadow: 0 0 20px rgba(0,255,136,0.4); }

.tertiary-btn { border-color: var(--purple-glow); }
.tertiary-btn:hover { background: rgba(168, 85, 247, 0.2); transform: translateY(-2px); box-shadow: 0 0 20px rgba(168,85,247,0.4); }

.small-btn {
    padding: 8px 16px;
    font-size: 0.9rem;
    border-radius: 8px;
}

.credits {
    position: absolute;
    bottom: 15px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* CARDS & QUESTIONS */
.question-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    width: 90%;
    max-width: 600px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
    backdrop-filter: blur(12px);
    margin-top: 60px;
    z-index: 5;
}

.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    background: rgba(0, 240, 255, 0.15);
    color: var(--cyan-glow);
    font-family: var(--font-heading);
    font-size: 0.75rem;
    letter-spacing: 1px;
    margin-bottom: 10px;
    border: 1px solid rgba(0, 240, 255, 0.3);
}

.question-card h2 {
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.3;
}

/* LAB GAME OPTIONS GRID */
.options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    width: 90%;
    max-width: 600px;
    margin-top: auto;
    margin-bottom: 25px;
    z-index: 5;
}

@media (max-width: 500px) {
    .options-grid {
        grid-template-columns: 1fr;
    }
}

.option-btn {
    background: var(--card-bg);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 14px;
    color: #fff;
    font-family: var(--font-body);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
}

.option-btn:hover {
    border-color: var(--cyan-glow);
    background: rgba(0, 240, 255, 0.15);
    transform: translateY(-2px);
}

.option-btn.correct {
    background: rgba(0, 255, 136, 0.3) !important;
    border-color: var(--green-glow) !important;
    box-shadow: 0 0 15px rgba(0, 255, 136, 0.5);
}

.option-btn.wrong {
    background: rgba(255, 0, 119, 0.3) !important;
    border-color: var(--magenta-glow) !important;
    box-shadow: 0 0 15px rgba(255, 0, 119, 0.5);
}

/* BUBBLES AREA (QUIZ ARCADE) */
#bubbles-area {
    position: absolute;
    top: 150px;
    bottom: 20px;
    left: 0;
    right: 0;
    pointer-events: auto;
    z-index: 6;
}

.quiz-bubble {
    position: absolute;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 30% 30%, rgba(0, 240, 255, 0.8), rgba(0, 100, 200, 0.9));
    border: 2px solid var(--cyan-glow);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 0 20px rgba(0, 240, 255, 0.4);
    transition: transform 0.1s linear;
    animation: pulse 2s infinite alternate;
}

@keyframes pulse {
    0% { transform: scale(0.98); }
    100% { transform: scale(1.03); }
}

.quiz-bubble .symbol {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 900;
}

.quiz-bubble .name {
    font-size: 0.75rem;
    opacity: 0.9;
}

/* EXPLORE SCREEN & PERIODIC TABLE */
.explore-header {
    width: 100%;
    max-width: 900px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    margin-top: 10px;
}

.explore-header h2 {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    color: var(--cyan-glow);
}

.tab-buttons {
    display: flex;
    gap: 8px;
}

.tab-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 6px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-family: var(--font-body);
    font-size: 0.9rem;
    transition: 0.2s;
}

.tab-btn.active {
    background: var(--cyan-glow);
    color: #000;
    font-weight: bold;
    border-color: var(--cyan-glow);
}

.explore-view {
    width: 100%;
    max-width: 900px;
    height: calc(100vh - 120px);
    overflow-y: auto;
    padding-right: 5px;
}

/* Periodic table layout grid */
.ptable-container {
    display: grid;
    grid-template-columns: repeat(18, 1fr);
    gap: 4px;
    width: 100%;
    min-width: 750px;
    overflow-x: auto;
    padding: 10px;
    background: var(--card-bg);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.element-tile {
    aspect-ratio: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    padding: 2px;
}

.element-tile:hover {
    transform: scale(1.15);
    z-index: 10;
    border-color: var(--cyan-glow);
    box-shadow: 0 0 12px var(--cyan-glow);
}

.element-tile .z-num {
    position: absolute;
    top: 2px;
    left: 3px;
    font-size: 0.55rem;
    color: var(--text-muted);
}

.element-tile .elem-sym {
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 700;
}

.element-tile .elem-name {
    font-size: 0.5rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* Category colors for periodic table */
.cat-nonmetal { border-color: #00ff88; background: rgba(0, 255, 136, 0.1); }
.cat-noble { border-color: #a855f7; background: rgba(168, 85, 247, 0.1); }
.cat-alkali { border-color: #ff9900; background: rgba(255, 153, 0, 0.1); }
.cat-alkaline { border-color: #ffcc00; background: rgba(255, 204, 0, 0.1); }
.cat-metalloid { border-color: #00f0ff; background: rgba(0, 240, 255, 0.1); }
.cat-halogen { border-color: #ff0077; background: rgba(255, 0, 119, 0.1); }
.cat-transition { border-color: #3b82f6; background: rgba(59, 130, 246, 0.1); }
.cat-post-transition { border-color: #10b981; background: rgba(16, 185, 129, 0.1); }

/* Utensils List Layout */
.utensils-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 15px;
}

.utensil-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.utensil-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 0 20px rgba(0, 240, 255, 0.3);
}

.utensil-card canvas {
    width: 100px;
    height: 100px;
    margin-bottom: 10px;
}

.utensil-card h3 {
    font-family: var(--font-heading);
    font-size: 1rem;
    color: var(--cyan-glow);
    margin-bottom: 5px;
}

.utensil-card p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* MODAL */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: #0f172a;
    border: 2px solid var(--cyan-glow);
    border-radius: 16px;
    padding: 25px;
    width: 90%;
    max-width: 450px;
    position: relative;
    box-shadow: 0 0 30px rgba(0, 240, 255, 0.3);
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.8rem;
    cursor: pointer;
}

/* RESULTS CARD */
.results-card {
    background: var(--card-bg);
    border: 2px solid var(--cyan-glow);
    border-radius: 20px;
    padding: 30px;
    width: 90%;
    max-width: 480px;
    text-align: center;
    box-shadow: 0 0 40px rgba(0, 240, 255, 0.25);
    backdrop-filter: blur(15px);
}

.results-card h2 {
    font-family: var(--font-heading);
    color: var(--yellow-glow);
    font-size: 1.8rem;
    margin-bottom: 15px;
}

.score-display {
    margin: 15px 0;
}

.score-display .label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    letter-spacing: 1px;
}

.big-number {
    font-family: var(--font-heading);
    font-size: 3.5rem;
    font-weight: 900;
    color: var(--cyan-glow);
    text-shadow: 0 0 20px var(--cyan-glow);
}

.stats-row {
    display: flex;
    justify-content: space-around;
    margin: 20px 0;
    padding: 12px;
    background: rgba(255,255,255,0.05);
    border-radius: 10px;
}

.stat-item {
    display: flex;
    flex-direction: column;
}

.stat-val {
    font-family: var(--font-heading);
    font-size: 1.3rem;
    color: #fff;
}

.stat-lbl {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.feedback-msg {
    font-size: 1rem;
    color: var(--text-main);
    margin-bottom: 25px;
}

.action-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.action-buttons .btn {
    padding: 12px 20px;
}