/* Styles for the play-lab additions: bubbles, music, paint, the video board
 * and Meadowbrook.
 *
 * Loaded after games.css and before access.css, which is deliberate — the scan
 * highlight and the reduced-motion rules must still win over everything here.
 *
 * Two conventions carried over from games.css and worth keeping:
 *   - stages that hold a canvas or absolutely-positioned children set
 *     `container-type: size`, so type can be sized against the stage rather
 *     than the viewport and stays sane at any Overall size setting.
 *   - nothing scrolls. Every region either fits, pages itself with
 *     `data-fit-pages`, or is a fixed-size stage that clips.
 */

/* ============ Shared: a big press button that is not the whole stage ============
   Fireworks' .ce-button fills its stage. Bubbles and Paint both need the same
   button sitting under a stage that is doing its own drawing, so this is the
   same control at action-bar height. */
.ce-button-wide {
    width: min(520px, 100%);
    height: auto; min-height: clamp(64px, calc(11 * var(--vh)), 120px);
    grid-auto-flow: column; gap: 16px; padding: 10px 28px;
}
.ce-button-wide .ce-button-emoji { font-size: clamp(24px, calc(4.4 * var(--vh)), 44px); }
.ce-button-wide .ce-button-text { font-size: clamp(20px, calc(3.6 * var(--vh)), 36px); }

body.is-tight .ce-button-wide { min-height: 56px; }
body.is-tighter .ce-button-wide { min-height: 48px; padding: 6px 20px; }

/* ============ Pop the Bubbles ============ */
.bubble-stage {
    position: relative; overflow: hidden;
    min-height: 0; min-width: 0;
    margin: 6px 0 clamp(8px, calc(1.6 * var(--vh)), 20px);
    border-radius: var(--radius);
    background:
        radial-gradient(120% 90% at 50% 110%, color-mix(in srgb, var(--primary) 22%, transparent), transparent 70%),
        var(--surface-2);
    border: 1px solid var(--line);
    container-type: size;
}
.bubble {
    appearance: none; position: absolute; top: 0; left: 0;
    padding: 0; cursor: pointer;
    border-radius: 50%;
    border: 3px solid color-mix(in srgb, var(--bubble-color) 80%, white);
    background:
        radial-gradient(circle at 32% 28%, rgba(255,255,255,.85), rgba(255,255,255,0) 42%),
        color-mix(in srgb, var(--bubble-color) 55%, transparent);
    box-shadow: 0 6px 18px rgba(0,0,0,.28), inset 0 -6px 14px color-mix(in srgb, var(--bubble-color) 45%, transparent);
    /* Motion is driven from JS (see js/games/bubbles.js) — a CSS animation here
       would be switched off for reduced-motion players and freeze the bubbles
       at the bottom of the stage forever. */
    will-change: transform;
}
.bubble:hover { filter: brightness(1.12); }
.bubble.scan-current { border-radius: 50%; }

/* ============ Music Maker ============ */
.pad-grid {
    display: grid; gap: clamp(10px, 2vw, 20px);
    grid-template-columns: repeat(3, 1fr);
    grid-auto-rows: 1fr; min-height: 0;
    margin: 6px 0 clamp(8px, calc(1.6 * var(--vh)), 20px);
    container-type: size;
}
.pad {
    appearance: none; font-family: 'Fredoka', sans-serif;
    min-height: 0; padding: 8px;
    border: 4px solid transparent; border-radius: 22px;
    background: var(--pad-color, var(--primary));
    color: #fff; cursor: pointer;
    display: grid; place-items: center; align-content: center; gap: 8px;
    box-shadow: var(--shadow-lg);
    transition: transform .16s cubic-bezier(.34,1.56,.64,1), filter .16s ease;
}
.pad:hover { transform: translateY(-4px); filter: saturate(1.1); }
.pad:active { transform: scale(.96); }
.pad.scan-current { border-radius: 22px; }
.pad-dot {
    width: clamp(14px, 7cqh, 30px); aspect-ratio: 1; border-radius: 50%;
    background: rgba(255,255,255,.55); box-shadow: inset 0 -2px 6px rgba(0,0,0,.18);
}
.pad-label {
    font-size: clamp(16px, min(4.5vw, 16cqh), 34px); font-weight: 600;
    text-shadow: 0 2px 8px rgba(0,0,0,.3);
}
/* The press flash. Kept as a class rather than :active so it also fires for a
   switch or dwell selection, which never produce a pointer press at all. */
.pad.is-hit { transform: scale(1.05); filter: brightness(1.25); border-color: #fff; }

.mode-btn { display: inline-flex; align-items: center; gap: 9px; }
.mode-btn[aria-pressed="true"] {
    border-color: var(--primary-ink);
    background: color-mix(in srgb, var(--primary) 24%, var(--surface-2));
    color: var(--ink);
}

@media (max-width: 640px) {
    .pad-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ============ Paint Splat ============ */
.paint-stage {
    position: relative; overflow: hidden;
    min-height: 0; min-width: 0;
    margin: 6px 0 clamp(8px, calc(1.6 * var(--vh)), 20px);
    border-radius: var(--radius);
    /* Paper, not surface: the painting needs something to be *on*, and a light
       ground is the only one every paint colour shows up against. */
    background: #FBF7EF;
    border: 1px solid var(--line-strong);
    box-shadow: inset 0 2px 18px rgba(0,0,0,.12);
}
#ps-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* The paper is a target in its own right — a tap, a held press or a gaze
   resting on it paints at that exact spot. It has to be a real element rather
   than the canvas itself: the access engine finds targets by [data-scan], and
   the canvas is a drawing surface the game keeps rewriting. Transparent, last
   in the stage, and therefore on top of the paint. */
.paint-surface {
    appearance: none; -webkit-appearance: none;
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    margin: 0; padding: 0; border: 0;
    background: none;
    border-radius: inherit;
    cursor: crosshair;
    /* No double-tap zoom or tap delay: a splat must land as the finger does. */
    touch-action: manipulation;
}
/* Inset, so the ring is not clipped by the stage's own overflow: hidden. */
.paint-surface:focus-visible { outline: 4px solid var(--scan-ring); outline-offset: -4px; }

/* ============ Look & Play videos ============ */
.vid-board { position: relative; min-height: 0; display: flex; flex-direction: column; }

/* auto-FIT, not auto-fill: empty tracks collapse, so a board with two videos
   on it gives those two videos the whole row instead of leaving them as small
   tiles beside three empty columns. On a gaze board the target size is the
   whole point, and most of these boards will hold only a handful of videos. */
.vid-grid {
    display: grid; gap: clamp(10px, 1.8vw, 18px);
    grid-template-columns: repeat(auto-fit, minmax(clamp(140px, 20vw, 230px), 1fr));
    align-content: start;
    width: 100%; max-width: 1100px; margin-inline: auto;
    min-height: 0; overflow: hidden;
}
.vid-tile {
    appearance: none; font-family: 'Nunito', sans-serif;
    display: grid; gap: 8px; padding: 8px 8px 12px;
    border: 2px solid var(--line-strong); border-radius: 18px;
    background: var(--surface-2); color: var(--ink);
    cursor: pointer; text-align: center;
    transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.vid-tile:hover { transform: translateY(-3px); border-color: var(--primary-ink); box-shadow: var(--shadow-md); }
.vid-art {
    position: relative; display: block; aspect-ratio: 16 / 9;
    border-radius: 12px; overflow: hidden;
    background: hsl(var(--tile-hue, 200) 45% 26%);
}
.vid-thumb { width: 100%; height: 100%; object-fit: cover; display: block; }
.vid-thumb-plain { display: grid; place-items: center; color: rgba(255,255,255,.75); }
.vid-thumb-plain .ico { width: 38%; height: 38%; }
/* The play badge is the affordance — without it a tile is just a picture, and
   "this one is a button you can start" is the whole message. */
.vid-play {
    position: absolute; inset: 0; display: grid; place-items: center;
    background: rgba(0,0,0,.28);
}
.vid-play .ico {
    width: 34%; height: 34%; color: #fff;
    filter: drop-shadow(0 3px 10px rgba(0,0,0,.5));
}
.vid-title {
    font-weight: 800; font-size: clamp(14px, 1.5vw, 17px); line-height: 1.25;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden;
}

.vid-empty {
    margin: auto; max-width: 46ch; text-align: center;
    display: grid; justify-items: center; gap: 10px;
    color: var(--ink-dim);
}
.vid-empty-art { color: var(--primary-ink); }
.vid-empty-art .ico { width: 54px; height: 54px; }
.vid-empty h3 { color: var(--ink); font-size: clamp(19px, 2.4vw, 25px); }
.vid-empty p { font-weight: 600; font-size: 15px; line-height: 1.5; }
.vid-empty-eg { font-size: 14px; }
.vid-empty code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
    background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px;
    padding: 2px 6px; display: inline-block; margin-top: 4px;
}

/* The player and the editor both cover the board rather than replacing it, so
   the tiles and their scan positions survive underneath. */
.vid-player, .vid-editor {
    position: absolute; inset: 0; z-index: 5;
    display: none; flex-direction: column; gap: 10px;
    background: var(--surface); border-radius: var(--radius);
}
.screen.is-playing .vid-player { display: flex; }
.screen.is-editing .vid-editor { display: flex; }
/* Only one thing at a time can be operated, so the board's controls stand down
   while either is up — otherwise a switch sweep would keep landing on tiles
   hidden behind the player. */
.screen.is-playing .vid-grid, .screen.is-editing .vid-grid,
.screen.is-playing #vid-tools, .screen.is-editing #vid-tools { visibility: hidden; }

.vid-player-frame {
    flex: 1; min-height: 0; border-radius: 14px; overflow: hidden; background: #000;
}
.vid-media { width: 100%; height: 100%; display: block; border: 0; }
.vid-player-bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; flex-shrink: 0; }
.vid-now { font-weight: 800; color: var(--ink); flex: 1; min-width: 0; }
.vid-open { color: var(--ink-dim); font-weight: 700; font-size: 14px; }
.vid-open:hover { color: var(--primary-ink); }

.vid-editor { padding: clamp(10px, 2vh, 20px); overflow: hidden; }
.vid-editor-title { font-size: clamp(18px, 2.2vw, 23px); color: var(--ink); }
.vid-editor-help { color: var(--ink-dim); font-weight: 600; font-size: 14.5px; }
.vid-editor-help code, .vid-editor-note code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.vid-editor-text {
    flex: 1; min-height: 0; width: 100%; resize: none;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; line-height: 1.6;
    padding: 12px 14px; border-radius: 12px;
    border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--ink);
}
.vid-editor-text:focus { outline: 3px solid var(--primary-ink); outline-offset: 1px; }
.vid-editor-note { font-weight: 700; font-size: 14px; color: var(--ink-dim); }
.vid-editor-note.is-warn { color: var(--accent); }

/* ============ Meadowbrook ============ */

/* Stacked on a narrow screen, side by side on a wide one.
 *
 * This is a size decision, not a taste one. The direction pad is three rows of
 * targets that must stay comfortably pressable, which is roughly 200px however
 * it is arranged. Under the world on a typical landscape display that leaves
 * the world about 200px tall — the map ends up drawn at the minimum tile size,
 * the camera never needs to scroll, and the character is a speck. Beside it,
 * the world keeps the full height and the tiles roughly double. */
.rpg-play {
    display: flex; flex-direction: column; min-height: 0; min-width: 0;
    gap: clamp(8px, calc(1.4 * var(--vh)), 16px);
}
@media (min-width: 900px) {
    .rpg-play { flex-direction: row; align-items: stretch; }
    .rpg-play .rpg-controls { flex-direction: column; flex-shrink: 0; justify-content: center; }
}

.rpg-stage {
    position: relative; overflow: hidden;
    flex: 1; min-height: 0; min-width: 0;
    border-radius: var(--radius);
    border: 1px solid var(--line-strong);
    background: #3E8A4A;
    container-type: size;
}
#rpg-canvas {
    position: absolute; inset: 0; width: 100%; height: 100%; display: block;
    /* The world is drawn from chunky shapes on purpose; letting the browser
       smooth them on a HiDPI screen just makes it muddy. */
    image-rendering: auto;
}

.rpg-bag, .rpg-hint {
    position: absolute; z-index: 3; margin: 0;
    padding: 6px 12px; border-radius: var(--radius-pill);
    background: rgba(8, 18, 12, .62);
    color: #fff; font-weight: 700; font-size: clamp(12px, 1.5vw, 14.5px);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    pointer-events: none; max-width: calc(100% - 24px);
}
.rpg-bag { top: 10px; left: 10px; }
.rpg-hint { bottom: 10px; left: 50%; transform: translateX(-50%); text-align: center; }

/* Dialogue sits over the bottom of the world, the way it does in every game
   this borrows from — and it must never cover the middle, where the player is. */
.rpg-say {
    position: absolute; z-index: 4; left: 10px; right: 10px; bottom: 10px;
    display: grid; gap: 6px;
    padding: clamp(10px, 2.2cqh, 18px) clamp(14px, 3cqw, 22px);
    border-radius: 18px;
    background: rgba(10, 16, 24, .9);
    border: 2px solid var(--line-strong);
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.rpg-say-who {
    margin: 0; font-family: 'Fredoka', sans-serif; font-weight: 600;
    font-size: clamp(14px, 2cqh, 18px); color: var(--accent);
}
.rpg-say-text {
    margin: 0; color: #fff; font-weight: 700; line-height: 1.35;
    font-size: clamp(15px, min(2.4vw, 3.4cqh), 22px);
}
.rpg-say-next { justify-self: end; display: inline-flex; align-items: center; gap: 6px; min-width: 0; }

.rpg-quests {
    position: absolute; z-index: 5; inset: 8px 8px auto auto;
    width: min(340px, calc(100% - 16px));
    max-height: calc(100% - 16px); overflow: hidden;
    display: grid; gap: 10px; align-content: start;
    padding: 14px 16px; border-radius: 18px;
    background: rgba(10, 16, 24, .94);
    border: 2px solid var(--line-strong); box-shadow: var(--shadow-lg);
}
.rpg-quests-title { margin: 0; color: #fff; font-size: 18px; }
.quest-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.quest {
    display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 9px;
    color: #E6EAF2; font-weight: 700; font-size: 14px; line-height: 1.25;
}
.quest-tick { display: inline-flex; color: var(--ink-dim); }
.quest-tick .ico { width: 18px; height: 18px; }
.quest-count { color: var(--ink-dim); font-size: 13px; white-space: nowrap; }
.quest.is-pending .quest-count { color: var(--accent); }
.quest.is-done .quest-tick { color: var(--mint); }
.quest.is-done .quest-text { text-decoration: line-through; color: var(--ink-dim); }
.quest.is-done .quest-count { color: var(--mint); }

.rpg-controls {
    display: flex; align-items: center; justify-content: center;
    gap: clamp(12px, 3vw, 32px); flex-wrap: wrap; flex-shrink: 0;
}
/* A real cross, so "up" is above "down" — a row of four arrows makes the player
   translate a label into a direction on every single press. */
.rpg-pad {
    display: grid; gap: 6px;
    grid-template-columns: repeat(3, auto);
    grid-template-areas: '. up .' 'left . right' '. down .';
}
.pad-up { grid-area: up; }
.pad-left { grid-area: left; }
.pad-right { grid-area: right; }
.pad-down { grid-area: down; }
.rpg-pad-btn {
    appearance: none; cursor: pointer;
    width: clamp(52px, calc(9 * var(--vh)), 76px); aspect-ratio: 1;
    display: grid; place-items: center;
    border-radius: 18px;
    border: 1px solid var(--line-strong);
    background: var(--surface-2); color: var(--ink);
    transition: transform .14s ease, background .18s ease, border-color .18s ease;
}
.rpg-pad-btn .ico { width: 56%; height: 56%; }
.rpg-pad-btn:hover { border-color: var(--primary-ink); background: color-mix(in srgb, var(--primary) 16%, var(--surface-2)); }
.rpg-pad-btn:active { transform: scale(.94); }

.rpg-side { display: grid; gap: 8px; }
.rpg-side .btn-ghost { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.rpg-side .btn-ghost[aria-pressed="true"] {
    border-color: var(--primary-ink);
    background: color-mix(in srgb, var(--primary) 24%, var(--surface-2));
}

body.is-tight .rpg-pad-btn { width: clamp(46px, calc(7.4 * var(--vh)), 62px); }
body.is-tighter .rpg-pad-btn { width: 46px; border-radius: 14px; }
body.is-tighter .rpg-side .btn-ghost { padding: 7px 14px; font-size: 14px; }

@media (max-width: 720px) {
    .rpg-quests { width: calc(100% - 16px); }
}
