:root {
    --bg-dark: #121212;
    --hud-bg: #1e1e1e;
    --border-col: #444;
    --text-light: #f0f0f0;
    --accent: #ff4757;
    --accent-hover: #ff6b81;
    --primary: #2ed573;
    --primary-hover: #7bed9f;
    --panel-bg: rgba(30, 30, 30, 0.9);
    --font-main: "Courier New", Courier, monospace;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    font-family: var(--font-main);
}

body {
    background-color: var(--bg-dark);
    color: var(--text-light);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#game-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* HUD */
header#hud {
    background: var(--hud-bg);
    border-bottom: 2px solid var(--border-col);
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    z-index: 10;
}

.hud-left h1 {
    font-size: 1.5rem;
    color: var(--primary);
    text-shadow: 2px 2px 0px #000;
}

.hud-right {
    display: flex;
    gap: 15px;
    align-items: center;
}

.score-display {
    font-weight: bold;
    font-size: 1.2rem;
    color: #ffa502;
    margin-right: 10px;
}

.controls button {
    background: var(--border-col);
    color: var(--text-light);
    border: none;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 1rem;
    border-radius: 4px;
    transition: background 0.2s, transform 0.1s;
}

.controls button:hover {
    background: #555;
    transform: translateY(-2px);
}

.controls button:active {
    transform: translateY(1px);
}

/* Main Layout */
main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar Inventory */
aside#inventory {
    width: 250px;
    background: var(--panel-bg);
    border-right: 2px solid var(--border-col);
    display: flex;
    flex-direction: column;
    z-index: 5;
}

aside#inventory h2 {
    padding: 10px;
    text-align: center;
    border-bottom: 1px solid var(--border-col);
    font-size: 1.2rem;
}

.inventory-filters {
    display: flex;
    gap: 2px;
    padding: 5px;
    background: #2f3542;
}

.filter-btn {
    flex: 1;
    background: transparent;
    border: 1px solid var(--border-col);
    color: #ccc;
    cursor: pointer;
    padding: 5px 0;
    font-size: 0.8rem;
}

.filter-btn.active, .filter-btn:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.grid-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 10px;
    overflow-y: auto;
    flex: 1;
}

.element-item {
    background: #2f3542;
    border: 2px solid #57606f;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px 5px;
    cursor: grab;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    touch-action: none; /* Prevent scrolling when dragging */
}

.element-item:hover {
    transform: scale(1.05);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
    border-color: var(--text-light);
}

.element-item:active {
    cursor: grabbing;
    transform: scale(0.95);
}

.element-icon {
    font-size: 2rem;
    margin-bottom: 5px;
    filter: drop-shadow(2px 2px 0px rgba(0,0,0,0.5));
}

.element-name {
    font-size: 0.8rem;
    text-align: center;
    word-break: break-word;
}

/* Sandbox Play Area */
section#sandbox {
    flex: 1;
    position: relative;
    background: repeating-linear-gradient(
        45deg,
        #1a1a1a,
        #1a1a1a 10px,
        #222 10px,
        #222 20px
    );
    overflow: hidden;
}

#gameCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2; /* Below moving draggable DOM elements, but above background */
}

#drop-target-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2rem;
    color: rgba(255,255,255,0.1);
    pointer-events: none;
    text-transform: uppercase;
    letter-spacing: 5px;
    z-index: 1;
}

/* Draggable Element in Sandbox */
/* We'll use DOM elements for items on the board to make dragging simpler */
.board-element {
    position: absolute;
    width: 60px;
    height: 60px;
    background: rgba(47, 53, 66, 0.9);
    border: 2px solid #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grabbing;
    z-index: 10;
    transform: translate(-50%, -50%);
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
    transition: filter 0.2s;
}

.board-element .element-icon {
    margin: 0;
    font-size: 1.8rem;
}

.board-element.dragging {
    z-index: 100;
    box-shadow: 0 10px 25px rgba(0,0,0,0.8);
    opacity: 0.8;
}

/* Modals */
#modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.hidden {
    display: none !important;
}

.modal {
    background: #2f3542;
    border: 4px solid var(--border-col);
    padding: 30px;
    border-radius: 12px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 0 30px rgba(0,0,0,0.8);
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal h2 {
    margin-bottom: 20px;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.modal ul {
    list-style: none;
    text-align: left;
    margin-bottom: 20px;
    max-height: 250px;
    overflow-y: auto;
}

.modal li {
    padding: 8px;
    border-bottom: 1px solid #444;
    display: flex;
    justify-content: space-between;
}

.btn-close {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 10px 20px;
    font-size: 1.1rem;
    cursor: pointer;
    border-radius: 6px;
    font-weight: bold;
    text-transform: uppercase;
}

.btn-close:hover {
    background: var(--accent-hover);
}

/* Discovery Modal Specifics */
.rainbow-text {
    background-image: linear-gradient(to left, violet, indigo, blue, green, yellow, orange, red);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: rainbowAnim 3s linear infinite;
}

@keyframes rainbowAnim {
    0% { filter: hue-rotate(0deg); }
    100% { filter: hue-rotate(360deg); }
}

.big-icon {
    font-size: 5rem;
    margin: 20px 0;
    filter: drop-shadow(0 0 15px rgba(255,255,255,0.4));
    animation: float 2s ease-in-out infinite;
}

@keyframes float {
    0% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
    100% { transform: translateY(0px); }
}

/* Juice Effects */
.shake {
    animation: shakeAnim 0.4s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shakeAnim {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}

/* Floating Text */
.floating-text {
    position: absolute;
    color: #fff;
    font-weight: bold;
    font-size: 1.5rem;
    pointer-events: none;
    z-index: 500;
    text-shadow: 2px 2px 0 #000;
    transition: transform 1s ease-out, opacity 1s ease-in;
}

/* Responsive */
@media (max-width: 768px) {
    main {
        flex-direction: column-reverse; /* Inventory at bottom on mobile */
    }
    aside#inventory {
        width: 100%;
        height: 200px;
        border-right: none;
        border-top: 2px solid var(--border-col);
    }
    .hud-left h1 {
        font-size: 1rem;
    }
    .controls button {
        padding: 4px 8px;
        font-size: 0.9rem;
    }
}
