:root {
    /* DARK THEME */
    --bg-main: #121212;
    --box-bg: rgba(30, 30, 30, 0.75);
    --box-hover: rgba(50, 50, 50, 0.95);
    --text-primary: #fff;
    --text-secondary: #bdbdbd;
    --gold: #ffd700;
    --border: rgba(255, 255, 255, 0.1);
    --btn-primary: #4caf50;
    --btn-secondary: #2196f3;
    --btn-danger: #f44336;

    --dirt-top: #3e2723;
    --dirt-deep: #1b100b;
    --sky-top: #1a237e;
    --sky-bottom: #4a148c;
    --grass: #1b5e20;

    --stone-bg: #424242;
    --stone-border: #212121;
    --stone-text: #fff;
    --stone-shadow: #111;

    --xp-bg: #424242;
    --xp-fill: #00e676;
}

[data-theme="light"] {
    --bg-main: #f0f2f5;
    --box-bg: rgba(255, 255, 255, 0.85);
    --box-hover: #ffffff;
    --text-primary: #212121;
    --text-secondary: #5f6368;
    --gold: #f57f17;
    --border: rgba(0, 0, 0, 0.08);
    --btn-primary: #43a047;
    --btn-secondary: #1e88e5;
    --btn-danger: #e53935;

    --dirt-top: #8b5a2b;
    --dirt-deep: #5c3a21;
    --sky-top: #4fc3f7;
    --sky-bottom: #87CEEB;
    --grass: #8bc34a;

    --stone-bg: #e0e0e0;
    --stone-border: #9e9e9e;
    --stone-text: #212121;
    --stone-shadow: #757575;

    --xp-bg: #e0e0e0;
    --xp-fill: #43a047;
}

body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Nunito', 'Glegoo', sans-serif;
    color: var(--text-primary);
    background-color: var(--bg-main);
    transition: background-color 0.3s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

h1,
h2,
h3 {
    margin: 0;
    font-family: 'Glegoo', serif;
}

button {
    font-family: 'Nunito', sans-serif;
    cursor: pointer;
}

#fx-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
}

#game-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    z-index: 10;
}

/* ================= XP TOP BAR ================= */
#xp-bar-container {
    background: #111;
    /* Keep it dark always for premium look */
    color: white;
    padding: 8px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #333;
    z-index: 200;
}

.xp-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 200px;
}

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

.rank-info {
    display: flex;
    flex-direction: column;
}

#rank-title {
    font-weight: bold;
    color: var(--gold);
    font-family: 'Glegoo';
}

#rank-level {
    font-size: 0.8rem;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.xp-progress-wrapper {
    flex: 1;
    max-width: 400px;
    background: var(--xp-bg);
    height: 16px;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    margin: 0 20px;
    border: 1px solid #555;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}

#xp-progress-fill {
    width: 0%;
    height: 100%;
    background: var(--xp-fill);
    transition: width 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.xp-text {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    text-align: center;
    font-size: 0.75rem;
    font-weight: bold;
    line-height: 16px;
    color: white;
    text-shadow: 1px 1px 0 #000;
}

.header-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

.icon-btn {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    transition: transform 0.2s, background 0.2s;
    color: white;
    border-radius: 50%;
    padding: 6px;
    width: 44px;
    height: 44px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.icon-btn:active {
    transform: scale(0.9);
}

#reset-xp-btn {
    color: #ff5252;
}

html[data-theme="light"] #theme-toggle,
html[data-theme="light"] #sound-toggle {
    color: #fff;
}

/* Tooltips */
.tooltip-host {
    position: relative;
}

.tooltip-host .tooltip {
    visibility: hidden;
    width: max-content;
    background-color: #333;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 5px 10px;
    position: absolute;
    z-index: 1000;
    bottom: -35px;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity 0.3s;
    font-size: 0.8rem;
    pointer-events: none;
}

.tooltip-host:hover .tooltip {
    visibility: visible;
    opacity: 1;
}

/* ================= HEADER ================= */
#game-header {
    background: var(--box-bg);
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--border);
    backdrop-filter: blur(10px);
    z-index: 100;
}

.logo {
    font-size: 1.4rem;
    color: var(--gold);
    text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.2);
}

.sm-btn {
    padding: 6px 15px;
    font-size: 1.1rem;
    border-radius: 20px;
    box-shadow: 0 2px 0px rgba(0, 0, 0, 0.2);
    width: auto;
}

.screen {
    display: none;
    flex: 1;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
}

.screen.active {
    display: flex;
}

.hidden {
    display: none !important;
}

/* ================= HUB SCREEN (POLISHED) ================= */
#hub-screen {
    background: radial-gradient(circle at center, rgba(255, 215, 0, 0.05) 0%, transparent 60%);
}

.hub-container {
    padding: 20px;
    max-width: 1100px;
    margin: 0 auto;
    text-align: center;
}

.hub-header {
    margin: 10px 0 30px 0;
}

.hub-header h2 {
    font-size: 2.8rem;
    margin-bottom: 5px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

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

.hub-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 20px;
    padding-bottom: 40px;
}

.hub-card {
    background: var(--box-bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 25px 20px;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s, box-shadow 0.2s, border-color 0.2s;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    backdrop-filter: blur(12px);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.premium-card {
    border-color: rgba(255, 215, 0, 0.5);
    background: linear-gradient(135deg, var(--box-bg), rgba(255, 215, 0, 0.08));
    box-shadow: 0 4px 20px rgba(255, 215, 0, 0.1);
}

.hub-card:hover {
    transform: translateY(-7px);
    background: var(--box-hover);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.15);
    border-color: var(--gold);
}

.hub-card:active {
    transform: scale(0.98);
}

.hub-icon {
    font-size: 4rem;
    margin-bottom: 15px;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.2));
}

.hub-card h3 {
    font-size: 1.5rem;
    color: var(--gold);
    margin-bottom: 10px;
}

.hub-card p {
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

/* ================= PLAY SCREEN ================= */
.play-subheader {
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 50;
}

.stat-group {
    display: flex;
    align-items: center;
    gap: 15px;
}

.hearts {
    font-size: 1.3rem;
    display: flex;
    gap: 3px;
}

.heart-lost {
    opacity: 0.3;
    filter: grayscale(1);
}

.level-badge {
    background: #795548;
    padding: 5px 12px;
    border-radius: 8px;
    font-weight: bold;
    border: 2px solid #5d4037;
}

.timer-badge {
    background: #d32f2f;
    padding: 5px 15px;
    border-radius: 8px;
    font-weight: bold;
    font-size: 1.5rem;
    border: 2px solid #b71c1c;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.8;
    }

    100% {
        opacity: 1;
    }
}

.score-board {
    background: #ffee58;
    color: #4e342e;
    padding: 5px 15px;
    border-radius: 30px;
    font-weight: bold;
    font-size: 1.2rem;
    position: relative;
    border: 3px solid #fbc02d;
    box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.2);
}

#streak-counter {
    position: absolute;
    top: -18px;
    right: -5px;
    color: #ff5722;
    font-size: 1rem;
    text-shadow: 1px 1px 0 #fff;
}

.sky-bg {
    height: 8vh;
    background: linear-gradient(to bottom, var(--sky-top), var(--sky-bottom));
    border-bottom: 6px solid var(--grass);
    position: relative;
}

.progress-bar-container {
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 60%;
    height: 12px;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 6px;
    border: 2px solid white;
    z-index: 100;
    overflow: hidden;
}

#level-progress {
    height: 100%;
    width: 0%;
    background: #69f0ae;
    transition: width 0.3s ease;
}

.dirt-bg {
    flex: 1;
    background: linear-gradient(to bottom, var(--dirt-top), var(--dirt-deep));
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 10px;
    position: relative;
}

.question-box {
    background: rgba(255, 255, 255, 0.1);
    border: 2px dashed rgba(255, 255, 255, 0.4);
    border-radius: 15px;
    padding: 15px 20px;
    text-align: center;
    margin-bottom: 25px;
    width: 90%;
    max-width: 700px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(5px);
}

.question-box.shake {
    animation: shake 0.4s;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25%,
    75% {
        transform: translateX(10px);
    }

    50% {
        transform: translateX(-10px);
    }
}

.glow-text {
    color: white;
    font-size: 1.8rem;
    line-height: 1.4;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.3), 0 2px 0px rgba(0, 0, 0, 0.8);
}

.highlight-name {
    color: #ffd54f;
    font-weight: 800;
    font-size: 2rem;
    display: block;
    margin-bottom: 5px;
}

/* Fossils Grid */
.fossil-grid {
    display: flex;
    gap: 15px;
    justify-content: center;
    flex-wrap: wrap;
    width: 100%;
    max-width: 900px;
}

.fossil-card {
    background: var(--stone-bg);
    width: 100%;
    max-width: 400px;
    min-height: 80px;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 15px 10px;
    cursor: pointer;
    border: 3px solid var(--stone-border);
    position: relative;
    overflow: hidden;
    box-shadow: 0 6px 0 var(--stone-shadow), 0 8px 15px rgba(0, 0, 0, 0.5);
    transition: transform 0.1s, box-shadow 0.1s;
}

.fossil-card:active {
    transform: translateY(6px);
    box-shadow: 0 0px 0 var(--stone-shadow);
}

.fossil-name {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--stone-text);
    line-height: 1.2;
    text-shadow: -1px -1px 0 #555, 1px -1px 0 #555, -1px 1px 0 #555, 1px 1px 0 #555;
    z-index: 2;
    word-wrap: break-word;
    word-break: break-word;
}

.fossil-card.correct {
    background: var(--gold);
    border-color: #fbc02d;
    box-shadow: 0 6px 0 #f57f17;
}

.fossil-card.wrong {
    background: #616161;
    opacity: 0.5;
    box-shadow: none;
    transform: translateY(6px);
    cursor: not-allowed;
}

.fossil-card.wrong .fossil-name {
    text-shadow: none;
    color: #ccc;
}

.feedback {
    position: absolute;
    top: 150px;
    font-size: 2.2rem;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 4px 10px rgba(0, 0, 0, 0.8);
    animation: floatUp 1.5s ease-out forwards;
    pointer-events: none;
    z-index: 50;
}

.feedback.success {
    color: #69f0ae;
}

.feedback.error {
    color: #ff5252;
}

@keyframes floatUp {
    0% {
        transform: translateY(20px) scale(0.8);
        opacity: 0;
    }

    20% {
        transform: translateY(0) scale(1.1);
        opacity: 1;
    }

    80% {
        transform: translateY(-30px) scale(1);
        opacity: 1;
    }

    100% {
        transform: translateY(-50px) scale(0.9);
        opacity: 0;
    }
}

.xp-floater {
    position: absolute;
    font-size: 1.8rem;
    font-family: 'Glegoo';
    font-weight: 900;
    color: #69f0ae;
    text-shadow: 0 2px 5px #000;
    z-index: 51;
    pointer-events: none;
}

@keyframes floatUpXP {
    0% {
        transform: translateY(0) scale(0.5);
        opacity: 1;
    }

    100% {
        transform: translateY(-40px) scale(1.5);
        opacity: 0;
    }
}

/* ================= OVERLAYS ================= */
.transient-screen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 500;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
    text-align: center;
}

.bounce-text {
    font-size: 3.5rem;
    color: var(--gold);
    animation: pop 0.5s infinite alternate;
    text-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
}

.rank-sparkles {
    font-size: 5rem;
    animation: spin 4s linear infinite;
}

.overlay-screen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 600;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.modal {
    background: var(--box-bg);
    padding: 40px;
    border-radius: 20px;
    border: 2px solid var(--border);
    text-align: center;
    color: var(--text-primary);
    max-width: 400px;
    width: 90%;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(20px);
}

.modal h2 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    color: var(--wrong);
}

.final-score-box {
    margin: 25px 0;
    padding: 20px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 15px;
    border: 1px solid var(--border);
}

.final-score-box span {
    font-size: 1.2rem;
    color: var(--text-secondary);
}

.final-score-box h3 {
    font-size: 3.5rem;
    color: var(--gold);
    margin-top: 5px;
    text-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.xp-gain {
    font-weight: bold;
    color: #69f0ae;
    margin-top: 10px;
    font-size: 1.2rem;
    background: rgba(0, 230, 118, 0.1);
    padding: 5px;
    border-radius: 8px;
}

.primary-btn,
.secondary-btn,
.danger-btn {
    width: 100%;
    color: white;
    font-size: 1.5rem;
    font-weight: bold;
    padding: 12px;
    border: none;
    border-radius: 30px;
    margin-bottom: 15px;
    box-shadow: 0 4px 0px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.1s;
}

.primary-btn {
    background: var(--btn-primary);
}

.secondary-btn {
    background: var(--btn-secondary);
}

.danger-btn {
    background: var(--btn-danger);
}

.primary-btn:active,
.secondary-btn:active,
.danger-btn:active {
    transform: translateY(4px);
    box-shadow: none;
}

/* ================= STUDY GRID (NEW) ================= */
#study-screen {
    position: relative;
    overflow-y: auto;
}

.study-overlay {
    position: sticky;
    top: 0;
    z-index: 90;
    display: flex;
    gap: 15px;
    padding: 15px 20px;
    background: var(--bg-main);
    border-bottom: 1px solid var(--border);
    align-items: center;
    justify-content: space-between;
}

#search-box {
    flex: 1;
    padding: 12px 20px;
    border-radius: 25px;
    border: 2px solid var(--border);
    background: var(--box-bg);
    color: var(--text-primary);
    font-size: 1.1rem;
    outline: none;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
    transition: border-color 0.3s;
    max-width: 600px;
}

#search-box:focus {
    border-color: var(--gold);
}

#study-count-badge {
    background: var(--btn-secondary);
    color: white;
    padding: 5px 15px;
    border-radius: 20px;
    font-weight: bold;
}

#study-grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    padding: 20px;
    padding-bottom: 100px;
    /* Space for drawer */
}

.grid-node-card {
    background: var(--box-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 15px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 100px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.grid-node-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.1);
    border-color: var(--gold);
}

.gnc-name {
    font-size: 1.15rem;
    font-weight: bold;
    color: var(--text-primary);
    word-break: break-word;
    line-height: 1.2;
}

.gnc-gen {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 8px;
}

/* Profile Drawer Bottom Sheet (EXPANDED) */
.drawer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--box-bg);
    backdrop-filter: blur(25px);
    border-top: 3px solid var(--gold);
    border-radius: 30px 30px 0 0;
    padding: 25px 30px 40px 30px;
    box-sizing: border-box;
    transform: translateY(110%);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 500;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
    max-height: 80vh;
    overflow-y: auto;
}

.drawer.open {
    transform: translateY(0);
}

.drawer-header {
    margin-bottom: 25px;
    padding-right: 40px;
}

#close-drawer {
    position: absolute;
    top: 25px;
    right: 25px;
    color: var(--text-primary);
    font-size: 1.5rem;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    padding: 8px 12px;
}

#close-drawer:hover {
    background: rgba(255, 50, 50, 0.5);
}

.prof-stat {
    color: var(--text-secondary);
    font-weight: bold;
    font-size: 1.1rem;
}

.prof-relations {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

.full-width-rel {
    grid-column: span 2;
}

.rel-box {
    background: rgba(0, 0, 0, 0.2);
    padding: 15px;
    border-radius: 12px;
    text-align: center;
    border: 1px solid var(--border);
}

.rel-title {
    display: block;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.rel-val {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--gold);
    word-break: break-word;
}

/* Spinners */
.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--gold);
    border-radius: 50%;
    animation: spin 1s infinite linear;
    margin-top: 20px;
}

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

/* Mobile Tweaks */
@media (max-width: 600px) {
    #xp-bar-container {
        flex-direction: column;
        padding: 12px;
        gap: 12px;
    }

    .xp-progress-wrapper {
        width: 100%;
        margin: 0;
    }

    .header-controls {
        display: flex;
        gap: 15px;
        justify-content: center;
        width: 100%;
        margin-top: 5px;
    }

    .hub-header h2 {
        font-size: 2.2rem;
    }

    .hub-card {
        padding: 20px 15px;
    }

    .fossil-card {
        padding: 10px;
        min-height: 70px;
    }

    .fossil-name {
        font-size: 1.1rem;
    }

    .highlight-name {
        font-size: 1.5rem;
    }

    .glow-text {
        font-size: 1.3rem;
    }

    .drawer {
        padding: 20px 15px;
    }

    .prof-relations {
        grid-template-columns: 1fr;
    }

    .full-width-rel {
        grid-column: auto;
    }

    #study-grid-container {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 10px;
        padding: 15px;
    }

    .grid-node-card {
        min-height: 80px;
        padding: 10px;
    }

    .gnc-name {
        font-size: 1rem;
    }
}