/* ==========================================================================
   Yoto Pixel Art tool — /tools/yoto-pixel-art/ (R2)
   Prefix: pxt- (DESIGN.md §2.0 register). Consumes styles.css tokens only;
   restyles no existing class. Visual contract: DESIGN.md §2.8.
   The 16 paint-palette hexes are CONTENT and live in the template markup /
   pixel_tool.js — this sheet contains no literal colour hexes.
   ========================================================================== */

/* --- Hidden-state guard: [hidden] must beat the display rules below --- */
.pxt-tool [hidden],
.pxt-stage [hidden] {
    display: none !important;
}

/* --- Visually hidden (labels, live region, hidden file input, vh headings) --- */
.pxt-vh {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* --- Page headings + prose (charcoal — never gold text, R-2) --- */
.pxt-intro {
    background: var(--cloud);
    padding-bottom: var(--space-4);
}

.pxt-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: var(--text-3xl);
    line-height: var(--line-height-tight);
    color: var(--color-text-primary);
    margin: 0 0 var(--space-4);
}

.pxt-lede {
    font-size: var(--text-lg);
    line-height: 1.6;
    color: var(--color-text-primary);
    max-width: 62ch;
    margin: 0;
}

.pxt-h2 {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: var(--text-3xl);
    line-height: var(--line-height-tight);
    color: var(--color-text-primary);
    margin: 0 0 var(--space-4);
}

.pxt-body {
    font-size: var(--text-base);
    line-height: 1.7;
    color: var(--color-text-primary);
    max-width: 68ch;
    margin: 0 0 var(--space-4);
}

@media (max-width: 767px) {
    .pxt-title,
    .pxt-h2 {
        font-size: var(--text-2xl);
    }
}

/* Reference link recipe (DESIGN §2 conventions) for pxt-owned prose */
.pxt-lede a,
.pxt-body a,
.pxt-related a,
.pxt-noscript a {
    color: var(--color-primary);
    font-weight: 500;
    text-decoration: none;
}

.pxt-lede a:hover,
.pxt-body a:hover,
.pxt-related a:hover,
.pxt-noscript a:hover {
    color: var(--color-primary-hover);
    text-decoration: underline;
}

.pxt-lede a:focus-visible,
.pxt-body a:focus-visible,
.pxt-related a:focus-visible,
.pxt-noscript a:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* --- Tool section shell --- */
.pxt-tool {
    background: var(--cloud);
    padding: var(--space-4) 0 var(--space-10);
}

.pxt-noscript {
    font-size: var(--text-lg);
    line-height: 1.6;
    color: var(--color-text-primary);
    max-width: 62ch;
}

/* --- Error notice (.form-error recipe supplies the colours; pxt-error adds
       layout + the dismiss control only) --- */
.pxt-error {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-4);
}

.pxt-error-dismiss {
    background: none;
    border: 0;
    color: var(--color-danger);
    font-family: var(--font-body);
    font-weight: 600;
    font-size: var(--text-sm);
    text-decoration: underline;
    cursor: pointer;
    min-height: 44px;
    min-width: 44px;
    padding: 0 var(--space-2);
    flex-shrink: 0;
}

.pxt-error-dismiss:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* --- Dropzone (empty state) --- */
.pxt-dropzone {
    background: var(--color-surface);
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-8) var(--space-5);
    text-align: center;
    cursor: pointer;
}

/* Drag-over: three simultaneous cues — solid gold border + parchment bg +
   copy swap to "Drop it!" (gold is never the sole indicator, R-2) */
.pxt-dropzone--drag {
    border-style: solid;
    border-color: var(--color-border-hover);
    background: var(--parchment);
}

.pxt-dropzone-glyph {
    display: block;
    font-size: var(--text-4xl);
    margin-bottom: var(--space-3);
}

.pxt-dropzone-title {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: var(--text-xl);
    color: var(--color-text-primary);
    margin: 0 0 var(--space-1);
}

.pxt-dropzone-alt {
    font-size: var(--text-base);
    color: var(--color-text-primary);
    margin: 0 0 var(--space-4);
}

.pxt-dropzone-blank {
    margin: var(--space-3) 0 0;
}

.pxt-blank-link {
    background: none;
    border: 0;
    color: var(--color-primary);
    font-family: var(--font-body);
    font-weight: 600;
    font-size: var(--text-base);
    min-height: 44px;
    padding: var(--space-2) var(--space-3);
    cursor: pointer;
}

.pxt-blank-link:hover {
    color: var(--color-primary-hover);
    text-decoration: underline;
}

.pxt-blank-link:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

.pxt-micro {
    font-size: var(--text-sm);
    color: var(--color-text-primary);
    margin: var(--space-4) 0 0;
}

/* --- Processing --- */
.pxt-processing {
    padding: var(--space-8) var(--space-5);
    text-align: center;
}

.pxt-processing-text {
    font-size: var(--text-lg);
    color: var(--color-text-primary);
    margin: 0;
}

.pxt-dots span {
    opacity: 0.2;
    animation: pxtDot 1.2s infinite;
}

.pxt-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.pxt-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes pxtDot {
    0%, 60%, 100% { opacity: 0.2; }
    30% { opacity: 1; }
}

/* --- Editor layout: 320 stacked in DOM order; ≥768 grid left + rail right,
       toolbar and download row span the stage (DESIGN §2.8 responsive) --- */
.pxt-editor {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-5);
}

@media (min-width: 768px) {
    /* The canvas column is capped at the grid's own natural width (527px = 16 ×
       32px cells + 15 × 1px gaps — see .pxt-grid). With minmax(0, 1fr) the column
       took ALL the remaining stage width (708px at 1440), while .pxt-grid stayed
       527px and start-aligned inside it, opening a 181px void between the grid and
       the rail with the toolbar and download row spanning across it. Capping the
       track at 527px moves that slack outside the grid+rail pair. Below ~899px the
       free space never reaches 527px, so the track still fills the column exactly
       as it did before (396px at 768) — this changes nothing at tablet. */
    .pxt-editor {
        grid-template-columns: minmax(0, 527px) 300px;
        justify-content: start;
        align-items: start;
    }

    .pxt-toolbar,
    .pxt-download {
        grid-column: 1 / -1;
    }
}

/* --- Toolbar: wrapping control row, every control ≥44×44px --- */
.pxt-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
}

.pxt-toolbar .btn {
    min-height: 44px;
}

/* Disabled Undo/Redo visual (mirrors the .btn-disabled recipe without its
   pointer-events:none, so activation can still announce "Nothing to undo.") */
.pxt-toolbar .pxt-btn-disabled {
    opacity: 0.5;
    cursor: not-allowed;
    border-color: var(--color-border);
    color: var(--color-text-secondary);
    background: var(--cloud);
}

.pxt-text-btn {
    background: none;
    border: 0;
    color: var(--color-text-primary);
    font-family: var(--font-body);
    font-weight: 600;
    font-size: var(--text-sm);
    min-height: 44px;
    min-width: 44px;
    padding: 0 var(--space-3);
    cursor: pointer;
}

.pxt-text-btn:hover {
    text-decoration: underline;
}

.pxt-text-btn:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* Zoom control exists <768px only */
@media (min-width: 768px) {
    .pxt-zoom {
        display: none;
    }
}

/* --- Segmented radiogroups (Crop/Fit, Drawing tool) --- */
.pxt-seg-group {
    border: 0;
    margin: 0;
    padding: 0;
    display: inline-flex;
}

.pxt-seg {
    display: inline-flex;
}

.pxt-seg + .pxt-seg {
    margin-left: -1px;
}

.pxt-seg-input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

.pxt-seg-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    min-width: 44px;
    padding: 0 var(--space-4);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text-primary);
    font-family: var(--font-body);
    font-weight: 600;
    font-size: var(--text-sm);
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.pxt-seg:first-of-type .pxt-seg-label {
    border-radius: var(--radius-md) 0 0 var(--radius-md);
}

.pxt-seg:last-of-type .pxt-seg-label {
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.pxt-seg-input:checked + .pxt-seg-label {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: var(--cloud);
}

.pxt-seg-input:focus-visible + .pxt-seg-label {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    position: relative;
    z-index: 1;
}

/* --- The 16×16 grid --- */
.pxt-grid-scroll {
    overflow: auto;
    max-width: 100%;
}

.pxt-grid {
    /* fluid cells: min(32px, (container − gaps)/16); 16×32px + 15×1px gaps = 527px */
    width: min(100%, 527px);
    border: 1px solid var(--color-border);
    background: var(--color-border); /* shows through the 1px gaps */
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.pxt-grid--zoom2 {
    width: 200%;
    max-width: none;
}

.pxt-row {
    display: grid;
    grid-template-columns: repeat(16, 1fr);
    gap: 1px;
}

.pxt-cell {
    position: relative;
    aspect-ratio: 1;
    /* transparent-pixel checkerboard: cloud/parchment quadrants */
    background: conic-gradient(
        var(--parchment) 0 25%,
        var(--cloud) 0 50%,
        var(--parchment) 0 75%,
        var(--cloud) 0
    );
    cursor: crosshair;
}

.pxt-grid[data-tool="eyedropper"] .pxt-cell {
    cursor: copy;
}

.pxt-grid[data-tool="move"] .pxt-cell {
    cursor: grab;
}

.pxt-cell-paint {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* Double focus ring (DESIGN §2.8): 2px cloud outline + 1px charcoal outer ring —
   ≥3:1 against any painted cell colour. Never suppressed. */
.pxt-cell:focus {
    outline: 2px solid var(--cloud);
    outline-offset: 0;
    box-shadow: 0 0 0 3px var(--charcoal-brown);
    z-index: 2;
}

/* --- Grid paint-in: the surface's ONE orchestrated motion moment.
       Row-sweep ≤400ms total (15 × 17ms delay + 140ms fade = 395ms), decorative
       only; pixel_tool.js removes .pxt-sweep on any input landing mid-sweep and
       never adds it under prefers-reduced-motion. --- */
.pxt-grid.pxt-sweep .pxt-cell-paint {
    opacity: 0;
    animation: pxtPaintIn 140ms ease-out forwards;
    animation-delay: calc(var(--pxt-row, 0) * 17ms);
}

@keyframes pxtPaintIn {
    to { opacity: 1; }
}

/* --- Rail --- */
.pxt-rail {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    min-width: 0;
}

.pxt-rail-title {
    font-family: var(--font-body);
    font-weight: 600;
    font-size: var(--text-xs);
    line-height: 1.2;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-primary);
    margin: 0 0 var(--space-2);
}

/* --- Actual-size preview chips (icon at exactly 16×16 CSS px) --- */
.pxt-preview {
    display: flex;
    gap: var(--space-3);
}

.pxt-chip {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}

.pxt-chip--white {
    background: var(--cloud);
}

.pxt-chip--player {
    background: var(--charcoal-brown);
}

.pxt-chip canvas {
    width: 16px;
    height: 16px;
    image-rendering: pixelated;
}

.pxt-chip-label {
    font-size: var(--text-xs);
    font-weight: 500;
    color: var(--color-text-primary);
}

.pxt-chip--player .pxt-chip-label {
    color: var(--cloud);
}

.pxt-note {
    font-size: var(--text-sm);
    line-height: 1.6;
    color: var(--color-text-primary);
    margin: var(--space-2) 0 0;
}

/* --- Palettes: swatches ≥44×44px, 6px gap (specced), radius-sm --- */
.pxt-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.pxt-swatch {
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background-color: var(--pxt-c, transparent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: box-shadow var(--transition-fast);
}

.pxt-swatch:hover {
    box-shadow: var(--shadow-sm);
}

/* Selected: 2px charcoal ring offset 2px + ✓ glyph — never colour alone */
.pxt-swatch[aria-checked="true"] {
    box-shadow: 0 0 0 2px var(--color-surface), 0 0 0 4px var(--charcoal-brown);
}

.pxt-swatch:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.pxt-tick {
    display: none;
    font-size: 20px;
    line-height: 1;
    pointer-events: none;
    color: var(--charcoal-brown);
}

.pxt-swatch[aria-checked="true"] .pxt-tick {
    display: block;
}

.pxt-swatch--dark .pxt-tick {
    color: var(--cloud);
}

.pxt-swatch--light .pxt-tick {
    color: var(--charcoal-brown);
}

/* --- Custom colour --- */
.pxt-custom-row {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-1);
    border-radius: var(--radius-sm);
}

.pxt-custom-row input[type="color"] {
    width: 56px;
    height: 44px;
    padding: 2px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    cursor: pointer;
}

.pxt-custom-row input[type="color"]:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Active-custom ring mirrors the swatch selection treatment */
.pxt-custom--active {
    box-shadow: 0 0 0 2px var(--color-surface), 0 0 0 4px var(--charcoal-brown);
}

.pxt-custom-hex {
    font-size: var(--text-sm);
    color: var(--color-text-primary);
}

/* --- Download row --- */
.pxt-download {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-4);
}

.pxt-download-note {
    font-size: var(--text-sm);
    color: var(--color-text-primary);
    margin: 0;
}

.pxt-saved {
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--color-success);
    margin: 0;
}

@media (max-width: 767px) {
    .pxt-download .btn-cta-primary {
        width: 100%;
    }
}

/* --- Upsell instance spacing (visuals belong to marketing_kit.css) --- */
.pxt-upsell {
    margin-top: var(--space-6);
}

/* --- Example strip (optional, ships empty — DESIGN §5) --- */
.pxt-examples-section {
    background: var(--cloud);
}

.pxt-kicker {
    font-family: var(--font-body);
    font-weight: 600;
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-primary);
    margin: 0 0 var(--space-3);
}

.pxt-examples {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-5);
}

.pxt-example {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.pxt-example img {
    image-rendering: pixelated;
    display: block;
}

/* --- How-to --- */
.pxt-howto-section {
    background: var(--cloud);
}

.pxt-howto {
    list-style: none;
    margin: var(--space-5) 0 0;
    padding: 0;
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-5);
}

/* 3-up needs ~1024px to breathe: at exactly 768 a third of the container is a
   224px card = ~174px of measure = ~21 characters per line, which shredded the
   step copy into 4-word lines, wrapped step 3's title onto two lines while steps
   1–2 stayed on one, and left steps 1–2 with ~89px of empty card below the text.
   2-up at the 768 band gives ~340px cards (~40ch); 1024 is a DESIGN breakpoint. */
@media (min-width: 768px) and (max-width: 1023px) {
    .pxt-howto {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .pxt-howto {
        grid-template-columns: repeat(3, 1fr);
    }
}

.pxt-howto-step {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
}

.pxt-howto-emoji {
    display: block;
    font-size: var(--text-3xl);
    margin-bottom: var(--space-2);
}

.pxt-howto-title {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: var(--text-xl);
    color: var(--color-text-primary);
    margin: 0 0 var(--space-2);
}

.pxt-howto-step .pxt-body {
    margin-bottom: 0;
}

/* --- FAQ section (parchment band; mk-faq visuals live in marketing_kit.css) --- */
.pxt-faq-section {
    background: var(--parchment);
}

/* The shared .mk-faq recipe centres its 720px column (margin: 0 auto), which in
   the 1032px container at 1440 pushed every question, answer and hairline rule
   156px right of the .pxt-h2 above them and the .pxt-related paragraph below —
   three left edges in one section, on a page that is left-aligned throughout.
   Anchor the block to the page axis; the 720px reading measure is unchanged.
   Scoped to .pxt-faq-section so mk-faq stays centred everywhere else. */
.pxt-faq-section .mk-faq {
    margin-left: 0;
    margin-right: 0;
}

.pxt-related {
    font-size: var(--text-base);
    line-height: 1.7;
    color: var(--color-text-primary);
    margin: var(--space-6) 0 0;
    max-width: 68ch;
}

/* --- Reduced motion: no sweep, no dots animation (paint-in also gated in JS) --- */
@media (prefers-reduced-motion: reduce) {
    .pxt-dots span {
        animation: none;
        opacity: 1;
    }

    .pxt-grid.pxt-sweep .pxt-cell-paint {
        animation: none;
        opacity: 1;
    }
}
