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

:root {
    --frame: #c0392b;
    --frame-dark: #962d22;
    --screen: #e9ecef;
    --text: #fdf6f0;
    --knob: #f4f1ec;
}

body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 16px;
    background: #2b2d31;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    color: var(--text);
}

.toy {
    width: min(560px, 100%);
    padding: 20px 22px 24px;
    background: var(--frame);
    border-radius: 22px;
    box-shadow: inset 0 -6px 0 var(--frame-dark), 0 18px 40px rgba(0, 0, 0, 0.45);
}

.toy__title {
    font-size: 1.4rem;
    letter-spacing: 0.04em;
    text-align: center;
    margin-bottom: 14px;
    font-style: italic;
}

/* the grid is always square and fills the "screen" of the toy */
.board {
    --size: 16;
    display: grid;
    grid-template-columns: repeat(var(--size), 1fr);
    aspect-ratio: 1;
    width: 100%;
    background: var(--screen);
    border-radius: 8px;
    overflow: hidden;
    touch-action: none; /* lets a finger draw instead of scrolling the page */
    user-select: none;
}

.square {
    background-color: var(--screen);
    outline: 1px solid rgba(0, 0, 0, 0.04);
}

.controls {
    margin-top: 18px;
    display: flex;
    flex-wrap: wrap;
    gap: 14px 20px;
    align-items: center;
    justify-content: space-between;
}

.size {
    display: grid;
    gap: 6px;
    font-size: 0.9rem;
    flex: 1 1 180px;
}

.size input {
    accent-color: var(--knob);
}

.modes {
    border: 0;
    display: flex;
    gap: 12px;
    font-size: 0.9rem;
}

.modes legend {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

.btn {
    padding: 10px 16px;
    border: 0;
    border-radius: 999px;
    background: var(--knob);
    color: #5a1d16;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
}

.btn:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}

.btn:focus-visible,
.size input:focus-visible,
.modes input:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 2px;
}

.shake {
    animation: shake 0.4s;
}

@keyframes shake {
    20% { transform: translateX(-6px) rotate(-1deg); }
    40% { transform: translateX(6px) rotate(1deg); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

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

/* the screen holds the grid and a hint that fades out after the first stroke */
.screen {
    position: relative;
}

.hint {
    position: absolute;
    left: 50%;
    bottom: 12px;
    transform: translateX(-50%);
    width: max-content;
    max-width: calc(100% - 24px);
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(20, 20, 20, 0.72);
    color: #fff;
    font-size: 0.82rem;
    text-align: center;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.hint.is-hidden {
    opacity: 0;
}
