/* ==========================================================================
   Etch A Sketch
   A nod to the physical toy: red frame, pale screen, knobs along the bottom.
   ========================================================================== */

:root {
    --paper:   #f5f2ec;
    --ink:     #1b1a16;
    --muted:   #6a665c;
    --rule:    #ddd6c7;
    --frame:   #c8452f;
    --frame-2: #a8351f;
    --screen:  #fbf9f4;

    --font: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

body {
    min-height: 100svh;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

:focus-visible {
    outline: 2px solid var(--frame);
    outline-offset: 2px;
    border-radius: 3px;
}

.page {
    max-width: 44rem;
    margin-inline: auto;
    padding: clamp(1.5rem, 5vw, 3.5rem) clamp(1rem, 4vw, 2rem) 3rem;
    display: flex;
    flex-direction: column;
    gap: clamp(1.5rem, 4vw, 2.25rem);
}

/* --- Intro ---------------------------------------------------------------- */

.intro h1 {
    font-size: clamp(1.75rem, 1.4rem + 1.6vw, 2.5rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.intro p {
    margin-top: 0.5rem;
    max-width: 46ch;
    color: var(--muted);
}

/* --- The device ----------------------------------------------------------- */

.device {
    background: linear-gradient(180deg, var(--frame) 0%, var(--frame-2) 100%);
    border-radius: 20px;
    padding: clamp(0.875rem, 3vw, 1.5rem);
    padding-bottom: 0.5rem;
    box-shadow: 0 12px 28px rgba(27, 26, 22, 0.18);
}

.screen {
    background: var(--screen);
    border-radius: 8px;
    padding: 6px;
    box-shadow: inset 0 2px 6px rgba(27, 26, 22, 0.22);
}

.grid {
    display: grid;
    aspect-ratio: 1 / 1;
    width: 100%;
    /* Stops a drag on the canvas scrolling the page on touch devices. */
    touch-action: none;
    background: var(--screen);
    cursor: crosshair;
}

.cell { background-color: transparent; }

/* Hairlines drawn with a shared border so they don't double up between cells. */
.grid.show-lines .cell {
    border-right: 1px solid rgba(27, 26, 22, 0.07);
    border-bottom: 1px solid rgba(27, 26, 22, 0.07);
}

.knobs {
    display: flex;
    justify-content: space-between;
    padding: 0.625rem 0.25rem 0.5rem;
}

.knob {
    width: clamp(1.5rem, 5vw, 2rem);
    aspect-ratio: 1;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #fdfcfa, #d9d2c6 60%, #b3aa9b);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
}

/* --- Controls ------------------------------------------------------------- */

.controls {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 1rem 1.5rem;
}

.control {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    border: 0;
    padding: 0;
    margin: 0;
    min-width: 0;
}

.control label,
.control legend {
    font-family: var(--mono);
    font-size: 0.6875rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 0;
}

.value { color: var(--ink); }

.control--modes { flex: 0 0 auto; }

.segmented {
    display: inline-flex;
    border: 1px solid var(--rule);
    border-radius: 999px;
    background: #fff;
    overflow: hidden;
}

.segmented button {
    appearance: none;
    border: 0;
    background: none;
    padding: 0.5rem 0.9rem;
    font: inherit;
    font-size: 0.8125rem;
    color: var(--muted);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.segmented button + button { border-left: 1px solid var(--rule); }

.segmented button:hover { color: var(--ink); }

.segmented button[aria-checked='true'] {
    background: var(--frame);
    color: #fff;
}

.control--checkbox {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}

.control--checkbox label { text-transform: none; letter-spacing: 0.02em; font-size: 0.8125rem; }

input[type='color'] {
    width: 3rem;
    height: 2.25rem;
    padding: 2px;
    border: 1px solid var(--rule);
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
}

input[type='range'] {
    width: clamp(8rem, 30vw, 12rem);
    accent-color: var(--frame);
    cursor: pointer;
}

input[type='checkbox'] { accent-color: var(--frame); width: 1rem; height: 1rem; cursor: pointer; }

.btn {
    padding: 0.55rem 1.1rem;
    border: 1px solid var(--ink);
    border-radius: 999px;
    background: var(--ink);
    color: var(--paper);
    font: inherit;
    font-size: 0.8125rem;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.btn:hover { background: var(--frame); border-color: var(--frame); }

.btn--ghost {
    background: none;
    color: var(--ink);
    border-color: var(--rule);
}

.btn--ghost:hover { background: none; border-color: var(--frame); color: var(--frame); }

.control--actions { flex-direction: row; gap: 0.5rem; }

/* --- Credit --------------------------------------------------------------- */

.credit {
    border-top: 1px solid var(--rule);
    padding-top: 1.25rem;
    font-size: 0.8125rem;
    color: var(--muted);
}

.credit a { color: inherit; text-underline-offset: 2px; }
.credit a:hover { color: var(--frame); }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition-duration: 0.01ms !important; }
}
