/* ========================================
   ガチャ：街から開くアップ画面
   ======================================== */
.ae-gacha,
.ae-gacha * {
    box-sizing: border-box;
}

.ae-gacha {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: none;
    height: 100dvh;
    max-height: none;
    margin: 0;
    padding: 0;
    border: 0;
    overflow: hidden;
    background: #eee9df;
    color: #123e68;
    isolation: isolate;
}

.ae-gacha::backdrop {
    background: #eee9df;
}

/* お店・地面・木をまとめてぼかす */
.ae-gacha__background {
    position: absolute;
    inset: -20px;
    z-index: -1;
    overflow: hidden;
    filter: blur(9px) saturate(0.78);
    pointer-events: none;
}

.ae-gacha__shop {
    position: absolute;
    inset: 0;
    background:
        #eee9df
        url("../../images/town/entrance-closeup.png")
        88% 80% / cover no-repeat;
    transform: scale(1.65);
    transform-origin: 88% 80%;
}

/* ガチャの左隣にある木を、背景として配置 */
.ae-gacha__tree {
    position: absolute;
    left: calc(50% - 55dvh);
    bottom: 4%;
    width: auto;
    height: 115%;
    max-width: none;
    margin: 0;
    opacity: 0.5;
    filter: saturate(0.7);
}

/* 白い薄膜で、背景の存在感だけを抑える */
.ae-gacha__background::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgb(255 250 240 / 28%);
}

.ae-gacha__back {
    cursor: pointer;
}

/* 本体とハンドルは同じ面に重ね、背景から独立させる */
.ae-gacha__machine {
    position: absolute;
    left: 50%;
    bottom: max(10px, env(safe-area-inset-bottom));
    width: min(calc((100dvh - 24px) * 2 / 3), 130vw);
    aspect-ratio: 2 / 3;
    transform: translateX(-50%);
    filter: drop-shadow(0 12px 10px rgb(30 47 63 / 18%));
}
.ae-gacha__machine::before {
    content: "";
    position: absolute;
    z-index: -1;
    left: 15%;
    right: 15%;
    bottom: 0;
    height: 5%;
    border-radius: 50%;
    background: rgb(30 47 63 / 24%);
    filter: blur(8px);
}

.ae-gacha__machine > img {
    display: block;
    max-width: none;
    margin: 0;
    user-select: none;
    pointer-events: none;
}

.ae-gacha__body {
    width: 100%;
    height: auto;
}

/* 内部カプセル：ガラスの輪郭より内側だけに表示 */
.ae-gacha__inside {
    position: absolute;
    z-index: 1;
    left: 24%;
    top: 23%;
    width: 52%;
    height: 30%;
    overflow: hidden;
    border-radius: 12% 12% 16% 16%;
    pointer-events: none;
    user-select: none;
}

.ae-gacha__inside[hidden] {
    display: none;
}

/* 位置と傾きは、内部演出のJSから指定する */
.ae-gacha__inside-capsule {
    position: absolute;
    display: block;
    left: var(--inside-x, 50%);
    top: var(--inside-y, 70%);
    width: 27%;
    aspect-ratio: 898 / 918;
    transform:
        translate(-50%, -50%)
        rotate(var(--inside-tilt, 0deg));
    filter: drop-shadow(0 2px 2px rgb(12 48 94 / 18%));
}

/* 開封用と同じ画像・接合位置を使う */
.ae-gacha__inside-top,
.ae-gacha__inside-bottom {
    position: absolute;
    display: block;
    left: 0;
    width: 100%;
    overflow: hidden;
    background-image: url("../../images/town/gacha-capsule.png");
    background-repeat: no-repeat;
    background-size: 139.64% auto;
}

.ae-gacha__inside-top {
    z-index: 2;
    top: 0;
    height: 53.6%;
    border-radius: 50% 50% 0 0 / 100% 100% 0 0;
    background-position: 50% 15.5%;
}

.ae-gacha__inside-bottom {
    z-index: 1;
    bottom: 0;
    height: 47.3%;
    border-radius: 0 0 50% 50% / 0 0 100% 100%;
    background-position: 50% 90.7%;
}

.ae-gacha[data-time="night"] .ae-gacha__inside {
    filter: brightness(1.06) saturate(0.94);
}

/* 夜だけ表示する、ガラス内部の明るい画像 */
.ae-gacha__machine > .ae-gacha__lit {
    display: none;
    position: absolute;
    inset: 0;
    width: 100%;
    height: auto;
    mask-image: radial-gradient(
        ellipse 29% 16% at 50% 37%,
        #000 0%,
        #000 75%,
        transparent 100%
    );
}

/* 画像の透明余白も含め、従来と同じ位置に配置 */
.ae-gacha__crank {
    position: absolute;
    z-index: 2;
    left: 35%;
    top: 54.5%;
    width: 30%;
    aspect-ratio: 1;
    min-width: 44px;
    min-height: 44px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    box-shadow: none;
    color: inherit;
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.ae-gacha__crank > img {
    display: block;
    width: 100%;
    height: auto;
    max-width: none;
    margin: 0;
    transform: rotate(var(--gacha-angle, 0deg));
    transform-origin: 50% 50%;
    pointer-events: none;
}

.ae-gacha__crank.is-dragging {
    cursor: grabbing;
}

.ae-gacha__crank:focus-visible {
    outline: 2px solid #123e68;
    outline-offset: 4px;
}

/* 操作案内は、ハンドルの右側 */
.ae-gacha__controls {
    position: absolute;
    z-index: 3;
    top: 66%;
    left: calc(50% + 25dvh);
    width: min(280px, calc(50vw - 25dvh - 12px));
    text-align: center;
}

.ae-gacha__spin {
    min-height: 44px;
    margin: 0;
    padding: 11px 20px;
    border: 1px solid #123e68;
    border-radius: 999px;
    background: #fffaf0;
    color: #123e68;
    box-shadow: 0 3px 8px rgb(25 48 70 / 16%);
    font: 700 16px/1.5 sans-serif;
    cursor: pointer;
}

.ae-gacha__spin:hover {
    background: #edf5ff;
}

.ae-gacha__spin:focus-visible {
    outline: 2px solid #123e68;
    outline-offset: 4px;
}

.ae-gacha__spin:disabled {
    opacity: 0.7;
    cursor: wait;
}

.ae-gacha__controls p {
    margin: 14px 0 0;
    font-size: 14px;
    line-height: 1.8;
    text-wrap: pretty;
}

.ae-gacha__controls .ae-gacha__status {
    min-height: 1.8em;
    margin-top: 16px;
    font-size: 15px;
    font-weight: 700;
    color: #123e68;
}

.ae-gacha[data-time="night"] .ae-gacha__controls {
    color: #123e68;
}

/* 内部照明：白い光を重ねず、元画像をわずかに明るく */
.ae-gacha[data-time="night"] .ae-gacha__lit {
    display: block;
    filter: brightness(1.06) saturate(0.94);
}

/* 夜の店内灯：背景画像と同じ拡大・位置で窓だけ照らす */
.ae-gacha__shop::after {
    content: "";
    position: absolute;
    inset: 0;
    display: none;
    background:
        linear-gradient(
            125deg,
            transparent 30%,
            rgb(255 255 255 / 15%) 32%,
            transparent 40%
        ),
        linear-gradient(
            180deg,
            #fff8df 0%,
            #ffe9b5 55%,
            #f5c678 100%
        );

    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1672' height='941' viewBox='0 0 1672 941'%3E%3Cg fill='white'%3E%3Crect x='94' y='360' width='399' height='326'/%3E%3Crect x='649' y='365' width='178' height='398'/%3E%3Crect x='847' y='365' width='178' height='398'/%3E%3Crect x='1180' y='360' width='398' height='326'/%3E%3C/g%3E%3C/svg%3E");
    mask-size: cover;
    mask-position: 88% 80%;
    mask-repeat: no-repeat;
    opacity: 0.88;
    pointer-events: none;
}

.ae-gacha[data-time="night"] {
    background: #384656;
}

/* 背景全体を強く暗くする処理は外す */
.ae-gacha[data-time="night"] .ae-gacha__background {
    filter: blur(9px) saturate(0.78);
}

.ae-gacha[data-time="night"] .ae-gacha__shop::after {
    display: block;
}

/* 店内の暖色が、足元にも薄く広がる */
.ae-gacha[data-time="night"] .ae-gacha__background::after {
    background:
        radial-gradient(
            ellipse at 65% 90%,
            rgb(255 196 111 / 26%),
            transparent 65%
        ),
        rgb(30 48 73 / 10%);
}

.ae-gacha[data-time="night"] .ae-gacha__tree {
    filter: brightness(0.65) saturate(0.7);
}

.ae-gacha[data-time="night"] .ae-gacha__machine {
    filter: drop-shadow(0 12px 10px rgb(10 20 35 / 30%));
}

/* 受け皿の青い開口部に合わせた表示範囲 */
.ae-gacha__outlet {
    position: absolute;
    z-index: 1;
    left: 39%;
    top: 75%;
    width: 22%;
    height: 10.4%;
    overflow: hidden;
    border-radius: 32% 32% 12% 12%;
    pointer-events: none;
}

/* 青と白の丸いカプセル */
.ae-gacha__capsule {
    position: absolute;
    display: block;
    left: 20%;
    bottom: 4%;
    width: 60%;
    height: auto;
    min-width: 0;
    min-height: 0;
    aspect-ratio: 898 / 918;
    margin: 0;
    padding: 0;
    appearance: none;
    color: inherit;
    opacity: 1;
    pointer-events: auto;
    touch-action: manipulation;
    border: 0;
    border-radius: 50%;
    background: transparent;
    box-shadow: none;
    filter: drop-shadow(2px 4px 3px rgb(0 18 51 / 35%));
    transform: rotate(35deg);
}

.ae-gacha__capsule:enabled {
    cursor: pointer;
}

.ae-gacha__capsule:disabled {
    cursor: default;
}

.ae-gacha__capsule:focus-visible {
    outline: 3px solid #ffffff;
    outline-offset: -4px;
}

.ae-gacha__capsule[hidden] {
    display: none;
}

/* 既存画像から上下を組み合わせる */
.ae-gacha__capsule::before,
.ae-gacha__capsule::after {
    content: "";
    position: absolute;
    left: 0;
    width: 100%;
    overflow: hidden;
    background-image: url("../../images/town/gacha-capsule.png");
    background-repeat: no-repeat;
    background-size: 139.64% auto;
    pointer-events: none;
}

.ae-gacha__capsule::before {
    z-index: 2;
    top: 0;
    height: 53.6%;
    border-radius: 50% 50% 0 0 / 100% 100% 0 0;
    background-position: 50% 15.5%;
}

.ae-gacha__capsule::after {
    z-index: 1;
    bottom: 0;
    height: 47.3%;
    border-radius: 0 0 50% 50% / 0 0 100% 100%;
    background-position: 50% 90.7%;
}

/* 放置時：閉じたカプセルを中央へアップ表示 */
.ae-gacha__preview {
    position: absolute;
    z-index: 4;
    left: 50%;
    top: 50%;
    display: block;
    width: min(340px, 72vw, 55dvh);
    height: auto;
    min-width: 0;
    min-height: 0;
    aspect-ratio: 898 / 918;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    overflow: visible;
    transform: translate(-50%, -50%);
    cursor: pointer;
}

.ae-gacha__preview[hidden] {
    display: none;
}

.ae-gacha__preview:focus-visible {
    outline: 3px solid #0755ba;
    outline-offset: 8px;
    border-radius: 50%;
}

.ae-gacha__preview-note {
    position: absolute;
    top: calc(100% + 18px);
    left: 50%;
    width: max-content;
    max-width: calc(100vw - 32px);
    min-height: 44px;
    padding: 11px 20px;
    border: 1px solid #123e68;
    border-radius: 999px;
    background: #fffaf0;
    color: #123e68;
    box-shadow: 0 3px 8px rgb(25 48 70 / 16%);
    font: 700 16px/1.5 sans-serif;
    text-align: center;
    transform: translateX(-50%);
}

/* カプセル部分だけにホバーの動きを付ける */
@media (hover: hover) and (pointer: fine)
       and (prefers-reduced-motion: no-preference) {
    .ae-gacha__preview > .ae-gacha__opening-top {
        transition: transform 420ms cubic-bezier(.22, .61, .36, 1);
    }

    .ae-gacha__preview:has(
        > .ae-gacha__opening-top:hover,
        > .ae-gacha__opening-bottom:hover
    ) > .ae-gacha__opening-top {
        transform: translateY(-6px) rotate(-2deg);
    }

    .ae-gacha__capsule:enabled {
        transition: transform 420ms cubic-bezier(.22, .61, .36, 1);
    }

    .ae-gacha__capsule:enabled:hover {
        transform: translateY(-4px) rotate(35deg);
    }
}

.ae-gacha.is-capsule-preview > .ae-gacha__machine,
.ae-gacha.is-capsule-preview > .ae-gacha__controls {
    display: none;
}

/* 開封演出：中央で青と白のカプセルが開く */
.ae-gacha__opening {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: grid;
    place-items: center;
    overflow: hidden;
    pointer-events: none;
}

.ae-gacha__opening[hidden] {
    display: none;
}

.ae-gacha__opening-shell {
    position: relative;
    width: min(340px, 72vw, 55dvh);
    aspect-ratio: 898 / 918;
    filter: drop-shadow(0 14px 18px rgb(12 48 94 / 25%));
}

/* 1枚の画像から、上下それぞれの範囲を表示 */
.ae-gacha__opening-top,
.ae-gacha__opening-bottom {
    position: absolute;
    left: 0;
    width: 100%;
    overflow: hidden;
    border: 0;
    box-shadow: none;
    background-image: url("../../images/town/gacha-capsule.png");
    background-repeat: no-repeat;
    background-size: 139.64% auto;
    transform-origin: 50% 50%;
}

/* 青い上半分：周囲の余白と中央の隙間を除外 */
.ae-gacha__opening-top {
    z-index: 2;
    top: 0;
    height: 53.6%;
    border-radius: 50% 50% 0 0 / 100% 100% 0 0;
    background-position: 50% 15.5%;
}

/* 白い下半分：縁を上半分に少し重ねて閉じる */
.ae-gacha__opening-bottom {
    z-index: 1;
    bottom: 0;
    height: 47.3%;
    border-radius: 0 0 50% 50% / 0 0 100% 100%;
    background-position: 50% 90.7%;
}

/* スーパーレア：開く瞬間に、柔らかな光が広がる */
.ae-gacha__opening[data-rarity="super-rare"]::before {
    content: "";
    position: absolute;
    width: min(640px, 110vw, 95dvh);
    aspect-ratio: 1;
    border-radius: 50%;
    background: radial-gradient(
        circle,
        rgb(255 255 255 / 95%) 0%,
        rgb(255 242 180 / 80%) 22%,
        rgb(255 215 100 / 25%) 42%,
        transparent 68%
    );
    opacity: 0;
    animation: ae-gacha-super-light 1000ms ease-out both;
}

@keyframes ae-gacha-super-light {
    0%, 40% {
        opacity: 0;
        transform: scale(0.4);
    }
    65% {
        opacity: 0.95;
        transform: scale(1);
    }
    100% {
        opacity: 0;
        transform: scale(1.5);
    }
}

/* 上位レア：裏向きカードの登場演出 */
.ae-gacha__summon {
    --summon-accent: #c9e7ff;
    --summon-light: #b7f4ff;
    position: absolute;
    inset: 0;
    z-index: 4;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 22px;
    padding: 24px;
    overflow: hidden;
    pointer-events: none;
    background: radial-gradient(
        ellipse at center,
        rgb(65 103 174 / 70%),
        rgb(5 17 48 / 94%)
    );
}

.ae-gacha__summon[hidden] {
    display: none;
}

.ae-gacha__summon[data-rarity="miracle-rare"] {
    --summon-accent: #fff0ac;
    --summon-light: #ffd973;
    background: radial-gradient(
        ellipse at 50% 65%,
        #243459,
        #050b1c 80%
    );
}

/* 演出中の本体と操作案内を隠す */
.ae-gacha[data-stage="summoning"] > .ae-gacha__machine,
.ae-gacha[data-stage="summoning"] > .ae-gacha__controls {
    display: none;
}

.ae-gacha[data-stage="summoning"] > .ae-gacha__header {
    z-index: 7;
}

/* 回転するカードの大きさと遠近感 */
.ae-gacha__card-stage {
    position: relative;
    z-index: 1;
    width: min(340px, 64vw, 40dvh);
    aspect-ratio: 5 / 7;
    perspective: 1100px;
}

.ae-gacha__card-spinner {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
}

.ae-gacha__card-face {
    position: absolute;
    inset: 0;
    overflow: hidden;
    border: 4px solid var(--summon-accent);
    border-radius: 22px;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    box-shadow:
        0 0 22px rgb(189 230 255 / 35%),
        0 18px 32px rgb(0 0 0 / 35%);
}

/* 背面：濃紺・シルバー・中央の∞ */
.ae-gacha__card-face--back {
    display: grid;
    place-items: center;
    background:
        repeating-linear-gradient(
            45deg,
            transparent 0 18px,
            rgb(180 219 255 / 8%) 18px 19px
        ),
        radial-gradient(circle, #28588e, #091c3d 75%);
    color: var(--summon-accent);
}

.ae-gacha__card-face--back::before {
    content: "";
    position: absolute;
    inset: 10px;
    border: 1px solid var(--summon-accent);
    border-radius: 13px;
    opacity: 0.8;
}

.ae-gacha__card-face--back::after {
    content: "";
    position: absolute;
    width: 65%;
    aspect-ratio: 1;
    border: 1px solid var(--summon-accent);
    transform: rotate(45deg);
    opacity: 0.35;
}

.ae-gacha__back-brand,
.ae-gacha__back-caption {
    position: absolute;
    z-index: 1;
    left: 14px;
    right: 14px;
    text-align: center;
    font: 700 clamp(9px, 2.2vw, 12px)/1.5 sans-serif;
    letter-spacing: 0.1em;
}

.ae-gacha__back-brand {
    top: 25px;
}

.ae-gacha__back-caption {
    bottom: 25px;
}

.ae-gacha__back-symbol {
    position: relative;
    z-index: 1;
    font: 700 clamp(85px, 20vw, 150px)/1 sans-serif;
    text-shadow: 0 0 22px var(--summon-light);
}

/* 回転後に見える人物側 */
.ae-gacha__card-face--front {
    transform: rotateY(180deg);
    padding: 14px;
    background: linear-gradient(
        135deg,
        #bfeaff,
        #e4cdff,
        #fff0b8,
        #bff5e8
    );
}

.ae-gacha__card-face--front > img {
    display: block;
    width: 100%;
    height: 100%;
    margin: 0;
    object-fit: contain;
}

.ae-gacha__summon-label {
    position: relative;
    z-index: 1;
    margin: 0;
    color: var(--summon-accent);
    font: 800 clamp(18px, 5vw, 30px)/1.4 sans-serif;
    letter-spacing: 0.12em;
    text-align: center;
    text-shadow: 0 0 18px var(--summon-light);
}

/* ミラクル：円柱を囲むように上昇する光線 */
.ae-gacha__beams {
    display: none;
    position: absolute;
    inset: 0;
}

.ae-gacha__summon[data-rarity="miracle-rare"] .ae-gacha__beams {
    display: block;
}

.ae-gacha__beams > span {
    position: absolute;
    left: var(--beam-x, 50%);
    bottom: -35%;
    width: var(--beam-width, 2px);
    height: var(--beam-height, 30%);
    border-radius: 999px;
    background: linear-gradient(
        to top,
        transparent,
        var(--summon-light) 60%,
        #ffffff
    );
    box-shadow: 0 0 10px var(--summon-light);
    opacity: 0;
    animation: ae-gacha-beam-rise
        var(--beam-duration, 1000ms)
        var(--beam-delay, 0ms)
        linear infinite;
}

.ae-gacha__beams::after {
    content: "";
    position: absolute;
    left: 12%;
    right: 12%;
    bottom: 12%;
    height: 10%;
    border: 2px solid rgb(255 230 150 / 65%);
    border-radius: 50%;
    box-shadow:
        0 0 25px rgb(255 220 120 / 45%),
        inset 0 0 20px rgb(255 220 120 / 25%);
}

@keyframes ae-gacha-beam-rise {
    0% {
        opacity: 0;
        transform: translateY(0);
    }
    15%, 70% {
        opacity: var(--beam-alpha, 0.8);
    }
    100% {
        opacity: 0;
        transform: translateY(-140dvh);
    }
}

@media (prefers-reduced-motion: reduce) {
    .ae-gacha__beams > span {
        animation: none;
    }
}

/* 結果画面：背景のお店を残し、中央にカードを表示 */
.ae-gacha__result {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding:
        max(18px, env(safe-area-inset-top))
        max(16px, env(safe-area-inset-right))
        max(18px, env(safe-area-inset-bottom))
        max(16px, env(safe-area-inset-left));
    overflow-y: auto;
    overscroll-behavior: contain;
    color: #083474;
    font-family: sans-serif;
}

/* display:flex よりも非表示を優先 */
.ae-gacha__result[hidden] {
    display: none;
}

/* 開封・結果表示中は、本体と操作案内を隠す */
.ae-gacha[data-stage="opening"] > .ae-gacha__machine,
.ae-gacha[data-stage="opening"] > .ae-gacha__controls,
.ae-gacha[data-stage="result"] > .ae-gacha__machine,
.ae-gacha[data-stage="result"] > .ae-gacha__controls,
.ae-gacha[data-stage="result"] > .ae-gacha__header {
    display: none;
}

/* 基本カード：ノーマルは青とアイボリー */
.ae-gacha__card {
    flex: none;
    width: min(500px, 100%);
    margin-top: auto;
    padding: clamp(12px, 3vw, 22px);
    border: 6px solid #0755ba;
    border-radius: 28px;
    background: #fff9eb;
    box-shadow:
        inset 0 0 0 5px #fffdf6,
        inset 0 0 0 7px #174889,
        0 12px 28px rgb(12 48 94 / 22%);
}

.ae-gacha__card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: clamp(10px, 2.6vw, 14px);
    font-weight: 800;
    line-height: 1.5;
    letter-spacing: 0.05em;
}

.ae-gacha__card-meta > :last-child {
    flex: none;
    white-space: nowrap;
}

.ae-gacha__rarity {
    position: relative;
    z-index: 1;
    width: fit-content;
    min-width: 140px;
    margin: 12px auto -14px;
    padding: 5px 20px;
    border: 2px solid #0755ba;
    border-radius: 999px;
    background: #fff9eb;
    color: #083474;
    font-size: 14px;
    font-weight: 800;
    line-height: 1.5;
    letter-spacing: 0.12em;
    text-align: center;
}

.ae-gacha__prize-art {
    display: grid;
    place-items: center;
    height: clamp(150px, 38dvh, 380px);
    padding: 24px 12px 12px;
    overflow: hidden;
    border: 3px solid #0755ba;
    border-radius: 24px;
    background:
        radial-gradient(
            ellipse at 50% 85%,
            #ffffff 0%,
            rgb(255 255 255 / 55%) 35%,
            transparent 70%
        ),
        linear-gradient(#93d8ff, #e5f6ff);
}

.ae-gacha__prize-art > img {
    display: block;
    width: 100%;
    height: 100%;
    min-height: 0;
    max-width: 100%;
    max-height: 100%;
    margin: 0;
    object-fit: contain;
    user-select: none;
}

.ae-gacha__prize-name {
    margin: 12px 0;
    padding: 9px 8px;
    border: 2px solid #174889;
    border-radius: 18px;
    color: #083474;
    font-size: clamp(19px, 5vw, 28px);
    font-weight: 800;
    line-height: 1.35;
    text-align: center;
    overflow-wrap: anywhere;
}

.ae-gacha__prize-name:focus-visible {
    outline: 3px solid #0755ba;
    outline-offset: 3px;
}

.ae-gacha__trivia {
    padding: 12px;
    border: 2px solid #174889;
    border-radius: 18px;
    text-align: center;
}

.ae-gacha__trivia > h3 {
    width: fit-content;
    margin: 0 auto 8px;
    padding: 4px 16px;
    border-radius: 999px;
    background: #0755ba;
    color: #ffffff;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.5;
}

.ae-gacha__trivia > p {
    margin: 0;
    color: #083474;
    font-size: clamp(13px, 3.5vw, 16px);
    font-weight: 600;
    line-height: 1.7;
    overflow-wrap: anywhere;
}

/* レア：シルバーの縁と、一度だけ流れる光 */
.ae-gacha__card[data-rarity="rare"],
.ae-gacha__card[data-rarity="super-rare"] {
    position: relative;
    isolation: isolate;
    border: 6px solid #b8c6d6;
    box-shadow:
        inset 0 0 0 2px #174889,
        0 0 18px rgb(205 225 245 / 40%),
        0 12px 28px rgb(12 48 94 / 25%);
}

.ae-gacha__card[data-rarity="rare"] .ae-gacha__rarity {
    border-color: #8193aa;
    background: linear-gradient(
        135deg,
        #ffffff,
        #c4cfdd,
        #f8fbff,
        #b8c6d6
    );
}

.ae-gacha__card[data-rarity="super-rare"] .ae-gacha__rarity {
    border-color: #9d741b;
    background: linear-gradient(135deg, #fff7d1, #f6c44e, #fff2b1);
}
/* レアは一度、スーパーレアはゆっくり繰り返す反射 */
.ae-gacha__card[data-rarity="rare"]::after,
.ae-gacha__card[data-rarity="super-rare"]::after {
    content: "";
    position: absolute;
    z-index: 3;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background: linear-gradient(
        115deg,
        transparent 35%,
        rgb(255 255 255 / 60%) 50%,
        transparent 65%
    );
    background-size: 300% 100%;
    opacity: 0;
    animation: ae-gacha-card-shine 1400ms ease-out both;
}
/* スーパーレア：カード全体にもホログラムの色を載せる */
.ae-gacha__card[data-rarity="super-rare"] {
    border-color: transparent;
    background:
        linear-gradient(
            125deg,
            #fff5c9,
            #d5efff 25%,
            #edd8ff 50%,
            #d7fff1 75%,
            #fff5c9
        ) padding-box,
        conic-gradient(
            from 30deg,
            #fff1a5,
            #b1f8ff,
            #e3b7ff,
            #ffe69a,
            #b1f8ff,
            #fff1a5
        ) border-box;
    box-shadow:
        inset 0 0 0 2px #174889,
        0 0 28px rgb(255 224 136 / 55%),
        0 14px 30px rgb(12 48 94 / 28%);
}
.ae-gacha__card[data-rarity="super-rare"]::after {
    animation-duration: 4200ms;
    animation-iteration-count: infinite;
}

.ae-gacha__card[data-rarity="super-rare"] .ae-gacha__card-meta {
    padding: 0;
    border-radius: 8px;
    background: rgb(255 250 240 / 88%);
}
/* 人物を大きく載せ、背後の色がゆっくり動く */
.ae-gacha__card[data-rarity="super-rare"] .ae-gacha__prize-art {
    position: relative;
    isolation: isolate;
    background:
        radial-gradient(
            ellipse at 50% 70%,
            rgb(255 255 255 / 75%),
            transparent 65%
        ),
        repeating-linear-gradient(
            115deg,
            #b8eaff 0%,
            #e2c9ff 18%,
            #fff0ba 36%,
            #c4f7e8 54%,
            #b8eaff 72%
        );
    background-size: 100% 100%, 250% 250%;
    animation: ae-gacha-holo-flow 7s ease-in-out infinite alternate;
}

.ae-gacha__card[data-rarity="super-rare"] .ae-gacha__prize-art > img {
    position: relative;
    z-index: 1;
    filter: drop-shadow(0 6px 8px rgb(21 53 112 / 20%));
}
/* 星は画像ではなく装飾なので、人物素材には焼き込まない */
.ae-gacha__card[data-rarity="super-rare"] .ae-gacha__prize-art::before {
    content: "";
    position: absolute;
    z-index: 2;
    inset: 0;
    pointer-events: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 400'%3E%3Cdefs%3E%3Cpath id='s' d='M0 -16 L3 -3 L16 0 L3 3 L0 16 L-3 3 L-16 0 L-3 -3 Z'/%3E%3C/defs%3E%3Cg fill='white'%3E%3Cuse href='%23s' transform='translate(48 65)'/%3E%3Cuse href='%23s' transform='translate(340 115) scale(1.5)'/%3E%3Cuse href='%23s' transform='translate(62 265) scale(.7)'/%3E%3Cuse href='%23s' transform='translate(325 330)'/%3E%3C/g%3E%3Cg fill='%23fff2a5'%3E%3Cuse href='%23s' transform='translate(105 160) scale(.7)'/%3E%3Cuse href='%23s' transform='translate(300 45) scale(.65)'/%3E%3Cuse href='%23s' transform='translate(115 355)'/%3E%3C/g%3E%3C/svg%3E");
    background-size: 100% 100%;
    background-repeat: no-repeat;
    opacity: 0.8;
    filter: drop-shadow(0 0 5px rgb(255 255 255 / 85%));
    animation: ae-gacha-star-glow 2200ms ease-in-out infinite alternate;
}
/* 豆知識と景品名は、読みやすい明るさを保つ */
.ae-gacha__card[data-rarity="super-rare"] .ae-gacha__prize-name,
.ae-gacha__card[data-rarity="super-rare"] .ae-gacha__trivia {
    background: rgb(255 250 240 / 94%);
}

@keyframes ae-gacha-card-shine {
    0% {
        background-position: 100% 0;
        opacity: 0;
    }
    25%, 65% {
        opacity: 0.55;
    }
    100% {
        background-position: 0% 0;
        opacity: 0;
    }
}

@keyframes ae-gacha-holo-flow {
    from { background-position: 0 0, 0% 0%; }
    to { background-position: 0 0, 100% 100%; }
}
@keyframes ae-gacha-star-glow {
    from { opacity: 0.4; }
    to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
    .ae-gacha__opening[data-rarity="super-rare"]::before,
    .ae-gacha__card[data-rarity="rare"]::after,
    .ae-gacha__card[data-rarity="super-rare"]::after,
    .ae-gacha__card[data-rarity="super-rare"] .ae-gacha__prize-art,
    .ae-gacha__card[data-rarity="super-rare"] .ae-gacha__prize-art::before {
        animation: none;
    }
}

/* カード外の操作ボタン */
.ae-gacha__result-actions {
    display: flex;
    flex: none;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    width: min(500px, 100%);
    margin-bottom: auto;
}

.ae-gacha__result-actions > button {
    flex: 1 1 140px;
    min-height: 48px;
    margin: 0;
    padding: 10px 16px;
    border: 2px solid #0755ba;
    border-radius: 999px;
    background: #fff9eb;
    color: #083474;
    box-shadow: 0 4px 10px rgb(12 48 94 / 15%);
    font: 700 clamp(15px, 4vw, 18px)/1.5 sans-serif;
    cursor: pointer;
}

.ae-gacha__result-actions > .ae-gacha__again {
    background: linear-gradient(#1688ff, #0054df);
    color: #ffffff;
}

.ae-gacha__result-actions > button:hover {
    filter: brightness(1.06);
}

.ae-gacha__result-actions > button:focus-visible {
    outline: 3px solid #0755ba;
    outline-offset: 4px;
}

/* 縦長画面：本体を少し小さくし、下に操作案内をまとめる */
/* 縦長画面：本体と、カードに揃えた操作案内 */
@media (max-aspect-ratio: 4 / 3) {
    .ae-gacha__machine {
        top: 50%;
        bottom: auto;
        width: min(
            calc(
                (100dvh - 276px - env(safe-area-inset-bottom, 0px)
                - env(safe-area-inset-bottom, 0px)) * 2 / 3
            ),
            110vw
        );
        transform: translate(-50%, -50%);
    }

    .ae-gacha__controls {
        top: auto;
        bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        left: 50%;
        display: grid;
        justify-items: center;
        gap: 4px;
        width: min(280px, calc(100% - 40px));
        padding: 8px 10px;
        border: 2px solid #0755ba;
        border-radius: 16px;
        background: #fff9eb;
        box-shadow:
            inset 0 0 0 4px #fffdf6,
            inset 0 0 0 5px #174889,
            0 5px 18px rgb(12 48 94 / 15%);
        transform: translateX(-50%);
    }

    .ae-gacha__spin {
        min-height: 44px;
        padding: 6px 18px;
        border: 2px solid #0755ba;
        background: linear-gradient(#1688ff, #0054df);
        color: #fff;
        box-shadow: 0 3px 8px rgb(12 48 94 / 15%);
        font-size: 13px;
    }

    .ae-gacha__spin:hover {
        background: linear-gradient(#2993ff, #0860ed);
    }

    .ae-gacha__controls p {
        margin: 0;
        color: #083474;
        font-size: 11px;
        font-weight: 600;
        line-height: 1.5;
    }

    .ae-gacha__controls .ae-gacha__status {
        min-height: 19px;
        margin: 0;
        color: #083474;
        font-size: 12px;
        line-height: 1.5;
    }
}

/* スマホ：戻るボタンの下に、小さめの結果カードを配置 */
@media (max-width: 650px) {
.ae-gacha__result {
    gap: 12px;
    padding:
        calc(var(--ae-return-top, 16px) + 56px)
        20px;
}

    .ae-gacha__card {
        width: min(300px, 100%);
        margin-top: auto;
        padding: 12px;
        border-radius: 24px;
    }

    .ae-gacha__rarity {
        min-width: 120px;
        margin-top: 10px;
        padding: 4px 16px;
        font-size: 12px;
    }

    .ae-gacha__prize-art {
        height: clamp(120px, 27dvh, 210px);
        padding: 20px 10px 10px;
        border-radius: 20px;
    }

    .ae-gacha__prize-name {
        margin: 10px 0;
        padding: 7px 8px;
        border-radius: 15px;
        font-size: 18px;
    }

    .ae-gacha__trivia {
        padding: 10px;
        border-radius: 15px;
    }

    .ae-gacha__trivia > h3 {
        padding: 4px 12px;
        font-size: 12px;
    }

    .ae-gacha__trivia > p {
        font-size: 12px;
        line-height: 1.7;
    }

    .ae-gacha__result-actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
        width: min(300px, 100%);
        margin-bottom: auto;
    }

    .ae-gacha__result-actions > button {
        min-width: 0;
        min-height: 44px;
        padding: 8px 10px;
        font-size: 13px;
    }
}