/*
    app.css: the pixie look, 8-bit. Hard black outlines, offset shadows instead of blur, square corners,
    pixel fonts (Press Start 2P for labels, Pixelify Sans for reading) and accents from the NES palette.
*/

:root {
    --ink: #1c1030;
    --paper: #fcfcfc;
    --bg: #fce0a8;          /* NES $37 */
    --grid: rgba(28, 16, 48, 0.07);
    --accent: #e40058;      /* NES $15 */
    --pink: #f85898;        /* NES $25 */
    --blue: #0058f8;        /* NES $12 */
    --sky: #3cbcfc;         /* NES $21 */
    --green: #00a800;       /* NES $1A */
    --yellow: #f8b800;      /* NES $28 */
    --cream: #f8d878;       /* NES $38 */
    --muted: #6a5d7b;
    --line: 3px;
    --shadow: 4px 4px 0 var(--ink);
    --shadow-big: 6px 6px 0 var(--ink);
    --px: "Press Start 2P", ui-monospace, monospace;
    --body: "Pixelify Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
    --bottom-h: 64px;
    --top-h: 60px;
    color-scheme: light;
}

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

html {
    -webkit-text-size-adjust: 100%;
    /* Focusing or scrolling to something keeps it clear of the sticky top bar and the bottom bar. */
    scroll-padding-top: calc(120px + env(safe-area-inset-top));
    scroll-padding-bottom: calc(var(--bottom-h) + 40px + env(safe-area-inset-bottom));
}

body {
    margin: 0;
    min-height: 100vh;
    font: 500 17px/1.45 var(--body);
    /* Pixelify Sans draws "fi" as one glyph that reads like an F. */
    font-variant-ligatures: none;
    color: var(--ink);
    background-color: var(--bg);
    /* Graph paper. */
    background-image:
        linear-gradient(var(--grid) 2px, transparent 2px),
        linear-gradient(90deg, var(--grid) 2px, transparent 2px);
    background-size: 32px 32px;
    padding-bottom: calc(var(--bottom-h) + 24px + env(safe-area-inset-bottom));
}

body.locked {
    overflow: hidden;
}

img {
    max-width: 100%;
}

a {
    color: var(--blue);
    text-underline-offset: 3px;
    text-decoration-thickness: 2px;
}

h1,
h2,
h3 {
    font-family: var(--px);
    font-weight: 400;
    line-height: 1.5;
    letter-spacing: 0;
}

h1 { font-size: 15px; margin: 0; }
h2 { font-size: 12px; margin: 0; }
h3 { font-size: 10px; margin: 1.6rem 0 .6rem; }

small { font-size: .85em; }

button,
input,
textarea,
select {
    font: inherit;
    color: inherit;
}

button {
    cursor: pointer;
}

svg {
    fill: currentColor;
    shape-rendering: crispEdges;
}

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

[hidden] {
    display: none !important;
}

/* ---------------------------------------------------------- buttons */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 10px 16px;
    border: var(--line) solid var(--ink);
    border-radius: 0;
    background: var(--paper);
    color: var(--ink);
    font: 400 11px/1.3 var(--px);
    text-decoration: none;
    box-shadow: var(--shadow);
    transition: transform 60ms steps(2), box-shadow 60ms steps(2);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.btn:hover { background: #fff; }
.btn:active:not(:disabled):not([aria-disabled="true"]) { transform: translate(4px, 4px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { opacity: .45; cursor: default; }
/* A button at work keeps focus (setWorking() in js/app.js), so it is aria-disabled, not disabled. */
.btn[aria-disabled="true"]:not(.busy) { opacity: .45; cursor: default; }
.btn svg { width: 15px; height: 15px; flex: none; }

.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: #f8306f; }
.btn.danger { color: var(--accent); }
.btn.small { min-height: 36px; padding: 7px 11px; font-size: 9px; box-shadow: 3px 3px 0 var(--ink); }
.btn.small:active:not(:disabled):not([aria-disabled="true"]) { transform: translate(3px, 3px); }
.btn.icon-only { padding: 7px 9px; }
.btn.wide { width: 100%; }
.btn.following { background: var(--cream); }

.icon-btn {
    position: relative;
    display: inline-grid;
    place-items: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    -webkit-tap-highlight-color: transparent;
}

.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: rgba(28, 16, 48, .08); }
.icon-btn.small { width: 34px; height: 34px; }
.icon-btn.small svg { width: 15px; height: 15px; }
.icon-btn:disabled { opacity: .4; cursor: default; }

.link-btn {
    padding: 0;
    border: 0;
    background: none;
    color: var(--blue);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 2px;
    font: inherit;
}

.spacer { flex: 1; }
.flip-x { transform: scaleX(-1); }
.rot-90 { transform: rotate(90deg); }
.rot-180 { transform: rotate(180deg); }
.rot-270 { transform: rotate(270deg); }

.badge {
    position: absolute;
    top: 3px;
    right: 1px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    display: grid;
    place-items: center;
    background: var(--accent);
    color: #fff;
    border: 2px solid var(--ink);
    font: 400 8px/1 var(--px);
}

/* ---------------------------------------------------------- avatars (8 x 8 critters) */

.avatar {
    display: block;
    flex: none;
    width: 40px;
    height: 40px;
    border: var(--line) solid var(--ink);
    background: var(--paper);
    image-rendering: pixelated;
    object-fit: cover;
}

.avatar.xs { width: 26px; height: 26px; border-width: 2px; }
.avatar.sm { width: 34px; height: 34px; }
.avatar.xl { width: 80px; height: 80px; border-width: 4px; box-shadow: var(--shadow); }

/* ---------------------------------------------------------- top bar */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: calc(var(--top-h) + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
    background: var(--ink);
    color: var(--paper);
    border-bottom: 4px solid #000;
}

.logo {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: inherit;
    text-decoration: none;
    font: 400 18px/1 var(--px);
    letter-spacing: 1px;
}

.logo img {
    width: 32px;
    height: 32px;
    image-rendering: pixelated;
}

.topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 4px;
}

.topbar .icon-btn:hover { background: rgba(255, 255, 255, .12); }

.me-btn {
    padding: 0;
    border: 0;
    background: none;
    margin-left: 4px;
}

.me-btn .avatar { border-color: var(--paper); }

/* ---------------------------------------------------------- view tabs */

.tabs {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 16px max(14px, env(safe-area-inset-left)) 14px;
    scrollbar-width: none;
    max-width: 760px;
    margin: 0 auto;
}

.tabs::-webkit-scrollbar { display: none; }

.tabs a {
    flex: none;
    padding: 9px 11px;
    border: var(--line) solid var(--ink);
    background: var(--paper);
    color: var(--ink);
    font: 400 9px/1.2 var(--px);
    text-decoration: none;
    box-shadow: 3px 3px 0 var(--ink);
    white-space: nowrap;
}

.tabs a:hover { background: #fff; }

.tabs a[aria-current="page"] {
    background: var(--yellow);
    transform: translate(3px, 3px);
    box-shadow: 0 0 0 var(--ink);
}

/* On a wide screen every view fits: no sideways scrolling. */
@media (min-width: 720px) {
    .tabs {
        flex-wrap: wrap;
        justify-content: center;
        overflow: visible;
    }
}

/* ---------------------------------------------------------- feed */

.feed-wrap {
    width: min(540px, 100%);
    margin: 0 auto;
    padding: 4px 16px 0;
}

.view-head {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 40px;
    margin: 6px 0 18px;
}

.view-head h1 {
    flex: 1;
    overflow-wrap: anywhere;
}

.empty {
    margin: 2rem 0;
    padding: 22px 18px;
    border: var(--line) dashed var(--ink);
    background: rgba(252, 252, 252, .7);
    text-align: center;
    color: var(--muted);
}

#fetchMoreButton { margin: 8px 0 24px; }

/* A pixie */
.post {
    margin: 0 0 30px;
    background: var(--paper);
    border: 4px solid var(--ink);
    box-shadow: var(--shadow-big);
}

.post-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 8px 10px 12px;
    border-bottom: var(--line) solid var(--ink);
}

.post-who {
    flex: 1;
    min-width: 0;
    display: grid;
}

.uploader {
    justify-self: start;
    max-width: 100%;
    padding: 0;
    border: 0;
    background: none;
    font: 700 17px/1.25 var(--body);
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.uploader:hover { text-decoration: underline; text-underline-offset: 3px; }
.post-who small { color: var(--muted); }

.art {
    position: relative;
    background: #fcfcfc;
    border-bottom: var(--line) solid var(--ink);
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.art img {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    image-rendering: crisp-edges;
    image-rendering: pixelated;
}

.private-tag {
    position: absolute;
    top: 10px;
    left: 10px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    background: var(--ink);
    color: var(--paper);
    font: 400 8px/1 var(--px);
}

.private-tag svg { width: 10px; height: 10px; }

/* "Keep your drawing?" over the studio */
.panel.draft-dialog { z-index: 70; align-items: center; padding: 16px; }
/* ".panel-card" (later in this file) would win over a plain class. */
.panel-card.dialog-card {
    width: min(380px, 100%);
    max-height: none;
    padding: 22px 20px 18px;
    border: 4px solid var(--ink);
    box-shadow: 8px 8px 0 #000;
    text-align: center;
}
.dialog-card h2 { margin: 0 0 14px; }
.dialog-art {
    width: 120px;
    margin: 0 auto 14px;
    border: var(--line) solid var(--ink);
    box-shadow: var(--shadow);
    background: repeating-conic-gradient(#e8e4f0 0 25%, #fcfcfc 0 50%) 0 0 / 15px 15px;
    line-height: 0;
}
.dialog-art img { width: 100%; aspect-ratio: 1; image-rendering: pixelated; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 6px; }
.dialog-cancel { margin-top: 16px; }

/* The Frames editor */
.frame-list {
    list-style: none;
    margin: 0 0 18px;
    padding: 0;
    display: grid;
    gap: 8px;
}

.frame-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
    border: 2px solid var(--ink);
    background: var(--paper);
}

.frame-row img {
    flex: none;
    width: 48px;
    height: 48px;
    image-rendering: pixelated;
    border: 2px solid var(--ink);
    background: repeating-conic-gradient(#e8e4f0 0 25%, #fcfcfc 0 50%) 0 0 / 12px 12px;
}

.frame-row > div { flex: 1; min-width: 0; display: grid; }
.frame-row strong { font: 400 9px/1.6 var(--px); }
.frame-row small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.frame-tools { display: inline-flex; gap: 6px; }
.frame-tools .btn.small { min-height: 34px; }

/* Remix animation: frame number and who drew it. */
.frame-badge {
    position: absolute;
    left: 10px;
    bottom: 10px;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    max-width: calc(100% - 20px);
    padding: 7px 9px;
    border: 2px solid var(--paper);
    background: var(--ink);
    color: var(--paper);
    box-shadow: 0 0 0 2px var(--ink);
    font: 400 9px/1 var(--px);
    -webkit-tap-highlight-color: transparent;
}

.frame-badge svg { width: 10px; height: 10px; flex: none; }
.frame-badge.own { background: var(--accent); }
.frame-by {
    font: 600 14px/1 var(--body);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.heart-burst {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    pointer-events: none;
    color: var(--accent);
    opacity: 0;
}

.heart-burst svg {
    width: 30%;
    height: 30%;
    filter: drop-shadow(4px 4px 0 var(--ink));
}

.heart-burst.go { animation: burst 700ms steps(6) forwards; }

@keyframes burst {
    0% { opacity: 1; transform: scale(.4); }
    40% { opacity: 1; transform: scale(1.1); }
    70% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(1.2); }
}

.post-body { padding: 8px 14px 14px; }

.actions {
    display: flex;
    align-items: center;
    gap: 2px;
    margin: 0 -6px 2px;
}

.actions { flex-wrap: wrap; row-gap: 8px; }
.actions .btn.small { margin-right: 6px; white-space: nowrap; }

/*
    Frames (the first pixie's maker, when it has remixes) sits right before Remix; ▶ Remixes is on the art. On a
    narrow phone the row is packed tighter so it stays on one line: Frames and Remix drop their icons, and below
    360px Frames is its icon alone.
*/
@media (max-width: 430px) {
    .actions.with-frames .icon-btn { width: 40px; }
    .actions.with-frames .btn.small { padding: 7px; margin-right: 4px; }
    .actions.with-frames .btn.small svg { display: none; }
}

@media (max-width: 359px) {
    .actions.with-frames .btn.small.frames-edit svg { display: block; }
    .actions.with-frames .frames-edit .label { display: none; }
}
.like[aria-pressed="true"] { color: var(--accent); }

.likes-line {
    margin: 0 0 4px;
    font-weight: 700;
}

.caption {
    margin: 0 0 6px;
    overflow-wrap: anywhere;
}

.caption.no-text { display: none; }
.cap-name { margin-right: 8px; }

.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 10px;
    margin: 0 0 6px;
}

.tags a { font-weight: 600; }

.comments-block {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 2px dashed rgba(28, 16, 48, .3);
}

.comments-block h3 { margin: 0 0 8px; font-size: 8px; color: var(--muted); }

.comments {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 10px;
}

.comments li {
    display: flex;
    gap: 9px;
    align-items: flex-start;
}

.comments p {
    margin: 0;
    overflow-wrap: anywhere;
    line-height: 1.35;
}

.comments strong { margin-right: 6px; }
.comments time { font-size: 13px; color: var(--muted); }
.more-comments { margin: 8px 0 0; }

.inline-form {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.inline-form input {
    flex: 1;
    min-width: 0;
    margin: 0;
    padding: 9px 11px;
    font-size: 16px;
}

.inline-form button {
    padding: 0 12px;
    border: var(--line) solid var(--ink);
    background: var(--yellow);
    font: 400 9px/1 var(--px);
    box-shadow: 3px 3px 0 var(--ink);
}

.inline-form button:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: none; }
.inline-form button:disabled { opacity: .5; }

/* ---------------------------------------------------------- forms */

form label {
    display: block;
    margin: 0 0 16px;
    font-weight: 700;
}

form label small {
    font-weight: 500;
    color: var(--muted);
}

input[type="text"],
input[type="email"],
input[type="password"],
textarea {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 11px 12px;
    border: var(--line) solid var(--ink);
    border-radius: 0;
    background: #fff;
    font: 500 18px/1.35 var(--body);
    box-shadow: inset 3px 3px 0 rgba(28, 16, 48, .08);
    -webkit-appearance: none;
    appearance: none;
}

textarea {
    min-height: 92px;
    resize: vertical;
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px var(--sky);
}

.switch {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    font-weight: 500;
}

.switch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.switch-ui {
    position: relative;
    flex: none;
    width: 52px;
    height: 28px;
    border: var(--line) solid var(--ink);
    background: var(--paper);
}

.switch-ui::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    background: var(--ink);
    transition: transform 120ms steps(3);
}

.switch input:checked + .switch-ui { background: var(--green); }
.switch input:checked + .switch-ui::after { transform: translateX(24px); background: var(--paper); box-shadow: 0 0 0 2px var(--ink); }
.switch input:focus-visible + .switch-ui { outline: 3px solid var(--blue); outline-offset: 2px; }

.hint {
    color: var(--muted);
    font-size: 15px;
    margin: 0 0 10px;
}

/* ---------------------------------------------------------- bottom bar */

.bottombar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: center;
    height: calc(var(--bottom-h) + env(safe-area-inset-bottom));
    padding: 0 max(6px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(6px, env(safe-area-inset-left));
    background: var(--ink);
    color: var(--paper);
    border-top: 4px solid #000;
}

.bottombar > a,
.bottombar > button {
    position: relative;
    justify-self: center;
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    -webkit-tap-highlight-color: transparent;
}

.bottombar svg { width: 20px; height: 20px; }
.bottombar > a[aria-current="page"] { color: var(--yellow); }
.bottombar > a[aria-current="page"]::after {
    content: "";
    position: absolute;
    bottom: 4px;
    width: 6px;
    height: 6px;
    background: var(--yellow);
}

.bottombar .avatar { border-color: var(--paper); }

.bottombar .paint {
    width: 62px;
    height: 62px;
    margin-top: -26px;
    background: var(--accent);
    color: #fff;
    border: 4px solid var(--paper);
    box-shadow: 0 0 0 4px #000, 6px 6px 0 4px #000;
}

.bottombar .paint svg { width: 30px; height: 30px; }
.bottombar .paint:active { transform: translate(3px, 3px); }

@media (min-width: 720px) {
    .bottombar {
        left: 50%;
        right: auto;
        bottom: 16px;
        width: 440px;
        transform: translateX(-50%);
        height: var(--bottom-h);
        padding: 0 8px;
        border: 4px solid #000;
        box-shadow: 6px 6px 0 rgba(28, 16, 48, .35);
    }
    body { padding-bottom: calc(var(--bottom-h) + 48px); }
}

/* ---------------------------------------------------------- full screen sheets: studio and compose */

.sheet {
    position: fixed;
    inset: 0;
    z-index: 50;
    overflow-y: auto;
    overscroll-behavior: contain;
    background-color: var(--bg);
    background-image:
        linear-gradient(var(--grid) 2px, transparent 2px),
        linear-gradient(90deg, var(--grid) 2px, transparent 2px);
    background-size: 32px 32px;
}

.sheet.compose { z-index: 60; }

.sheet-head {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: calc(var(--top-h) + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
    background: var(--ink);
    color: var(--paper);
    border-bottom: 4px solid #000;
}

.sheet-head h2 { flex: 1; }
.sheet-head h2 small { font-size: 9px; color: var(--yellow); margin-left: 6px; }
.sheet-head .icon-btn:hover { background: rgba(255, 255, 255, .12); }
.sheet-head .btn { box-shadow: 3px 3px 0 #000; border-color: #000; }

/* The studio */
.studio-body {
    display: grid;
    gap: 16px;
    width: min(520px, 100%);
    margin: 0 auto;
    padding: 16px 16px calc(28px + env(safe-area-inset-bottom));
}

.remix-note {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0;
    padding: 8px 12px;
    background: var(--cream);
    border: var(--line) solid var(--ink);
    font-weight: 600;
}

.remix-note svg { width: 15px; height: 15px; }

.canvas-frame {
    justify-self: center;
    width: min(100%, 520px, calc(100svh - 330px));
    min-width: min(100%, 280px);
    border: 4px solid var(--ink);
    box-shadow: var(--shadow-big);
    background: var(--paper);
    line-height: 0;
}

#pixelCanvas {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    image-rendering: pixelated;
    touch-action: none;
    cursor: crosshair;
}

#pixelCanvas[data-tool="fill"] { cursor: cell; }
#pixelCanvas[data-tool="picker"] { cursor: copy; }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px 14px;
}

.tool-group {
    display: flex;
    gap: 6px;
}

.tool {
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 5px;
    width: 54px;
    height: 54px;
    padding: 0;
    border: var(--line) solid var(--ink);
    background: var(--paper);
    box-shadow: 3px 3px 0 var(--ink);
    -webkit-tap-highlight-color: transparent;
}

.tool svg { width: 20px; height: 20px; }
.tool span { font: 400 7px/1 var(--px); }
.tool:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: none; }
.tool[aria-checked="true"] { background: var(--yellow); transform: translate(3px, 3px); box-shadow: none; }
.tool.toggle[aria-pressed="true"] { background: var(--sky); transform: translate(3px, 3px); box-shadow: none; }
.tool:disabled { opacity: .35; cursor: default; }

.palette-box {
    padding: 12px;
    background: var(--paper);
    border: var(--line) solid var(--ink);
    box-shadow: var(--shadow);
}

.current {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.current > span:nth-child(2) { display: grid; flex: 1; }
.current strong { font: 400 10px/1.4 var(--px); }
.current small { color: var(--muted); font-size: 14px; }

.swatch-big {
    flex: none;
    width: 42px;
    height: 42px;
    border: var(--line) solid var(--ink);
    box-shadow: inset 0 0 0 3px var(--paper);
}

.tiny-preview {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.tiny-preview img {
    image-rendering: pixelated;
    border: 2px solid var(--ink);
    background: repeating-conic-gradient(#e8e4f0 0 25%, #fcfcfc 0 50%) 0 0 / 8px 8px;
    box-sizing: content-box;
}

.palette {
    display: grid;
    grid-template-columns: repeat(14, 1fr);
    gap: 3px;
}

.swatch {
    aspect-ratio: 1;
    min-width: 0;
    padding: 0;
    border: 2px solid var(--ink);
    background: var(--c);
    -webkit-tap-highlight-color: transparent;
}

/* Transparent: the checkerboard of empty pixels, with a red slash. */
.swatch.clear,
.swatch-big.clear {
    background:
        linear-gradient(135deg, transparent 0 calc(50% - 1.5px), var(--accent) calc(50% - 1.5px) calc(50% + 1.5px), transparent calc(50% + 1.5px)),
        repeating-conic-gradient(#e8e4f0 0 25%, #fcfcfc 0 50%) 0 0 / 50% 50%;
}
.swatch:hover { transform: translateY(-2px); }

.swatch[aria-checked="true"] {
    position: relative;
    z-index: 1;
    transform: scale(1.1);
    box-shadow: inset 0 0 0 2px var(--paper), 0 0 0 2px var(--ink);
}

.adjust {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.nudge { display: inline-flex; gap: 6px; }
.adjust label.btn { margin: 0; cursor: pointer; font-weight: 400; }
.studio-hint { text-align: center; margin: 0; }

@media (min-width: 900px) {
    .studio-body {
        width: min(1000px, 100%);
        grid-template-columns: minmax(0, 1fr) 380px;
        grid-template-areas:
            "note note"
            "canvas tools"
            "canvas palette"
            "canvas adjust"
            "canvas hint";
        align-items: start;
        gap: 18px 28px;
        padding-top: 24px;
    }
    .studio-body .remix-note { grid-area: note; }
    .canvas-frame { grid-area: canvas; width: min(100%, calc(100vh - 140px)); justify-self: end; }
    .toolbar { grid-area: tools; justify-content: flex-start; }
    .palette-box { grid-area: palette; }
    .adjust { grid-area: adjust; justify-content: flex-start; }
    .studio-hint { grid-area: hint; text-align: left; }
}

/* Compose */
.compose-body {
    width: min(520px, 100%);
    margin: 0 auto;
    padding: 18px 16px calc(2rem + var(--kb, 0px));
}

.art-frame {
    width: min(100%, 340px);
    margin: 0 auto 18px;
    border: 4px solid var(--ink);
    box-shadow: var(--shadow-big);
    background: #fcfcfc;
    line-height: 0;
}

.art-frame img {
    width: 100%;
    aspect-ratio: 1;
    image-rendering: pixelated;
}

.compose-body .remix-note { margin-bottom: 16px; }

/* ---------------------------------------------------------- panels (activity, profile) */

.panel {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: rgba(28, 16, 48, .55);
}

.panel-card {
    width: min(560px, 100%);
    max-height: 88vh;
    max-height: 88svh;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--paper);
    border-top: 4px solid var(--ink);
    padding: 0 18px calc(1.2rem + env(safe-area-inset-bottom) + var(--kb, 0px));
    animation: rise 160ms steps(4);
}

.panel-card > .sheet-head {
    margin: 0 -18px 16px;
    padding: 0 8px 0 18px;
    min-height: var(--top-h);
}

@keyframes rise {
    from { transform: translateY(40px); opacity: 0; }
}

@media (min-width: 720px) {
    .panel { align-items: center; padding: 24px; }
    .panel-card { border: 4px solid var(--ink); box-shadow: 8px 8px 0 #000; }
}

.push-box {
    display: grid;
    gap: 10px;
    justify-items: start;
    padding: 14px;
    margin-bottom: 14px;
    background: var(--cream);
    border: var(--line) solid var(--ink);
}

.push-box p { margin: 0; }

.activity-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 8px;
}

.activity-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 8px 10px;
    border: 2px solid var(--ink);
    background: var(--paper);
    text-align: left;
}

.activity-item:hover { background: #fff7e8; }
.activity-item.unread { background: #fdeec9; border-width: 3px; }
.activity-item p { margin: 0; overflow-wrap: anywhere; line-height: 1.3; }
.activity-item small { color: var(--muted); }

/* Profile */
.profile-top {
    display: flex;
    align-items: center;
    gap: 18px;
    margin: 4px 0 12px;
}

.profile-top > div { min-width: 0; flex: 1; }
.profile-name-row { display: flex; align-items: center; gap: 4px; margin: 0; }
.profile-name { font: 400 13px/1.5 var(--px); overflow-wrap: anywhere; }
.name-form { display: flex; align-items: center; gap: 8px; margin: 0 0 4px; }
.name-form input[type="text"] { margin: 0; padding: 7px 9px; min-width: 0; flex: 1; font-size: 16px; }
.name-hint { margin: 2px 0 0; }
.name-hint:empty { display: none; }
.profile-stats { display: flex; gap: 16px; margin: 6px 0 2px; }
.profile-stats strong { font-family: var(--px); font-size: 11px; font-weight: 400; }
.profile-links { margin: 4px 0 0; }

.avatar-picker {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(68px, 1fr));
    gap: 10px;
    margin: 0 0 14px;
}

.avatar-opt {
    display: grid;
    justify-items: center;
    gap: 6px;
    padding: 6px 4px 8px;
    border: 2px solid transparent;
    background: none;
    font: 400 7px/1.2 var(--px);
    color: var(--ink);
}

.avatar-opt img {
    width: 52px;
    height: 52px;
    image-rendering: pixelated;
    border: var(--line) solid var(--ink);
    background: var(--paper);
    box-shadow: 3px 3px 0 var(--ink);
}

.avatar-opt:hover img { transform: translateY(-2px); }
.avatar-opt[aria-checked="true"] { border-color: var(--ink); background: var(--yellow); }
.avatar-opt:disabled { opacity: .5; cursor: default; }

.guest-note {
    padding: 12px 14px;
    background: #fdeec9;
    border: var(--line) dashed var(--ink);
}

.profile-foot { margin: 26px 0 10px; }

.source-link {
    margin: 14px 0 0;
    font-size: 15px;
}

.source-link a {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
}

.source-link svg { width: 18px; height: 18px; shape-rendering: auto; }

/* ---------------------------------------------------------- the guest banner */

.guest-banner {
    position: relative;
    margin: 0 0 18px;
    padding: 14px 48px 14px 16px;
    background: #fdeec9;
    border: var(--line) solid var(--ink);
    box-shadow: var(--shadow);
}

.guest-banner p { margin: 0 0 8px; }
.guest-banner .guest-title { font: 400 11px/1.6 var(--px); margin-bottom: 10px; }
.guest-close { position: absolute; top: 6px; right: 6px; }
.guest-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.guest-actions .btn.google { background: #fff; }
.guest-actions .g-logo { width: 15px; height: 15px; shape-rendering: auto; }

/* ---------------------------------------------------------- install / notifications banner */

.pwa-banner {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin: 0 0 18px;
    padding: 12px 14px;
    background: var(--paper);
    border: var(--line) solid var(--ink);
    box-shadow: var(--shadow);
}

.pwa-banner img { image-rendering: pixelated; flex: none; }
.pwa-banner p { flex: 1 1 200px; margin: 0; }
.pwa-banner-actions { display: flex; align-items: center; gap: 14px; }

/* ---------------------------------------------------------- toast */

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(var(--bottom-h) + 24px + env(safe-area-inset-bottom));
    z-index: 90;
    display: flex;
    align-items: center;
    gap: 10px;
    width: max-content;
    max-width: min(92vw, 440px);
    padding: 11px 14px;
    background: var(--ink);
    color: var(--paper);
    border: var(--line) solid var(--paper);
    box-shadow: 0 0 0 3px var(--ink), 6px 6px 0 3px rgba(0, 0, 0, .35);
    font-weight: 600;
    transform: translate(-50%, 20px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 150ms steps(3), transform 150ms steps(3);
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.show.actionable { pointer-events: auto; cursor: pointer; }
.toast img { width: 28px; height: 28px; image-rendering: pixelated; border: 2px solid var(--paper); flex: none; }

/* ---------------------------------------------------------- on-screen keyboard (service.js) */

/* While typing, the bottom bar steps aside so it never covers the field. */
html.keyboard-open .bottombar { display: none; }
html.keyboard-open { scroll-padding-bottom: 16px; }

/* ---------------------------------------------------------- account pages */

body.auth-body { padding-bottom: var(--kb, 0px); }

.auth {
    display: grid;
    place-items: center;
    min-height: 100vh;
    min-height: 100svh;
    padding: max(24px, env(safe-area-inset-top)) 16px 32px;
}

.auth-card {
    width: min(440px, 100%);
    padding: 26px 24px 24px;
    background: var(--paper);
    border: 4px solid var(--ink);
    box-shadow: 8px 8px 0 var(--ink);
}

.auth-card .logo { color: var(--ink); font-size: 20px; }

.auth-hero {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    margin: 22px 0 10px;
}

.auth-hero img {
    width: 96px;
    height: 96px;
    image-rendering: pixelated;
    animation: hop 1.2s steps(2) infinite;
}

@keyframes hop {
    50% { transform: translateY(-8px); }
}

/* A strip of NES colors. */
.palette-strip {
    height: 14px;
    margin: 0 0 22px;
    border: var(--line) solid var(--ink);
    background: linear-gradient(90deg,
            #e40058 0 8.33%, #f83800 0 16.66%, #fca044 0 25%, #f8b800 0 33.33%, #b8f818 0 41.66%, #00b800 0 50%,
            #58f898 0 58.33%, #00e8d8 0 66.66%, #3cbcfc 0 75%, #0058f8 0 83.33%, #6844fc 0 91.66%, #d800cc 0);
}

.auth-card h1 { margin: 6px 0 10px; font-size: 16px; line-height: 1.6; }
.auth-card > p { margin: 0 0 18px; }
.auth-card form { margin-top: 18px; }

.auth-card > .or {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 18px 0;
    color: var(--muted);
    font: 400 9px/1 var(--px);
}

.or::before,
.or::after {
    content: "";
    flex: 1;
    height: 3px;
    background: repeating-linear-gradient(90deg, var(--ink) 0 6px, transparent 6px 10px);
}

/* ".auth-card > p" would win over a plain class: these keep their room below the buttons above them. */
.auth-card > .auth-links {
    margin: 30px 0 0;
    text-align: center;
    line-height: 1.9;
}

.auth-card > .source-link {
    margin: 18px 0 0;
    text-align: center;
}

/* ---------------------------------------------------------- privacy policy, terms */

body.doc-body { padding-bottom: 40px; }
.doc-body .topbar-actions .btn { box-shadow: 3px 3px 0 #000; border-color: #000; }

.doc {
    width: min(760px, calc(100% - 32px));
    margin: 28px auto 0;
    padding: 28px clamp(18px, 4vw, 40px) 30px;
    background: var(--paper);
    border: 4px solid var(--ink);
    box-shadow: 8px 8px 0 var(--ink);
    line-height: 1.55;
}

.doc h1 { font-size: 18px; line-height: 1.5; }
.doc h2 { font-size: 12px; margin: 2rem 0 .7rem; }
.doc h3 { font-family: var(--body); font-size: 18px; font-weight: 700; margin: 1.2rem 0 .3rem; }
.doc p, .doc li { overflow-wrap: anywhere; }
.doc ul { padding-left: 1.3rem; }
.doc li { margin: .35rem 0; }
.doc-date { color: var(--muted); margin-top: .4rem; }

.doc-summary {
    margin: 1.4rem 0 .4rem;
    padding: 4px 18px 8px;
    background: #fdeec9;
    border: var(--line) solid var(--ink);
}

.doc-summary h2 { margin-top: 1rem; }
.doc-note { margin-top: 2rem; color: var(--muted); font-size: 15px; }
.doc-links { margin: 1rem 0 0; }

/* Links to the policies on the account pages and in the profile. */
.legal-links { margin: 10px 0 0; text-align: center; font-size: 15px; }
.shared-note { padding: 10px 12px; background: #fdeec9; border: var(--line) dashed var(--ink); }
.legal-links a { color: var(--muted); }
.auth-card > .legal-links { margin: 8px 0 0; }
.agree { color: var(--muted); font-size: 15px; margin: 14px 0 0; }

/* The Share panel */
.share-top {
    display: grid;
    grid-template-columns: 132px 1fr;
    gap: 16px;
    align-items: center;
}

.share-preview {
    border: var(--line) solid var(--ink);
    box-shadow: var(--shadow);
    background: #fcfcfc;
    line-height: 0;
}

.share-preview img { width: 100%; aspect-ratio: 1; image-rendering: pixelated; }
.share-top .hint { margin: 10px 0 0; }

.share-links,
.share-saves {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 0 0 14px;
}

.share-tip { margin-top: 4px; }

/* A button making a video: "Making video… 42%", filling up as it goes. */
.btn.busy,
.btn.busy:hover {
    background-image: linear-gradient(90deg, rgba(28, 16, 48, .2) var(--progress, 0%), transparent var(--progress, 0%));
    cursor: progress;
}

.btn.busy:disabled { opacity: 1; }

/* Continue with Google: white, with Google's own "G". */
.btn.google { background: #fff; gap: 12px; }
.btn.google .g-logo { width: 18px; height: 18px; shape-rendering: auto; }
.auth-card .btn.google { margin-bottom: 16px; }

.danger-zone { margin: 18px 0 0; padding-top: 14px; border-top: 2px dashed rgba(28, 16, 48, .3); }
.danger-zone .link-btn { color: var(--accent); }

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