/* ============================================================
   Slip Studio — minimal, modern, calm.
   Warm-charcoal palette. NOT the teal+pink onioncore brand
   used by the 2D Madderverse games; this app's visual
   language is deliberately quiet.
   ============================================================ */

/* Quicksand — soft rounded sans, vendored locally (offline, no CDN). */
@font-face { font-family: "Quicksand"; font-style: normal; font-weight: 400; font-display: swap; src: url("vendor/fonts/quicksand-400.woff2") format("woff2"); }
@font-face { font-family: "Quicksand"; font-style: normal; font-weight: 500; font-display: swap; src: url("vendor/fonts/quicksand-500.woff2") format("woff2"); }
@font-face { font-family: "Quicksand"; font-style: normal; font-weight: 600; font-display: swap; src: url("vendor/fonts/quicksand-600.woff2") format("woff2"); }
@font-face { font-family: "Quicksand"; font-style: normal; font-weight: 700; font-display: swap; src: url("vendor/fonts/quicksand-700.woff2") format("woff2"); }

:root {
    --bg:        #1b1815;   /* warm near-black charcoal (matches scene bg) */
    --ink:       #f3ede6;   /* soft warm off-white */
    --ink-dim:   rgba(243, 237, 230, 0.45);
    --ink-faint: rgba(243, 237, 230, 0.22);
    --accent:    #c98a64;   /* muted terracotta, used sparingly */
    /* Dark translucent chip behind controls — readable over any backdrop. */
    --chip:      rgba(24, 21, 18, 0.62);
    --chip-hi:   rgba(44, 38, 32, 0.74);
    --font: "Quicksand", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    overflow: hidden;            /* full-bleed; no scrolling */
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    overscroll-behavior: none;   /* no rubber-band on mobile */
}

/* The kiln view: a dark vignette frames the scene during firing, with
   a warm inner glow that builds + fades. JS controls each layer's
   opacity per frame via the firing sequence in tick(); CSS only
   provides the gradients + a tiny transition so frame-to-frame
   opacity changes stay smooth. Pointer-events:none lets the (now
   muted) underlying controls stay unclickable but visible. */
.kiln-vignette {
    position: fixed;
    inset: 0;
    z-index: 38;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.18s linear;
}
.kiln-vignette > * {
    position: absolute;
    inset: 0;
    transition: opacity 0.18s linear;
}
.kiln-edge {
    /* dark chamber walls — transparent in the middle, opaque at the rim */
    background: radial-gradient(ellipse 60% 70% at 50% 56%,
        transparent 0%,
        transparent 28%,
        rgba(8, 5, 3, 0.55) 50%,
        rgba(6, 4, 2, 0.96) 82%);
}
.kiln-inner-glow {
    /* warm orange flame light pulsing inside the chamber */
    background: radial-gradient(ellipse 52% 60% at 50% 58%,
        rgba(255, 130, 40, 0.55) 0%,
        rgba(255,  90, 30, 0.30) 22%,
        transparent 56%);
    mix-blend-mode: screen;
    opacity: 0;
}
@media (prefers-reduced-motion: reduce) {
    .kiln-vignette { transition: none; opacity: 0; }
}

/* Looping video backdrop, same plane as .backdrop. JS toggles
   is-active to fade between static-image + motion backgrounds. */
.backdrop-video {
    position: fixed;
    inset: 0;
    z-index: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background-color: var(--bg);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s ease;
}
.backdrop-video.is-active { opacity: 1; }
.backdrop { transition: opacity 0.4s ease; }
.backdrop.is-hidden { opacity: 0; }

/* Backdrop image sits behind the transparent canvas. */
.backdrop {
    position: fixed;
    inset: 0;
    z-index: 0;
    background-color: var(--bg);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    transition: background-image 0.3s ease;
}

#scene {
    position: fixed;
    inset: 0;
    z-index: 1;                  /* above the backdrop */
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;          /* no scroll/zoom gestures on the canvas */
}

/* ---------- Soft loading state ---------- */
.loader {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    background: var(--bg);
    transition: opacity 0.7s ease;
}
.loader.is-hidden {
    opacity: 0;
    pointer-events: none;
}

.loader-ring {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 2px solid var(--ink-faint);
    border-top-color: var(--accent);
    animation: slip-spin 1.1s linear infinite;
}
@keyframes slip-spin {
    to { transform: rotate(360deg); }
}

.loader-label {
    font-size: 0.78rem;
    letter-spacing: 0.32em;
    text-transform: uppercase;
    color: var(--ink-dim);
    padding-left: 0.32em;        /* compensate trailing letter-spacing */
}

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

/* ---------- Title / landing screen ---------- */
.landing {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 24px;
    /* Translucent scrim so the chosen backdrop previews behind the title. */
    background: rgba(20, 18, 16, 0.74);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    transition: opacity 0.6s ease;
}
.landing[hidden] { display: none; }
.landing.is-gone { opacity: 0; pointer-events: none; }
.landing-title {
    margin: 0;
    font-size: 2.4rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--ink);
}
.landing-tag {
    margin: 0 0 28px;
    color: var(--ink-dim);
    font-size: 0.9rem;
    letter-spacing: 0.1em;
}
.landing-btn {
    -webkit-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: transparent;
    font: inherit;
    font-size: 0.95rem;
    letter-spacing: 0.04em;
    color: var(--bg);
    background: var(--accent);
    border: none;
    border-radius: 999px;
    padding: 12px 40px;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.08s ease;
}
.landing-btn:hover { background: #d89a74; }
.landing-btn:active { transform: scale(0.97); }
.landing-link {
    -webkit-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: transparent;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--ink-dim);
    font: inherit;
    font-size: 0.82rem;
    letter-spacing: 0.04em;
    padding: 6px;
    transition: color 0.2s ease;
}
.landing-link:hover { color: var(--ink); }

/* Get-the-app link on the title screen. Same minimal weight as the
   gallery link, with a touch of breathing room above so it reads as
   an aside rather than a third action competing with Begin. Hidden
   inside the Capacitor wrap (where you're already in the app). */
.landing-app-link {
    margin-top: 14px;
    text-decoration: none;
    font-size: 0.78rem;
    opacity: 0.85;
}
.landing-app-link:hover { opacity: 1; }

/* Starter-shape picker on the title screen */
.shape-picker {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    max-width: 320px;
    margin-bottom: 10px;
}
.shape-swatch {
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
    width: 56px;
    height: 64px;
    padding: 6px 4px 2px;
    border-radius: 12px;
    border: 2px solid var(--ink-faint);
    background: var(--chip);
    color: var(--ink-dim);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    gap: 2px;
    transition: border-color 0.15s ease, color 0.15s ease,
                background 0.15s ease, transform 0.1s ease;
}
.shape-swatch svg {
    width: 40px;
    height: 40px;
    display: block;
}
.shape-swatch span {
    font-size: 0.62rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.shape-swatch.is-active {
    border-color: var(--accent);
    color: var(--ink);
    background: rgba(201, 138, 100, 0.18);
    transform: scale(1.04);
}

/* Backdrop picker on the title screen — category tabs on top, one
   row of swatches below. Only the active category's swatches show,
   so the picker stays compact even as more backdrops are added. */
.bg-picker {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: 100%;
    max-width: 340px;
    margin-bottom: 6px;
}
.bg-tabs {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 2px;
}
.bg-tab {
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    border: 1px solid transparent;
    padding: 4px 10px;
    font: inherit;
    font-size: 0.6rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-faint);
    cursor: pointer;
    border-radius: 999px;
    transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.bg-tab:hover:not(.is-active) { color: var(--ink-dim); }
.bg-tab.is-active {
    color: var(--ink);
    background: var(--chip);
    border-color: var(--ink-faint);
}
.bg-row {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 4px 8px;
    max-width: 100%;
    justify-content: safe center;
}
.bg-row::-webkit-scrollbar { display: none; }
.bg-row .bg-swatch { flex: 0 0 auto; }
.bg-swatch {
    -webkit-tap-highlight-color: transparent;
    width: 52px;
    height: 36px;
    padding: 0;
    border-radius: 8px;
    border: 2px solid var(--ink-faint);
    background-size: cover;
    background-position: center;
    cursor: pointer;
    transition: border-color 0.15s ease, transform 0.1s ease;
}
.bg-swatch.is-active { border-color: var(--ink); transform: scale(1.06); }
/* Motion-category swatches: chip-coloured tile with a play glyph
   instead of a static thumbnail so we don't preload video bytes
   just for the picker. */
.bg-swatch.is-video {
    background-color: var(--chip-hi);
    position: relative;
    color: var(--ink);
}
.bg-swatch.is-video::after {
    content: "▸";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    color: var(--ink-dim);
}
.bg-swatch.is-video.is-active::after { color: var(--ink); }

/* Locked-pack tab: an uninstalled category in the Capacitor wrap. Same
   layout, a soft download glyph after the label so it reads as "needs
   a tap to fetch" without a heavier sub-tab structure. */
.bg-tab.is-pack-locked::after {
    content: " \2913";   /* downwards arrow to bar */
    margin-left: 4px;
    opacity: 0.7;
    font-size: 0.6rem;
}
.bg-tab.bg-manage {
    color: var(--ink-dim);
    border-color: var(--ink-faint);
    background: transparent;
    margin-left: 4px;
}
.bg-tab.bg-manage:hover { color: var(--ink); }

/* Inline install prompt — replaces the swatch row for an uninstalled
   category. Same vertical footprint as a swatch row so the title
   screen layout doesn't jump when the user flips between tabs. */
.bg-row.bg-row-install {
    justify-content: center;
    overflow: hidden;
}
.bg-install {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 4px 6px 4px 10px;
    border-radius: 999px;
    background: var(--chip);
    border: 1px solid var(--ink-faint);
    color: var(--ink);
    font-size: 0.72rem;
    max-width: 100%;
}
.bg-install-label {
    color: var(--ink-dim);
    letter-spacing: 0.04em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.bg-install-btn {
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
    border: none;
    background: var(--accent);
    color: #1b1815;
    font: inherit;
    font-weight: 600;
    font-size: 0.7rem;
    letter-spacing: 0.04em;
    padding: 4px 12px;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
}
.bg-install-btn:hover:not(:disabled) { background: #d89a74; }
.bg-install-btn:active { transform: scale(0.97); }
.bg-install-btn:disabled { opacity: 0.55; cursor: default; }
.bg-install-pct {
    color: var(--ink);
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 999px;
    background: var(--chip-hi);
    font-size: 0.7rem;
    min-width: 44px;
    text-align: center;
}
.bg-install.bg-install-error { border-color: rgba(217, 122, 92, 0.55); }
.bg-install.bg-install-error .bg-install-label { color: var(--ink); }

/* Pack manager — a slide-up sheet over the studio. Mirrors the
   gallery's full-screen treatment but takes only the bottom band so
   the studio (and the title screen behind it) stays visible behind. */
/* Custom confirm dialog — centered card over a dimmed backdrop. Used
   by returnToTitle when the user has unsaved work; generic helper
   `showConfirm()` returns a promise so future callers can reuse it
   for any yes/no decision. Matches the rest of the app's calm
   palette (no native browser-modal harshness). */
.confirm-modal {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(10, 8, 6, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity 0.18s ease;
}
.confirm-modal[hidden] { display: none; }
.confirm-modal.is-open { opacity: 1; }
.confirm-modal-card {
    background: var(--bg);
    border: 1px solid var(--ink-faint);
    border-radius: 16px;
    padding: 22px 22px 18px;
    max-width: 360px;
    width: 100%;
    color: var(--ink);
    transform: translateY(8px);
    transition: transform 0.18s ease;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
}
.confirm-modal.is-open .confirm-modal-card { transform: translateY(0); }
.confirm-modal-message {
    margin: 0 0 18px;
    font-size: 0.95rem;
    line-height: 1.45;
    text-align: center;
    color: var(--ink);
}
.confirm-modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}
.confirm-modal-btn {
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    border: 1px solid var(--ink-faint);
    color: var(--ink-dim);
    font: inherit;
    font-size: 0.82rem;
    letter-spacing: 0.04em;
    padding: 8px 16px;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.confirm-modal-btn:hover,
.confirm-modal-btn:focus-visible {
    color: var(--ink);
    border-color: var(--ink);
    outline: none;
}
.confirm-modal-btn:active { transform: scale(0.97); }
.confirm-modal-btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #1b1815;
    font-weight: 600;
}
.confirm-modal-btn-primary:hover,
.confirm-modal-btn-primary:focus-visible {
    background: #d89a74;
    border-color: #d89a74;
    color: #1b1815;
}

.pack-sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 70;
    background: rgba(20, 17, 14, 0.96);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid var(--ink-faint);
    border-radius: 16px 16px 0 0;
    padding: max(14px, env(safe-area-inset-top, 0px)) 16px max(16px, env(safe-area-inset-bottom, 0px));
    transform: translateY(100%);
    transition: transform 0.22s ease;
    color: var(--ink);
}
.pack-sheet.is-open { transform: translateY(0); }
.pack-sheet[hidden] { display: none; }
.pack-sheet-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.pack-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 50vh;
    overflow-y: auto;
}
.pack-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--chip);
    border: 1px solid var(--ink-faint);
}
.pack-item-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.pack-item-name {
    font-size: 0.86rem;
    color: var(--ink);
    letter-spacing: 0.02em;
}
.pack-item-size {
    font-size: 0.7rem;
    color: var(--ink-dim);
    letter-spacing: 0.06em;
}
.pack-item-action { display: flex; align-items: center; gap: 8px; }
.pack-item-tag {
    font-size: 0.62rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--ink-dim);
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid var(--ink-faint);
}
.pack-item-tag.is-busy { color: var(--ink); }
.pack-note {
    margin: 10px 2px 0;
    font-size: 0.7rem;
    color: var(--ink-dim);
    text-align: center;
}

.sound-toggles {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
}
.music-toggle {
    -webkit-appearance: none;
    appearance: none;
    -webkit-tap-highlight-color: transparent;
    font: inherit;
    font-size: 0.8rem;
    letter-spacing: 0.03em;
    color: var(--ink-dim);
    background: var(--chip);
    border: 1px solid var(--ink-faint);
    border-radius: 999px;
    padding: 7px 16px;
    cursor: pointer;
    transition: color 0.2s ease, border-color 0.2s ease;
}
.music-toggle.is-on { color: var(--ink); border-color: var(--ink-dim); }

/* Back-to-title button (top-left, beside home) */
.title-btn {
    position: fixed;
    top:  max(16px, env(safe-area-inset-top, 0px));
    left: calc(max(16px, env(safe-area-inset-left, 0px)) + 46px);
    z-index: 40;
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--chip);
    border: 1px solid var(--ink-faint);
    color: var(--ink-dim);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.title-btn:hover,
.title-btn:focus-visible {
    color: var(--ink);
    border-color: var(--ink-dim);
    background: var(--chip-hi);
    outline: none;
}

/* ---------- Minimal home affordance ---------- */
.home {
    position: fixed;
    top:  max(16px, env(safe-area-inset-top, 0px));
    left: max(16px, env(safe-area-inset-left, 0px));
    z-index: 40;
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--chip);
    border: 1px solid var(--ink-faint);
    color: var(--ink-dim);
    font-size: 20px;
    line-height: 1;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.home:hover,
.home:focus-visible {
    color: var(--ink);
    border-color: var(--ink-dim);
    background: var(--chip-hi);
    outline: none;
}

/* ---------- Lid style picker (only while shaping a lid) ---------- */
.lid-style-picker {
    position: fixed;
    left: 0;
    right: 0;
    bottom: max(132px, calc(env(safe-area-inset-bottom, 0px) + 132px));
    z-index: 35;
    display: flex;
    justify-content: center;
    gap: 6px;
    pointer-events: none;
}
.lid-style-picker[hidden] { display: none; }
.lid-style-btn {
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
    font: inherit;
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-dim);
    background: var(--chip);
    border: 1px solid var(--ink-faint);
    border-radius: 999px;
    padding: 6px 16px;
    cursor: pointer;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.lid-style-btn.is-active {
    color: var(--ink);
    border-color: var(--accent);
    background: rgba(201, 138, 100, 0.18);
}

/* ---------- Brush size bar (only while wet) ---------- */
.brush-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: max(84px, calc(env(safe-area-inset-bottom, 0px) + 84px));
    z-index: 35;
    display: flex;
    justify-content: center;
    gap: 8px;
    pointer-events: none;
}
/* `display: flex` above would otherwise defeat the hidden attribute. */
.brush-bar[hidden] { display: none; }
.brush-btn {
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--ink-faint);
    background: var(--chip);
    cursor: pointer;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition: border-color 0.2s ease, background 0.2s ease;
}
.brush-btn.is-active {
    border-color: var(--accent);
    background: rgba(201, 138, 100, 0.18);
}
.brush-dot {
    display: block;
    border-radius: 50%;
    background: var(--ink-dim);
    transition: background 0.2s ease;
}
.brush-btn.is-active .brush-dot { background: var(--accent); }
.brush-dot-s { width: 5px;  height: 5px;  }
.brush-dot-m { width: 9px;  height: 9px;  }
.brush-dot-l { width: 15px; height: 15px; }

/* ---------- Decoration controls (bone-dry / decorate) ---------- */
/* A bottom-anchored column: tab row (Glaze | Decorate) + the active
   panel. Palettes are single horizontally-scrolling strips, so adding
   content never wraps into a taller, messier tray. */
.deco-stack {
    position: fixed;
    left: 0;
    right: 0;
    bottom: max(76px, calc(env(safe-area-inset-bottom, 0px) + 76px));
    z-index: 35;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}
.deco-stack[hidden] { display: none; }

/* Tab row */
.deco-tabs {
    display: flex;
    gap: 6px;
    pointer-events: none;
}
.deco-tab {
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
    font: inherit;
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-dim);
    background: var(--chip);
    border: 1px solid var(--ink-faint);
    border-radius: 999px;
    padding: 6px 18px;
    cursor: pointer;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.deco-tab.is-active {
    color: var(--ink);
    border-color: var(--accent);
    background: rgba(201, 138, 100, 0.18);
}

.deco-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
}
.deco-panel[hidden] { display: none; }

/* A single scrolling row of controls (glazes, colours, options). */
.deco-strip {
    display: flex;
    flex-wrap: nowrap;
    justify-content: safe center;
    align-items: center;
    gap: 8px;
    padding: 2px 14px;
    max-width: 100vw;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    pointer-events: none;
}
.deco-strip::-webkit-scrollbar { display: none; }
.deco-strip > * { pointer-events: auto; flex: 0 0 auto; }
/* `display: flex` above would otherwise defeat the `hidden` attribute. */
.deco-strip[hidden] { display: none; }

/* The tools row (centred, may wrap on very narrow screens). */
.deco-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    max-width: 100vw;
    pointer-events: none;
}
.deco-row > * { pointer-events: auto; }

.deco-sub {
    display: inline-flex;
    gap: 8px;
}
.deco-sub[hidden] { display: none; }

/* Contextual sub-palette: stamp shapes (glyphs) / overlay patterns. */
.deco-sub-btn {
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
    min-width: 34px;
    height: 34px;
    padding: 0 10px;
    font: inherit;
    font-size: 1rem;
    line-height: 1;
    color: var(--ink-dim);
    background: var(--chip);
    border: 1px solid var(--ink-faint);
    border-radius: 999px;
    cursor: pointer;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.deco-sub-text { font-size: 0.72rem; letter-spacing: 0.03em; }
.deco-sub-btn.is-active {
    color: var(--ink);
    border-color: var(--accent);
    background: rgba(201, 138, 100, 0.18);
}
.deco-tool {
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
    font: inherit;
    font-size: 0.72rem;
    letter-spacing: 0.03em;
    color: var(--ink-dim);
    background: var(--chip);
    border: 1px solid var(--ink-faint);
    border-radius: 999px;
    padding: 7px 13px;
    cursor: pointer;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.deco-tool.is-active {
    color: var(--ink);
    border-color: var(--accent);
    background: rgba(201, 138, 100, 0.18);
}
.deco-sizes {
    display: inline-flex;
    gap: 6px;
}
.deco-size {
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid var(--ink-faint);
    background: var(--chip);
    cursor: pointer;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition: border-color 0.2s ease, background 0.2s ease;
}
.deco-size.is-active {
    border-color: var(--accent);
    background: rgba(201, 138, 100, 0.18);
}
.deco-size.is-active .brush-dot { background: var(--accent); }

.deco-colors {
    display: inline-flex;
    gap: 6px;
}
.deco-swatch {
    -webkit-tap-highlight-color: transparent;
    width: 26px;
    height: 26px;
    padding: 0;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.18);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease;
}
.deco-swatch.is-active {
    border-color: var(--ink);
    transform: scale(1.14);
}

/* ---------- Glaze palette (in the decorate stack) ----------
   The bar lives inside a .deco-strip whose default is a single
   scrolling row. With 16+ glazes we explicitly wrap into a centred
   grid so users see all swatches without horizontal scroll. */
#glazeBar {
    flex-wrap: wrap;
    overflow-x: visible;
    justify-content: center;
    max-width: 360px;
    margin: 0 auto;
    row-gap: 8px;
}
.glaze-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    pointer-events: none;
}
.glaze-bar[hidden] { display: none; }
.glaze-btn {
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
    width: 34px;
    height: 34px;
    padding: 0;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.18);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
    cursor: pointer;
    transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.glaze-btn:hover,
.glaze-btn:focus-visible { outline: none; transform: scale(1.08); }
.glaze-btn.is-active {
    border-color: var(--ink);
    box-shadow: 0 0 0 2px rgba(243, 237, 230, 0.3), 0 2px 8px rgba(0, 0, 0, 0.35);
    transform: scale(1.12);
}

/* ---------- Tool bar ----------
   Buttons + the stage chip share one centred row. On narrow screens
   they wrap so nothing overlaps; padding tightens on mobile so a
   busy set+fired toolbar (Swap / Photo / Save / + Lid / advance)
   still fits. */
.toolbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: max(34px, calc(env(safe-area-inset-bottom, 0px) + 34px));
    z-index: 35;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    padding: 0 10px;
    pointer-events: none;        /* gaps stay pass-through */
}
.tool-btn {
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
    font: inherit;
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    color: var(--ink-dim);
    background: var(--chip);
    border: 1px solid var(--ink-faint);
    border-radius: 999px;
    padding: 8px 14px;
    cursor: pointer;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    transition: color 0.2s ease, border-color 0.2s ease,
                background 0.2s ease, transform 0.08s ease;
}
.tool-btn:hover,
.tool-btn:focus-visible {
    color: var(--ink);
    border-color: var(--ink-dim);
    background: var(--chip-hi);
    outline: none;
}
.tool-btn:active { transform: scale(0.97); }

/* The advance control reads as primary: warm clay accent. */
.tool-btn-primary {
    color: var(--bg);
    background: var(--accent);
    border-color: var(--accent);
}
.tool-btn-primary:hover,
.tool-btn-primary:focus-visible {
    color: var(--bg);
    background: #d89a74;
    border-color: #d89a74;
}

/* Non-interactive stage label. */
.stage-chip {
    align-self: center;
    pointer-events: none;
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(243, 237, 230, 0.7);
    background: var(--chip);
    border-radius: 999px;
    padding: 7px 14px;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

/* ---------- Gallery open button (top-right) ---------- */
.gallery-open {
    position: fixed;
    top:   max(16px, env(safe-area-inset-top, 0px));
    right: max(16px, env(safe-area-inset-right, 0px));
    z-index: 40;
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--chip);
    border: 1px solid var(--ink-faint);
    color: var(--ink-dim);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.gallery-open:hover,
.gallery-open:focus-visible {
    color: var(--ink);
    border-color: var(--ink-dim);
    background: var(--chip-hi);
    outline: none;
}

/* ---------- Gallery overlay ---------- */
.gallery {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(20, 18, 16, 0.96);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    padding: max(16px, env(safe-area-inset-top, 0px)) 16px 16px;
}
.gallery[hidden] { display: none; }
.gallery-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.gallery-title {
    font-size: 0.82rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--ink-dim);
}
.gallery-grid {
    flex: 1;
    overflow-y: auto;
    display: grid;
    gap: 12px;
    align-content: start;
}
/* Compact = the classic thumbnail grid. Shelf = larger cards with
   metadata: title (tap to rename), glaze name, save date. */
.gallery-grid.compact {
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
}
.gallery-grid.shelf {
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.gallery-item {
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid var(--ink-faint);
    background: var(--bg);
}
.gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    cursor: pointer;
}

/* Compact paired set: two thumbnails side-by-side, unless we have
   an assembly thumb in which case the single composite fills the
   whole tile like a solo entry. */
.gallery-item.gallery-set:not(.is-shelf):not(.has-assembly) {
    display: flex;
    flex-direction: row;
}
.gallery-item.gallery-set:not(.is-shelf):not(.has-assembly) .gallery-half {
    flex: 1 1 0;
    height: 100%;
    overflow: hidden;
}
.gallery-item.gallery-set:not(.is-shelf):not(.has-assembly) .gallery-half + .gallery-half {
    border-left: 1px solid var(--ink-faint);
}

/* Shelf-mode tile: thumbnail on the left, metadata on the right. */
.gallery-item.is-shelf {
    aspect-ratio: auto;
    height: 140px;
    display: grid;
    grid-template-columns: 140px 1fr;
    background: var(--chip);
}
.gallery-item.is-shelf .pot-thumb-wrap {
    position: relative;
    height: 100%;
    overflow: hidden;
}
.gallery-item.is-shelf .pot-thumb {
    width: 100%;
    height: 100%;
}
.gallery-item.is-shelf.gallery-set:not(.has-assembly) .pot-thumb-wrap {
    display: flex;
    flex-direction: column;
}
/* Each half takes 50% of the wrap; height:auto lets flex sizing
   actually work (the old height:100% forced both to overlap). */
.gallery-item.is-shelf.gallery-set:not(.has-assembly) .gallery-half {
    flex: 1 1 0;
    width: 100%;
    height: auto;
    min-height: 0;
    overflow: hidden;
}
.gallery-item.is-shelf.gallery-set:not(.has-assembly) .gallery-half img {
    object-fit: cover;
}
.gallery-item.is-shelf.gallery-set:not(.has-assembly) .gallery-half + .gallery-half {
    border-top: 1px solid var(--ink-faint);
}
/* When a single assembly thumb is captured, render it as ONE image
   filling the thumb area — the set reveal in miniature. */
.gallery-item.is-shelf.has-assembly .pot-thumb {
    width: 100%;
    height: 100%;
}
.pot-meta {
    padding: 12px 14px 12px 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    min-width: 0; /* allow ellipsis */
}
.pot-title {
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
    background: none;
    border: none;
    text-align: left;
    padding: 0;
    font: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--ink);
    cursor: pointer;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: color 0.15s ease;
}
.pot-title.is-empty {
    color: var(--ink-dim);
    font-weight: 400;
    font-style: italic;
}
.pot-title:hover,
.pot-title:focus-visible {
    color: var(--accent);
    outline: none;
}
.pot-sub {
    font-size: 0.75rem;
    color: var(--ink-dim);
    letter-spacing: 0.03em;
}

.gallery-bar-right {
    display: inline-flex;
    gap: 6px;
}

/* ---------- Photo modal ---------- */
.photo-modal {
    position: fixed;
    inset: 0;
    z-index: 70;
    background: rgba(20, 18, 16, 0.96);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: max(16px, env(safe-area-inset-top, 0px)) 16px 16px;
    gap: 14px;
    overflow-y: auto;
}
.photo-modal[hidden] { display: none; }
.photo-modal-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 4px;
}
.photo-preview-wrap {
    flex: 0 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 360px;
    background: var(--bg);
    border-radius: 14px;
    overflow: hidden;
    border: 1px solid var(--ink-faint);
}
.photo-preview {
    display: block;
    width: 100%;
    height: auto;
}
.photo-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}
.photo-chip {
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
    font: inherit;
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    color: var(--ink-dim);
    background: var(--chip);
    border: 1px solid var(--ink-faint);
    border-radius: 999px;
    padding: 8px 16px;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.photo-chip.is-active {
    color: var(--ink);
    border-color: var(--accent);
    background: rgba(201, 138, 100, 0.18);
}
.photo-chip:hover:not(.is-active) {
    color: var(--ink);
    border-color: var(--ink-dim);
}
.gallery-del {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.gallery-empty {
    margin: auto;
    color: var(--ink-faint);
    font-size: 0.85rem;
    text-align: center;
    padding: 0 2rem;
}
.gallery-grid:not(:empty) + .gallery-empty { display: none; }

/* ---------- Quiet footer ---------- */
.footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 25;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 6px 12px;
    padding-bottom: max(6px, env(safe-area-inset-bottom, 0px));
    color: rgba(243, 237, 230, 0.5);
    font-size: 0.66rem;
    letter-spacing: 0.04em;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.75); /* readable over light backdrops */
    pointer-events: none;        /* let the scene own the space */
    user-select: none;
}
.footer .sep { opacity: 0.6; }
.footer a {
    color: var(--ink-dim);
    text-decoration: none;
    pointer-events: auto;        /* links stay clickable */
    transition: color 0.2s ease;
}
.footer a:hover { color: var(--ink); }
