/* root styles */
:root {
    --page: #1f2a36;
    --frame: #c8312b;
    --frame-dark: #9c2420;
    --screen: #c7cac6;
    --ink: #262626;
    --knob: #f3efe8;
    --text: #ffffff;
}

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

body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem 1rem 2.5rem;
    background: var(--page);
    color: var(--text);
    font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

/* Red frame */
.toy {
    width: min(100%, 680px);
    padding: 1.25rem 1.5rem 1.5rem;
    background: var(--frame);
    border-radius: 18px;
    box-shadow: 0 10px 0 var(--frame-dark), 0 24px 40px rgba(0, 0, 0, 0.35);
}

.brand {
    margin-bottom: 1rem;
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-align: center;
}

/* Screen */
.screen-wrap {
    padding: 14px;
    background: var(--frame-dark);
    border-radius: 10px;
    box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.4);
}

.grid {
    --n: 16;
    display: grid;
    grid-template-columns: repeat(var(--n), 1fr);
    grid-template-rows: repeat(var(--n), 1fr);
    width: 100%;
    aspect-ratio: 1;
    background: var(--screen);
    border-radius: 4px;
    cursor: crosshair;
    touch-action: none;
    overflow: hidden;
}

.grid.show-lines .cell {
    outline: 1px solid rgba(0, 0, 0, 0.14);
    outline-offset: -0.5px;
}

/* Controls */
.controls {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    margin-top: 1.5rem;
}

.knob {
    flex: none;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #ffffff, var(--knob) 55%, #cfc9be);
    box-shadow: 0 4px 0 rgba(0, 0, 0, 0.28);
}

.panel {
    flex: 1;
    display: grid;
    gap: 0.9rem;
    min-width: 0;
}

.field {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.field label {
    font-size: 0.95rem;
    white-space: nowrap;
}

.field input[type="range"] {
    flex: 1;
    min-width: 0;
    accent-color: var(--knob);
}

#size-label {
    min-width: 5.5ch;
    font-size: 0.95rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.modes {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

button {
    padding: 0.5rem 0.9rem;
    border: 2px solid var(--knob);
    border-radius: 999px;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

button:hover {
    background: rgba(255, 255, 255, 0.18);
}

.mode-btn[aria-pressed="true"] {
    background: var(--knob);
    color: var(--frame-dark);
    font-weight: 700;
}

.actions {
    justify-content: space-between;
    flex-wrap: wrap;
}

.check {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.check input {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: var(--knob);
}

.clear-btn {
    background: var(--knob);
    color: var(--frame-dark);
    font-weight: 700;
}

.clear-btn:hover {
    background: #ffffff;
}

:focus-visible {
    outline: 3px solid #ffffff;
    outline-offset: 3px;
}

.toy.shake {
    animation: shake 0.45s ease-in-out;
}

@keyframes shake {

    0%,
    100% {
        transform: translate(0, 0) rotate(0);
    }

    15% {
        transform: translate(-10px, 3px) rotate(-1.5deg);
    }

    30% {
        transform: translate(9px, -3px) rotate(1.5deg);
    }

    45% {
        transform: translate(-8px, 2px) rotate(-1deg);
    }

    60% {
        transform: translate(7px, -2px) rotate(1deg);
    }

    80% {
        transform: translate(-3px, 1px) rotate(-0.5deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .toy.shake {
        animation: none;
    }
}

@media (max-width: 560px) {
    .toy {
        padding: 1rem;
    }

    .knob {
        display: none;
    }

    .brand {
        font-size: 1.3rem;
    }
}