:root {
    --bg: #181818;
    --panel: #212121;
    --panel-2: #303030;
    --text: #ddeace;
    --muted: #aeb8a7;
    --accent: #fa423e;
    --border: #3d3d3d;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
}

main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

h1 {
    margin: 0 0 0.35rem;
    font-size: clamp(1.8rem, 4vw, 3rem);
    line-height: 1;
}

.lede {
    margin: 0 0 1rem;
    color: var(--muted);
}

.app {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 1rem;
    align-items: start;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    padding: 1rem;
}

.controls {
    position: sticky;
    top: 1rem;
}

.control {
    margin-bottom: 1rem;
}

label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 700;
}

input[type="file"],
input[type="number"],
input[type="range"],
input[type="color"],
button {
    width: 100%;
}

input[type="number"],
input[type="file"] {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 0.55rem;
}

input[type="range"] {
    accent-color: var(--accent);
}

input[type="color"] {
    height: 2.5rem;
    background: var(--panel-2);
    border: 1px solid var(--border);
    padding: 0.2rem;
}

.row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.75rem;
    align-items: center;
}

.value {
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    min-width: 4.5rem;
    text-align: right;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.check-row input {
    width: auto;
}

button {
    border: 0;
    background: var(--accent);
    color: white;
    padding: 0.75rem 1rem;
    font-weight: 800;
    cursor: pointer;
}

button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.stats {
    background: var(--panel-2);
    border: 1px solid var(--border);
    padding: 0.75rem;
    font-size: 0.95rem;
    line-height: 1.4;
}

.preview-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.preview h2 {
    margin: 0 0 0.5rem;
    font-size: 1rem;
}

.image-box {
    min-height: 260px;
    background:
        linear-gradient(45deg, #222 25%, transparent 25%),
        linear-gradient(-45deg, #222 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #222 75%),
        linear-gradient(-45deg, transparent 75%, #222 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0;
    border: 1px solid var(--border);
    display: grid;
    place-items: center;
    overflow: auto;
}

.image-box img {
    max-width: 100%;
    height: auto;
    display: block;
}

.image-box canvas {
    max-width: none;
    width: auto;
    height: auto;
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.empty {
    color: var(--muted);
    padding: 1rem;
    text-align: center;
}

.note {
    color: var(--muted);
    font-size: 0.9rem;
    margin-top: 1rem;
}

@media (max-width: 850px) {
    .app,
    .preview-grid {
        grid-template-columns: 1fr;
    }

    .controls {
        position: static;
    }
}
