/* Playable ad overlays: persistent Install CTA + end card. Palette follows MathSolitaire's cream/orange popups. */

/* MathSolitaire's UI font (Unity: Inter_18pt-ExtraBold), subset by scripts/import_unity_art.py. */
@font-face {
    font-family: 'Inter';
    src: url('./assets/fonts/Inter-ExtraBold.woff2') format('woff2');
    font-weight: 100 900;
    font-style: normal;
    font-display: block;
}

/* ---- MathSolitaire in-app HUD (GameplayAreaView): level tab + cream moves panel, booster bar ---- */

#game-ui {
    --hud-width: clamp(90px, 22vmin, 170px);
}

/* "Level N" tab centred just above the booster bar, same translucent box as the bar. */
#game-ui #playable-level-tab {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 6px);
    transform: translateX(-50%);
    padding: 6px 26px;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-radius: 14px;
    background: rgba(0, 0, 0, 0.22);
    color: #fff;
    font: 800 clamp(21px, 5vmin, 32px)/1.1 Inter, Arial, sans-serif;
    white-space: nowrap;
    z-index: 1000;
    pointer-events: none;
}

/* Moves panel hugs the left screen edge (rounded right side), as in the app. */
#game-ui #moves-counter-widget {
    top: calc(var(--safe-area-inset-top, 0px) + 8px);
    left: var(--safe-area-inset-left, 0px);
    width: var(--hud-width);
}

/* Variant 2: the art has a transparent shadow margin on its left (~6% of its width); push it off
   screen so the panel's left edge sits flush with the screen edge. */
body.pe-variant-2 #game-ui #moves-counter-widget {
    left: calc(var(--safe-area-inset-left, 0px) - var(--hud-width) * 0.06);
}

/* Reserve the art's box before the image decodes, so GameConfig measures the real panel height. */
#game-ui .moves-counter-bg {
    aspect-ratio: 286 / 321;
}

#game-ui .moves-counter-label {
    top: 15%;
    color: #a0663a;
    font-family: Inter, Arial, sans-serif;
    font-size: calc(var(--hud-width) * 0.2) !important;
    font-weight: 800;
    letter-spacing: 0;
}

#game-ui .moves-counter-value {
    top: 62%;
    color: #6b2f10;
    font-family: Inter, Arial, sans-serif;
    font-size: calc(var(--hud-width) * 0.38) !important;
    font-weight: 800;
    text-shadow: none;
}

#game-ui #playable-level-badge {
    display: none;
}

@media (orientation: landscape) {
    #game-ui {
        --hud-width: clamp(70px, 15vmin, 120px);
    }

    #game-ui #playable-level-tab {
        display: none;
    }

    /* Same translucent box as the portrait tab, under the moves panel. */
    #game-ui #playable-level-badge {
        display: block;
        position: absolute;
        top: calc(100% + 6px);
        left: 8px;
        padding: 5px 14px;
        border: 2px solid rgba(255, 255, 255, 0.35);
        border-radius: 12px;
        background: rgba(0, 0, 0, 0.22);
        color: #fff;
        font: 800 clamp(17px, 5.5vmin, 26px)/1.1 Inter, Arial, sans-serif;
        white-space: nowrap;
        pointer-events: none;
    }
}

/* ---- Level intro banner: pops in over the board, then fades; never blocks input ---- */
#playable-level-intro {
    position: fixed;
    left: 0;
    right: 0;
    top: 50%;
    z-index: 19000;
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 14px 0 16px;
    transform: translateY(-50%);
    background: linear-gradient(90deg, rgba(40, 18, 4, 0) 0%, rgba(40, 18, 4, .72) 18%, rgba(40, 18, 4, .72) 82%, rgba(40, 18, 4, 0) 100%);
    pointer-events: none;
}

#playable-level-intro.is-visible {
    display: flex;
    animation: pe-intro 1.9s ease-out both;
}

#playable-level-intro-title {
    color: #ffd54a;
    font: 800 clamp(40px, 13vmin, 72px)/1 Inter, Arial, sans-serif;
    letter-spacing: .03em;
    text-shadow: 0 3px 0 #8a3d0c, 0 6px 14px rgba(0, 0, 0, .45);
    animation: pe-pop .45s cubic-bezier(.2, 1.4, .4, 1) both;
}

#playable-level-intro-tag {
    padding: 4px 16px;
    border-radius: 999px;
    background: #e5392b;
    color: #fff;
    font: 800 clamp(15px, 4.4vmin, 22px)/1.2 Inter, Arial, sans-serif;
    letter-spacing: .08em;
    box-shadow: 0 3px 0 #9c1d12;
    animation: pe-pop .45s cubic-bezier(.2, 1.4, .4, 1) .15s both;
}

/* Playable: no hint/undo boosters. The bar keeps only its level tab (the bar itself collapses to
   the bottom edge, so GameConfig's HUD measurement reserves just the tab). */
#game-ui #bottom-panel {
    height: 0 !important;
    pointer-events: none;
}

#game-ui #bottom-panel .panel-background,
#game-ui #bottom-panel .panel-buttons {
    display: none;
}

/* ---- Combo (the game's "COMBO X2" + "+2 Extra" on the Moves panel), built by PlayableCombo ---- */
#game-ui .pe-combo {
    position: absolute;
    left: calc(100% + 10px);
    top: 14%;
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    pointer-events: none;
}

#game-ui .pe-combo.is-visible {
    display: flex;
}

#game-ui .pe-combo.is-pop .pe-combo-text {
    animation: pe-pop .35s cubic-bezier(.2, 1.6, .4, 1) both;
}

#game-ui .pe-combo-text {
    color: #ffd54a;
    font: 800 calc(var(--hud-width) * 0.26)/1 Inter, Arial, sans-serif;
    white-space: nowrap;
    text-shadow: 0 2px 0 #8a3d0c, 0 0 3px #8a3d0c, 0 4px 10px rgba(0, 0, 0, .35);
}

#game-ui .pe-combo-timer {
    height: 6px;
    border-radius: 3px;
    background: #ffd54a;
    box-shadow: 0 1px 0 #8a3d0c;
    transform-origin: left center;
    animation: pe-combo-timer linear both;
}

#game-ui .pe-combo-extra {
    position: absolute;
    left: 6%;
    right: 6%;
    top: -7px;
    display: none;
    padding: 1px 0;
    border-radius: 6px;
    background: #ffc93a;
    color: #7a3a0c;
    font: 800 calc(var(--hud-width) * 0.15)/1.2 Inter, Arial, sans-serif;
    text-align: center;
    box-shadow: 0 2px 0 #b8692c;
    pointer-events: none;
}

#game-ui .pe-combo-extra.is-visible {
    display: block;
    animation: pe-pop .3s cubic-bezier(.2, 1.4, .4, 1) both;
}

#game-ui .pe-combo-float {
    position: absolute;
    left: 50%;
    top: 55%;
    color: #ffd54a;
    font: 800 calc(var(--hud-width) * 0.36)/1 Inter, Arial, sans-serif;
    text-shadow: 0 2px 0 #8a3d0c, 0 0 3px #8a3d0c;
    pointer-events: none;
    animation: pe-combo-float .9s ease-out both;
}

@media (orientation: landscape) {
    #game-ui .pe-combo {
        left: 8px;
        top: calc(100% + 52px);
    }
}

@keyframes pe-combo-timer {
    from { transform: scaleX(1); }
    to { transform: scaleX(0); }
}

@keyframes pe-combo-float {
    0% { opacity: 0; transform: translate(-50%, 40%) scale(.6); }
    25% { opacity: 1; transform: translate(-50%, 0) scale(1.15); }
    100% { opacity: 0; transform: translate(-50%, -60%) scale(1); }
}

/* ---- Variant 2: "REVEAL NUMBER" popup (the app's popup.png frame with its orange header tab) ---- */
#pe-reveal {
    position: fixed;
    inset: 0;
    z-index: 19600;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, .35);
    animation: pe-fade .25s ease-out both;
}

#pe-reveal.is-closing {
    animation: pe-fade-out .22s ease-in both;
}

#pe-reveal .pe-reveal-card {
    /* Everything inside is sized from the card width, so it fits the frame on any screen. */
    --w: min(86vw, 380px, 76vh);
    position: relative;
    flex: none;
    width: var(--w);
    height: calc(var(--w) * 457 / 482);
    box-sizing: border-box;
    padding: calc(var(--w) * 0.24) calc(var(--w) * 0.08) calc(var(--w) * 0.09);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    background: center / 100% 100% no-repeat;
    font-family: Inter, Arial, sans-serif;
    font-weight: 800;
    text-align: center;
    animation: pe-pop .4s cubic-bezier(.2, 1.4, .4, 1) both;
}

/* Centred in the orange header tab (top ~18% of popup.png). */
#pe-reveal .pe-reveal-title {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(var(--w) * 0.095);
    transform: translateY(-50%);
    color: #fff;
    font-size: calc(var(--w) * 0.068);
    line-height: 1;
    text-shadow: 0 2px 0 #8a4b1f, 0 0 2px #8a4b1f;
    white-space: nowrap;
}

#pe-reveal .pe-reveal-subtitle {
    color: #b8692c;
    font-size: calc(var(--w) * 0.068);
    white-space: nowrap;
}

#pe-reveal .pe-reveal-rows {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: calc(var(--w) * 0.06);
    width: 100%;
}

#pe-reveal .pe-reveal-row {
    display: flex;
    align-items: center;
    gap: calc(var(--w) * 0.02);
    color: #5c3d28;
    font-size: calc(var(--w) * 0.1);
    white-space: nowrap;
}

#pe-reveal .pe-reveal-row img {
    width: calc(var(--w) * 0.19);
    height: auto;
}

#pe-reveal .pe-reveal-hint {
    color: #b8692c;
    font-size: calc(var(--w) * 0.05);
    animation: pe-cta-pulse 1.1s ease-in-out infinite;
}

/* ---- Blue button: the app's main-menu PLAY button (button_blue.png) ---- */
.pe-blue-btn {
    border: 0;
    padding: 0;
    background: url('./assets/playable/button_blue.png') center / 100% 100% no-repeat;
    color: #fff;
    font-family: Inter, Arial, sans-serif;
    font-weight: 800;
    letter-spacing: .04em;
    text-shadow: 0 2px 2px rgba(10, 40, 120, .55);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

/* Install: bottom centre, in the thumb zone. It fills the band reserved by
   PlayablePlatform.getInstallBandHeight() (the game's bottom safe-area offset); shown after the first tap. */
#playable-install-btn {
    position: fixed;
    bottom: 8px;
    left: 50%;
    z-index: 20001;
    display: none;
    /* Keep button_blue.png's own proportions (444x128 ≈ 3.47:1) so the art is not squashed. */
    height: calc(var(--safe-area-inset-bottom, 76px) - 12px);
    width: calc((var(--safe-area-inset-bottom, 76px) - 12px) * 3.47);
    max-width: 92vw;
    transform: translateX(-50%);
    font-size: calc((var(--safe-area-inset-bottom, 76px) - 12px) * 0.42);
}

#playable-install-btn.is-visible {
    display: block;
    animation: pe-install-pulse 1.3s ease-in-out infinite;
}

/* ---- End card: the app's main-menu look, the whole screen opens the store ---- */
#playable-endcard {
    position: fixed;
    inset: 0;
    z-index: 20000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    box-sizing: border-box;
    background: #f6efdd url('./assets/playable/menu_background.webp') center / cover no-repeat;
    cursor: pointer;
}

#playable-endcard.is-visible {
    display: flex;
    animation: pe-fade .35s ease-out both;
}

#playable-endcard .pe-content {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: clamp(8px, 2.5vmin, 18px);
    width: min(420px, 92vw);
    text-align: center;
}

#playable-endcard-title {
    color: #6b2f10;
    font: 800 clamp(30px, 9vmin, 46px)/1.05 Inter, Arial, sans-serif;
    animation: pe-pop .5s cubic-bezier(.2, 1.4, .4, 1) both;
}

.pe-logo-wrap {
    position: relative;
    width: min(78vw, 46vh, 360px);
    aspect-ratio: 1;
}

.pe-shine {
    position: absolute;
    inset: -22%;
    width: 144%;
    height: 144%;
    opacity: .85;
    animation: pe-spin 9s linear infinite;
    pointer-events: none;
}

#playable-endcard-icon {
    position: relative;
    width: 100%;
    height: 100%;
    animation: pe-pop .55s cubic-bezier(.2, 1.4, .4, 1) .1s both, pe-bob 2.4s ease-in-out .7s infinite;
}

#playable-endcard-subtitle {
    color: #8a4b1f;
    font: 800 clamp(16px, 4.6vmin, 22px)/1.25 Inter, Arial, sans-serif;
}

#playable-endcard-cta {
    width: min(84vw, 360px);
    aspect-ratio: 444 / 128;
    font-size: clamp(28px, 8vmin, 42px);
    animation: pe-cta-pulse 1.1s ease-in-out .6s infinite;
}

/* Finger tapping the button (the game's tutorial finger) with a ripple under its tip.
   The tip sits at --tip-x / --tip-y of the image: the press scales around it and the ripple is centred on it. */
.pe-finger {
    --tip-x: 43%;
    --tip-y: 12%;
    position: absolute;
    right: 2%;
    bottom: calc(min(84vw, 360px) / 3.47 * -0.75);
    width: clamp(84px, 23vmin, 124px);
    transform: rotate(-12deg);
    pointer-events: none;
}

.pe-finger img {
    position: relative;
    display: block;
    width: 100%;
    transform-origin: var(--tip-x) var(--tip-y);
    animation: pe-tap 1.2s ease-in-out .6s infinite;
}

.pe-ripple {
    position: absolute;
    left: var(--tip-x);
    top: var(--tip-y);
    width: 80%;
    aspect-ratio: 1;
    box-sizing: border-box;
    border: 4px solid #fff;
    border-radius: 50%;
    background: rgba(255, 255, 255, .25);
    opacity: 0;
    transform: translate(-50%, -50%) scale(.2);
    animation: pe-ripple 1.2s ease-out .6s infinite;
}

/* Variant 2: 3D hand pointing up. Its tip sits exactly at (--finger-left, --finger-top) of the host;
   PlayableFlow.layoutFinger sets those and the pose (--sx / --sy / --rot) that keeps the hand on screen. */
body.pe-variant-2 #playable-install-btn .pe-finger,
body.pe-variant-2 #playable-endcard .pe-finger {
    --tip-x: 73%;
    --tip-y: 5%;
    left: var(--finger-left, 80%);
    top: var(--finger-top, 55%);
    right: auto;
    bottom: auto;
    width: var(--finger-w, 80px);
    transform-origin: var(--tip-x) var(--tip-y);
    transform: translate(calc(-1 * var(--tip-x)), calc(-1 * var(--tip-y))) rotate(var(--rot, 0deg)) scale(var(--sx, 1), var(--sy, 1));
}

/* Level complete (between the ad's levels): INSTALL is the big primary button with the finger on it,
   NEXT LEVEL shrinks to a secondary button. PlayableFlow toggles body.pe-level-complete. */
body.pe-level-complete {
    --pe-install-w: min(84vw, 360px, 70vh);
}

body.pe-level-complete #playable-install-btn {
    bottom: max(24px, 4vh);
    width: var(--pe-install-w);
    height: calc(var(--pe-install-w) / 3.47);
    max-width: none;
    font-size: calc(var(--pe-install-w) / 3.47 * 0.42);
    animation: pe-install-pulse 1.1s ease-in-out infinite;
}

body.pe-level-complete #playable-endcard {
    padding-bottom: calc(var(--pe-install-w) / 3.47 + max(24px, 4vh) + 16px);
}

body.pe-level-complete .pe-logo-wrap {
    width: min(64vw, 34vh, 300px);
}

body.pe-level-complete #playable-endcard-cta {
    width: min(50vw, 210px);
    font-size: clamp(16px, 4.6vmin, 24px);
    animation: none;
}

/* Variant 2: on the level-complete screen INSTALL is the app's green button (444x148 ≈ 3:1). */
body.pe-variant-2.pe-level-complete #playable-install-btn {
    background-image: url('./assets/playable/button_green.webp');
    height: calc(var(--pe-install-w) / 3);
    text-shadow: 0 2px 2px rgba(10, 80, 40, .55);
}

body.pe-variant-2.pe-level-complete #playable-endcard {
    padding-bottom: calc(var(--pe-install-w) / 3 + max(24px, 4vh) + 16px);
}

body:not(.pe-level-complete) #playable-install-btn .pe-finger {
    display: none;
}

/* Tip on the button's right part; the hand overhangs the button bottom by less than the button's
   bottom margin, so it never leaves the screen. */
#playable-install-btn .pe-finger {
    right: 8%;
    top: 30%;
    bottom: auto;
    width: calc(var(--pe-install-w, 300px) / 3.47 * 0.9);
}

/* Landscape phones: logo beside nothing — just shrink everything to fit the short edge. */
@media (orientation: landscape) and (max-height: 520px) {
    #playable-endcard .pe-content { gap: 6px; }
    .pe-logo-wrap { width: min(38vh, 260px); }
    #playable-endcard-title { font-size: clamp(24px, 7vh, 36px); }
    #playable-endcard-subtitle { font-size: clamp(14px, 4vh, 18px); }
    #playable-endcard-cta { width: min(56vw, 52vh, 320px); font-size: clamp(22px, 6.5vh, 34px); }
    .pe-finger { bottom: -44px; width: 78px; }
}

@keyframes pe-install-pulse {
    0%, 100% { transform: translateX(-50%) scale(1); }
    50% { transform: translateX(-50%) scale(1.08); }
}

@keyframes pe-cta-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.07); }
}

@keyframes pe-tap {
    0%, 100% { transform: translate(8%, 14%) scale(1.04); }
    45%, 55% { transform: translate(0, 0) scale(.92); }
}

@keyframes pe-ripple {
    0%, 44% { opacity: 0; transform: translate(-50%, -50%) scale(.2); }
    46% { opacity: .95; transform: translate(-50%, -50%) scale(.25); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1.15); }
}

@keyframes pe-spin {
    to { transform: rotate(360deg); }
}

@keyframes pe-bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3%); }
}

@keyframes pe-intro {
    0% { opacity: 0; }
    12% { opacity: 1; }
    78% { opacity: 1; }
    100% { opacity: 0; }
}

@keyframes pe-fade-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes pe-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes pe-pop {
    from { opacity: 0; transform: scale(.6); }
    to { opacity: 1; transform: scale(1); }
}
