/* Lucky spin — card pull UI (face-down → spin → flip reveal). Scoped to .lucky-spin-window */

.lucky-spin-window.rpg-window.hidden {
    display: none;
}

/* Fill overlay under header so intro/cards can scroll and spin buttons stay at bottom */
.lucky-spin-window .rpg-window-content {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.lucky-spin-window-content {
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
}

/* Mode toggles use global .rpg-window-icon-btn (same as Endless Tower HoF / Mechanics). */
.lucky-spin-window .rpg-window-icon-btn.lucky-spin-type-toggle--active {
    background: #ddd;
    color: #333;
}

/* First-open placeholder (edit markup in index.html) */
.lucky-spin-initial-placeholder {
    width: 100%;
    min-height: 120px;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    border: 1px dashed rgba(148, 163, 184, 0.45);
    border-radius: 10px;
    padding: 16px;
    color: #333;
    font-size: 1rem;
    text-align: center;
}

.lucky-spin-app-root {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    width: 100%;
    align-self: stretch;
    align-items: center;
}

/* No DB row for current day (or load failure): message only, no default card pool */
.lucky-spin-status-message {
    width: 100%;
    flex: 1;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    padding: 16px;
}

.lucky-spin-status-message-text {
    margin: 0;
    text-align: center;
    font-size: 0.95rem;
    line-height: 1.45;
    color: #64748b;
}

.lucky-pull-root {
    width: 100%;
    max-width: 48rem;
    margin: 0 auto;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-self: stretch;
}

.lucky-spin-intro-host {
    flex-shrink: 0;
    text-align: center;
}

.lucky-spin-title {
    margin: 0 0 0.35rem;
    font-size: 1.05rem;
    font-weight: 600;
    color: #333;
    line-height: 1.3;
}

.lucky-spin-desc {
    margin: 0;
    padding-bottom: 10px;
    font-size: 0.9rem;
    color: #555;
    line-height: 1.45;
}

.lucky-spin-intro {
    margin: 0;
    font-size: 0.95rem;
    color: #555;
    text-align: center;
    line-height: 1.4;
    flex-shrink: 0;
}

/* Scrollport: must stay overflow auto (mobile). Inner centers short content without breaking tall grids. */
.lucky-pull-stage-wrap {
    width: 100%;
    min-height: 0;
    flex: 1;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    touch-action: pan-y;
}

.lucky-pull-stage-inner {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    width: 100%;
    min-height: 100%;
    box-sizing: border-box;
}

/* Same width as one cell in the 10× grid (5 cols / 3 cols on narrow) */
.lucky-pull-single {
    display: flex;
    justify-content: center;
    padding: 8px 0;
    width: 100%;
    max-width: 44rem;
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
}

.lucky-pull-single .lucky-card {
    width: calc((100% - 32px) / 5);
    max-width: none;
    max-height: none;
    min-height: 12rem;
}

@media (max-width: 420px) {
    .lucky-pull-single .lucky-card {
        width: calc((100% - 16px) / 3);
    }
}

.lucky-pull-single.hidden,
.lucky-pull-ten.hidden {
    display: none;
}

.lucky-pull-ten {
    width: 100%;
}

.lucky-pull-ten-grid {
    position: relative;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    width: 100%;
    max-width: 44rem;
    margin: 0 auto;
}

@media (max-width: 420px) {
    .lucky-pull-ten-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 6px;
    }
}

/* After 10× jackpot focus on narrow screens: one card, same width as spin-once (scroll reset in JS). */
.lucky-pull-ten--jackpot-solo .lucky-pull-ten-grid {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0;
    width: 100%;
    max-width: 44rem;
    margin: 0 auto;
    padding: 8px 0;
    box-sizing: border-box;
}

.lucky-pull-ten--jackpot-solo .lucky-pull-ten-cell--fade-out {
    display: none !important;
}

.lucky-pull-ten--jackpot-solo .lucky-pull-ten-cell {
    width: calc((100% - 16px) / 3);
    max-width: 100%;
    aspect-ratio: 5 / 7;
}

.lucky-pull-ten-cell {
    aspect-ratio: 5 / 7;
    min-width: 0;
}

/* After 10×: non-jackpot cells fade; jackpot cell translates to grid center (see lucky-spin.js) */
.lucky-pull-ten-cell--fade-out {
    transition:
        opacity 0.45s ease,
        visibility 0.45s ease;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.lucky-pull-ten-cell--jackpot-move {
    transition: transform 0.7s cubic-bezier(0.32, 1, 0.48, 1);
    will-change: transform;
}

@media (prefers-reduced-motion: reduce) {
    .lucky-pull-ten-cell--fade-out {
        transition-duration: 0.01ms;
    }

    .lucky-pull-ten-cell--jackpot-move {
        transition-duration: 0.01ms;
    }
}

/* Card shell — perspective for Y flip; intrinsic height from aspect-ratio (not height:100%), so backs with abs bg art don’t collapse */
.lucky-card {
    --lucky-card-accent: #7c3aed;
    container-type: inline-size;
    box-sizing: border-box;
    width: 100%;
    aspect-ratio: 5 / 7;
    height: auto;
    margin: 0 auto;
    perspective: 1000px;
    position: relative;
}

/* Fill the grid cell (cell supplies 5:7 height); avoids tiny cards when outer aspect-ratio stacks oddly */
.lucky-pull-ten-cell .lucky-card {
    max-width: none;
    max-height: none;
    height: 100%;
    aspect-ratio: auto;
    min-height: 0;
}

.lucky-card-spin-layer {
    width: 100%;
    height: 100%;
    -webkit-transform-style: preserve-3d;
    transform-style: preserve-3d;
    transform-origin: center center;
}

.lucky-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    -webkit-transform-style: preserve-3d;
    transform-style: preserve-3d;
    transition: transform 0.7s cubic-bezier(0.32, 1.12, 0.48, 1);
}

.lucky-card-inner--revealed {
    transform: rotateY(180deg);
}

/* Hide back face after flip — mobile WebKit often still paints back-face text on the front */
.lucky-card-inner--revealed .lucky-card-back {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.lucky-card-face {
    position: absolute;
    inset: 0;
    border-radius: 10px;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 6px;
    box-sizing: border-box;
    border: 4px solid rgba(0, 0, 0, 0.18);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.26);
}

/* Do not set position here — it would override .lucky-card-face (absolute + inset 0) and collapse the inner */
.lucky-card-back {
    transform: translateZ(0.1px);
    flex-direction: column;
    justify-content: center;
    align-items: stretch;
    background: linear-gradient(145deg, #3d2b5c 0%, #241838 42%, #120c1f 100%);
    overflow: hidden;
}

/* Logged-in hero class portrait (assets/img/class-<name>.png), same as Hero panel */
.lucky-card-back-class-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center center;
    z-index: 0;
    border-radius: 8px;
    pointer-events: none;
}

.lucky-card-back--has-class {
    background: #120c1f;
}

.lucky-card-back--has-class::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 8px;
    z-index: 1;
    pointer-events: none;
    background: linear-gradient(
        165deg,
        rgba(18, 12, 31, 0.72) 0%,
        rgba(36, 24, 56, 0.55) 45%,
        rgba(12, 8, 20, 0.88) 100%
    );
}

/* Whole back face: one line that swaps (drops in from top) */
.lucky-card-back-display {
    position: relative;
    z-index: 2;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 0;
    padding: 4px 3px;
    box-sizing: border-box;
    overflow: hidden;
}

.lucky-card-back-line {
    display: block;
    width: 100%;
    font-family: Oswald, sans-serif;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    line-height: 1.2;
    text-align: center;
    color: #fef9c3;
    text-shadow:
        0 0 12px rgba(251, 191, 36, 0.45),
        0 1px 0 rgba(0, 0, 0, 0.9);
    word-break: break-word;
}

.lucky-card-back-line--swap {
    animation: lucky-card-back-drop-in 0.08s ease-out;
}

@keyframes lucky-card-back-drop-in {
    from {
        opacity: 0.25;
        transform: translateY(-0.9em);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.lucky-card-back-line--winner-jackpot {
    color: #fef08a;
    text-shadow:
        0 0 16px rgba(250, 204, 21, 0.9),
        0 0 4px rgba(180, 83, 9, 0.85);
}

@supports (font-size: 1cqi) {
    .lucky-card-back-line {
        font-size: clamp(0.5rem, 9cqi, 0.72rem);
    }
}

.lucky-card-front {
    transform: rotateY(180deg) translateZ(0.1px);
    background: linear-gradient(
        165deg,
        #f5f3ff 0%,
        #fafafa 45%,
        #e8e8ec 100%
    );
    border-color: rgba(107, 33, 168, 0.45);
    overflow: hidden;
}

/* Same class art as back, dim; light veil keeps the face reading as “white” vs the dark back */
.lucky-card-front.lucky-card-front--has-class {
    background: transparent;
}

.lucky-card-front-class-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center center;
    z-index: 0;
    border-radius: 8px;
    pointer-events: none;
    opacity: 0.55;
    /* Mirror vs back face so the class art reads distinct on reveal */
    transform: scaleX(-1);
}

/* Slightly lighter veil than before so the portrait reads clearly; face still reads “white” vs back */
.lucky-card-front--has-class::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 1;
    border-radius: 8px;
    pointer-events: none;
    background: linear-gradient(
        165deg,
        rgba(245, 243, 255, 0.78) 0%,
        rgba(250, 250, 250, 0.74) 45%,
        rgba(232, 232, 236, 0.78) 100%
    );
}

/* Shared drop-shadow for reward art: gem/crystal PNG + ritual / debuff icons in prize stack */
.lucky-card-front-gem-img,
.lucky-card-prize-icon {
    filter: drop-shadow(0 2px 4px rgba(15, 23, 42, 0.6))
        drop-shadow(0 4px 12px rgba(0, 0, 0, 0.42))
        drop-shadow(0 8px 22px rgba(0, 0, 0, 0.22))
        drop-shadow(0 0 18px rgba(15, 23, 42, 0.35));
}

/* Narrow cards: heavy multi-layer drop-shadow reads as a fog over the whole face */
@media (max-width: 420px) {
    .lucky-card-front-gem-img,
    .lucky-card-prize-icon {
        filter: drop-shadow(0 1px 2px rgba(15, 23, 42, 0.45))
            drop-shadow(0 2px 8px rgba(0, 0, 0, 0.3));
    }
}

/* Gemstone stat or Rare/Epic/Legendary/Mythic Crystals → assets/img/gemstone/*.png or assets/img/crystal/*.png */
.lucky-card-front-gem-img {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    max-width: 46%;
    max-height: 32%;
    width: auto;
    height: auto;
    object-fit: contain;
    z-index: 2;
    pointer-events: none;
}

/* Column flex so prize sits at bottom; art is absolutely centered (top:50%) — was row + top:26%, huge gap below */
.lucky-card-front--has-gem {
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    padding: 10px 6px 10px;
    box-sizing: border-box;
    /* Let drop-shadow on gem/crystal img extend past inner clip (base .lucky-card-front is overflow:hidden) */
    overflow: visible;
}

.lucky-card-front--has-gem .lucky-card-prize {
    display: block;
    margin-top: 0;
    max-height: none;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    text-align: center;
    white-space: normal;
    word-break: break-word;
    hyphens: auto;
    line-height: 1.2;
}

.lucky-card-front-gem-img[hidden] {
    display: none !important;
}

@supports (border-color: color-mix(in srgb, red, blue)) {
    .lucky-card-front {
        border-color: color-mix(in srgb, var(--lucky-card-accent, #7c3aed) 40%, #374151);
    }
}

.lucky-card-prize {
    position: relative;
    z-index: 3;
    font-family: Oswald, sans-serif;
    font-weight: 700;
    font-size: 0.68rem;
    line-height: 1.15;
    color: #1f2937;
    word-break: break-word;
    hyphens: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    max-height: 100%;
    min-height: 0;
}

@supports (color: color-mix(in srgb, red, blue)) {
    /* Darker than border: same hue family as --lucky-card-accent (set in JS) */
    .lucky-card-prize {
        color: color-mix(in srgb, var(--lucky-card-accent, #4b5563) 42%, #111827 58%);
    }
}

.lucky-card-prize--with-debuff-icon {
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    align-items: center;
}

.lucky-card-prize-name {
    display: block;
    font-weight: 700;
    font-size: 1rem;
    text-transform: uppercase;
    line-height: 1.15;
    text-align: center;
    width: 100%;
    flex-shrink: 0;
}

.lucky-card-prize-icon {
    display: block;
    flex-shrink: 1;
    min-height: 0;
    max-width: 100%;
    max-height: min(56px, 100%);
    width: auto;
    height: auto;
    object-fit: contain;
}

@supports (font-size: 1cqi) {
    .lucky-card-prize {
        font-size: clamp(0.52rem, 10cqi, 0.8rem);
    }
}

.lucky-card--jackpot .lucky-card-front:not(.lucky-card-front--has-class) {
    background: linear-gradient(165deg, #fffbeb 0%, #fde68a 45%, #fbbf24 100%);
    border-color: #b45309;
}

.lucky-card--jackpot .lucky-card-front--has-class::before {
    background: linear-gradient(
        165deg,
        rgba(255, 251, 235, 0.8) 0%,
        rgba(253, 230, 138, 0.76) 45%,
        rgba(251, 191, 36, 0.82) 100%
    );
}

.lucky-card--jackpot .lucky-card-front--has-class {
    border-color: #b45309;
}

.lucky-card--jackpot .lucky-card-prize {
    color: #78350f;
}

.lucky-card--jackpot .lucky-card-prize-name {
    color: #78350f;
}

/* Actions — pinned to bottom of window (flex footer) */
.lucky-spin-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
    max-width: 44rem;
    align-self: center;
    flex-shrink: 0;
    margin-top: auto;
    padding-top: 8px;
    padding-bottom: 4px;
    box-sizing: border-box;
}

.lucky-spin-actions-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    width: 100%;
}

.lucky-spin-btn-class-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: #fff;
    border: 1px solid rgba(15, 23, 42, 0.12);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.7);
}

.lucky-spin-btn-class-icon-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
    pointer-events: none;
}

.lucky-spin-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 12px;
    box-sizing: border-box;
    font-family: Oswald, sans-serif;
    font-size: 0.98rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    background: linear-gradient(135deg, #ed3a52 0%, #b62121 50%, #911021 100%);
    box-shadow: 0 4px 14px rgba(91, 33, 182, 0.45);
}

/* Same width so "Summon" and "Summon 10x" align (fits label + class icon + padding). */
.lucky-spin-btn--once,
.lucky-spin-btn--ten {
    flex: 0 0 auto;
    width: 12rem;
    min-width: 0;
}

.lucky-spin-btn--once {
    background: linear-gradient(135deg, #5b6b8a 0%, #3d4a63 50%, #2c3545 100%);
    box-shadow: 0 4px 12px rgba(44, 53, 69, 0.35);
}

.lucky-spin-btn:hover:not(:disabled) {
    filter: brightness(1.06);
}

.lucky-spin-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    box-shadow: none;
}
