/*
 * Story Hour Academy — Placement Game Styles
 *
 * Harmonizes the Story Hour Academy interface teal (#14b8a6) with the warm
 * golden-age storybook illustration palette from the homepage: cream parchment,
 * honey ochre, terracotta, meadow sage, botanical teal, and warm ink brown.
 */

:root {
    --pl-cream: #fdf9e7;
    --pl-cream-deep: #f6eccb;
    --pl-paper: #fffdf5;
    --pl-ink: #33251a;
    --pl-ink-soft: #665545;

    --pl-teal: #14b8a6;
    --pl-teal-bright: #2dd4bf;
    --pl-teal-mid: #0f7f75;
    --pl-teal-deep: #0b5d56;
    --pl-teal-shadow: #073f3a;

    --pl-honey: #e89b38;
    --pl-honey-light: #f6c96b;
    --pl-honey-deep: #bf6d1b;
    --pl-honey-pale: #fef2d1;

    --pl-sage: #7ea15e;
    --pl-sage-deep: #4f7337;
    --pl-sage-pale: #edf5e4;

    --pl-terracotta: #d96b38;
    --pl-terracotta-pale: #fdf0e8;

    --pl-lavender: #6d64b8;
    --pl-lavender-deep: #4e468f;
    --pl-lavender-glow: rgba(109, 100, 184, 0.45);

    --pl-border: #e5d7b3;
    --pl-radius-lg: 24px;
    --pl-radius-md: 16px;
    --pl-radius-sm: 12px;
    --pl-tile-font: 'Nunito', 'Glacial Indifference', system-ui, -apple-system, sans-serif;
    --pl-serif-font: 'Playfair Display', Georgia, serif;
}

/* Page wrapper */
body.placement-page {
    background: linear-gradient(180deg, var(--pl-cream) 0%, #fbf5df 45%, var(--pl-cream-deep) 100%);
    min-height: 100vh;
    color: var(--pl-ink);
}

body.placement-playing {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
    touch-action: manipulation;
}

.placement-main {
    max-width: 980px;
    margin: 0 auto;
    padding: 1.75rem 1.25rem 3.5rem;
}

.placement-screen {
    display: none;
}

.placement-screen.is-active {
    display: block;
    animation: plFadeIn 260ms ease-out;
}

@keyframes plFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   SCREEN 1: HUB / WELCOME / RESUME
   ============================================================ */
.hub-card {
    background: var(--pl-paper);
    border: 2px solid var(--pl-border);
    border-radius: var(--pl-radius-lg);
    box-shadow: 0 14px 36px rgba(51, 37, 26, 0.09);
    overflow: hidden;
}

.hub-hero {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 2rem;
    align-items: center;
    padding: 2.25rem 2.5rem;
    background: radial-gradient(circle at top right, #fff8dc 0%, var(--pl-paper) 65%);
    border-bottom: 2px solid var(--pl-border);
}

.hub-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    background: var(--pl-honey-pale);
    color: var(--pl-honey-deep);
    border: 1.5px solid #ecc678;
    border-radius: 999px;
    padding: 0.3rem 0.9rem;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 0.85rem;
}

.hub-title {
    font-family: var(--pl-serif-font);
    font-size: clamp(2rem, 4vw, 2.75rem);
    line-height: 1.15;
    color: var(--pl-ink);
    margin: 0 0 0.75rem;
}

.hub-subtitle {
    font-size: 1.1rem;
    line-height: 1.6;
    color: var(--pl-ink-soft);
    margin: 0 0 1.4rem;
}

.hub-illustration-frame {
    background: #fefae8;
    border: 3px solid var(--pl-ink);
    border-radius: 18px;
    padding: 8px;
    box-shadow: 6px 6px 0 rgba(212, 126, 34, 0.25);
    transform: rotate(0.8deg);
}

.hub-illustration-frame img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 11px;
    aspect-ratio: 4 / 3;
    object-fit: cover;
}

/* Compact clickable unit stepper strip above the fold */
.hub-stepper {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.3rem;
    margin-bottom: 0.9rem;
}

.hub-step-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.28rem;
    padding: 0.3rem 0.65rem;
    border-radius: 999px;
    border: 1.5px solid var(--pl-border);
    background: var(--pl-cream);
    color: var(--pl-ink-soft);
    font-family: var(--pl-tile-font);
    font-size: 0.82rem;
    font-weight: 800;
    cursor: pointer;
    touch-action: manipulation;
    transition: transform 120ms ease, background-color 140ms ease, border-color 140ms ease;
}

.hub-step-pill:hover {
    transform: translateY(-1px);
    border-color: var(--pl-teal);
    color: var(--pl-ink);
}

.hub-step-pill.is-done {
    background: var(--pl-sage-pale);
    border-color: #9dc27e;
    color: var(--pl-sage-deep);
}

.hub-step-pill.is-next {
    background: var(--pl-teal);
    border-color: var(--pl-teal-deep);
    color: #fff;
    box-shadow: 0 2px 8px rgba(20, 184, 166, 0.3);
}

.hub-step-pill.is-progress {
    background: var(--pl-honey-pale);
    border-color: var(--pl-honey);
    color: var(--pl-honey-deep);
}

.hub-step-pill.is-final {
    background: linear-gradient(180deg, #f3b24c 0%, #dd8623 100%);
    border-color: var(--pl-honey-deep);
    color: #fff;
    box-shadow: 0 2px 8px rgba(191, 109, 27, 0.28);
}

.hub-step-sep {
    color: #b8a88a;
    font-weight: 800;
    font-size: 0.95rem;
    line-height: 1;
}

/* Resume / status banner inside Hub */
.hub-status-box {
    background: var(--pl-cream);
    border: 2px solid var(--pl-border);
    border-radius: var(--pl-radius-md);
    padding: 1.1rem 1.25rem;
    margin-bottom: 1.35rem;
}

.hub-status-box.is-resume {
    background: #eef9f7;
    border-color: #98ded5;
}

.hub-status-box.is-complete {
    background: var(--pl-sage-pale);
    border-color: #b7d39e;
}

.hub-status-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--pl-ink);
    margin-bottom: 0.5rem;
}

.hub-status-pill {
    background: var(--pl-teal);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 700;
    padding: 0.2rem 0.7rem;
    border-radius: 999px;
    white-space: nowrap;
}

.hub-status-box.is-complete .hub-status-pill {
    background: var(--pl-sage-deep);
}

.hub-progress-track {
    height: 12px;
    background: rgba(51, 37, 26, 0.1);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.hub-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--pl-teal) 0%, var(--pl-honey) 100%);
    border-radius: 999px;
    transition: width 300ms ease;
}

.hub-status-detail {
    font-size: 0.95rem;
    color: var(--pl-ink-soft);
    margin: 0;
}

/* Primary & Secondary Tactile Buttons */
.pl-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.85rem;
    align-items: center;
}

.pl-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    font-family: var(--pl-tile-font);
    font-weight: 800;
    font-size: 1.15rem;
    padding: 0.95rem 1.75rem;
    border-radius: 999px;
    border: 2.5px solid transparent;
    cursor: pointer;
    text-decoration: none;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: transform 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
}

.pl-btn:active {
    transform: translateY(3px);
}

.pl-btn-primary {
    background: linear-gradient(180deg, #19c3b0 0%, #0f9688 100%);
    color: #fff;
    border-color: var(--pl-teal-deep);
    box-shadow: 0 5px 0 var(--pl-teal-deep), 0 8px 18px rgba(15, 127, 117, 0.25);
}

.pl-btn-primary:hover {
    background: linear-gradient(180deg, #21d1be 0%, #12a596 100%);
}

.pl-btn-primary:active {
    box-shadow: 0 2px 0 var(--pl-teal-deep);
}

.pl-btn-honey {
    background: linear-gradient(180deg, #f3b24c 0%, #dd8623 100%);
    color: #fff;
    border-color: var(--pl-honey-deep);
    box-shadow: 0 5px 0 var(--pl-honey-deep), 0 8px 18px rgba(191, 109, 27, 0.25);
}

.pl-btn-honey:hover {
    background: linear-gradient(180deg, #f7bf63 0%, #e59330 100%);
}

.pl-btn-honey:active {
    box-shadow: 0 2px 0 var(--pl-honey-deep);
}

.pl-btn-outline {
    background: var(--pl-paper);
    color: var(--pl-ink);
    border-color: var(--pl-border);
    box-shadow: 0 3px 0 #d9c89f;
    font-size: 1rem;
    padding: 0.78rem 1.35rem;
}

.pl-btn-outline:hover {
    background: var(--pl-cream);
    border-color: var(--pl-honey);
}

.pl-btn-outline:active {
    box-shadow: 0 1px 0 #d9c89f;
}

.pl-btn-ghost {
    background: transparent;
    color: var(--pl-ink-soft);
    border-color: transparent;
    font-size: 0.95rem;
    font-weight: 700;
    padding: 0.65rem 1rem;
}

.pl-btn-ghost:hover {
    color: var(--pl-ink);
    background: rgba(51, 37, 26, 0.06);
}

.pl-btn-lg {
    font-size: 1.3rem;
    padding: 1.05rem 2.2rem;
    min-height: 60px;
}

/* Inline reset confirmation (avoids native window.confirm) */
.inline-confirm {
    display: none;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.65rem;
    margin-top: 0.9rem;
    padding: 0.75rem 1rem;
    background: var(--pl-terracotta-pale);
    border: 1.5px solid #e7a98a;
    border-radius: var(--pl-radius-sm);
    font-size: 0.95rem;
    color: var(--pl-ink);
}

.inline-confirm.is-open {
    display: flex;
}

.inline-confirm .pl-btn {
    font-size: 0.9rem;
    padding: 0.45rem 1rem;
}

/* Unit Path / Roadmap Section */
.hub-journey {
    padding: 1.75rem 2.5rem 2.25rem;
}

.hub-journey-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.15rem;
}

.hub-journey-title {
    font-family: var(--pl-serif-font);
    font-size: 1.35rem;
    color: var(--pl-ink);
    margin: 0;
}

.hub-journey-note {
    font-size: 0.92rem;
    color: var(--pl-ink-soft);
    margin: 0;
}

.unit-path-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 0.85rem;
}

.unit-path-card {
    position: relative;
    background: var(--pl-cream);
    border: 2px solid var(--pl-border);
    border-radius: var(--pl-radius-md);
    padding: 0.95rem 1.05rem;
    text-align: left;
    transition: transform 150ms ease, border-color 150ms ease;
}

.unit-path-card.is-ready {
    background: #fff;
    border-color: var(--pl-teal);
    box-shadow: 0 4px 12px rgba(20, 184, 166, 0.14);
    cursor: pointer;
}

.unit-path-card.is-ready:hover {
    transform: translateY(-2px);
}

.unit-path-card.is-coming-soon {
    opacity: 0.72;
}

.unit-path-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
}

.unit-badge {
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--pl-teal-mid);
}

.unit-path-card.is-coming-soon .unit-badge {
    color: var(--pl-ink-soft);
}

.unit-state-tag {
    font-size: 0.72rem;
    font-weight: 700;
    padding: 0.16rem 0.55rem;
    border-radius: 999px;
    background: var(--pl-honey-pale);
    color: var(--pl-honey-deep);
}

.unit-path-card.is-ready .unit-state-tag {
    background: #dff7f4;
    color: var(--pl-teal-deep);
}

.unit-path-card.is-completed .unit-state-tag {
    background: var(--pl-sage-pale);
    color: var(--pl-sage-deep);
}

.unit-path-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--pl-ink);
    margin: 0 0 0.25rem;
    line-height: 1.25;
}

.unit-path-meta {
    font-size: 0.84rem;
    color: var(--pl-ink-soft);
    margin: 0;
    line-height: 1.35;
}

/* ============================================================
   SCREEN 2: FULL-VIEWPORT KID-SAFE GAME STAGE
   ============================================================ */
.game-stage {
    position: fixed;
    inset: 0;
    z-index: 2000;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    display: none;
    flex-direction: column;
    background: radial-gradient(circle at 50% 24%, #fffef5 0%, var(--pl-cream) 55%, #f3e4bc 100%);
    overflow: hidden;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.game-stage.is-active {
    display: flex;
    animation: plFadeIn 220ms ease-out;
}

/* Subtle storybook meadow scenery pinned along the bottom */
.stage-meadow-bg {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: clamp(72px, 13vh, 130px);
    pointer-events: none;
    z-index: 0;
}

.stage-meadow-bg svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* Top HUD bar */
.stage-topbar {
    position: relative;
    z-index: 2;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 0.75rem;
    padding: max(0.75rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) 0.5rem max(1rem, env(safe-area-inset-left));
    max-width: 960px;
    width: 100%;
    margin: 0 auto;
    flex-shrink: 0;
}

.stage-pill-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    background: rgba(255, 253, 245, 0.9);
    border: 2px solid var(--pl-border);
    border-radius: 999px;
    padding: 0.48rem 0.95rem;
    font-family: var(--pl-tile-font);
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--pl-ink-soft);
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 140ms ease, color 140ms ease, border-color 140ms ease;
}

.stage-pill-btn:hover {
    background: #fff;
    color: var(--pl-ink);
    border-color: var(--pl-honey);
}

.stage-pill-btn.icon-only {
    width: 44px;
    height: 44px;
    padding: 0;
    justify-content: center;
}

/* Stepping-stone progress bar */
.stage-progress-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    min-width: 0;
}

.stage-progress-label {
    font-family: var(--pl-tile-font);
    font-size: 0.92rem;
    font-weight: 800;
    color: var(--pl-ink-soft);
    letter-spacing: 0.03em;
}

.stage-progress-label strong {
    color: var(--pl-ink);
}

.stage-stones {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(3px, 0.8vw, 7px);
    width: 100%;
    max-width: 460px;
}

.stage-stone {
    flex: 1;
    max-width: 24px;
    height: 11px;
    border-radius: 999px;
    background: rgba(51, 37, 26, 0.13);
    border: 1.5px solid rgba(51, 37, 26, 0.12);
    transition: background-color 260ms ease, transform 260ms ease, border-color 260ms ease;
}

.stage-stone.is-done {
    background: var(--pl-sage);
    border-color: var(--pl-sage-deep);
}

.stage-stone.is-current {
    background: var(--pl-honey);
    border-color: var(--pl-honey-deep);
    transform: scaleY(1.25);
}

/* Main interactive play area */
.stage-play-area {
    position: relative;
    z-index: 2;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(0.9rem, 2.8vh, 1.85rem);
    padding: 0.4rem 1.25rem max(1.25rem, env(safe-area-inset-bottom));
    max-width: 820px;
    width: 100%;
    margin: 0 auto;
}

/* Giant circular Play / Replay Sound button (inspired by uploaded photo + site teal) */
.sound-prompt-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
}

.sound-play-btn {
    position: relative;
    width: clamp(86px, 13.5vmin, 116px);
    height: clamp(86px, 13.5vmin, 116px);
    border-radius: 50%;
    border: 4px solid #fffdf5;
    background: linear-gradient(155deg, #25d1be 0%, #14b8a6 45%, #0d7f75 100%);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow:
        0 0 0 4px rgba(20, 184, 166, 0.28),
        0 8px 0 var(--pl-teal-deep),
        0 14px 26px rgba(11, 93, 86, 0.28);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: transform 140ms ease, box-shadow 140ms ease;
}

.sound-play-btn:hover {
    transform: scale(1.04);
}

.sound-play-btn:active {
    transform: translateY(4px) scale(0.97);
    box-shadow:
        0 0 0 4px rgba(20, 184, 166, 0.28),
        0 3px 0 var(--pl-teal-deep),
        0 6px 14px rgba(11, 93, 86, 0.25);
}

/* Outer stylized crescent ring echoing the uploaded photo's play icon */
.sound-play-btn::before {
    content: '';
    position: absolute;
    inset: 6px;
    border-radius: 50%;
    border: 4px solid rgba(255, 255, 255, 0.85);
    border-top-color: rgba(255, 255, 255, 0.25);
    pointer-events: none;
}

.sound-play-icon-svg {
    width: 44%;
    height: 44%;
    margin-left: 6%;
    fill: #fff;
    filter: drop-shadow(0 2px 3px rgba(7, 63, 58, 0.35));
}

/* Animated sound ripples when playing */
.sound-play-btn .sound-ripple {
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 3px solid var(--pl-teal);
    opacity: 0;
    pointer-events: none;
}

.sound-play-btn.is-playing {
    animation: plSoundPulse 650ms ease-in-out infinite;
}

.sound-play-btn.is-playing .sound-ripple-1 {
    animation: plRipple 1.1s ease-out infinite;
}

.sound-play-btn.is-playing .sound-ripple-2 {
    animation: plRipple 1.1s ease-out 0.45s infinite;
}

.sound-play-btn.needs-tap {
    animation: plInvitePulse 1.3s ease-in-out infinite;
}

@keyframes plSoundPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.06); }
}

@keyframes plRipple {
    0% { transform: scale(0.95); opacity: 0.75; }
    100% { transform: scale(1.52); opacity: 0; }
}

@keyframes plInvitePulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 4px rgba(232, 155, 56, 0.4), 0 8px 0 var(--pl-teal-deep), 0 14px 26px rgba(11, 93, 86, 0.28); }
    50% { transform: scale(1.07); box-shadow: 0 0 0 12px rgba(232, 155, 56, 0.15), 0 8px 0 var(--pl-teal-deep), 0 18px 30px rgba(11, 93, 86, 0.32); }
}

.syllable-prompt-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--pl-honey-pale);
    color: var(--pl-ink);
    border: 2px solid #eab962;
    border-radius: 999px;
    padding: 0.42rem 1.25rem;
    font-family: var(--pl-serif-font);
    font-size: clamp(1.1rem, 2.8vmin, 1.45rem);
    font-weight: 700;
    box-shadow: 0 3px 10px rgba(191, 109, 27, 0.14);
}

.sound-hint {
    font-family: var(--pl-tile-font);
    font-size: clamp(0.95rem, 2vmin, 1.1rem);
    font-weight: 700;
    color: var(--pl-ink-soft);
    margin: 0;
    min-height: 1.4em;
}

/* 2x2 Tactile Phonogram Tile Grid */
.choices-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: clamp(14px, 3vmin, 26px);
    width: min(92vw, 480px);
    max-width: min(480px, 60vh);
}

/* Tactile beveled tile inspired by the reference photo + Story Hour teal */
.phonogram-tile {
    position: relative;
    aspect-ratio: 1 / 1;
    width: 100%;
    border-radius: clamp(18px, 3vmin, 26px);
    border: 3px solid var(--pl-teal-shadow);
    background: linear-gradient(155deg, #1a8f84 0%, #106c64 60%, #0c5952 100%);
    color: #fffef9;
    font-family: var(--pl-tile-font);
    font-weight: 900;
    font-size: clamp(3.3rem, 10.5vmin, 5.4rem);
    line-height: 1;
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow:
        0 9px 0 var(--pl-teal-shadow),
        0 14px 24px rgba(11, 70, 65, 0.26),
        inset 0 2px 2px rgba(255, 255, 255, 0.25);
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: transform 130ms cubic-bezier(0.22, 1, 0.36, 1),
                box-shadow 130ms ease,
                background 180ms ease,
                border-color 180ms ease,
                opacity 200ms ease;
    animation: plTilePopIn 280ms cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.phonogram-tile:nth-child(2) { animation-delay: 40ms; }
.phonogram-tile:nth-child(3) { animation-delay: 80ms; }
.phonogram-tile:nth-child(4) { animation-delay: 120ms; }

@keyframes plTilePopIn {
    from { opacity: 0; transform: scale(0.86) translateY(12px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Molded inner bevel frame (just like the reference photo!) */
.phonogram-tile::before {
    content: '';
    position: absolute;
    inset: clamp(7px, 1.4vmin, 12px);
    border-radius: clamp(11px, 2vmin, 17px);
    border: 2.5px solid rgba(255, 255, 255, 0.2);
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.18);
    pointer-events: none;
}

.phonogram-tile .tile-glyph {
    position: relative;
    z-index: 1;
    text-shadow:
        0 3px 0 rgba(7, 45, 41, 0.55),
        0 -1px 0 rgba(7, 45, 41, 0.35),
        2px 0 0 rgba(7, 45, 41, 0.35),
        -2px 0 0 rgba(7, 45, 41, 0.35);
    padding-bottom: 0.04em;
}

.phonogram-tile.is-len-2 {
    font-size: clamp(2.8rem, 8.8vmin, 4.5rem);
}

.phonogram-tile.is-len-3 {
    font-size: clamp(2.3rem, 7.2vmin, 3.7rem);
}

.phonogram-tile.is-len-4 {
    font-size: clamp(1.9rem, 6vmin, 3.1rem);
}

.phonogram-tile.is-len-5 {
    font-size: clamp(1.65rem, 5.2vmin, 2.7rem);
}

.phonogram-tile.is-len-6 {
    font-size: clamp(1.45rem, 4.6vmin, 2.35rem);
}

.phonogram-tile:hover:not(:disabled) {
    transform: translateY(-3px);
    background: linear-gradient(155deg, #20a296 0%, #137d74 60%, #0e665e 100%);
    box-shadow:
        0 12px 0 var(--pl-teal-shadow),
        0 18px 28px rgba(11, 70, 65, 0.3),
        inset 0 2px 3px rgba(255, 255, 255, 0.32);
}

.phonogram-tile:active:not(:disabled) {
    transform: translateY(6px);
    box-shadow:
        0 3px 0 var(--pl-teal-shadow),
        0 6px 12px rgba(11, 70, 65, 0.22);
}

/* Selected / active purple glow echo from uploaded photo */
.phonogram-tile.is-correct {
    background: linear-gradient(155deg, #74b956 0%, #55943c 65%, #467d30 100%);
    border-color: #356122;
    box-shadow:
        0 0 0 7px rgba(244, 200, 104, 0.65),
        0 8px 0 #356122,
        0 16px 32px rgba(79, 115, 55, 0.38);
    animation: plCorrectCelebrate 620ms cubic-bezier(0.22, 1, 0.36, 1);
    z-index: 3;
}

@keyframes plCorrectCelebrate {
    0% { transform: scale(1); }
    35% { transform: scale(1.1); }
    65% { transform: scale(0.97); }
    100% { transform: scale(1.03); }
}

.phonogram-tile.is-wrong {
    background: linear-gradient(155deg, #867bc9 0%, #6d64b8 65%, #554d9c 100%);
    border-color: var(--pl-lavender-deep);
    box-shadow:
        0 0 0 6px var(--pl-lavender-glow),
        0 7px 0 var(--pl-lavender-deep);
    animation: plGentleWobble 420ms ease-in-out;
}

@keyframes plGentleWobble {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px) rotate(-2deg); }
    50% { transform: translateX(8px) rotate(2deg); }
    80% { transform: translateX(-4px) rotate(-1deg); }
}

.phonogram-tile.is-dimmed {
    opacity: 0.45;
}

/* Celebratory burst stars on correct answer */
.celebration-burst {
    position: absolute;
    inset: -35%;
    pointer-events: none;
    z-index: 4;
}

.burst-star {
    position: absolute;
    left: 50%;
    top: 50%;
    font-size: 1.75rem;
    color: var(--pl-honey);
    text-shadow: 0 2px 4px rgba(51, 37, 26, 0.25);
    animation: plStarFly 780ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes plStarFly {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(0.4) rotate(0deg);
    }
    70% {
        opacity: 1;
    }
    100% {
        opacity: 0;
        transform: translate(calc(-50% + var(--tx)), calc(-50% + var(--ty))) scale(1.25) rotate(140deg);
    }
}

/* Landscape tablet / short viewport refinement so everything fits cleanly without scroll */
@media (min-width: 720px) and (max-height: 680px) {
    .stage-play-area {
        flex-direction: row;
        justify-content: center;
        gap: clamp(1.5rem, 5vw, 4rem);
    }

    .choices-grid {
        max-width: min(420px, 74vh);
    }
}

/* ============================================================
   5-SECOND TEACHING ANIMATION OVERLAY
   ============================================================ */
.teach-overlay {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    background: rgba(51, 37, 26, 0.42);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.teach-overlay.is-active {
    display: flex;
    animation: plTeachFadeIn 240ms ease-out;
}

@keyframes plTeachFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.teach-card {
    position: relative;
    width: min(92vw, 470px);
    background: radial-gradient(circle at top, #fffef6 0%, var(--pl-cream) 75%, #f5e6be 100%);
    border: 3.5px solid var(--pl-ink);
    border-radius: 30px;
    padding: clamp(1.4rem, 4vmin, 2.25rem) clamp(1.25rem, 4vmin, 2rem);
    text-align: center;
    box-shadow:
        0 18px 48px rgba(34, 24, 15, 0.34),
        0 0 0 6px rgba(246, 201, 107, 0.45);
    animation: plTeachCardPop 340ms cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes plTeachCardPop {
    from { opacity: 0; transform: scale(0.84) translateY(18px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.teach-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    background: var(--pl-honey-pale);
    color: var(--pl-honey-deep);
    border: 2px solid #ecc678;
    border-radius: 999px;
    padding: 0.32rem 1rem;
    font-family: var(--pl-tile-font);
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    margin-bottom: 1.1rem;
}

.teach-hero-wrap {
    position: relative;
    width: clamp(150px, 32vmin, 210px);
    height: clamp(150px, 32vmin, 210px);
    margin: 0 auto 1.15rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.teach-wave {
    position: absolute;
    inset: 0;
    border-radius: 36px;
    border: 4px solid var(--pl-honey);
    opacity: 0;
    pointer-events: none;
}

.teach-hero-wrap.is-speaking .teach-wave-1 {
    animation: plTeachWave 1.3s ease-out infinite;
}

.teach-hero-wrap.is-speaking .teach-wave-2 {
    animation: plTeachWave 1.3s ease-out 0.55s infinite;
}

@keyframes plTeachWave {
    0% { transform: scale(0.95); opacity: 0.85; }
    100% { transform: scale(1.36); opacity: 0; }
}

.teach-hero-tile {
    position: relative;
    z-index: 2;
    width: 100%;
    height: 100%;
    border-radius: 28px;
    border: 4px solid var(--pl-honey-deep);
    background: linear-gradient(155deg, #f5be59 0%, #e59633 58%, #d27b1d 100%);
    color: #fffef9;
    font-family: var(--pl-tile-font);
    font-weight: 900;
    font-size: clamp(4.8rem, 15vmin, 7.2rem);
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow:
        0 10px 0 var(--pl-honey-deep),
        0 18px 34px rgba(191, 109, 27, 0.34),
        inset 0 3px 4px rgba(255, 255, 255, 0.38);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: transform 140ms ease;
}

.teach-hero-tile::before {
    content: '';
    position: absolute;
    inset: 11px;
    border-radius: 19px;
    border: 3px solid rgba(255, 255, 255, 0.34);
    pointer-events: none;
}

.teach-hero-tile.is-len-2 {
    font-size: clamp(3.9rem, 12vmin, 5.8rem);
}

.teach-hero-tile.is-len-3 {
    font-size: clamp(3.2rem, 9.8vmin, 4.6rem);
}

.teach-hero-tile.is-len-4 {
    font-size: clamp(2.6rem, 8vmin, 3.7rem);
}

.teach-hero-tile.is-len-5 {
    font-size: clamp(2.15rem, 6.6vmin, 3.05rem);
}

.teach-hero-tile.is-len-6 {
    font-size: clamp(1.85rem, 5.6vmin, 2.65rem);
}

.teach-highlight {
    color: #fffef9;
    text-decoration: underline;
    text-decoration-color: #fffef9;
    text-decoration-thickness: 4px;
    text-underline-offset: 6px;
}

.teach-hero-tile.is-pulse {
    animation: plHeroBounce 700ms cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes plHeroBounce {
    0% { transform: scale(1); }
    30% { transform: scale(1.1); }
    65% { transform: scale(0.96); }
    100% { transform: scale(1); }
}

.teach-hero-glyph {
    position: relative;
    z-index: 1;
    text-shadow:
        0 4px 0 rgba(122, 62, 10, 0.55),
        0 -1px 0 rgba(122, 62, 10, 0.3);
}

.teach-speaker-badge {
    position: absolute;
    right: -10px;
    bottom: -10px;
    z-index: 3;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--pl-teal);
    color: #fff;
    border: 3.5px solid #fffdf5;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    box-shadow: 0 4px 10px rgba(11, 93, 86, 0.3);
}

.teach-caption {
    font-family: var(--pl-serif-font);
    font-size: clamp(1.35rem, 3.6vmin, 1.7rem);
    color: var(--pl-ink);
    margin: 0 0 0.25rem;
}

.teach-subcaption {
    font-family: var(--pl-tile-font);
    font-size: 1rem;
    font-weight: 700;
    color: var(--pl-ink-soft);
    margin: 0 0 1.2rem;
}

/* 5-second visual timer bar */
.teach-timer-wrap {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.teach-timer-track {
    flex: 1;
    height: 14px;
    background: rgba(51, 37, 26, 0.12);
    border-radius: 999px;
    overflow: hidden;
    border: 1.5px solid rgba(51, 37, 26, 0.14);
}

.teach-timer-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, var(--pl-teal) 0%, var(--pl-honey) 100%);
    border-radius: 999px;
    transform-origin: left center;
    will-change: width;
}

.teach-timer-count {
    font-family: var(--pl-tile-font);
    font-weight: 800;
    font-size: 0.95rem;
    color: var(--pl-ink-soft);
    min-width: 2.2rem;
    text-align: right;
}

/* ============================================================
   SCREEN 3: RESULTS PAGE
   ============================================================ */
.results-shell {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.results-card {
    background: var(--pl-paper);
    border: 2.5px solid var(--pl-border);
    border-radius: var(--pl-radius-lg);
    box-shadow: 0 14px 36px rgba(51, 37, 26, 0.09);
    overflow: hidden;
}

.results-banner {
    background: linear-gradient(135deg, #eefaf8 0%, var(--pl-cream) 52%, #fcecc4 100%);
    border-bottom: 2px solid var(--pl-border);
    padding: 2rem 2rem 1.75rem;
    text-align: center;
}

.results-stars {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.75rem;
    color: var(--pl-honey);
    margin-bottom: 0.5rem;
}

.results-stars i:nth-child(2) {
    font-size: 2.2rem;
    transform: translateY(-4px);
}

.results-unit-tag {
    display: block;
    font-size: 0.85rem;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--pl-teal-mid);
    margin-bottom: 0.25rem;
}

.results-heading {
    font-family: var(--pl-serif-font);
    font-size: clamp(1.9rem, 4vw, 2.5rem);
    color: var(--pl-ink);
    margin: 0 0 0.75rem;
}

.results-score-row {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.6rem;
}

.results-score-badge {
    background: var(--pl-teal-mid);
    color: #fff;
    font-family: var(--pl-tile-font);
    font-weight: 900;
    font-size: 1.45rem;
    padding: 0.45rem 1.25rem;
    border-radius: 999px;
    box-shadow: 0 4px 0 var(--pl-teal-shadow);
}

.results-date {
    font-size: 0.92rem;
    color: var(--pl-ink-soft);
    margin: 0;
}

/* Primary results actions: Save Screenshot + Continue to Next Unit */
.results-actions-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.9rem;
    padding: 1.5rem 1.75rem;
    background: #fff;
    border-bottom: 1.5px solid var(--pl-border);
}

.screenshot-toast {
    width: 100%;
    text-align: center;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--pl-sage-deep);
    min-height: 1.3em;
    margin: 0;
}

/* Phonogram breakdown grid */
.results-body {
    padding: 1.75rem 2rem 2rem;
}

.results-section-title {
    font-family: var(--pl-serif-font);
    font-size: 1.35rem;
    color: var(--pl-ink);
    margin: 0 0 0.35rem;
}

.results-section-hint {
    font-size: 0.95rem;
    color: var(--pl-ink-soft);
    margin: 0 0 1.15rem;
}

.results-phonogram-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.8rem;
}

.result-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.9rem 0.6rem;
    border-radius: var(--pl-radius-md);
    border: 2px solid var(--pl-border);
    background: var(--pl-cream);
    cursor: pointer;
    text-align: center;
    touch-action: manipulation;
    transition: transform 140ms ease, box-shadow 140ms ease;
}

.result-tile:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 14px rgba(51, 37, 26, 0.1);
}

.result-tile.is-correct {
    background: var(--pl-sage-pale);
    border-color: #9dc27e;
}

.result-tile.is-missed {
    background: var(--pl-terracotta-pale);
    border-color: #e7a07d;
}

.result-tile-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0 0.25rem;
    font-size: 0.8rem;
    font-weight: 700;
}

.result-tile-ipa {
    color: var(--pl-ink-soft);
    font-family: 'Noto Sans', Arial, sans-serif;
}

.result-tile-mark {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    color: #fff;
}

.result-tile.is-correct .result-tile-mark {
    background: var(--pl-sage-deep);
}

.result-tile.is-missed .result-tile-mark {
    background: var(--pl-terracotta);
}

.result-tile-letter {
    font-family: var(--pl-tile-font);
    font-weight: 900;
    font-size: 2.3rem;
    line-height: 1.05;
    color: var(--pl-ink);
}

.result-tile-note {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--pl-sage-deep);
    min-height: 1.1em;
}

.result-tile.is-missed .result-tile-note {
    color: #b44b1e;
}

/* Recommended lessons box */
.results-lessons-box {
    margin-top: 1.75rem;
    padding: 1.4rem 1.5rem;
    background: var(--pl-cream);
    border: 2px solid var(--pl-border);
    border-radius: var(--pl-radius-md);
}

.results-lessons-box.is-all-correct {
    background: #eef9f7;
    border-color: #98ded5;
}

.results-lesson-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-top: 0.85rem;
}

.lesson-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    background: #fff;
    border: 1.5px solid var(--pl-teal);
    color: var(--pl-teal-deep);
    font-weight: 700;
    font-size: 0.94rem;
    padding: 0.5rem 0.95rem;
    border-radius: 999px;
    text-decoration: none;
    transition: background-color 140ms ease, color 140ms ease;
}

.lesson-chip:hover {
    background: var(--pl-teal);
    color: #fff;
}

.results-footer-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.85rem;
    padding: 0.25rem 0 0.5rem;
}

/* ============================================================
   SCREEN 4: FINAL PLACEMENT RESULTS
   ============================================================ */
.final-results-banner {
    background: linear-gradient(135deg, #e7f8f5 0%, #fdf8e2 48%, #f8df9c 100%);
}

.final-units-pill {
    display: inline-flex;
    align-items: center;
    background: var(--pl-honey-pale);
    color: var(--pl-honey-deep);
    border: 2px solid #eab962;
    font-family: var(--pl-tile-font);
    font-weight: 800;
    font-size: 1.05rem;
    padding: 0.45rem 1.05rem;
    border-radius: 999px;
}

.final-units-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.final-unit-card {
    background: var(--pl-cream);
    border: 2px solid var(--pl-border);
    border-radius: var(--pl-radius-md);
    padding: 1.15rem 1.25rem;
}

.final-unit-card.is-perfect {
    background: #f3f9ee;
    border-color: #b7d39e;
}

.final-unit-card.is-not-started {
    opacity: 0.78;
}

.final-unit-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.65rem;
    margin-bottom: 0.75rem;
}

.final-unit-title-group {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.final-unit-num {
    font-size: 0.8rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--pl-teal-mid);
}

.final-unit-name {
    font-family: var(--pl-serif-font);
    font-size: 1.18rem;
    color: var(--pl-ink);
    margin: 0;
}

.final-unit-right {
    display: flex;
    align-items: center;
    gap: 0.55rem;
}

.final-unit-score {
    font-family: var(--pl-tile-font);
    font-weight: 800;
    font-size: 0.92rem;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    background: #fff;
    border: 1.5px solid var(--pl-border);
    color: var(--pl-ink);
}

.final-unit-card.is-perfect .final-unit-score {
    background: var(--pl-sage-deep);
    border-color: var(--pl-sage-deep);
    color: #fff;
}

.final-unit-action {
    font-family: var(--pl-tile-font);
    font-weight: 800;
    font-size: 0.84rem;
    padding: 0.28rem 0.75rem;
    border-radius: 999px;
    border: 1.5px solid var(--pl-teal);
    background: #fff;
    color: var(--pl-teal-deep);
    cursor: pointer;
    touch-action: manipulation;
    transition: background-color 140ms ease, color 140ms ease;
}

.final-unit-action:hover {
    background: var(--pl-teal);
    color: #fff;
}

.final-phonogram-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.final-ph-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.7rem;
    border-radius: 10px;
    border: 1.5px solid var(--pl-border);
    font-family: var(--pl-tile-font);
    font-weight: 800;
    font-size: 1.05rem;
    cursor: pointer;
    touch-action: manipulation;
    transition: transform 120ms ease;
}

.final-ph-pill:hover {
    transform: translateY(-1px);
}

.final-ph-pill.is-correct {
    background: var(--pl-sage-pale);
    border-color: #9dc27e;
    color: var(--pl-ink);
}

.final-ph-pill.is-missed {
    background: var(--pl-terracotta-pale);
    border-color: #e7a07d;
    color: #9b3d15;
}

.final-ph-pill .ph-mark {
    font-size: 0.78rem;
}

.final-ph-pill.is-correct .ph-mark {
    color: var(--pl-sage-deep);
}

.final-ph-pill.is-missed .ph-mark {
    color: var(--pl-terracotta);
}

.final-unit-empty {
    font-size: 0.92rem;
    color: var(--pl-ink-soft);
    margin: 0;
}

/* Desktop & laptop only Close the Gaps styling on Final Results */
.desktop-only-close-gaps {
    max-width: 100%;
    margin: 0;
    background: var(--pl-paper);
    border: 2px solid var(--pl-border);
    border-top: 5px solid var(--pl-teal);
    border-radius: var(--pl-radius-lg);
    box-shadow: 0 10px 28px rgba(51, 37, 26, 0.08);
}

@media (hover: none) and (pointer: coarse), (max-width: 900px) {
    .desktop-only-close-gaps {
        display: none !important;
    }
}

/* ============================================================
   RESPONSIVE BREAKPOINTS
   ============================================================ */
@media (max-width: 780px) {
    .hub-hero {
        grid-template-columns: 1fr;
        padding: 1.5rem 1.35rem;
        gap: 1.35rem;
    }

    .hub-illustration-frame {
        order: -1;
        max-width: 380px;
        margin: 0 auto;
        transform: none;
    }

    .hub-journey {
        padding: 1.4rem 1.35rem 1.75rem;
    }

    .results-banner {
        padding: 1.5rem 1.25rem;
    }

    .results-body {
        padding: 1.35rem 1.25rem 1.6rem;
    }

    .results-phonogram-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 480px) {
    .placement-main {
        padding: 1rem 0.85rem 2.5rem;
    }

    .stage-pill-btn .pill-text {
        display: none;
    }

    .pl-btn-lg {
        width: 100%;
    }

    .results-actions-bar .pl-btn {
        width: 100%;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
