/* ─── Reset ──────────────────────────────────────────────── */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #f5f5f4;
    --surface: #ffffff;
    --border: #e2e2e0;
    --text: #1c1c1a;
    --muted: #9b9b96;
    --accent: #4f46e5;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
    background: var(--bg);
    color: var(--text);
    height: 100dvh;
    overflow: hidden;
}

/* ─── Layout ─────────────────────────────────────────────── */
#container {
    display: flex;
    width: 100vw;
    height: 100dvh;
}

#left {
    flex: 1;
    min-width: 0;
}

#right {
    display: flex;
    flex-direction: column;
    width: 33.333%;
    flex-shrink: 0;
    height: 100%;
    background: var(--surface);
    border-left: 1px solid var(--border);
}

/* ─── Canvas ─────────────────────────────────────────────── */
#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    background: #47aba9 url('../img/background.png');
    background-size: 100% auto;
    background-repeat: repeat-y;
    background-position: top;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* ─── Level title ────────────────────────────────────────── */
#level-title {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 14px 18px 12px;
    border-bottom: 1px solid var(--border);
}

/* ─── Toolbox ────────────────────────────────────────────── */
#toolbox {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}

#toolbox h3 {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 10px;
}

#toolbox-blocks {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* ─── Workspace ──────────────────────────────────────────── */
#workspace {
    padding: 14px 18px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    overflow: hidden;
}

#workspace>div:first-child {
    display: flex;
    align-items: center;
    gap: 8px;
}

#workspace h3 {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
}

#program-status {
    font-size: 11px;
    font-weight: 500;
    color: var(--accent);
}

/* ─── Dropzone ───────────────────────────────────────────── */
#dropzone {
    flex: 1;
    min-height: 0;
    border: 1.5px dashed var(--border);
    border-radius: 8px;
    padding: 8px;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    gap: 5px;
    overflow-y: auto;
    transition: border-color 0.15s;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    position: relative;
}

#dropzone.locked {
    pointer-events: none;
}

#dropzone:empty::before {
    content: 'Drop blocks here';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 13px;
    pointer-events: none;
}

#dropzone.drag-over {
    border-color: var(--accent);
    background: #eef2ff;
}

/* ─── Blocks ─────────────────────────────────────────────── */
.block {
    display: flex;
    flex-direction: column;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    cursor: grab;
    user-select: none;
    transition: box-shadow 0.12s, transform 0.12s;
}

.block:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transform: translateY(-1px);
}

.block:active {
    cursor: grabbing;
    transform: scale(0.98);
}

.block-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 10px;
}

.block-label {
    display: block;
    padding: 7px 0;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}

.block-times-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
}

.block-progress {
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
}

.block-count-input {
    width: 42px;
    padding: 3px 5px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    color: var(--accent);
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    border-radius: 4px;
    text-align: center;
    cursor: text;
    /* Hide the spinners for a cleaner look */
    -moz-appearance: textfield;
}

select.block-count-input {
    width: 52px;
    cursor: pointer;
    text-align-last: center;
    padding-right: 2px;
}

.block-count-input::-webkit-outer-spin-button,
.block-count-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

#toolbox-blocks .block-count-input {
    pointer-events: none;
}

.block-count-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.15);
}

.block.highlighted>.block-header {
    background-color: #eef2ff;
    border-radius: 5px;
}

.block.highlighted>.block-header>.block-label,
.block.highlighted>.block-header>.block-progress {
    color: var(--accent);
}

/* Inner dropzone (while block) */
.block-inner-dropzone {
    min-height: 30px;
    margin: 0 8px 6px 8px;
    border: 1px dashed var(--border);
    border-radius: 5px;
    padding: 5px;
    background: var(--bg);
    display: none;
    flex-direction: column;
    gap: 4px;
}

#dropzone .block-inner-dropzone {
    display: flex;
}

.block-placeholder {
    opacity: 0.4 !important;
    pointer-events: none !important;
    transform: none !important;
}

.block.dragging {
    display: none !important;
}

/* ─── Controls ───────────────────────────────────────────── */
#controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

button {
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
    cursor: pointer;
    background: var(--surface);
    color: var(--text);
    transition: background 0.12s;
}

button:hover {
    background: var(--bg);
}

button:active {
    opacity: 0.8;
}

/* Primary – Run */
#run-btn {
    grid-column: 1 / -1;
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

#run-btn:hover {
    background: #4338ca;
    border-color: #4338ca;
}

/* ─── Modals ─────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-overlay.hidden {
    display: none;
}

.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 32px 28px;
    text-align: center;
    max-width: 380px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

.modal-content h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
    letter-spacing: -0.01em;
}

.modal-content p {
    font-size: 14px;
    color: var(--muted);
    margin-bottom: 24px;
    line-height: 1.6;
}

.modal-content button {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    padding: 10px 28px;
    font-size: 14px;
}

.modal-content button:hover {
    background: #4338ca;
}

.promo-text {
    margin-top: 16px;
    margin-bottom: 16px;
    line-height: 1.5;
}

.promo-btn {
    display: inline-block;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    padding: 10px 28px;
    border-radius: 6px;
    text-decoration: none;
    background: var(--accent);
    color: #fff;
    border: 1px solid var(--accent);
    transition: background 0.12s, transform 0.12s;
    margin-top: 8px;
}

.promo-btn:hover {
    background: #4338ca;
    border-color: #4338ca;
    transform: translateY(-1px);
}

.promo-btn:active {
    transform: scale(0.98);
}