:root {
    --bg-color: #0A0F14;
    --primary-color: #636E72;
    --secondary-color: #B2BEC3;
    --accent-color: #0984E3;
    --accent-glow: rgba(9, 132, 227, 0.4);
    --glass-bg: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
    --text-color: #DFE6E9;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
    --gate-size: 60px;
    --toolbar-height: 80px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

body, html {
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-family);
    overflow: hidden;
}

#game-canvas {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none; /* Let clicks pass through to canvas unless on interactive elements */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: auto;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 10px 20px;
    border: 1px solid var(--glass-border);
    max-width: 600px;
    margin: 0 auto;
}

h1 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent-color);
    text-shadow: 0 0 10px var(--accent-glow);
}

#level-display {
    font-size: 1rem;
    color: var(--secondary-color);
}

button {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-color);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s ease;
    pointer-events: auto;
}

button:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: var(--accent-color);
    box-shadow: 0 0 8px var(--accent-glow);
}

button:active {
    transform: scale(0.95);
}

#toolbar {
    display: flex;
    justify-content: center;
    gap: 10px;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    padding: 10px;
    border-radius: 16px;
    pointer-events: auto;
    margin-bottom: 20px;
    overflow-x: auto;
    max-width: 100%;
    white-space: nowrap;
    scrollbar-width: none; /* Hide scrollbar */
}

#toolbar::-webkit-scrollbar {
    display: none;
}

.gate-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: bold;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid transparent;
}

.gate-btn.selected {
    border-color: var(--accent-color);
    background: var(--accent-glow);
}

#controls {
    position: absolute;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: auto;
}

#controls button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

#modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    pointer-events: auto;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#modal-overlay:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}

#modal-content {
    background: #1e272e;
    padding: 30px;
    border-radius: 16px;
    max-width: 500px;
    width: 90%;
    border: 1px solid var(--glass-border);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    text-align: center;
}

#modal-title {
    margin-bottom: 15px;
    color: var(--accent-color);
}

#modal-body {
    margin-bottom: 20px;
    line-height: 1.6;
    color: var(--secondary-color);
}

#truth-table-panel {
    position: absolute;
    top: 80px; /* Below header */
    right: 20px;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    padding: 15px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    pointer-events: auto;
    max-width: 300px;
    font-size: 0.9rem;
}

#truth-table-panel.hidden {
    display: none;
}

#truth-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

#truth-table th, #truth-table td {
    padding: 5px;
    text-align: center;
    border-bottom: 1px solid var(--glass-border);
}

#truth-table th {
    color: var(--accent-color);
}

.row-success {
    color: #00b894; /* Green */
}

.row-fail {
    color: #ff7675; /* Red */
}

/* Animations */
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(9, 132, 227, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(9, 132, 227, 0); }
    100% { box-shadow: 0 0 0 0 rgba(9, 132, 227, 0); }
}

.pulse {
    animation: pulse 1.5s infinite;
}
