/* =============================================================================
   THE TILE — stylesheet
   -----------------------------------------------------------------------------
   Playful, pixel-art flavour: a real pixel font, blocky cards with hard
   (no-blur) drop shadows, square corners, and bright palette-legal colours.
   Read top to bottom: font + tokens, base styles, then one block per UI region
   in page order, then responsive + accessibility at the end.
   ========================================================================== */

/* Self-hosted pixel font (OFL). Used only for chrome/labels — never body prose,
   which stays in a readable sans. Degrades to monospace if it fails to load. */
@font-face {
    font-family: "Press Start 2P";
    src: url("PressStart2P.ttf") format("truetype");
    font-display: swap;
}

/* -----------------------------------------------------------------------------
   1. Design tokens
   Brand colours are real GColor8 palette values — the exact colours a tile can
   be painted with (each channel only exists at 0 / 85 / 170 / 255).
   -------------------------------------------------------------------------- */
:root {
    /* Colour */
    --bg:       #eceef5;        /* soft blue-grey paper                      */
    --surface:  #ffffff;        /* cards, screens                           */
    --ink:      #1a1a2e;        /* deep indigo — text, borders, hard shadows*/
    --ink-soft: #6a6a86;        /* secondary text                           */
    --line:     #d9dce6;        /* faint dividers                           */

    /* Bright palette pops (all GColor8-legal) */
    --accent: #ff5500;   /* (255,85,0)  orange — primary        */
    --cyan:   #00aaff;   /* (0,170,255)                         */
    --pink:   #ff00aa;   /* (255,0,170)                         */
    --amber:  #ffaa00;   /* (255,170,0)                         */
    --vote:   #00aa55;   /* (0,170,85)  chosen / success        */
    --on-accent: #ffffff;

    /* Type */
    --font-pixel: "Press Start 2P", ui-monospace, Menlo, monospace;
    --font-body:  ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

    /* Spacing scale */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-12: 3rem;
    --space-16: 4rem;

    /* Blocky shape language: square corners + hard offset shadow, no blur. */
    --border: 3px solid var(--ink);
    --shadow-hard: 4px 4px 0 var(--ink);
    --shadow-lift: 6px 6px 0 var(--ink);
}

/* -----------------------------------------------------------------------------
   2. Base + reset
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font-body);
    color: var(--ink);
    background: var(--bg);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

/* Every tile is drawn on a tiny 16x16 canvas then scaled up: keep it crisp. */
canvas {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    display: block;
}

/* Author `display` values (e.g. .preview { display:flex }) would otherwise beat
   the UA rule for [hidden]; make the attribute win everywhere. */
[hidden] { display: none !important; }

/* Faint graph-paper texture behind the whole page. */
.pixel-grid {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background-image:
        linear-gradient(to right, rgba(26, 26, 46, 0.04) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(26, 26, 46, 0.04) 1px, transparent 1px);
    background-size: 24px 24px;
}

/* A single lit pixel that marks each section. */
.eyebrow__tick {
    display: inline-block;
    width: 0.7em;
    height: 0.7em;
    background: var(--accent);
    flex: none;
}

/* -----------------------------------------------------------------------------
   3. Page shell
   -------------------------------------------------------------------------- */
.page {
    max-width: 720px;
    margin: 0 auto;
    padding: var(--space-8) var(--space-4) var(--space-16);
}

/* -----------------------------------------------------------------------------
   4. Masthead
   -------------------------------------------------------------------------- */
.masthead {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
    padding-bottom: var(--space-6);
    border-bottom: var(--border);
}

.wordmark {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    font-family: var(--font-pixel);
    font-size: 1.1rem;
    line-height: 1;
    text-decoration: none;
    color: var(--ink);
}

.wordmark__mark {
    width: 20px;
    height: 20px;
    background: var(--accent);
    box-shadow: 3px 3px 0 var(--ink);
    /* A pixel with one corner notched out — a single tile. */
    clip-path: polygon(0 0, 100% 0, 100% 66%, 66% 66%, 66% 100%, 0 100%);
}

.masthead__note {
    margin: 0;
    font-family: var(--font-pixel);
    font-size: 0.55rem;
    line-height: 1.6;
    color: var(--ink-soft);
}

/* -----------------------------------------------------------------------------
   5. Shared section furniture (eyebrow + panels)
   -------------------------------------------------------------------------- */
.eyebrow {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0 0 var(--space-4);
    font-family: var(--font-pixel);
    font-size: 0.6rem;
    line-height: 1.6;
    color: var(--ink-soft);
    text-transform: uppercase;
}

.panel { margin-top: var(--space-12); }

.panel__head { margin-bottom: var(--space-6); }

.panel__title {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin: 0 0 var(--space-3);
    font-family: var(--font-pixel);
    font-size: 0.95rem;
    line-height: 1.4;
    text-transform: uppercase;
}

.panel__hint {
    margin: 0;
    color: var(--ink-soft);
    font-size: 0.95rem;
}

/* -----------------------------------------------------------------------------
   6. Hero — the winning tile on a Pebble Time 2 device frame
   The watch is the one real object here, so it keeps rounded corners while the
   rest of the page stays blocky.
   -------------------------------------------------------------------------- */
.hero {
    margin-top: var(--space-12);
    text-align: center;
}

.hero .eyebrow { justify-content: center; }

.watch {
    display: inline-block;
    padding: 14px;
    background: var(--ink);
    border-radius: 28px;
    box-shadow: var(--shadow-hard);
}

.watch__screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    width: 216px;
    padding: 16px 16px 12px;
    background: var(--surface);
    border-radius: 14px;
}

.watch__tile {
    width: 184px;
    height: 184px;
    background: #000;
}

.watch__clock {
    font-family: var(--font-pixel);
    font-size: 1.4rem;
    line-height: 1;
    color: var(--ink);
}

.hero__meta {
    margin: var(--space-4) 0 0;
    font-family: var(--font-pixel);
    font-size: 0.55rem;
    line-height: 1.8;
    color: var(--ink-soft);
}

.countdown {
    margin-bottom: var(--space-8);
}

.countdown__label {
    margin: 0 0 var(--space-2);
    font-family: var(--font-pixel);
    font-size: 0.55rem;
    line-height: 1.6;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--ink-soft);
}

.countdown__value {
    margin: 0;
    font-family: var(--font-pixel);
    font-size: clamp(1.5rem, 6vw, 2.4rem);
    line-height: 1.3;
    color: var(--accent);
    text-shadow: 3px 3px 0 var(--ink);
    letter-spacing: 0.03em;
}

/* -----------------------------------------------------------------------------
   7. Vote — three challenger tiles
   Each card borrows a different palette pop so the trio feels like game pieces.
   -------------------------------------------------------------------------- */
.matchup {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-4);
}

/* Each challenger is a real button so it is keyboard-operable for free. */
.tile-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    background: var(--surface);
    border: var(--border);
    box-shadow: var(--shadow-hard);
    cursor: pointer;
    font-family: var(--font-pixel);
    color: var(--ink);
    /* Let the card shrink inside its grid track instead of forcing overflow. */
    min-width: 0;
    transition: transform 0.1s steps(2), box-shadow 0.1s steps(2);
}

/* Colour the trio: cyan / pink / amber shadows. */
.tile-card:nth-child(1) { box-shadow: 4px 4px 0 var(--cyan); }
.tile-card:nth-child(2) { box-shadow: 4px 4px 0 var(--pink); }
.tile-card:nth-child(3) { box-shadow: 4px 4px 0 var(--amber); }

.tile-card:hover {
    transform: translate(-2px, -2px);
    box-shadow: var(--shadow-lift);
}

/* Press the button into the page on click. */
.tile-card:active {
    transform: translate(2px, 2px);
    box-shadow: 0 0 0 var(--ink);
}

.tile-card:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 3px;
}

/* Green confirmation when a vote lands. */
.tile-card.is-chosen {
    box-shadow: 4px 4px 0 var(--vote);
    border-color: var(--vote);
}

.tile-card__tile {
    width: 100%;
    aspect-ratio: 1;
    background: #000;
}

/* -----------------------------------------------------------------------------
   8. Notices (contribution gate + errors) and loading states
   -------------------------------------------------------------------------- */
.state {
    grid-column: 1 / -1;
    margin: 0;
    padding: var(--space-8) 0;
    text-align: center;
    color: var(--ink-soft);
    font-family: var(--font-pixel);
    font-size: 0.6rem;
    line-height: 1.9;
}

.state--error { color: var(--accent); }

.notice {
    margin: var(--space-6) 0 0;
    padding: var(--space-4);
    background: var(--surface);
    border: var(--border);
    box-shadow: 4px 4px 0 var(--accent);
    font-size: 0.9rem;
}

.notice--ok { box-shadow: 4px 4px 0 var(--vote); }

.notice__link {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    color: var(--accent);
    font-weight: 700;
    text-decoration: underline;
    cursor: pointer;
}

/* -----------------------------------------------------------------------------
   9. Buttons
   -------------------------------------------------------------------------- */
.btn {
    align-self: stretch;
    padding: var(--space-4) var(--space-8);
    background: var(--accent);
    color: var(--on-accent);
    border: var(--border);
    box-shadow: var(--shadow-hard);
    font-family: var(--font-pixel);
    font-size: 0.7rem;
    line-height: 1.4;
    text-transform: uppercase;
    cursor: pointer;
    transition: transform 0.1s steps(2), box-shadow 0.1s steps(2);
}

.btn:hover { transform: translate(-2px, -2px); box-shadow: var(--shadow-lift); }
.btn:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--ink); }
.btn:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
.btn:disabled { filter: grayscale(0.5); cursor: progress; transform: none; box-shadow: var(--shadow-hard); }

/* -----------------------------------------------------------------------------
   9b. Tile editor
   -------------------------------------------------------------------------- */
.btn--ghost {
    background: var(--surface);
    color: var(--ink);
}

/* One vertical column at any screen size — canvas, then the compact palette
   strip, then a combined tool/action row, then the submit CTA on its own.
   Capped width keeps the canvas the biggest thing on screen instead of it
   competing sideways with the palette. */
.editor {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    max-width: 440px;
}

/* Square drawing surface: the 16x16 canvas scaled up crisp, with a grid overlay
   so individual cells are visible while painting. */
.editor__stage {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    background: var(--surface);
    border: var(--border);
    box-shadow: 4px 4px 0 var(--cyan);
}

.editor__canvas {
    width: 100%;
    height: 100%;
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    cursor: crosshair;
    touch-action: none;        /* dragging paints instead of scrolling */
}

.editor__grid {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(to right, rgba(26, 26, 46, 0.14) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(26, 26, 46, 0.14) 1px, transparent 1px);
    background-size: calc(100% / 16) calc(100% / 16);
}

.editor__canvas.is-fill { cursor: cell; }
.editor__canvas.is-picker { cursor: copy; }

/* The full 64-colour Pebble palette (4 levels per channel), kept as a short,
   wide strip (16 columns) rather than a tall square so it never dominates
   the canvas above it. */
.editor__swatches {
    display: grid;
    grid-template-columns: repeat(16, 1fr);
    gap: 3px;
}

.swatch {
    aspect-ratio: 1;
    padding: 0;
    border: 2px solid var(--ink);
    cursor: pointer;
}

.swatch[aria-selected="true"] {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
    position: relative;
    z-index: 1;
}

/* Tool selection (left) and undo/clear (right) share one compact row. */
.editor__controls {
    display: flex;
    justify-content: space-between;
    gap: var(--space-3);
}

.editor__toolbar {
    display: flex;
    gap: var(--space-3);
}

.editor__toolbar .btn[aria-pressed="true"] {
    background: var(--accent);
    color: var(--on-accent);
}

.editor__actions {
    display: flex;
    gap: var(--space-3);
}

/* Icon-only buttons: pencil/fill/picker/undo/clear all read via a symbol +
   aria-label/title rather than text, so the toolbar stays compact. The
   doubled-up selector beats the small-screen `.btn { flex: 1 1 100% }`
   rule below, which would otherwise stretch these to full-width rows. */
.btn.btn--icon {
    flex: 0 0 auto;
    width: 2.75rem;
    height: 2.75rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.icon {
    width: 1.35rem;
    height: 1.35rem;
}

/* -----------------------------------------------------------------------------
   10. Colophon
   -------------------------------------------------------------------------- */
.colophon {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    flex-wrap: wrap;
    margin-top: var(--space-16);
    padding-top: var(--space-6);
    border-top: 1px solid var(--line);
    font-family: var(--font-pixel);
    font-size: 0.5rem;
    line-height: 1.8;
    color: var(--ink-soft);
    text-align: center;
}

.colophon__dot { width: 6px; height: 6px; background: var(--accent); flex: none; }

/* -----------------------------------------------------------------------------
   11. Responsive — small screens
   -------------------------------------------------------------------------- */
@media (max-width: 480px) {
    .page { padding-top: var(--space-6); }
    .matchup { gap: var(--space-3); }
    .tile-card { padding: var(--space-2); }
    .btn { flex: 1 1 100%; }
    .wordmark { font-size: 0.95rem; }
    .panel__title { font-size: 0.8rem; }
}

/* -----------------------------------------------------------------------------
   11b. Responsive — desktop palette dock
   -------------------------------------------------------------------------- */
@media (min-width: 768px) {
    /* There's width to spare, so the palette becomes a tall dock to the left
       of the canvas instead of a strip above it — effectively the same 64
       swatches, just transposed from 16 columns x 4 rows to 4 columns x 16
       rows, so the canvas can grow into the freed horizontal space. */
    .editor {
        max-width: none;
        display: grid;
        grid-template-columns: 112px 1fr;
        grid-template-areas:
            "swatches stage"
            "controls controls"
            "submit submit";
        gap: var(--space-4);
    }
    .editor__stage { grid-area: stage; }
    .editor__swatches {
        grid-area: swatches;
        grid-template-columns: repeat(4, 1fr);
        align-self: start;
    }
    .editor__controls { grid-area: controls; }
    .editor__submit { grid-area: submit; }
}

/* -----------------------------------------------------------------------------
   12. Accessibility — honour reduced motion
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}
