/* =========================================
   ATOMIC GENESIS - CORE (DEMO) STYLES
========================================= */

:root {
    --panel-bg: #2b2b36;
    --border-color: #555;
}

/* --- CUSTOM FONT --- */
@font-face {
    font-family: 'Atgen';
    src: url('images/Atgen-Bold.ttf') format('truetype');
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: 'Atgen';
    src: url('images/Atgen-Bold.ttf') format('truetype');
    font-weight: bold;
    font-style: normal;
}

/* --- CUSTOM DARK SCROLLBARS --- */
* {
    scrollbar-width: thin;
    scrollbar-color: #555 var(--panel-bg);
}

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--panel-bg); border-radius: 4px; }
::-webkit-scrollbar-thumb { background: #555; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #1abc9c; }

body {
    font-family: 'Atgen', Arial, sans-serif;
    font-size: 20px;
    text-align: center;
    background-color: #1e1e24;
    color: #fff;
    margin: 0; /* THE FIX: Removed top margin */
    user-select: none;
    overflow-x: hidden;
}

body.arial-font {
    font-family: Arial, sans-serif !important;
    font-size: 18px !important;
}
body.arial-font button { font-family: Arial, sans-serif !important; }
body.hide-trophy .atom-visualization { display: none !important; }

#top-nav::after {
    content: ''; position: absolute; bottom: -20px; left: 0; width: 100%; height: 20px; background: transparent;
}

#top-nav:hover { transform: translateY(0); }

#top-nav .setting-btn {
    flex: 0 1 auto;
    width: auto;
    padding: 8px 20px;
    margin: 0;
}

/* DESKTOP LAYOUT */
.left-panel {
    float: left; width: 300px; display: flex; flex-direction: column; gap: 15px;
    z-index: 100;
    height: calc(100vh - 40px); /* THE FIX: Expanded to fill the screen */
    position: fixed;
    top: 20px; /* THE FIX: Moved back to the top */
    left: 20px;
}

.right-panel {
    float: right; position: fixed;
    top: 20px; /* THE FIX: Moved back to the top */
    right: 20px; width: 300px;
    height: calc(100vh - 40px); /* THE FIX: Expanded to fill the screen */
    display: flex; flex-direction: column; gap: 15px; z-index: 100;
}

.main-content {
    margin: 20px 340px 0 340px;
    display: flex; flex-direction: column; align-items: center;
    min-height: calc(100vh - 20px);
    position: relative; transition: margin 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
    pointer-events: none; /* THE FIX: Lets clicks pass through the empty space */
}

/* THE FIX: Re-enables clicking on the Trophy, Menus, and Fusion Chamber */
.main-content > * {
    pointer-events: auto;
}

h1 { position: relative; top: 0; left: 0; transform: none; margin: 20px 0 40px 0; z-index: 1000; text-shadow: 2px 2px 4px rgba(0,0,0,0.8); width: 100%; }

/* UI COMPONENTS */
.hud-box {
    background-color: var(--panel-bg); border-radius: 8px; padding: 12px 20px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.5); display: flex; flex-direction: column; align-items: center;
}
.energy-hud { border: 2px solid #f1c40f; }
.energy-main { font-size: 26px; font-weight: bold; }
.energy-rate { font-size: 16px; opacity: 0.9; margin-top: 2px; }

.resource-box {
    border: 2px solid var(--border-color); padding: 20px; background-color: var(--panel-bg);
    border-radius: 8px; text-align: left; overflow-y: auto; box-shadow: 0 4px 8px rgba(0,0,0,0.5); flex-grow: 1;
}

.actions-box {
	background-color: var(--panel-bg); border: 2px solid var(--border-color); border-radius: 8px;
    padding: 20px; overflow-y: auto; box-shadow: 0 4px 8px rgba(0,0,0,0.5); box-sizing: border-box;
    flex-grow: 1; max-height: 100%;
}

/* BUTTON STYLES */
button {
    font-family: inherit; font-size: 1.15em; padding: 10px 8px; margin: 5px 0; width: 100%;
    cursor: pointer; border-radius: 4px; border: none; color: white; font-weight: bold;
    transition: filter 0.2s; line-height: 1.4;
}
button:disabled { background-color: #555 !important; color: #888 !important; cursor: not-allowed; filter: none !important; }
.element-btn { background-color: var(--btn-color); color: var(--text-color, white); }
.element-btn:hover:not(:disabled) { filter: brightness(1.15); }

.bulk-btn { background-color: #2c3e50; border: 1px solid #555; font-size: 0.75em; margin-top: -5px; margin-bottom: 10px; }
.setting-btn { background-color: #34495e; color: white; margin: 0; flex: 1; font-size: 0.85em; padding: 10px 5px; border: 2px solid #2f3542; }
.setting-btn:hover { filter: brightness(1.2); }
.mute-active { background-color: #2f3542 !important; color: #a4b0be !important; border-color: #1e1e24; }

/* --- MODALS & SETTINGS DRAWER --- */
.settings-drawer { position: absolute; top: 0; left: 100%; margin-left: 15px; width: 200px; background: var(--panel-bg); border: 2px solid var(--border-color); border-radius: 8px; padding: 20px; display: flex; flex-direction: column; gap: 8px; box-shadow: 0 4px 15px rgba(0,0,0,0.8); opacity: 0; pointer-events: none; transform: translateX(-20px); transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); }
.settings-drawer.settings-open { opacity: 1; pointer-events: auto; transform: translateX(0); }
.settings-box { background-color: var(--panel-bg); border: 2px solid var(--border-color); border-radius: 8px; padding: 15px; box-shadow: 0 4px 8px rgba(0,0,0,0.5); text-align: left; }

.modal-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background-color: rgba(10, 10, 15, 0.85); z-index: 20000; display: flex; justify-content: center; align-items: center; animation: fadeIn 0.2s ease-out; backdrop-filter: blur(3px); }
.modal-content { background: var(--panel-bg); border: 2px solid var(--border-color); padding: 30px; border-radius: 8px; box-shadow: 0 0 30px rgba(0,0,0,0.8); max-width: 400px; width: 90%; text-align: center; }

/* PANEL TOGGLES */
.panel-toggle {
    position: absolute; top: 35px; width: 30px; height: 60px; background-color: var(--panel-bg);
    border: 2px solid var(--border-color); color: #a4b0be; font-family: Arial, sans-serif; font-size: 18px;
    cursor: pointer; z-index: 101; display: flex; align-items: center; justify-content: center;
    padding: 0; margin-top: -30px; transition: background-color 0.2s, color 0.2s;
}
.panel-toggle:hover { background-color: #1abc9c; color: #111; }
.left-toggle { right: -32px; border-left: none; border-radius: 0 8px 8px 0; }
.right-toggle { left: -32px; border-right: none; border-radius: 8px 0 0 8px; }

body.left-collapsed .left-panel { transform: translateX(calc(-100% - 20px)); }
body.right-collapsed .right-panel { transform: translateX(calc(100% + 20px)); }
body.left-collapsed .main-content { margin-left: 20px; }
body.right-collapsed .main-content { margin-right: 20px; }

/* ATOM GRID & VISUALIZATIONS */
.atom-visualization { margin-bottom: 10px; height: 260px; display: flex; justify-content: center; align-items: center; width: 100%; }

.atom-container {
    position: relative;
    z-index: 5;
    width: 250px;
    height: 250px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--panel-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.6);
    cursor: pointer;
    transition: box-shadow 0.2s ease, border-color 0.2s ease; /* THE FIX: Smoothly animates the hover state */
}

/* THE FIX: Adds a glowing gold border and soft shadow when the mouse hovers over it */
.atom-container:hover {
    border-color: #f1c40f;
    box-shadow: 0 0 20px rgba(241, 196, 15, 0.3), inset 0 0 15px rgba(241, 196, 15, 0.1);
}

.pulse { transform: scale(0.9); }

.nucleus {
    position: absolute; display: flex; align-items: center; justify-content: center; font-weight: bold;
    white-space: nowrap; overflow: hidden; padding: 0; line-height: 1;
    -webkit-mask-image: url('images/atom_model.png'); -webkit-mask-size: contain; -webkit-mask-repeat: no-repeat; -webkit-mask-position: center;
    mask-image: url('images/atom_model.png'); mask-size: contain; mask-repeat: no-repeat; mask-position: center;
}

.mini-nucleus {
    position: absolute; z-index: 10; display: flex; align-items: center; justify-content: center; font-weight: bold;
    -webkit-mask-image: url('images/atom_model.png'); -webkit-mask-size: contain; -webkit-mask-repeat: no-repeat; -webkit-mask-position: center;
    mask-image: url('images/atom_model.png'); mask-size: contain; mask-repeat: no-repeat; mask-position: center;
}

.shell { position: absolute; border-radius: 50%; border: 2px dashed #555; box-sizing: border-box; animation: spin 4s linear infinite; pointer-events: none; }
.electron { position: absolute; top: 50%; left: 50%; width: 10px; height: 10px; background: #1e90ff; border-radius: 50%; margin-top: -5px; margin-left: -5px; box-shadow: 0 0 6px #1e90ff; }

#atom-grid-container {
    position: fixed !important;
    top: 0; left: 0; width: 100vw !important; height: 100vh !important;
    z-index: 1; /* Sets it behind the UI panels */
    margin: 0; padding: 0;
}

.atom-grid {
    display: block; position: relative; padding: 0;
    background-color: transparent !important; border: none !important;
    border-radius: 0; width: 100%; height: 100%;
    box-sizing: border-box; overflow: hidden;
}

/* --- ATOM GRID COUNTER --- */
.atom-count-display {
    position: absolute;
    bottom: 15px;
    right: 340px;
    background: rgba(10, 10, 15, 0.85);
    color: #a4b0be;
    font-size: 14px;
    font-weight: bold;
    padding: 6px 12px;
    border: 1px solid #444;
    border-radius: 6px;
    pointer-events: none;
    z-index: 100;
    box-shadow: 0 2px 6px rgba(0,0,0,0.8);
}

.mini-atom-container {
    position: absolute; display: flex; justify-content: center; align-items: center;
    transition: opacity 0.3s ease, transform 0.3s ease, filter 0.1s ease; will-change: transform, opacity;
}
.mini-shell { position: absolute; border-radius: 50%; border: 1px dashed #444; box-sizing: border-box; animation: spin 2s linear infinite; }
.mini-electron { position: absolute; top: 50%; left: 50%; width: 4px; height: 4px; background: #1e90ff; border-radius: 50%; margin-top: -2px; margin-left: -2px; box-shadow: 0 0 3px #1e90ff; }

/* --- ATOM SPEED BOOST VISUALS --- */
.boost-active {
    filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.8)) brightness(1.3);
    z-index: 20; /* Forces boosted atoms to float in front of normal atoms */
}
.boost-active .mini-nucleus {
    transform: scale(1.3);
    transition: transform 0.2s ease;
}
.boost-active .mini-shell {
    border-color: rgba(255, 255, 255, 0.8);
    animation-duration: 0.5s !important; /* Spins the electrons 4x faster! */
}

.floating-text { position: fixed; color: #f1c40f; font-weight: bold; font-size: 26px; pointer-events: none; z-index: 9999; text-shadow: 1px 1px 3px black; animation: floatUp 1s ease-out forwards; }
@keyframes floatUp { 0% { opacity: 1; transform: translateY(0) scale(1); } 100% { opacity: 0; transform: translateY(-60px) scale(1.2); } }
@keyframes spin { 100% { transform: rotate(360deg); } }

.inventory-item { padding: 8px; transition: background 0.2s; border-radius: 4px; }
.inventory-item:hover { background: rgba(255,255,255,0.05); }

/* --- FUSION CHAMBER --- */
.fusion-title {
    position: relative; /* Enables z-index stacking */
    z-index: 5; /* Puts it above the grid */
    color: #a4b0be; font-size: 0.9em; font-weight: bold; letter-spacing: 2px; text-transform: uppercase; margin-bottom: 25px; text-shadow: 0 2px 4px rgba(0,0,0,0.5); transition: color 0.3s ease, text-shadow 0.3s ease;
}
.fusion-chamber {
    z-index: 5; /* Puts it above the grid */
    width: 300px; height: 80px; margin: -20px auto 20px auto; border: 2px solid #444; border-radius: 40px; background: radial-gradient(circle, #1a1a2e 0%, #0f0f1a 100%); position: relative; overflow: hidden; box-shadow: inset 0 0 15px rgba(0, 255, 255, 0.1);
}

.fusion-particle { position: absolute; width: 20px; height: 20px; border-radius: 50%; top: 50%; margin-top: -10px; opacity: 0; z-index: 5; line-height: 1; text-shadow: 0 0 2px rgba(0,0,0,0.3); }
#fusion-particle-l { left: -30px; } #fusion-particle-r { right: -30px; }

@keyframes product-reveal { 0% { transform: scale(0); opacity: 0; } 10% { transform: scale(1.4); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }
.fusing-reveal #fusion-particle-product { animation: product-reveal 0.3s ease-out forwards; }
#fusion-symbol-text { pointer-events: none; line-height: 1; text-shadow: 0 0 2px rgba(0,0,0,0.5); }
#fusion-flash { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: white; opacity: 0; z-index: 10; pointer-events: none; }

/* THE FIX: Combined scale into transform for smoother rendering */
@keyframes collide {
    0% { transform: translateX(0) scale(1); opacity: 1; }
    90% { transform: translateX(130px) scale(0.8); opacity: 1; }
    100% { transform: translateX(150px) scale(2); opacity: 0; }
}
@keyframes collide-reverse {
    0% { transform: translateX(0) scale(1); opacity: 1; }
    90% { transform: translateX(-130px) scale(0.8); opacity: 1; }
    100% { transform: translateX(-150px) scale(2); opacity: 0; }
}

/* THE FIX: Applied identical cubic-bezier easing to both particles so they accelerate in perfect sync */
.fusing #fusion-particle-l { animation: collide 1.5s cubic-bezier(0.5, 0, 1, 1) forwards; }
.fusing #fusion-particle-r { animation: collide-reverse 1.5s cubic-bezier(0.5, 0, 1, 1) forwards; }
.fusing #fusion-flash { animation: flashEffect 1.6s ease-out; }
@keyframes flashEffect { 0% { opacity: 0; } 90% { opacity: 0; } 94% { opacity: 1; } 100% { opacity: 0; } }

.fusion-spark { position: fixed; width: 10px; height: 10px; border-radius: 50%; pointer-events: none; z-index: 10002; filter: blur(0.5px); box-shadow: 0 0 15px white, 0 0 5px var(--spark-color); transition: background 0.2s; }
@keyframes spark-fly { 0% { transform: translate(0, 0) scale(1.5); opacity: 1; } 20% { opacity: 1; } 100% { transform: translate(var(--tx), var(--ty)) scale(0.3); opacity: 0; } }

@keyframes trophy-react { 0% { transform: scale(1); filter: brightness(1); } 50% { transform: scale(1.1) rotate(1deg); filter: brightness(1.2); } 75% { transform: scale(1.15) rotate(-1deg); filter: brightness(1.3); } 100% { transform: scale(1); filter: brightness(1); } }
.trophy-reacting { animation: trophy-react 1.5s ease-in-out; }

/* --- TYPING BUFFER VISUAL --- */
#typing-buffer-display { position: fixed; background: rgba(10, 10, 15, 0.9); border: 1px solid #1abc9c; color: #1abc9c; font-size: 18px; font-weight: bold; padding: 4px 8px; border-radius: 4px; pointer-events: none; z-index: 10005; transition: opacity 0.2s ease, transform 0.2s ease; opacity: 0; transform: scale(0.8); box-shadow: 0 0 10px rgba(26, 188, 156, 0.3); }

/* --- PERIODIC TABLE --- */
#periodic-table-container { animation: fadeIn 0.3s ease; }
.pt-wrapper { width: 100%; overflow-x: auto; padding: 10px 0 20px 0; }
.periodic-grid { display: grid; grid-template-columns: repeat(18, 42px); grid-template-rows: repeat(10, 42px); gap: 4px; justify-content: center; min-width: 850px; }
.pt-cell { border: 1px solid #444; border-top: 4px solid var(--group-color, #555); border-radius: 4px; display: flex; flex-direction: column; justify-content: center; align-items: center; transition: transform 0.2s, box-shadow 0.2s, background-color 0.4s; cursor: default; line-height: 1; }
.pt-cell:hover { transform: scale(1.15); z-index: 10; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

.pt-legend-item { padding: 6px 12px; border-radius: 4px; font-size: 14px; font-weight: bold; display: flex; align-items: center; gap: 8px; opacity: 0.4; border: 2px solid #555; background: var(--panel-bg); transition: all 0.3s ease; cursor: help; }
.pt-legend-item.achieved { opacity: 1; border-color: var(--group-color); box-shadow: 0 0 10px var(--group-color), inset 0 0 10px rgba(255,255,255,0.1); color: white; }

/* --- MINI-LEGEND BADGES FOR PERIODS & COLUMNS (Achievements) --- */
.mini-legend-item { padding: 4px 8px; border-radius: 4px; font-size: 14px; font-weight: bold; opacity: 0.4; border: 2px solid #555; background: var(--panel-bg); transition: all 0.3s ease; cursor: help; color: #a4b0be; display: flex; align-items: center; gap: 5px; }
.mini-legend-item.achieved { opacity: 1; border-color: #9b59b6; box-shadow: 0 0 5px rgba(155, 89, 182, 0.5), inset 0 0 5px rgba(255,255,255,0.1); color: #fff; }

.achievement-toast { position: fixed; bottom: 20px; right: 20px; background: var(--panel-bg); border-left: 5px solid var(--group-color); padding: 15px 20px; border-radius: 4px; box-shadow: 0 4px 15px rgba(0,0,0,0.8); color: white; z-index: 10005; animation: toastSlide 4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards; pointer-events: none; display: flex; flex-direction: column; text-align: left; }
@keyframes toastSlide { 0% { transform: translateX(120%); opacity: 0; } 10% { transform: translateX(0); opacity: 1; } 85% { transform: translateX(0); opacity: 1; } 100% { transform: translateX(120%); opacity: 0; } }

/* --- ZEN MODE: FULL SCREEN PARTICLE EXPANSION --- */
body.zen-mode { margin: 0 !important; padding: 0 !important; overflow: hidden !important; }
body.zen-mode .atom-visualization, body.zen-mode #fusion-title, body.zen-mode #fusion-chamber, body.zen-mode .left-panel, body.zen-mode .right-panel, body.zen-mode #top-nav, body.zen-mode h1 { display: none !important; }
body.zen-mode .main-content, body.zen-mode #atom-grid-container, body.zen-mode .atom-grid { margin: 0 !important; padding: 0 !important; width: 100vw !important; height: 100vh !important; max-width: none !important; border: none !important; border-radius: 0 !important; }
body.zen-mode .atom-grid { background-color: #0a0a0f; }
body.zen-mode #zen-toggle { background: #27ae60; box-shadow: 0 0 15px rgba(39, 174, 96, 0.5); }
body.zen-mode .atom-count-display { right: 20px !important; }

.left-panel, .right-panel { transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1); }

/* --- DEMO COMPLETION SCREEN --- */
.supernova-flash { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background-color: black; z-index: 10000; opacity: 0; pointer-events: none; transition: opacity 2s ease-in-out; }
.supernova-text { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: white; font-size: 66px; font-weight: bold; text-transform: uppercase; letter-spacing: 15px; text-shadow: 0 0 20px rgba(255, 255, 255, 0.8), 0 0 40px #e74c3c, 0 0 60px #e74c3c; display: none; }
.supernova-active { opacity: 1; }

#demo-end-screen { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background-color: rgba(10, 10, 15, 0.95); z-index: 20000; display: flex; justify-content: center; align-items: center; animation: fadeIn 2s ease-in-out; }
.demo-content { background: #1e1e24; border: 2px solid #f1c40f; padding: 50px; border-radius: 15px; box-shadow: 0 0 50px rgba(241, 196, 15, 0.2); display: flex; flex-direction: column; align-items: center; }
.join-btn { background-color: #3498db; color: white; padding: 15px 30px; font-size: 20px; font-weight: bold; text-decoration: none; border-radius: 8px; border: 2px solid #2980b9; transition: all 0.2s; }
.join-btn:hover { background-color: #2980b9; box-shadow: 0 0 15px #3498db; transform: scale(1.05); }

#exit-zen-btn { display: none; position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 10001; background: #27ae60; color: white; padding: 12px 24px; border-radius: 8px; border: 2px solid #555; font-weight: bold; cursor: pointer; opacity: 0.2; transition: opacity 0.2s ease; }
#exit-zen-btn:hover { opacity: 1; }
body.zen-mode #exit-zen-btn { display: none !important; }

/* MOBILE ADAPTATION (< 1000px) */
@media (max-width: 1000px) {
	/* THE FIX: Force the body into a flex column so panel ordering works */
    body { margin-top: 20px; display: flex; flex-direction: column; align-items: center; }
    #top-nav { flex-wrap: wrap; padding: 10px; gap: 5px; }
    #top-nav .setting-btn { flex: 1 1 45%; font-size: 0.8em; padding: 8px 5px; }
    h1 { position: relative; top: 0; left: 0; transform: none; margin-bottom: 20px; width: 100%; }
	.panel-toggle { display: none !important; }

    /* THE FIX: Cleared the desktop left/right coordinates so they center perfectly */
	/* THE FIX: Removed max-height so the panel can stretch to fit the Settings drawer */
    .left-panel { order: 1; float: none; position: relative; left: auto; margin: 0 auto 20px auto; width: 90%; max-width: 340px; height: auto; max-height: none; z-index: 100; }

    /* THE FIX: Applies the height limit directly to the Inventory so it scrolls smoothly */
    .left-panel .resource-box { max-height: 250px; }
    .right-panel { order: 2; float: none; position: relative; right: auto; width: 90%; max-width: 340px; height: auto; margin: 0 auto 30px auto; z-index: 100; }
    .main-content { order: 3; margin: 0 auto 20px auto; width: 95%; position: relative; float: none; height: auto; z-index: 10; }

    .actions-box { float: none; position: relative; margin: 0 auto 0 auto; width: 100%; box-sizing: border-box; height: auto; max-height: 225px; }

    /* THE FIX: Aligns buttons to the left, leaving a wide, safe scrolling gutter on the right */
    .actions-box button { width: 85%; margin: 8px 0; display: block; }

    .atom-visualization { margin-bottom: 40px; height: 450px; display: flex; justify-content: center; align-items: center; width: 100%; }
    /* THE FIX: Deleted the .atom-grid margin rule so the background stays full-screen on mobile */
    .supernova-text { font-size: 27px; letter-spacing: 7px; width: 100%; text-align: center; }
    body.zen-mode #exit-zen-btn { display: block !important; }
	.settings-drawer { position: static; width: 100%; margin: 10px 0 0 0; transform: none; box-sizing: border-box; display: none; }
    .settings-drawer.settings-open { display: flex; }
    .atom-count-display { right: 15px !important; }
