:root {
    --bg-color: #e8f5e9;
    --accent-color: #2e7d32;
    --secondary-color: #d84315;
    /* Burnt Orange for refining */
    --glass-bg: rgba(255, 255, 255, 0.9);
    --glass-border: rgba(255, 255, 255, 0.6);
    --text-color: #1b5e20;
    --slot-bg: rgba(0, 0, 0, 0.03);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
}

body {
    font-family: 'Zen Maru Gothic', sans-serif;
    background-color: var(--bg-color);
    /* Background image removed for Ancient/Default era as requested */
    background-image: none;
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
}

body::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Use variable for dynamic themes, fallback to original */
    /* Drastically reduced opacity to make background pop like the user image */
    background: var(--bg-overlay, rgba(232, 245, 233, 0.2));
    z-index: -1;
    transition: background 0.5s ease;
    /* Smooth transition for overlay color */
}

/* --- Start Screen --- */
.start-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease;
}

.start-content {
    background: rgba(255, 255, 255, 0.95);
    padding: 60px 40px;
    border-radius: 25px;
    text-align: center;
    max-width: 450px;
    width: 90%;
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.2);
    animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes slideUp {
    0% {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }

    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes fadeInScale {
    0% {
        opacity: 0;
        transform: scale(1.1);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.start-title {
    font-size: 2.8rem;
    font-weight: bold;
    color: var(--accent-color, #2e7d32);
    margin: 0;
    line-height: 1.2;
}

.start-subtitle {
    font-size: 1.1rem;
    color: #888;
    margin: 5px 0 25px 0;
    letter-spacing: 1px;
}

.start-btn {
    padding: 15px 40px;
    font-size: 1.3rem;
    font-weight: bold;
    color: white;
    background: linear-gradient(135deg, var(--accent-color, #2e7d32), var(--secondary-color, #ef6c00));
    border: none;
    border-radius: 40px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    outline: none;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.start-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.start-btn:active {
    transform: translateY(1px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
}

.app-container {
    display: grid;
    grid-template-columns: 240px 1fr;
    grid-template-rows: 1fr 220px;
    height: 100vh;
    padding: 20px;
    gap: 20px;
}

.glass-panel {
    background: white;
    border: 1px solid #ddd;
    border-radius: 20px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
    padding: 20px;
    display: flex;
    flex-direction: column;
}

/* Nav & Sidebar */
.sidebar h1 {
    white-space: normal;
    font-size: 1.6rem;
    line-height: 1.2;
}

.sidebar {
    grid-column: 1;
    grid-row: 1 / 3;
    gap: 20px;
}

.main-nav {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

.nav-btn {
    background: rgba(255, 255, 255, 0.5);
    border: none;
    padding: 12px;
    border-radius: 12px;
    text-align: left;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: bold;
    color: #555;
}

.nav-btn.active {
    background: var(--accent-color);
    color: white;
    box-shadow: 0 4px 10px rgba(46, 125, 50, 0.3);
}

.nav-btn:hover:not(.active) {
    background: rgba(255, 255, 255, 0.8);
    transform: translateX(5px);
}

/* Specific styles for small footer nav buttons */
.stats .nav-btn:hover:not(.active) {
    transform: translateY(-2px);
}

.stats .nav-btn {
    text-align: center;
    border: 1px dashed rgba(0,0,0,0.1) !important;
    background: rgba(255,255,255,0.3);
    color: #666;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
}

.lite-mode-container {
    padding: 10px;
    /* background: rgba(255,255,255,0.3); */
    /* border-radius: 10px; */
    margin-top: auto;
    text-align: center;
}

.lite-mode-btn {
    border: 1px solid #aaa;
    background: rgba(255, 255, 255, 0.5);
    padding: 4px 8px;
    border-radius: 15px;
    cursor: pointer;
    font-size: 0.8rem;
    color: #555;
}

.message-log {
    flex-grow: 1;
    overflow-y: auto;
    font-size: 0.85rem;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 10px;
    padding: 10px;
}

.message-log p {
    margin-bottom: 6px;
    padding-bottom: 6px;
    border-bottom: 1px dashed #ccc;
}

/* Main Content Area */
main {
    grid-column: 2;
    grid-row: 1;
    overflow: hidden;
    /* Internal scroll */
    position: relative;
    /* For absolute positioning inside if needed */
}

/* Workspace Views */
.workspace {
    grid-column: 2;
    grid-row: 1;
    position: relative;
    overflow-y: auto;
}

/* 
   View Switching Logic 
   Instead of one big column, we have multiple 'view-panel' divs.
   Only one is visible at a time.
*/
.view-panel {
    height: 100%;
    width: 100%;
    overflow-y: auto;
    /* Scrollable content */
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s ease;
}

.view-panel[style*="none"] {
    display: none !important;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes popIn {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* Field View */
.field-container {
    height: 100%;
    overflow-y: auto;
    /* Allow scroll when content overflows */
    display: flex;
    flex-direction: column;
    padding: 10px;
}

.field-header {
    text-align: center;
    margin-bottom: 5px;
    width: 100%;
    flex-shrink: 0;
    /* Don't shrink header */
}

.nature-scene {
    display: grid;
    /* Fixed 2 columns as requested */
    grid-template-columns: repeat(2, 1fr);
    grid-auto-rows: minmax(60px, auto);
    gap: 12px;
    width: 100%;
    max-width: 750px;
    margin: 0 auto;
    padding-bottom: 30px;
}

.gather-spot {
    border-radius: 15px;
    /* Slightly smaller radius for tight spaces */
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    font-weight: 800;
    /* Bolder */
    cursor: pointer;
    transition: transform 0.1s;
    color: white;
    text-shadow: 0 2px 5px rgba(0, 0, 0, 0.6);
    /* Stronger shadow */
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
}

.gather-spot:active {
    transform: scale(0.95);
}

.water-spot {
    background: linear-gradient(135deg, #4fc3f7, #0288d1);
}

.forest-spot {
    background: linear-gradient(135deg, #66bb6a, #2e7d32);
}

.earth-spot {
    background: linear-gradient(135deg, #a1887f, #5d4037);
}

.tree-spot {
    background: linear-gradient(135deg, #aed581, #558b2f);
}

.sun-spot {
    background: linear-gradient(135deg, #ffb74d, #f57c00);
}

.cave-spot {
    background: linear-gradient(135deg, #78909c, #37474f);
}

.onsen-spot {
    background: linear-gradient(135deg, #81d4fa, #ffffff);
    color: #01579b;
    /* Darker blue */
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.8);
    /* Glow behind to separate form gradient */
}

.river-spot {
    background: linear-gradient(135deg, #26c6da, #006064);
    /* Slightly darker gradient for contrast */
}

.home-spot {
    background: linear-gradient(135deg, #a1887f, #4e342e);
}

.oil-spot {
    background: linear-gradient(135deg, #3e2723, #000000);
    color: #ffd700;
}


/* Lab View (Crafting) */
.machine-section {
    padding: 20px;
    align-items: center;
}

.machine-title {
    text-align: center;
    font-size: 1.2rem;
    margin-bottom: 20px;
    opacity: 0.7;
    width: 100%;
}

.slots-container {
    display: flex;
    align-items: flex-start;
    gap: 15px;
    margin-bottom: 20px;
}

.operator {
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: #999;
    font-weight: bold;
}

.element-slot {
    width: 100px;
    height: 100px;
    background: var(--slot-bg);
    border: 3px dashed rgba(0, 0, 0, 0.2);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.element-slot.filled {
    background: white;
    border-style: solid;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.element-slot.result.filled {
    background: #fffde7;
    border-color: #fdd835;
}

.control-area {
    display: flex;
    gap: 10px;
}

.action-btn {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 10px 30px;
    border-radius: 25px;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(46, 125, 50, 0.3);
    transition: transform 0.1s;
    font-weight: bold;
}

.action-btn.secondary {
    background: var(--secondary-color);
    box-shadow: 0 4px 10px rgba(216, 67, 21, 0.3);
}

/* Shop tabs - Buy/Sell buttons */
.action-btn.small {
    padding: 8px 20px;
    font-size: 0.95rem;
    box-shadow: none;
    border: 2px solid transparent;
    font-weight: bold;
    transition: all 0.2s;
}

/* Buy Tab (Always Green-ish) */
#tab-buy {
    color: #2e7d32;
    border-color: #2e7d32;
    background: rgba(255, 255, 255, 0.5);
}

#tab-buy.active {
    background: #2e7d32;
    color: white;
    box-shadow: 0 4px 10px rgba(46, 125, 50, 0.4);
}

/* Sell Tab (Always Red-ish) */
#tab-sell {
    color: #e53935;
    border-color: #e53935;
    background: rgba(255, 255, 255, 0.5);
}

#tab-sell.active {
    background: #e53935;
    color: white;
    box-shadow: 0 4px 10px rgba(229, 57, 53, 0.4);
}

.action-btn.small:hover {
    transform: translateY(-2px);
}

.action-btn:active {
    transform: scale(0.95);
}

.text-btn {
    background: none;
    border: none;
    text-decoration: underline;
    color: #777;
    cursor: pointer;
}

/* Refinery */
.refinery-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    width: 100%;
}

.refinery-info {
    font-size: 0.9rem;
    color: #666;
}

/* Inventory */
.inventory {
    grid-column: 2;
    grid-row: 2;
}

.element-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    overflow-y: auto;
    padding: 5px;
    align-content: flex-start;
}

.element-card {
    width: 90px;
    height: 100px;
    background: white;
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.05);
    border: 2px solid transparent;
    transition: transform 0.2s, box-shadow 0.2s;
}

.element-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 10px rgba(0, 0, 0, 0.1);
}

/* Drag and Drop Styles */
.element-card.dragging {
    opacity: 0.5;
    transform: scale(0.95);
    border: 2px dashed #4caf50;
    box-shadow: none;
}

.element-card.drag-over {
    border: 2px solid #2196f3;
    background-color: #e3f2fd;
    transform: scale(1.05);
    z-index: 10;
}

.element-card.trash-highlight {
    border: 2px solid #ff5252;
    background-color: #ffebee;
}

.trash-mode-btn-active {
    background: #ff5252 !important;
    color: white !important;
    box-shadow: 0 0 10px rgba(255, 82, 82, 0.4);
}

.trash-drop-zone {
    border: 2px dashed #ff5252 !important;
    background: rgba(255, 82, 82, 0.1) !important;
}

.element-card[draggable="true"] {
    cursor: grab;
}

.element-card[draggable="true"]:active {
    cursor: grabbing;
}

.element-emoji {
    font-size: 1.8rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    overflow: visible;
    /* Ensure it stays within bounds */
    white-space: nowrap;
    /* Prevent wrapping for multi-character emojis */
}

.element-name {
    font-size: 0.7rem;
    font-weight: bold;
    margin-top: 4px;
}

/* Count Badge */
.count-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ef5350;
    color: white;
    font-size: 0.75rem;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 10px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

/* Animations */
@keyframes pop {
    0% {
        transform: scale(0.5);
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

.pop-anim {
    animation: pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes pop {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Archives View */
.archives-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
}

#archives-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    padding: 5px;
}

#archives-list::-webkit-scrollbar {
    width: 6px;
}

#archives-list::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}

.shake-anim {
    animation: shake 0.4s;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.2s;
    pointer-events: auto !important;
}

.modal-content {
    background: white;
    width: 90%;
    max-width: 400px;
    /* Default max-width, overridden by inline styles for map */
    padding: 30px;
    position: relative;
    text-align: center;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    border-radius: 20px;
    max-height: 85vh;
    /* Limit height to 85% of viewport */
    overflow-y: auto;
    /* Enable vertical scrolling */
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    font-size: 1.5rem;
    cursor: pointer;
    color: #888;
    line-height: 1;
}

.close-btn:hover {
    color: #333;
}

/* Encyclopedia */
.book-card {
    width: 120px;
    min-height: 130px;
    flex: 0 0 120px;
    background: white;
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 10px 6px;
    text-align: center;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.05);
    transition: transform 0.2s, box-shadow 0.2s;
    gap: 5px;
    overflow: hidden;
}

.book-card.unlocked {
    cursor: pointer;
    border: 1px solid transparent;
}

.book-card.unlocked:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.1);
    border-color: var(--accent-color);
}

.book-card.locked {
    background: rgba(0, 0, 0, 0.03);
    color: #aaa;
}

.book-card .element-emoji {
    font-size: 2rem;
    width: 45px;
    height: 45px;
    aspect-ratio: 1 / 1;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    overflow: hidden;
}

.book-card .element-name {
    font-size: 0.85rem;
    font-weight: bold;
    width: 100%;
    overflow: visible;
    white-space: normal;
    padding: 0 4px;
    line-height: 1.2;
    min-height: 1.2em;
}

.book-card .element-desc {
    font-size: 0.75rem;
    color: #666;
    line-height: 1.3;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    padding: 0 4px;
}

/* Encyclopedia */
#encyclopedia-grid {
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 15px;
    justify-items: center;
}

/* --- Mobile Responsive --- */
@media (max-width: 768px) {
    .app-container {
        display: flex;
        flex-direction: column;
        padding: 0;
        gap: 0;
        height: 100vh;
        width: 100vw;
        overflow: hidden;
    }

    .sidebar {
        grid-column: auto;
        grid-row: auto;
        flex: 0 0 auto;
        width: 100%;
        border-radius: 0 0 15px 15px;
        padding: 8px;
        z-index: 20;
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: center;
        background: rgba(255, 255, 255, 0.9);
    }

    .sidebar h1 {
        font-size: 1.1rem;
        margin: 0;
        margin-right: auto;
    }

    .main-nav {
        flex: 1;
        display: flex;
        justify-content: flex-end;
        gap: 5px;
        width: auto;
    }

    .nav-btn {
        width: auto;
        padding: 4px 8px;
        font-size: 0.8rem;
        margin: 0;
    }

    .stats {
        width: 100%;
        margin-top: 5px;
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: center;
        font-size: 0.8rem;
    }

    .message-log {
        display: none;
    }

    .workspace {
        grid-column: auto;
        grid-row: auto;
        flex: 1;
        width: 100%;
        padding: 10px;
        padding-bottom: 240px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .field-container {
        padding: 5px;
        border: none;
        box-shadow: none;
        background: transparent;
    }

    .nature-scene {
        gap: 8px;
    }

    .gather-spot {
        font-size: 1.1rem;
        height: 70px;
    }

    .inventory {
        grid-column: auto;
        grid-row: auto;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 220px;
        border-radius: 15px 15px 0 0;
        z-index: 100;
        background: rgba(255, 255, 255, 0.95);
        box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.1);
        padding: 10px;
        display: flex;
        flex-direction: column;
    }

    .element-list {
        flex: 1;
        overflow-y: auto;
    }

    .machine-section {
        padding: 10px;
    }

    .slots-container {
        transform: scale(0.9);
        transform-origin: left top;
        width: 110%;
        /* Compensate scale */
        margin-bottom: 0;
    }
}

/* --- Lite Mode (Performance Optimization) --- */
body.lite-mode {
    background-image: none !important;
    background-color: #f1f8e9 !important;
}

body.lite-mode::before {
    display: none !important;
}

body.lite-mode * {
    box-shadow: none !important;
    animation: none !important;
    transition: none !important;
    text-shadow: none !important;
}

/* Maintain usability with simplified styles */
body.lite-mode .glass-panel {
    background: white !important;
    border: 1px solid #ddd !important;
}

body.lite-mode .element-card {
    border: 1px solid #ddd !important;
    background: white !important;
}

body.lite-mode .element-slot {
    border: 2px dashed #bbb !important;
    background: #f5f5f5 !important;
}

body.lite-mode .element-slot.filled {
    border: 2px solid #ccc !important;
    background: white !important;
}

body.lite-mode .nav-btn {
    background: #f5f5f5 !important;
    border: 1px solid #eee !important;
}

body.lite-mode .nav-btn.active {
    background: var(--accent-color) !important;
    color: white !important;
    border: none !important;
}

body.lite-mode .gather-spot {
    background: #999 !important;
    border: 1px solid #777 !important;
}

body.lite-mode .water-spot {
    background: #4fc3f7 !important;
}

body.lite-mode .forest-spot {
    background: #66bb6a !important;
}

body.lite-mode .earth-spot {
    background: #a1887f !important;
}

body.lite-mode .tree-spot {
    background: #aed581 !important;
}

body.lite-mode .sun-spot {
    background: #ffb74d !important;
}

body.lite-mode .cave-spot {
    background: #90a4ae !important;
}

body.lite-mode .onsen-spot {
    background: #81d4fa !important;
    border-color: #0277bd !important;
    color: #0277bd !important;
}

body.lite-mode .river-spot {
    background: #4dd0e1 !important;
}

body.lite-mode .home-spot {
    background: #8d6e63 !important;
}

body.lite-mode .oil-spot {
    background: #5d4037 !important;
    color: #ffca28 !important;
}

body.lite-mode .jungle-spot {
    background: #66bb6a !important;
}

body.lite-mode .spice-spot {
    background: #ffa726 !important;
}

body.lite-mode .corn-spot {
    background: #fbc02d !important;
    color: black !important;
}

body.lite-mode .andes-spot {
    background: #795548 !important;
}

body.lite-mode .amazon-spot {
    background: #388e3c !important;
}

body.lite-mode .salt-lake-spot {
    background: #e0f7fa !important;
    color: #006064 !important;
}

body.lite-mode .olive-spot {
    background: #c0ca33 !important;
}

body.lite-mode .coast-spot {
    background: #03a9f4 !important;
}

body.lite-mode .desert-spot {
    background: #d32f2f !important;
}

body.lite-mode .savannah-spot {
    background: #ffca28 !important;
}

body.lite-mode .crater-spot {
    background: #37474f !important;
}

body.lite-mode .modal-overlay {
    background: rgba(0, 0, 0, 0.7) !important;
}

/* --- Dark Mode --- */
/* --- Dark Mode (Improved) --- */
body.dark-mode {
    --bg-color: #121212;
    --accent-color: #81c784;
    /* Light Green */
    --secondary-color: #ff8a65;
    /* Light Orange */
    --glass-bg: rgba(30, 30, 30, 0.95);
    /* More opaque for readability */
    --glass-border: rgba(255, 255, 255, 0.15);
    --text-color: #e0e0e0;
    --slot-bg: rgba(255, 255, 255, 0.08);
    color: #e0e0e0 !important;
}

body.dark-mode::before {
    background: rgba(5, 5, 5, 0.95) !important;
}

/* Force dark backgrounds on main panels */
body.dark-mode .glass-panel,
body.dark-mode .sidebar,
body.dark-mode .inventory,
body.dark-mode .workspace,
body.dark-mode .machine-section,
body.dark-mode .field-container {
    background: var(--glass-bg) !important;
    border-color: var(--glass-border) !important;
    color: var(--text-color) !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5) !important;
}

/* Text Colors */
body.dark-mode h1,
body.dark-mode h2,
body.dark-mode h3,
body.dark-mode p,
body.dark-mode div,
body.dark-mode span,
body.dark-mode label {
    color: #e0e0e0 !important;
}

/* Specific overrides for specific text that might be hardcoded elsewhere */
body.dark-mode .rank-badge {
    background: #333 !important;
    border-color: #555 !important;
}

/* Navigation Buttons */
body.dark-mode .nav-btn {
    background: rgba(255, 255, 255, 0.1) !important;
    color: #aaa !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
}

body.dark-mode .nav-btn.active {
    background: var(--accent-color) !important;
    color: #121212 !important;
    font-weight: bold;
    box-shadow: 0 0 10px rgba(129, 199, 132, 0.4) !important;
}

body.dark-mode .nav-btn:hover:not(.active) {
    background: rgba(255, 255, 255, 0.2) !important;
    color: #fff !important;
}

/* Cards & Slots */
body.dark-mode .element-card {
    background: #252525 !important;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.4) !important;
    border: 1px solid #444 !important;
    color: #eee !important;
}

body.dark-mode .element-card:hover {
    background: #333 !important;
    border-color: var(--accent-color) !important;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.6) !important;
}

body.dark-mode .element-slot {
    border-color: rgba(255, 255, 255, 0.2) !important;
    background: rgba(255, 255, 255, 0.05) !important;
}

body.dark-mode .element-slot.filled {
    background: #252525 !important;
    border-color: #666 !important;
}

/* Settings Modal Specifics (Dynamic content override) */
body.dark-mode #settings-modal .modal-content {
    background: #222 !important;
    border: 1px solid #444 !important;
    color: #eee !important;
}

body.dark-mode #settings-modal h2,
body.dark-mode #settings-modal h3 {
    color: #fff !important;
}

body.dark-mode #settings-modal button.action-btn {
    opacity: 0.9;
}

body.dark-mode #settings-modal label,
body.dark-mode #settings-modal button {
    background: #333 !important;
    border-color: #555 !important;
    color: #ddd !important;
}



/* Allow action buttons to keep their colors but maybe darken them */
body.dark-mode #settings-export-btn {
    background: #1976d2 !important;
    color: white !important;
}

body.dark-mode #settings-import-btn {
    background: #f57c00 !important;
    color: white !important;
}

body.dark-mode #settings-delete-btn {
    background: transparent !important;
    color: #ef5350 !important;
}

/* Inputs */
body.dark-mode input[type="text"] {
    background: #333 !important;
    color: white !important;
    border: 1px solid #555 !important;
}

/* Scrollbar */
body.dark-mode ::-webkit-scrollbar-track {
    background: #1e1e1e;
}

body.dark-mode ::-webkit-scrollbar-thumb {
    background: #555;
}

/* Modal Overlay */

/* Modal */
body.dark-mode .modal-content {
    background: #212121;
    color: #eee;
}

body.dark-mode .close-btn {
    color: #aaa;
}

body.dark-mode .close-btn:hover {
    color: white;
}

/* Text overrides */
body.dark-mode h1,
body.dark-mode h2,
body.dark-mode h3 {
    color: #fff;
}

body.dark-mode .machine-title {
    opacity: 0.9;
    color: #aaa;
}

body.dark-mode .refinery-info {
    color: #bbb;
}

body.dark-mode input[type="text"] {
    background: #333;
    color: white;
    border: 1px solid #555;
}

body.dark-mode .message-log {
    background: rgba(0, 0, 0, 0.3);
}

/* Book Card Dark Mode */
body.dark-mode .book-card {
    background: #1e1e1e;
    color: var(--text-color);
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
}

body.dark-mode .book-card .element-name {
    color: #ddd;
}

body.dark-mode .book-card .element-desc {
    color: #aaa;
}

body.dark-mode .book-card.locked {
    background: rgba(255, 255, 255, 0.05);
}

body.dark-mode .book-card.unlocked {
    border: 1px solid #333;
}

body.dark-mode .book-card.unlocked:hover {
    background: #2a2a2a;
    border-color: var(--accent-color);
}

/* Civilization Info Card */
.civ-info-card {
    background: #fff3e0;
    border: 1px solid #ffcc80;
    border-radius: 10px;
    padding: 15px;
    text-align: center;
    margin: 15px 10px;
    color: #e65100;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    cursor: pointer;
}

.civ-info-header {
    font-size: 0.85rem;
    color: #d84315;
}

.civ-info-title {
    font-size: 1.3rem;
    font-weight: bold;
    color: #e65100;
    margin: 5px 0;
}

.civ-info-desc {
    font-size: 0.85rem;
    color: #bf360c;
}

/* Civilization Card Dark Mode */
body.dark-mode .civ-info-card {
    background: #1e1e1e;
    /* Dark background matching other cards */
    border-color: #333;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
    color: #e0e0e0;
}

body.dark-mode .civ-info-header {
    color: #aaa;
}

body.dark-mode .civ-info-title {
    color: #fff;
}

body.dark-mode .civ-info-desc {
    color: #ccc;
}

/* Shop Dark Mode */
body.dark-mode #tab-buy.active,
body.dark-mode #tab-sell.active {
    background: var(--accent-color);
    color: #121212;
}

/* Map Destinations */
body.dark-mode .map-destination {
    background: #333 !important;
    border-color: #555 !important;
}

body.dark-mode .map-destination h3 {
    color: #ddd !important;
}

body.dark-mode .map-destination p {
    color: #aaa !important;
}

/* Inventory container in mobile */
@media (max-width: 768px) {
    body.dark-mode .inventory {
        background: #1e1e1e;
        border-top: 1px solid #333;
    }



    body.dark-mode .sidebar {
        background: #1e1e1e;
        border-bottom: 1px solid #333;
    }
}

/* Dark + Lite Mode Compatibility */
body.lite-mode.dark-mode .glass-panel {
    background: #1e1e1e !important;
    border-color: #333 !important;
    color: #e0e0e0 !important;
}

body.lite-mode.dark-mode .element-card {
    background: #1e1e1e !important;
    border-color: #333 !important;
    color: #e0e0e0 !important;
}

body.lite-mode.dark-mode .element-slot {
    background: #333 !important;
    border-color: #555 !important;
}

body.lite-mode.dark-mode .element-slot.filled {
    background: #2a2a2a !important;
}

body.lite-mode.dark-mode .nav-btn {
    background: #333 !important;
    border-color: #444 !important;
    color: #ccc !important;
}

body.lite-mode.dark-mode .nav-btn.active {
    background: var(--accent-color) !important;
    color: #121212 !important;
}

/* Tutorial Styles */
/* --- Modern Tutorial System (Premium Refresh) --- */
.tutorial-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at center, rgba(0,0,0,0.2) 0%, rgba(0,0,0,0.7) 100%);
    z-index: 9998;
    display: none;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

.tutorial-box {
    position: fixed;
    max-width: 420px;
    width: 90%;
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 24px;
    padding: 25px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2), inset 0 0 0 1px rgba(255,255,255,0.5);
    z-index: 10000;
    display: none;
    flex-direction: column;
    gap: 15px;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    user-select: none;
}

.tutorial-box.active {
    animation: tutorialBounceIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes tutorialBounceIn {
    from { opacity: 0; transform: translateY(30px) scale(0.9); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.tutorial-content-wrapper {
    display: flex;
    gap: 15px;
    align-items: flex-start;
}

.tutorial-mascot {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #64b5f6, #42a5f5);
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.2rem;
    box-shadow: 0 8px 15px rgba(33, 150, 243, 0.3);
    flex-shrink: 0;
    animation: mascotFloat 3s infinite ease-in-out;
}

@keyframes mascotFloat {
    0%, 100% { transform: translateY(0) rotate(0); }
    50% { transform: translateY(-8px) rotate(5deg); }
}

.tutorial-text-area {
    flex-grow: 1;
}

.tutorial-box h3 {
    margin: 0 0 8px 0;
    color: #1565c0;
    font-size: 1.2rem;
    font-weight: 800;
}

.tutorial-box p {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.6;
    color: #444;
}

.tutorial-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
}

.tutorial-progress {
    font-size: 0.8rem;
    color: #888;
    background: rgba(0,0,0,0.05);
    padding: 4px 12px;
    border-radius: 10px;
    letter-spacing: 1px;
}

.tutorial-btns {
    display: flex;
    gap: 10px;
}

.tutorial-btn {
    padding: 10px 22px;
    border-radius: 14px;
    border: none;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.9rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.tutorial-btn-next {
    background: linear-gradient(135deg, #4caf50, #43a047);
    color: white;
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
}

.tutorial-btn-next:hover {
    box-shadow: 0 6px 18px rgba(76, 175, 80, 0.4);
    transform: translateY(-2px);
}

.tutorial-btn-skip {
    background: transparent;
    color: #888;
    border: 1px solid rgba(0,0,0,0.1);
}

.tutorial-btn-skip:hover {
    background: rgba(0,0,0,0.03);
    color: #666;
}

/* Enhanced Highlight */
.tutorial-highlight {
    position: relative;
    z-index: 9999 !important;
    box-shadow: 0 0 0 4px #4caf50, 0 0 30px rgba(76, 175, 80, 0.8) !important;
    border-color: #4caf50 !important;
    pointer-events: auto !important; /* Ensure user can click the highlighted part */
}

/* Pointer animation to draw attention */
.tutorial-pointer {
    position: absolute;
    width: 20px;
    height: 20px;
    background: #4caf50;
    border-radius: 50%;
    z-index: 10001;
    pointer-events: none;
    animation: tutorialPointerPulse 1.5s infinite;
}

@keyframes tutorialPointerPulse {
    0% { transform: scale(0.8); opacity: 1; box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7); }
    70% { transform: scale(1.2); opacity: 0.5; box-shadow: 0 0 0 15px rgba(76, 175, 80, 0); }
    100% { transform: scale(0.8); opacity: 0; }
}

.dark-mode .tutorial-box {
    background: rgba(30, 30, 30, 0.85);
    border-color: rgba(255, 255, 255, 0.1);
}

.dark-mode .tutorial-box h3 { color: #64b5f6; }
.dark-mode .tutorial-box p { color: #ccc; }
.dark-mode .tutorial-progress { background: rgba(255,255,255,0.05); color: #777; }

/* === Civilization Themes === */

/* Level 0-1: Ancient (Nature & Harmony) */
body.theme-ancient {
    --bg-color: #f1f8e9;
    --accent-color: #2e7d32;
    --secondary-color: #ef6c00;
    --glass-bg: rgba(255, 255, 255, 0.75);
    --glass-border: rgba(255, 255, 255, 0.5);
    --text-color: #2e431f;
    --bg-overlay: rgba(240, 250, 235, 0.2);
}

body.theme-ancient .glass-panel {
    border: 1px solid rgba(255, 255, 255, 0.6);
    box-shadow: 0 8px 32px rgba(46, 125, 50, 0.15);
}

/* Level 2-3: Ice Age (Survival) */
body.theme-iceage {
    --bg-color: #e3f2fd;
    --accent-color: #0277bd;
    --secondary-color: #00bcd4;
    --glass-bg: rgba(255, 255, 255, 0.8);
    --glass-border: rgba(179, 229, 252, 0.6);
    --text-color: #014175;
    --bg-overlay: rgba(200, 230, 250, 0.3);
}

body.theme-iceage .glass-panel {
    border: 1px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 4px 24px rgba(2, 119, 189, 0.2);
}

/* Level 4-5: Classical (History & Craft) */
body.theme-classical {
    --bg-color: #fafafa;
    --accent-color: #795548;
    --secondary-color: #ffb300;
    --glass-bg: rgba(255, 253, 245, 0.85);
    --glass-border: rgba(215, 204, 200, 0.8);
    --text-color: #4e342e;
    --bg-overlay: rgba(250, 245, 240, 0.4);
}

body.theme-classical .glass-panel {
    border: 1px solid rgba(215, 204, 200, 0.6);
    box-shadow: 0 10px 40px rgba(121, 85, 72, 0.15);
}

/* Level 6-7: Medieval (Craft & Commerce) */
body.theme-medieval {
    --bg-color: #efebe9;
    --accent-color: #4e342e;
    --secondary-color: #8d6e63;
    --glass-bg: rgba(245, 240, 235, 0.88);
    --glass-border: rgba(141, 110, 99, 0.4);
    --text-color: #3e2723;
    --bg-overlay: rgba(220, 215, 210, 0.5);
}

body.theme-medieval .glass-panel {
    border: 1px solid rgba(141, 110, 99, 0.4);
    box-shadow: 0 8px 30px rgba(62, 39, 35, 0.25);
}

/* Level 8-11: Industrial (Structure & Steel) */
body.theme-industrial {
    --bg-color: #e0e0e0;
    --accent-color: #37474f;
    --secondary-color: #e64a19;
    --glass-bg: rgba(245, 247, 248, 0.85);
    --glass-border: #90a4ae;
    --text-color: #263238;
    --bg-overlay: rgba(200, 205, 210, 0.4);
}

body.theme-industrial .glass-panel {
    border-radius: 12px;
    border: 1px solid rgba(144, 164, 174, 0.6);
    box-shadow: 0 12px 35px rgba(55, 71, 79, 0.2);
}

/* Level 12-14: Modern (Technology & Science) */
body.theme-modern {
    --bg-color: #f0f7ff;
    --accent-color: #0277bd;
    --secondary-color: #d32f2f;
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(225, 245, 254, 0.9);
    --text-color: #01579b;
    --bg-overlay: rgba(230, 240, 255, 0.3);
}

body.theme-modern .glass-panel {
    border: 1px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 10px 30px rgba(2, 119, 189, 0.1);
}

/* Level 15: Cosmic (Space Age) */
body.theme-cosmic {
    --bg-color: #f0f7ff;
    --accent-color: #00b0ff;
    --secondary-color: #7c4dff;
    --glass-bg: rgba(255, 255, 255, 0.9);
    --glass-border: rgba(0, 176, 255, 0.3);
    --text-color: #1a237e;
    --slot-bg: rgba(0, 0, 0, 0.03);
    --bg-overlay: rgba(255, 255, 255, 0.5);
}

body.theme-cosmic .glass-panel {
    border: 1px solid rgba(0, 176, 255, 0.2);
    box-shadow: 0 10px 30px rgba(0, 176, 255, 0.1);
    background: rgba(255, 255, 255, 0.85);
    color: var(--text-color);
}

body.theme-cosmic .element-card {
    background: #ffffff;
    border: 1px solid rgba(0, 176, 255, 0.1);
    color: #1a237e;
}

body.theme-cosmic .nav-btn.active {
    background: linear-gradient(135deg, #00b0ff, #0081cb);
    box-shadow: 0 4px 10px rgba(0, 176, 255, 0.3);
    color: white;
}

body.theme-cosmic .element-name {
    color: #01579b;
    font-weight: bold;
}

body.theme-cosmic h2 {
    color: #0091ea;
}

/* Level 16: Digital (Information Age) */
body.theme-digital {
    --bg-color: #f0fff4;
    --accent-color: #2e7d32;
    --secondary-color: #2979ff;
    --glass-bg: rgba(255, 255, 255, 0.9);
    --glass-border: rgba(46, 125, 50, 0.3);
    --text-color: #1b3022;
    --slot-bg: rgba(0, 0, 0, 0.03);
    --bg-overlay: rgba(255, 255, 255, 0.5);
}

body.theme-digital .glass-panel {
    border: 1px solid rgba(46, 125, 50, 0.2);
    box-shadow: 0 10px 30px rgba(46, 125, 50, 0.1);
    background: rgba(255, 255, 255, 0.85);
    color: var(--text-color);
}

body.theme-digital .element-name {
    color: #2e7d32;
    font-weight: bold;
}

body.theme-digital .machine-title {
    color: #1565c0;
    text-shadow: none;
}

/* Level 17+: Future (Innovation & Evolution) */
/* Whitish sleek design, "Laboratory/Clean" feel */
body.theme-future {
    --bg-color: #f5fafd;
    --accent-color: #00bcd4;
    --secondary-color: #7c4dff;
    --glass-bg: rgba(255, 255, 255, 0.9);
    --glass-border: rgba(0, 188, 212, 0.3);
    --text-color: #263238;
    --slot-bg: rgba(0, 0, 0, 0.03);
    --bg-overlay: rgba(255, 255, 255, 0.4);
}

body.theme-future .glass-panel {
    border: 1px solid rgba(0, 188, 212, 0.2);
    box-shadow: 0 10px 40px rgba(0, 188, 212, 0.1);
    background: rgba(255, 255, 255, 0.85);
    color: var(--text-color);
}

body.theme-future .element-card {
    background: #ffffff;
    border: 1px solid rgba(0, 188, 212, 0.2);
    color: #37474f;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

body.theme-future .book-card {
    background: #ffffff;
    border: 1px solid rgba(0, 188, 212, 0.2);
    color: #37474f;
}

body.theme-future .element-name,
body.theme-future .book-card .element-name {
    color: #0097a7;
    font-weight: bold;
}

body.theme-future .book-card .element-desc {
    color: #78909c;
}

body.theme-future .book-card.unlocked:hover {
    background: #e0f7fa;
    box-shadow: 0 5px 15px rgba(0, 188, 212, 0.2);
    border-color: #00bcd4;
    transform: translateY(-3px);
}

body.theme-future .book-card.locked {
    background: rgba(0, 0, 0, 0.03);
    border-color: rgba(0, 0, 0, 0.05);
    color: #aaa;
}

body.theme-future .nav-btn.active {
    box-shadow: 0 0 10px rgba(0, 188, 212, 0.2);
    background: rgba(0, 188, 212, 0.1);
    border: 1px solid rgba(0, 188, 212, 0.5);
    color: #00838f;
}

/* Future Theme Detail Modal - Light Version */
body.theme-future #detail-modal .modal-content {
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(0, 188, 212, 0.3);
    color: #37474f;
    box-shadow: 0 0 40px rgba(0, 188, 212, 0.15);
}

body.theme-future #detail-modal h2 {
    color: #00838f;
    text-shadow: none;
}

body.theme-future #detail-modal p {
    color: #546e7a;
}

body.theme-future #detail-modal .modal-section h4 {
    color: #0097a7;
    border-bottom: 1px solid rgba(0, 188, 212, 0.2);
}

body.theme-future #detail-modal .recipe-row {
    background: #f1f8e9;
    /* Slight tint difference or generic light gray */
    background: rgba(240, 250, 255, 0.8);
    border: 1px solid rgba(0, 188, 212, 0.1);
}

body.theme-future #detail-modal .close-btn {
    color: #00bcd4;
}

body.theme-future #detail-modal .close-btn:hover {
    color: #00838f;
    text-shadow: none;
}

/* Refining Buttons Only */
body.theme-future #refine-btn,
body.theme-future #distill-btn,
body.theme-future #carbonize-btn,
body.theme-future #extract-btn {
    background: linear-gradient(135deg, #ef5350, #c62828);
    box-shadow: 0 4px 10px rgba(198, 40, 40, 0.3);
    border: none;
}

body.theme-future #refine-btn:hover,
body.theme-future #distill-btn:hover,
body.theme-future #carbonize-btn:hover,
body.theme-future #extract-btn:hover {
    background: linear-gradient(135deg, #e53935, #b71c1c);
}

/* Shop Buttons - Restoration for Future Theme */
body.theme-future #tab-buy {
    background: rgba(46, 125, 50, 0.2);
    color: #2e7d32;
    border: 1px solid #2e7d32;
    font-weight: bold;
}

body.theme-future #tab-buy.active {
    background: #2e7d32 !important;
    color: white !important;
}

body.theme-future #tab-sell {
    background: rgba(198, 40, 40, 0.2);
    color: #c62828;
    border: 1px solid #c62828;
    font-weight: bold;
}

body.theme-future #tab-sell.active {
    background: #c62828 !important;
    color: white !important;
}

/* Dragging Section Style */
.dragging-section {
    opacity: 0.5;
    border: 2px dashed #4caf50 !important;
    background: #e8f5e9 !important;
}

.machine-title {
    user-select: none;
    /* Prevent text selection while dragging */
}

/* Shop View Scroll Adjustment */
#view-shop.view-panel {
    overflow-y: hidden;
}

.shop-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.shop-grid {
    flex: 1;
    overflow-y: auto !important;
    max-height: none !important;
    min-height: 0;
    padding: 5px;
    align-content: flex-start;
}

/* Lock Button for Crafting Slots */
.slot-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.lock-btn {
    margin-top: 5px;
    cursor: pointer;
    opacity: 0.2;
    /* Faint when unlocked */
    font-size: 1rem;
    transition: opacity 0.2s;
    user-select: none;
}

.lock-btn:hover {
    opacity: 0.6;
}

.lock-btn.locked {
    opacity: 1;
    /* Fully visible when locked */
}

/* Settings Modal Buttons - Unified White */
#settings-modal .action-btn {
    background: #ffffff !important;
    color: #333 !important;
    border: 1px solid #ccc !important;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1) !important;
}

#settings-modal .action-btn:hover {
    background: #f5f5f5 !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1) !important;
}

/* --- DARK MODE FORCE OVERRIDE --- */
/* Use html body.dark-mode to increase specificity over anything else */
html body.dark-mode .glass-panel,
html body.dark-mode .machine-section,
html body.dark-mode .view-panel,
html body.dark-mode .sidebar,
html body.dark-mode .inventory,
html body.dark-mode .field-container,
html body.dark-mode aside,
html body.dark-mode section {
    background: rgba(30, 30, 30, 0.95) !important;
    background-color: rgba(30, 30, 30, 0.95) !important;
    color: #eeeeee !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    box-shadow: none !important;
}

html body.dark-mode input[type="text"] {
    background: rgba(255, 255, 255, 0.1) !important;
    color: #eee !important;
    border: 1px solid #555 !important;
}

html body.dark-mode button.text-btn {
    background: transparent !important;
    color: #aaa !important;
    border: none !important;
}

html body.dark-mode button.text-btn:hover {
    color: #fff !important;
}

html body.dark-mode h1,
html body.dark-mode h2,
html body.dark-mode h3,
html body.dark-mode h4,
html body.dark-mode p,
html body.dark-mode span,
html body.dark-mode div,
html body.dark-mode label {
    color: #eeeeee !important;
    text-shadow: none !important;
}


html body.dark-mode .gather-spot {
    /* 譏弱ｋ縺輔ｒ蟆代＠謚代∴繧九％縺ｨ縺ｧ縲√←縺弱▽縺・牡繧偵↑縺倥∪縺帙ｋ */
    filter: brightness(0.7) contrast(1.1);
    color: #ffffff !important;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.5) !important;
    /* 閭梧勹濶ｲ縺ｯJS縺ｧ蜍慕噪縺ｫ螟画峩縺輔ｌ繧句ｴ蜷医ｂ縺ゅｋ縺ｮ縺ｧ縲’ilter縺ｧ蟇ｾ蠢懊☆繧九・縺悟翠 */
}

/* 繝帙ヰ繝ｼ譎ゅ・蟆代＠譏弱ｋ縺・*/
html body.dark-mode .gather-spot:hover {
    filter: brightness(0.85) contrast(1.1);
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.7) !important;
    transform: translateY(-2px);
}

/* 縺､縺・〒縺ｫ繧ｿ繧､繝医Ν繝舌・繧ょｰ代＠證励￥ */
html body.dark-mode .field-header,
html body.dark-mode .shop-header,
html body.dark-mode .book-header,
html body.dark-mode .archives-header,
html body.dark-mode .inventory-header,
html body.dark-mode .machine-title {
    background: rgba(0, 0, 0, 0.3) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
    color: #eee !important;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5) !important;
}

/* --- Settings Modal Dark Mode Specifics --- */
/* 逋ｽ縺・き繝ｼ繝芽レ譎ｯ繧呈囓縺城城℃縺輔○繧・*/
html body.dark-mode #settings-modal div[style*="background:white"],
html body.dark-mode #settings-modal div[style*="background: white"],
html body.dark-mode #settings-modal div[style*="background:rgba(0,0,0,0.03)"],
html body.dark-mode #settings-modal div[style*="background: rgba(0,0,0,0.03)"] {
    background: rgba(255, 255, 255, 0.05) !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    box-shadow: none !important;
    color: #eee !important;
}

/* 繝懊ち繝ｳ縺ｨ繝ｩ繝吶Ν (騾壼ｸｸ縺ｮ繧ゅ・) */
html body.dark-mode #settings-modal button:not(.action-btn):not(.text-btn),
html body.dark-mode #settings-modal label {
    background: rgba(255, 255, 255, 0.1) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    color: #eee !important;
}

/* 髢狗匱閠・Γ繝｢ (繧ｯ繝ｪ繝ｼ繝濶ｲ) 繧呈囓縺・が繝ｬ繝ｳ繧ｸ邉ｻ縺ｫ */
html body.dark-mode #settings-modal div[style*="background:#fff3e0"],
html body.dark-mode #settings-modal div[style*="background: #fff3e0"] {
    background: rgba(255, 152, 0, 0.15) !important;
    border: 1px dashed rgba(255, 152, 0, 0.5) !important;
}

html body.dark-mode #settings-modal div[style*="background:#fff3e0"] p,
html body.dark-mode #settings-modal div[style*="background: #fff3e0"] p,
html body.dark-mode #settings-modal div[style*="background:#fff3e0"] h3,
html body.dark-mode #settings-modal div[style*="background: #fff3e0"] h3 {
    color: #ffcc80 !important;
}

/* 隕句・縺励・譁・ｭ苓牡隱ｿ謨ｴ */
html body.dark-mode #settings-modal h2,
html body.dark-mode #settings-modal h3 {
    color: #fff !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
}

/* 蜑企勁繝懊ち繝ｳ縺ｮ繝・く繧ｹ繝・*/
html body.dark-mode #settings-delete-btn {
    color: #ef5350 !important;
    background: transparent !important;
}

/* --- Glass Mode (Liquid Glass Style) --- */
/* Base Animation for Glass Background */
@keyframes gradientBG {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

/* Light Glass Mode */
html body.glass-mode {
    /* Liquid gradient background */
    background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
    background-size: 400% 400%;
    animation: gradientBG 15s ease infinite;
}



/* --- Roadmap Tree (Org Chart Style - Inverted: ingredients on top, goal on bottom) --- */
/* --- Roadmap Tree Logic (Upward Growth - Anti-Glitch Fix) --- */
.roadmap-tree, .roadmap-tree ul, .roadmap-tree li {
    margin: 0;
    padding: 0;
    list-style: none;
}

.roadmap-tree {
    text-align: center;
    padding: 120px;
    display: inline-block;
    width: max-content;
    min-width: 100%;
}

.roadmap-tree ul {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: flex-end;
}

.roadmap-tree li {
    position: relative;
    display: flex;
    flex-direction: column-reverse; /* 荳翫↓蟄・譚先侭)縲∽ｸ九↓隕ｪ(螳梧・蜩・ */
    align-items: center;
}

/* 1. 繝弱・繝牙・螳ｹ・育ｮｱ・峨・險ｭ螳・*/
.roadmap-tree .node-content {
    border: 1px solid #ccc;
    padding: 10px 15px;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    min-width: 100px;
    position: relative;
    z-index: 10;
    margin: 40px 10px !important; /* 荳贋ｸ九↓邨ｶ蟇ｾ逧・↑髫咎俣繧堤｢ｺ菫・*/
}

/* 2. 蝙ら峩邱・(邂ｱ縺九ｉ螟悶↓莨ｸ縺ｰ縺・ */
/* 荳翫∈・郁ｦｪ縺九ｉ譚先侭縺ｮ蜷域ｵ∫せ縺ｸ・・*/
.roadmap-tree .node-content::before {
    content: '';
    position: absolute;
    bottom: 100%; /* 邂ｱ縺ｮ荳顔ｫｯ縺九ｉ髢句ｧ・*/
    left: 50%;
    width: 2px;
    height: 40px; /* 繝槭・繧ｸ繝ｳ蛻・ｒ蝓九ａ繧・*/
    background: #bbb;
    transform: translateX(-50%);
    display: block;
}

/* 譚先侭繧呈戟縺溘↑縺・怙荳企Κ縺ｮ繝弱・繝峨・縲∽ｸ翫↓邱壹ｒ蠑輔°縺ｪ縺・*/
.roadmap-tree li:not(:has(ul)) > .node-content::before {
    display: none;
}

/* 荳九∈ (譚先侭縺九ｉ隕ｪ縺ｸ縺ｮ蜷域ｵ∫せ縺ｸ) */
.roadmap-tree ul ul li > .node-content::after {
    content: '';
    position: absolute;
    top: 100%; /* 邂ｱ縺ｮ荳狗ｫｯ縺九ｉ髢句ｧ・*/
    left: 50%;
    width: 2px;
    height: 40px; /* 繝槭・繧ｸ繝ｳ蛻・ｒ蝓九ａ繧・*/
    background: #bbb;
    transform: translateX(-50%);
    display: block;
}

/* 3. 豌ｴ蟷ｳ邱・(譚先侭縺溘■繧堤ｹ九＄) */
/* 譚先侭縲畦i縲阪◎縺ｮ繧ゅ・縺ｫ讓ｪ邱壹ｒ諡・ｽ薙＆縺帙ｋ */
.roadmap-tree ul ul li::before,
.roadmap-tree ul ul li::after {
    content: '';
    position: absolute;
    bottom: 0px; /* li縺ｮ蠎包ｼ茨ｼ晏ｮ梧・蜩√ヮ繝ｼ繝峨・荳顔ｫｯ縺ｨ蜷後§鬮倥＆・・*/
    right: 50%;
    border-top: 2px solid #bbb;
    width: 50%;
    height: 0;
    z-index: 1;
}

.roadmap-tree ul ul li::after {
    right: auto;
    left: 50%;
}

/* 遶ｯ縺ｮ菴呵ｨ医↑讓ｪ譽偵ｒ豸医☆ */
.roadmap-tree ul ul li:first-child::before,
.roadmap-tree ul ul li:last-child::after {
    border: none;
}
.roadmap-tree ul ul li:only-child::before,
.roadmap-tree ul ul li:only-child::after {
    display: none;
}

/* 逋ｺ隕九・譛ｪ逋ｺ隕九・繧ｹ繧ｿ繧､繝ｫ */
.roadmap-tree li.discovered .node-content {
    background: #e8f5e9;
    border: 2px solid #4caf50;
    color: #2e7d32;
}

.roadmap-tree li.undiscovered .node-content {
    background: #fdfdfd;
    color: #bbb;
}

/* 謠冗判縺ｮ螳牙ｮ・*/
#roadmap-scroll-area {
    background: #f8fbff;
}

.dark-mode .roadmap-tree .node-content {
    background: #2a2a2a;
    border-color: #444;
    color: #eee;
}

/* --- Small Screen Adjustments --- */
/* For laptops with small vertical resolution */
@media screen and (max-height: 800px) and (min-width: 769px) {
    .app-container {
        grid-template-rows: 1fr 180px;
        /* Shrink inventory height */
        gap: 10px;
        padding: 10px;
    }

    .sidebar {
        gap: 10px;
    }

    .sidebar h1 {
        font-size: 1.2rem;
    }

    .nav-btn {
        padding: 8px 10px;
        font-size: 0.9rem;
    }

    .field-container {
        overflow-y: auto !important;
        /* Allow scrolling if even with fixes it overflows */
    }

    .nature-scene {
        grid-auto-rows: minmax(50px, auto);
        /* Smaller spots */
        gap: 8px;
        padding-bottom: 15px;
    }

    .gather-spot {
        font-size: 1.2rem;
        padding: 5px;
    }

    /* Slot and operator scaling for crafting */
    .element-slot,
    .operator {
        width: 80px;
        height: 80px;
    }

    .operator {
        font-size: 1.2rem;
    }
}

/* Centering the exploration field content */
.field-container {
    align-items: center;
}

/* 
   Centering Hack: 
   Use margin: auto on the first and last child to center vertically 
   ONLY when there is enough space. If space is tight, it naturally scrolls from the top.
*/
.field-header {
    margin-top: auto;
}

.nature-scene {
    margin: 0 auto;
    margin-bottom: auto;
}

/* --- Timeline UI for Civilization History --- */
.timeline-container {
    position: relative;
    padding: 20px 0;
    margin: 0 auto;
    max-width: 100%;
}

.timeline-container::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 20px;
    width: 4px;
    background: linear-gradient(to bottom, #81c784, #ddd);
    border-radius: 2px;
}

.timeline-item {
    position: relative;
    margin-bottom: 30px;
    padding-left: 55px;
    opacity: 0;
    transform: translateY(20px);
    animation: slideUpFade 0.5s ease forwards;
}

@keyframes slideUpFade {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.timeline-item:last-child {
    margin-bottom: 0;
}

.timeline-icon {
    position: absolute;
    left: 3px;
    top: 0;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: white;
    border: 3px solid #ddd;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.timeline-item.reached .timeline-icon {
    border-color: #4caf50;
    background: #e8f5e9;
}

.timeline-item.current .timeline-icon {
    border-color: #ff9800;
    background: #fff3e0;
    transform: scale(1.15);
    box-shadow: 0 0 12px rgba(255, 152, 0, 0.4);
}

.timeline-content {
    background: white;
    border-radius: 12px;
    padding: 15px 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    border: 1px solid #eee;
    transition: all 0.3s ease;
    position: relative;
}

.timeline-item.reached .timeline-content {
    border-left: 4px solid #4caf50;
}

.timeline-item.current .timeline-content {
    border-left: 5px solid #ff9800;
    box-shadow: 0 4px 20px rgba(255, 152, 0, 0.15);
    background: #fffcf5;
}

.timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    gap: 10px;
}

.timeline-title {
    font-weight: bold;
    font-size: 1.1rem;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.timeline-year {
    font-size: 0.85rem;
    color: #888;
    background: #f5f5f5;
    padding: 3px 10px;
    border-radius: 12px;
    font-family: monospace;
    border: 1px solid #ddd;
    white-space: nowrap;
    flex-shrink: 0;
}

.timeline-desc {
    font-size: 0.9rem;
    color: #666;
    line-height: 1.5;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.timeline-item.locked .timeline-content {
    background: #fafafa;
    border-style: dashed;
    border-color: #ccc;
}

.timeline-item.locked .timeline-title {
    color: #999;
}

/* Dark Mode Adjustments */
body.dark-mode .timeline-container::before {
    background: linear-gradient(to bottom, #4caf50, #444);
}

body.dark-mode .timeline-icon {
    background: #252525;
    border-color: #444;
}

body.dark-mode .timeline-item.reached .timeline-icon {
    background: #1b5e20;
    border-color: #4caf50;
}

body.dark-mode .timeline-item.current .timeline-icon {
    background: #e65100;
    border-color: #ffb74d;
}

body.dark-mode .timeline-content {
    background: #1e1e1e;
    border-color: #333;
}

body.dark-mode .timeline-item.current .timeline-content {
    background: #2a2218;
    border-color: #ffb74d;
}

body.dark-mode .timeline-title {
    color: #eee;
}

body.dark-mode .timeline-year {
    background: #333;
    color: #aaa;
    border-color: #555;
}

body.dark-mode .timeline-desc {
    color: #bbb;
}

body.dark-mode .timeline-item.locked .timeline-content {
    background: #151515;
    border-color: #444;
}
