* {
    /* box-sizing: border-box; */
    user-select: none;
    -webkit-user-select: none;
}

:root {
    --bg-color: #0d1117;
    --panel-bg: #161b22;
    --panel-border: #30363d;
    --text-main: #c9d1d9;
    --text-muted: #8b949e;
    --text-highlight: #3fb950;
    --text-danger: #f85149;
    --text-magic: #a371f7;
    --text-gold: #e3b341;
    --text-blue: #58a6ff;
    --text-swamp: #7ee787;
    --text-dark: #b19cd9;
    /* Mithril color */
    --text-legacy: #f08c00;
    /* Soul Shard Color */
    /* New Resource Colors */
    --text-wood: #deb887;
    --text-stone: #9e9e9e;
    --text-iron: #b0c4de;
    --text-coal: #757575;

    /* CRT Variables */
    --crt-scanline: rgba(0, 0, 0, 0.4);
    --crt-glitch: rgba(255, 0, 0, 0.3), rgba(0, 255, 0, 0.1), rgba(0, 0, 255, 0.3);
    --crt-glow: 0 0 5px rgba(200, 255, 200, 0.5), 0 0 2px rgba(255, 255, 255, 0.3);
    --font-mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;
    --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
}

* {
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-color);
}

::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: var(--font-mono);
    margin: 0;
    padding: 0;
    height: 100vh;
    height: 100dvh;
    display: flex;
    overflow: hidden;
    font-size: 14px;
    width: 100%;
}

/* --- TOAST NOTIFICATION --- */
#toast-container {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    pointer-events: none;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.toast {
    background: #21262d;
    color: #fff;
    padding: 12px 24px;
    border-radius: 6px;
    border-left: 4px solid var(--text-highlight);
    font-size: 0.9rem;
    animation: slideUpFade 3s forwards;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    pointer-events: auto;
    max-width: 90%;
    text-align: center;
    backdrop-filter: blur(4px);
}

.toast.error {
    border-left-color: var(--text-danger);
}

@keyframes slideUpFade {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }

    10% {
        opacity: 1;
        transform: translateY(0);
    }

    90% {
        opacity: 1;
        transform: translateY(0);
    }

    100% {
        opacity: 0;
        transform: translateY(-20px);
    }
}

/* --- MODAL SYSTEM --- */
#modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(2px);
    z-index: 3000;
    display: none;
    align-items: center;
    justify-content: center;
}

#modal-content {
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    padding: 25px;
    border-radius: 8px;
    max-width: 90%;
    width: 450px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}

#modal-content h2 {
    margin-top: 0;
    color: var(--text-highlight);
    border-bottom: 1px solid var(--panel-border);
    padding-bottom: 15px;
    font-size: 1.5rem;
}

#modal-content p,
#modal-content ul {
    color: var(--text-main);
    line-height: 1.6;
}

.modal-close {
    margin-top: 20px;
    width: 100%;
    padding: 12px;
    background: #21262d;
    border: 1px solid var(--panel-border);
    color: var(--text-main);
    cursor: pointer;
    border-radius: 6px;
    font-weight: bold;
    transition: all 0.2s;
}

.modal-close:hover {
    background: #30363d;
    border-color: var(--text-highlight);
}

/* --- MENU OVERLAY --- */
#menu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(13, 17, 23, 0.95);
    z-index: 2500;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
    backdrop-filter: blur(5px);
}

#menu-overlay button {
    background: #161b22;
    border: 1px solid var(--panel-border);
    color: var(--text-main);
    padding: 15px 30px;
    width: 200px;
    border-radius: 6px;
    font-family: inherit;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s;
}

#menu-overlay button:hover {
    background: #21262d;
    border-color: var(--text-muted);
    transform: scale(1.02);
}

/* --- Sidebar (Resources) --- */
#sidebar {
    width: 280px;
    background: #0d1117;
    border-right: 1px solid var(--panel-border);
    padding: 20px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex-shrink: 0;
    z-index: 10;
}

#sidebar h1 {
    color: var(--text-main);
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: 1.2rem;
    border-bottom: 2px solid var(--panel-border);
    padding-bottom: 15px;
    margin: 0 0 20px 0;
    text-align: center;
    text-shadow: 0 0 5px rgba(63, 185, 80, 0.3);
}

.resource-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.res-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 8px;
    border-radius: 4px;
    transition: background 0.2s;
}

.res-row:hover {
    background: rgba(255, 255, 255, 0.03);
}

.res-label {
    color: var(--text-muted);
}

.res-val {
    font-weight: bold;
    color: var(--text-main);
}

.res-rate {
    font-size: 0.75em;
    color: #666;
    margin-left: 6px;
}

/* --- SIDEBAR QUEST --- */
#sidebar-quest {
    margin-top: 15px;
    border-top: 1px solid var(--panel-border);
    padding-top: 10px;
    display: none;
}

#sidebar-quest.visible {
    display: block;
}

.sb-quest-title {
    color: var(--text-blue);
    font-size: 0.85rem;
    font-weight: bold;
    margin-bottom: 5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sb-quest-bar-bg {
    width: 100%;
    height: 4px;
    background: #21262d;
    border-radius: 2px;
    overflow: hidden;
}

.sb-quest-bar-fill {
    height: 100%;
    background: var(--text-blue);
    width: 0%;
    transition: width 0.3s;
}

.sb-quest-prog {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: right;
    margin-top: 2px;
}

/* --- POPULATION PANEL (Desktop & Shared) --- */
#population-panel {
    margin-top: 20px;
    border-top: 1px solid var(--panel-border);
    padding-top: 15px;
    display: none;
    flex-direction: column;
    gap: 8px;
}

#population-panel.visible {
    display: flex;
}

.pop-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
    font-size: 0.9rem;
}

.pop-bar-bg {
    width: 100%;
    height: 6px;
    background: #21262d;
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 5px;
}

.pop-bar-fill {
    height: 100%;
    background: var(--text-blue);
    width: 0%;
    transition: width 0.3s ease;
}

.pop-bar-fill.full {
    background: var(--text-danger);
}

.pop-details {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 5px;
    padding-bottom: 5px;
    border-bottom: 1px dashed #30363d;
}

.pop-stat .val {
    color: var(--text-main);
    font-weight: bold;
}

.worker-grid {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Mastery Bars */
.w-mastery-bg {
    width: 100%;
    height: 3px;
    background: #111;
    margin-top: 4px;
    border-radius: 1px;
    grid-column: 1 / -1;
    overflow: hidden;
}
.w-mastery-fill {
    height: 100%;
    width: 0%;
    background: var(--text-magic);
    transition: width 0.3s;
}
.worker-row {
    display: grid;
    grid-template-columns: 1fr auto;
    font-size: 0.8rem;
    padding: 6px 4px;
    border-radius: 4px;
    border-bottom: 1px solid #1a1a1a;
}

.worker-row:hover {
    background: rgba(255, 255, 255, 0.03);
}

.w-name {
    color: var(--text-muted);
}

.w-val {
    color: var(--text-main);
    font-family: var(--font-mono);
}

#sb-q-claim {
    width: 100%;
    margin-top: 8px;
    background: #161b22;
    border: 1px solid var(--text-highlight);
    color: var(--text-highlight);
    border-radius: 4px;
    padding: 6px;
    font-size: 0.75rem;
    cursor: pointer;
    font-weight: bold;
    animation: pulseGlow 2s infinite;
}

#sb-q-claim:hover {
    background: rgba(63, 185, 80, 0.1);
}

@keyframes pulseGlow {
    0% {
        box-shadow: 0 0 0 0 rgba(63, 185, 80, 0.4);
    }

    70% {
        box-shadow: 0 0 0 6px rgba(63, 185, 80, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(63, 185, 80, 0);
    }
}

/* --- Sidebar Controls (Mobile Toggle) --- */
#mobile-header-controls {
    display: none;
    gap: 5px;
    padding-right: 15px;
    border-left: 1px solid var(--panel-border);
    padding-left: 10px;
    background: #161b22;
    z-index: 101;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0 8px;
    transition: color 0.2s;
    line-height: 1;
}

.icon-btn:hover {
    color: var(--text-highlight);
}

/* --- Main Content --- */
#main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    position: relative;
    background: var(--bg-color);
}

/* CRT Effect Overlay for Stage */
#stage-wrapper {
    width: 100%;
    display: flex;
    justify-content: flex-start;
    background: #000;
    border-bottom: 1px solid var(--panel-border);
    /* padding: 10px 0; */
    margin-bottom: 10px;
}

#stage-container {
    position: relative;
    background: #050a0f;
    border: 1px solid #333;
    padding: 0;
    border-radius: 6px;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8);
    display: block;
    overflow: hidden;
    max-height: 410px;
    height: auto;
    width: 100vw;
    transition: all 0.3s;
}

#stage-canvas {
    position: relative;
    left: -1%;
    top: -1%;
    width: 102% !important;
    height: 102% !important;
}

#stage-container.crt-on {
    border-radius: 6px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.02) 0%, rgba(255, 255, 255, 0) 50%), #04080c;
    box-shadow:
        0 20px 50px rgba(0, 0, 0, 0.5),
        0 0 15px rgba(63, 185, 80, 0.1),
        inset 0 0 120px rgba(0, 0, 0, 0.9);
    border-color: transparent;
}

/* Smoother Scanline effect */
#stage-container.crt-on::after {
    content: " ";
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.1) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.03), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.03));
    z-index: 2;
    background-size: 100% 2px, 3px 100%;
    pointer-events: none;
    border-radius: 6px;
}

/* Vignette (Curved & Deep) */
#stage-container.crt-on::before {
    content: " ";
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    /* Reduced vignette, softer falloff */
    background: radial-gradient(circle at center, transparent 70%, rgba(0, 0, 0, 0.15) 85%, rgba(0, 0, 0, 0.6) 100%);
    box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.4);
    z-index: 3;
    pointer-events: none;
    border-radius: 6px;
}

@keyframes turnOn {
    0% {
        transform: scale(0.01, 0.005);
        opacity: 0;
        filter: brightness(0);
    }

    20% {
        transform: scale(1, 0.005);
        opacity: 1;
        filter: brightness(5);
    }

    50% {
        transform: scale(1, 0.005);
        filter: brightness(5);
    }

    80% {
        transform: scale(1, 1.15);
        filter: brightness(2);
    }

    100% {
        transform: scale(1, 1);
        filter: brightness(1);
        opacity: 1;
    }
}

#stage-container.turn-on {
    animation: turnOn 0.6s cubic-bezier(0.23, 1, 0.32, 1) forwards;
}

#stage-canvas {
    display: block;
    /* image-rendering: pixelated; */
    z-index: 1;
}

.crt-on #stage-canvas {
    filter: contrast(1.15) brightness(1.1) saturate(1.1);
}

/* --- Tabs --- */
.tabs {
    display: flex;
    background: #161b22;
    border-bottom: 1px solid var(--panel-border);
    padding: 0 20px;
    gap: 2px;
    flex-shrink: 0;
    overflow-x: auto;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 12px 24px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.95rem;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    white-space: nowrap;
}

.tab-btn:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.02);
}

.tab-btn.active {
    color: var(--text-highlight);
    border-bottom-color: var(--text-highlight);
    font-weight: bold;
}

.tab-btn.legacy-tab {
    color: var(--text-legacy);
}

.tab-btn.legacy-tab.active {
    border-bottom-color: var(--text-legacy);
}

/* Spacer to push buy multiplier to the right */
.tabs-spacer {
    flex: 1;
    min-width: 20px;
}

/* Buy Multiplier Button */
.buy-multiplier-btn {
    background: #21262d;
    border: 1px solid var(--panel-border);
    color: var(--text-main);
    padding: 8px 16px;
    margin: 6px 0;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: bold;
    white-space: nowrap;
    transition: all 0.2s;
    flex-shrink: 0;
}

.buy-multiplier-btn:hover {
    background: #30363d;
    border-color: var(--text-muted);
}

.buy-multiplier-btn.mode-1 {
    color: var(--text-muted);
}

.buy-multiplier-btn.mode-10 {
    color: var(--text-blue);
    border-color: var(--text-blue);
}

.buy-multiplier-btn.mode-max {
    color: var(--text-highlight);
    border-color: var(--text-highlight);
}

/* Scroll Area */
.scroll-area {
    overflow-y: auto;
    flex: 1;
    padding: 20px;
}

/* Controls Area */
.controls-area {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-bottom: 20px;
    gap: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--panel-border);
}

.toggle-group {
    display: flex;
    background: #21262d;
    border-radius: 6px;
    padding: 2px;
    border: 1px solid var(--panel-border);
}

.toggle-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 6px 12px;
    cursor: pointer;
    font-size: 0.85rem;
    font-family: inherit;
    border-radius: 4px;
    transition: all 0.2s;
}

.toggle-btn.active {
    background: var(--panel-border);
    color: var(--text-main);
    font-weight: bold;
}

.toggle-btn:hover:not(.active) {
    color: var(--text-main);
}

/* Actions Grid */
.actions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 15px;
    font-family: inherit;
    min-height: 100px;
    position: relative;
}

.action-btn {
    background: #161b22;
    border: 1px solid #30363d;
    color: var(--text-main);
    border-radius: 6px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
    text-align: left;
    position: relative;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.action-btn:hover:not(:disabled) {
    background: #21262d;
    border-color: var(--text-muted);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

.action-btn:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.action-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: #0d1117;
    border-color: #21262d;
    color: #484f58;
}

.btn-title {
    font-weight: bold;
    font-size: 1.05em;
    color: var(--text-blue);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-cost {
    font-size: 0.85em;
    color: var(--text-muted);
    margin-bottom: 8px;
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
    align-self: flex-start;
}

.btn-desc {
    font-size: 0.8em;
    color: #777;
    margin-top: auto;
    font-style: italic;
    line-height: 1.3;
}

.auto-toggle {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #444;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.5);
}

.auto-toggle.on {
    background: var(--text-highlight);
    box-shadow: 0 0 6px var(--text-highlight);
}

/* Modal textarea for import */
#import-area {
    width: 100%;
    height: 100px;
    background: #0d1117;
    color: #fff;
    border: 1px solid #30363d;
    padding: 10px;
    border-radius: 4px;
    margin-top: 10px;
    font-family: var(--font-mono);
    resize: none;
}

/* Log */
#log-container {
    height: 160px;
    width: 100%;
    box-sizing: border-box;
    border-top: 1px solid var(--panel-border);
    background: #0d1117;
    padding: 15px 20px;
    font-size: 0.9em;
    color: var(--text-muted);
    flex-shrink: 0;
    overflow-y: auto;
}

.log-entry {
    margin-bottom: 6px;
    display: flex;
    gap: 8px;
}

.log-entry::before {
    content: ">";
    color: #444;
}

.log-entry.new {
    color: var(--text-main);
}

.log-entry.loot {
    color: var(--text-gold);
}

.log-entry.danger {
    color: var(--text-danger);
}

.log-entry.magic {
    color: var(--text-magic);
}

.hidden {
    display: none !important;
}

/* SPLIT COMPOSITE BUTTONS */
.action-btn.split-btn {
    flex-direction: row;
    padding: 0;
    overflow: hidden;
    align-items: stretch;
}

/* Equipment Grid UI */
.equip-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 20px;
    background: #111;
    padding: 15px;
    border-radius: 6px;
    border: 1px solid #333;
}

.equip-slot {
    display: flex;
    flex-direction: column;
    background: #161b22;
    border: 1px solid var(--panel-border);
    padding: 10px;
    border-radius: 4px;
    text-align: left;
}

.equip-slot .slot-title {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 4px;
}

.equip-slot .slot-item {
    font-size: 0.95rem;
    color: var(--text-main);
    font-weight: bold;
}

.equip-slot.empty-slot .slot-item {
    color: #666;
    font-style: italic;
    font-weight: normal;
}

.btn-main {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-main);
    padding: 12px;
    text-align: left;
    display: flex;
    flex-direction: column;
    cursor: pointer;
    font-family: inherit;
}

.btn-main:hover {
    background: rgba(255, 255, 255, 0.03);
}

.btn-auto {
    width: 32px;
    background: rgba(0, 0, 0, 0.2);
    border: none;
    border-left: 1px solid var(--panel-border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.btn-auto:hover {
    background: rgba(255, 255, 255, 0.05);
}


/* GAME MENU BUTTONS (DESKTOP) */
#game-menu {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 15px;
    border-top: 1px solid var(--panel-border);
    padding-top: 15px;
}

.menu-btn {
    background: #161b22;
    border: 1px solid var(--panel-border);
    color: var(--text-muted);
    padding: 8px 0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.menu-btn:hover {
    background: #21262d;
    color: var(--text-main);
    border-color: var(--text-muted);
    transform: translateY(-1px);
}

#game-menu-expanded {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 10px;
    border-top: 1px dashed var(--panel-border);
    padding-top: 10px;
}


/* Section Header in Grid */
.grid-header {
    grid-column: 1 / -1;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--panel-border);
    padding-bottom: 8px;
    margin-top: 20px;
    margin-bottom: 10px;
}

/* QUEST STYLES */
.quest-card {
    background: #161b22;
    border: 1px solid var(--panel-border);
    border-left: 4px solid var(--text-blue);
    padding: 20px;
    border-radius: 6px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-card);
}

.quest-title {
    color: var(--text-blue);
    font-weight: bold;
    font-size: 1.2em;
    margin-bottom: 5px;
}

.quest-desc {
    color: var(--text-muted);
    margin-bottom: 15px;
}

.quest-progress-bar {
    width: 100%;
    height: 6px;
    background: #30363d;
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 10px;
}

.quest-progress-fill {
    height: 100%;
    background: var(--text-blue);
    width: 0%;
    transition: width 0.3s ease;
}

/* --- MOBILE LAYOUT --- */
@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    /* Mobile Header Bar */
    #sidebar {
        width: 100%;
        height: auto;
        padding: 0;
        border-right: none;
        border-bottom: 1px solid var(--panel-border);
        flex-direction: column;
        /* Stack Top Bar and Resources vertical */
        background: #161b22;
        position: sticky;
        top: 0;
        z-index: 100;
        overflow: visible;
    }

    #sidebar h1 {
        display: none;
    }

    /* Hide Sidebar panels that take up too much vertical space */
    #population-panel,
    #sidebar-quest,
    #game-menu {
        display: none !important;
    }

    #player-status {
        padding: 6px 10px !important;
        border-top: 1px solid var(--panel-border);
        font-size: 0.8rem;
    }

    #player-status .action-btn {
        min-height: 32px !important;
        padding: 4px 8px !important;
        margin-top: 6px !important;
    }

    /* Horizontal Resource Scroll - Grid Layout */
    .resource-group {
        display: grid;
        grid-template-rows: repeat(2, auto);
        /* Force 2 rows */
        grid-auto-flow: column;
        /* Scroll horizontally */
        overflow-x: auto;
        width: 100%;
        padding: 8px 10px;
        gap: 6px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        /* Firefox */
        background: #0d1117;
        border-bottom: 1px solid var(--panel-border);
    }

    .resource-group::-webkit-scrollbar {
        display: none;
    }

    /* Chrome */
    .res-row {
        background: #161b22;
        padding: 4px 10px;
        border: 1px solid #30363d;
        border-radius: 4px;
        flex-shrink: 0;
        font-size: 0.8rem;
        white-space: nowrap;
        display: flex;
        align-items: center;
        justify-content: space-between;
        min-width: 100px;
        /* Ensure uniform look */
    }

    .res-rate {
        display: none;
    }

    /* Top Bar Controls */
    #mobile-header-controls {
        display: flex;
        width: 100%;
        justify-content: space-between;
        align-items: center;
        padding: 10px 15px;
        background: #161b22;
        border-bottom: 1px solid var(--panel-border);
        position: relative;
        z-index: 2;
        order: -1;
        /* Ensure it stays at top */
    }

    /* Mobile Title */
    .mobile-title {
        font-weight: bold;
        color: var(--text-highlight);
        letter-spacing: 1px;
        font-size: 1.1rem;
        display: block;
        /* Visible on mobile */
    }

    #game-menu {
        display: none;
    }

    /* Mobile Quest Bar */
    #mobile-quest-bar {
        display: block;
        height: 4px;
        flex-shrink: 0;
        background-color: var(--text-blue);
        width: 0%;
        transition: width 0.3s ease;
        z-index: 102;
        box-shadow: 0 0 4px var(--text-blue);
    }

    /* Main Content Adjustments */
    #stage-wrapper {
        padding: 10px;
    }

    #stage-container {
        min-height: 140px;
        padding: 5px;
    }

    /* Adjust Stage Font to fit width */
    #stage {
        font-size: 2.2vw;
        /* Responsive font size */
        line-height: 1.1;
    }

    .tabs {
        padding: 0 10px;
    }

    .tab-btn {
        padding: 10px 15px;
    }

    .btn-title {
        font-size: 0.95rem;
    }

    .btn-desc {
        font-size: 0.75rem;
    }

    #log-container {
        height: 80px;
        font-size: 0.75rem;
    }

    /* Modal Adjustments */
    #modal-content {
        width: 95%;
        padding: 20px;
    }

    /* --- GAME MENU GRID --- */
    #game-menu {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        padding-top: 15px;
        border-top: 1px solid var(--panel-border);
        margin-top: 15px;
        width: 100%;
    }

    #game-menu .resource-group {
        grid-column: 1 / -1;
        margin-bottom: 5px;
    }

    .menu-btn {
        background: #21262d;
        border: 1px solid var(--panel-border);
        color: var(--text-muted);
        padding: 10px 5px;
        border-radius: 6px;
        cursor: pointer;
        transition: all 0.2s;
        font-family: inherit;
        font-size: 0.85rem;
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
    }

    .menu-btn:hover {
        background: #30363d;
        color: var(--text-main);
        border-color: var(--text-muted);
        transform: translateY(-1px);
    }

    .menu-btn.danger {
        color: var(--text-danger);
        border-color: rgba(248, 81, 73, 0.3);
    }

    .menu-btn.danger:hover {
        background: rgba(248, 81, 73, 0.1);
        border-color: var(--text-danger);
    }

    /* --- EXPANDED MENU --- */
    #game-menu-expanded {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        padding-top: 10px;
        border-top: 1px dashed var(--panel-border);
        margin-top: 10px;
        width: 100%;
    }
}

#game-version {
    grid-column: 1 / -1;
    text-align: center;
    color: #444;
    font-size: 0.75rem;
    margin-top: 5px;
}

/* LEADERBOARD STYLES */
.leaderboard-table {
    width: 100%;
    font-family: var(--font-mono);
    border: 1px solid var(--panel-border);
    border-radius: 4px;
    overflow: hidden;
}

.lb-header {
    display: grid;
    grid-template-columns: 40px 1fr 50px 80px;
    gap: 10px;
    background: #222;
    padding: 8px;
    font-weight: bold;
    color: var(--text-muted);
    border-bottom: 1px solid var(--panel-border);
    font-size: 0.9em;
}

.lb-row {
    display: grid;
    grid-template-columns: 40px 1fr 50px 80px;
    gap: 10px;
    padding: 8px;
    border-bottom: 1px solid #222;
    font-size: 0.9em;
    align-items: center;
}

.lb-row:last-child {
    border-bottom: none;
}

.lb-row:nth-child(even) {
    background: rgba(255, 255, 255, 0.03);
}

.lb-rank {
    text-align: center;
    color: #666;
    font-weight: bold;
}

.lb-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lb-lvl {
    text-align: center;
    color: var(--text-highlight);
}

.lb-gold {
    text-align: right;
    color: var(--text-gold);
}

/* Rank Colors */
.rank-1 .lb-rank {
    color: #ffd700;
    text-shadow: 0 0 5px rgba(255, 215, 0, 0.3);
}

/* Gold */
.rank-2 .lb-rank {
    color: #c0c0c0;
}

/* Silver */
.rank-3 .lb-rank {
    color: #cd7f32;
}

/* Bronze */
.rank-1 {
    background: rgba(255, 215, 0, 0.05) !important;
}

/* Note: Mobile responsive styles are handled in the media query above */

/* --- Spell Cooldown Animation --- */
.spell-btn {
    position: relative;
    overflow: hidden;
}

.spell-btn.on-cooldown::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.55);
    animation: cooldownSweep var(--cd-duration, 3s) linear forwards;
    pointer-events: none;
    border-radius: inherit;
}

@keyframes cooldownSweep {
    0% {
        clip-path: inset(0 0 0 0);
    }

    100% {
        clip-path: inset(0 0 0 100%);
    }
}

/* Mini Buttons for Socketing */
.mini-btn {
    width: 24px;
    height: 24px;
    border: 1px solid #444;
    border-radius: 3px;
    background: #111;
    color: #fff;
    font-size: 0.7em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.mini-btn:hover { border-color: #777; transform: scale(1.1); }
.mini-btn.ruby { color: var(--text-danger); border-color: var(--text-danger); }
.mini-btn.sapphire { color: var(--text-blue); border-color: var(--text-blue); }
.mini-btn.emerald { color: var(--text-highlight); border-color: var(--text-highlight); }

.btn-main:not(.split-btn .btn-main) {
    background: #21262d;
    border: 1px solid var(--panel-border);
    color: var(--text-main);
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}
.btn-main:not(.split-btn .btn-main):hover { border-color: var(--text-highlight); background: #30363d; }