:root {
    --bg: #0f172a;
    --panel-bg: #1e293b;
    --text: #f8fafc;
    --accent: #38bdf8;
    --success: #34d399;
    --danger: #ef4444;
    --border: #334155;
    --font-ui: 'Fira Code', monospace;
    --font-retro: 'Press Start 2P', cursive;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

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

#game-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    padding: 1rem;
    position: relative;
    z-index: 10;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border);
    margin-bottom: 1rem;
}

h1 {
    font-family: var(--font-retro);
    font-size: 1.2rem;
    color: var(--accent);
    text-shadow: 2px 2px 0px rgba(0,0,0,0.5);
}

.stats {
    display: flex;
    gap: 2rem;
    font-size: 1.1rem;
    font-weight: 600;
}

button {
    background: var(--accent);
    color: #0f172a;
    border: none;
    padding: 0.5rem 1rem;
    font-family: var(--font-ui);
    font-weight: bold;
    cursor: pointer;
    border-radius: 4px;
    transition: transform 0.1s;
    box-shadow: 0 4px 0px #0284c7;
}

button:active {
    transform: translateY(4px);
    box-shadow: 0 0px 0px #0284c7;
}

main {
    display: flex;
    flex: 1;
    gap: 1rem;
    min-height: 0;
}

#editor-panel, #preview-panel {
    background: var(--panel-bg);
    border-radius: 8px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#editor-panel {
    flex: 1;
}

#preview-panel {
    flex: 1;
    padding: 1rem;
    gap: 1rem;
    overflow-y: auto;
}

.panel-header {
    background: #0f172a;
    padding: 0.75rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.panel-header h2 {
    font-size: 1rem;
    color: var(--accent);
}

#codeEditor {
    flex: 1;
    background: #1e293b;
    color: #e2e8f0;
    font-family: 'Fira Code', monospace;
    font-size: 1rem;
    padding: 1rem;
    border: none;
    resize: none;
    outline: none;
}

.target-section, .output-section {
    display: flex;
    flex-direction: column;
    align-items: center;
}

h2 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: var(--text);
}

canvas#targetCanvas, #outputContainer {
    width: 400px;
    height: 300px;
    background: #fff; /* Target base background */
    border-radius: 4px;
    box-shadow: 0 0 15px rgba(0,0,0,0.5);
}

#outputFrame {
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
    pointer-events: none;
}

.controls {
    display: flex;
    justify-content: center;
    margin-top: 1rem;
}

#matchResult {
    text-align: center;
    margin-top: 1rem;
    transition: opacity 0.3s;
    width: 100%;
}

#matchResult.hidden {
    opacity: 0;
    pointer-events: none;
}

.progress-bar {
    width: 100%;
    height: 10px;
    background: var(--border);
    border-radius: 5px;
    overflow: hidden;
    margin-top: 0.5rem;
}

#matchFill {
    height: 100%;
    width: 0%;
    background: var(--success);
    transition: width 0.5s ease-out;
}

/* Modals */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--panel-bg);
    padding: 2rem;
    border-radius: 8px;
    border: 2px solid var(--accent);
    min-width: 300px;
}

.close-btn {
    float: right;
    cursor: pointer;
    font-size: 1.5rem;
    color: var(--danger);
    line-height: 1;
}

#leaderboardList {
    list-style: none;
    margin-top: 1rem;
}

#leaderboardList li {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px dashed var(--border);
}

/* Particles Canvas Layer */
#particleCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 9999;
}

/* Screen Shake (Juice) */
@keyframes shake {
    0% { transform: translate(1px, 1px) rotate(0deg); }
    10% { transform: translate(-1px, -2px) rotate(-1deg); }
    20% { transform: translate(-3px, 0px) rotate(1deg); }
    30% { transform: translate(3px, 2px) rotate(0deg); }
    40% { transform: translate(1px, -1px) rotate(1deg); }
    50% { transform: translate(-1px, 2px) rotate(-1deg); }
    60% { transform: translate(-3px, 1px) rotate(0deg); }
    70% { transform: translate(3px, 1px) rotate(-1deg); }
    80% { transform: translate(-1px, -1px) rotate(1deg); }
    90% { transform: translate(1px, 2px) rotate(0deg); }
    100% { transform: translate(1px, -2px) rotate(-1deg); }
}

.shake {
    animation: shake 0.5s;
}

/* Floating scores */
.floating-score {
    position: absolute;
    color: var(--success);
    font-family: var(--font-retro);
    font-size: 1.5rem;
    pointer-events: none;
    z-index: 10000;
    animation: floatUp 1s ease-out forwards;
}

@keyframes floatUp {
    0% { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-50px) scale(1.5); }
}

@media (max-width: 768px) {
    main {
        flex-direction: column;
        overflow-y: auto;
    }
    .stats {
        font-size: 0.9rem;
    }
    #mobile-controls {
        display: block;
        position: fixed;
        bottom: 1rem;
        right: 1rem;
        z-index: 50;
    }
    #mobile-controls.hidden {
        display: none;
    }
}
