* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: #1f1008;
    font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", sans-serif;
    background-color: #07142d;
    overflow-x: hidden;
}

body.is-dialog-open {
    overflow: hidden;
}

button {
    font: inherit;
}

[hidden] {
    display: none !important;
}

.three-card-page {
    --three-card-card-width: clamp(86px, 10vw, 110px);
    --three-card-deck-width: clamp(108px, 13vw, 128px);

    min-height: 100vh;
    padding: 16px;
    background-color: #07142d;
    background-image: url("../images/menu/menu-stage1-space-bg.png");
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
}

.three-card-panel {
    position: relative;
    display: flex;
    width: min(100%, 720px);
    margin: 0 auto;
    padding: 170px 28px 28px;
    flex-direction: column;
    align-items: stretch;
    text-align: center;
    background-color: #fffdf7;
    background-image:
        linear-gradient(
            rgba(255, 253, 247, 0.78),
            rgba(255, 250, 238, 0.78)
        ),
        url("../images/menu/menu-stage1-parchment.png");
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
    border: 4px solid #c89b3c;
    border-radius: 18px;
    box-shadow: 0 10px 24px rgba(72, 48, 20, 0.2);
}

.three-card-panel::before {
    position: absolute;
    inset: 14px;
    border: 1px solid #d7b45b;
    border-radius: 10px;
    content: "";
    pointer-events: none;
}

.spread-heading {
    position: absolute;
    top: 22px;
    left: 50%;
    z-index: 2;
    width: min(80%, 420px);
    margin: 0;
    padding: 14px 24px 16px;
    text-align: center;
    background:
        linear-gradient(
            180deg,
            rgba(255, 255, 255, 0.32) 0%,
            rgba(255, 255, 255, 0.08) 20%,
            rgba(255, 255, 255, 0) 48%
        ),
        linear-gradient(
            180deg,
            #ffd15f 0%,
            #f3ad35 46%,
            #d98216 100%
        );
    border: 2px solid #f9d982;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.74),
        inset 0 -2px 0 rgba(125, 66, 18, 0.28),
        0 4px 0 #a95b10;
    transform: translateX(-50%);
}

#page-title {
    margin: 0;
    color: #fffdf7;
    font-size: clamp(1.6rem, 4vw, 2.2rem);
    letter-spacing: 0.08em;
    text-shadow: 0 1px 2px rgba(88, 56, 8, 0.4);
}

.spread-heading-description {
    margin: 10px 0 0;
    color: #fffdf7;
    font-size: clamp(0.78rem, 2.4vw, 0.94rem);
    font-weight: 500;
    line-height: 1.65;
    letter-spacing: 0.02em;
    text-shadow: 0 1px 2px rgba(88, 56, 8, 0.35);
}

.heading-description--sp,
.lead-copy--sp {
    display: none;
}

.back-to-menu-button {
    position: relative;
    z-index: 2;
    display: inline-flex;
    min-width: 210px;
    margin: 16px 0 14px;
    padding: 9px 16px;
    align-self: center;
    align-items: center;
    justify-content: center;
    order: 1;
    color: #211008;
    font-size: 1.02rem;
    font-weight: bold;
    text-decoration: none;
    background-color: #fff7e8;
    border: 1px solid #b9843f;
    border-radius: 8px;
    box-shadow: 0 2px 0 #d4ad72;
    transition:
        transform 0.2s,
        box-shadow 0.2s;
}

.back-to-menu-button:hover {
    color: #43260f;
    box-shadow: 0 4px 0 #d4ad72;
    transform: translateY(-2px);
}

.back-to-menu-button:active {
    box-shadow: 0 1px 0 #d4ad72;
    transform: translateY(1px);
}

.three-card-lead {
    position: relative;
    z-index: 6;
    min-height: 56px;
    margin: 0 0 10px;
    padding: 0 8px;
    order: 3;
    color: #241107;
    font-size: 1.08rem;
    font-weight: 500;
    line-height: 1.8;
    letter-spacing: 0.015em;
    background-color: #fffdf7;
}

.three-card-lead-action {
    display: inline-block;
    margin-top: 2px;
    color: #804003;
    font-weight: bold;
}

.mobile-line-break {
    display: none;
}

.theme-selector {
    position: relative;
    z-index: 2;
    width: min(100%, 620px);
    margin: 0 auto 10px;
    padding: 8px 16px 11px;
    align-self: center;
    order: 2;
    text-align: center;
    border: 1px solid rgba(192, 142, 47, 0.58);
}

.theme-selector legend {
    padding: 0 6px;
    color: #1f1008;
    font-size: 1.04rem;
    font-weight: bold;
}

.theme-selector label {
    margin: 0 4px;
    color: #241107;
    font-size: 1.02rem;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.2s;
}

.theme-selector label:has(input:checked) {
    color: #804003;
    font-weight: bold;
}

.theme-selector input[type="radio"] {
    accent-color: auto;
}

.theme-selector input:disabled {
    cursor: not-allowed;
}

.three-card-status {
    position: relative;
    z-index: 6;
    min-height: 42px;
    margin: 0 auto 8px;
    padding: 0 8px;
    order: 4;
    color: #241107;
    font-size: 1.08rem;
    font-weight: 500;
    line-height: 1.7;
    letter-spacing: 0.015em;
    background-color: #fffdf7;
}

.three-card-deck-area {
    position: relative;
    z-index: 1;
    display: flex;
    min-height: 286px;
    margin: 0 auto;
    align-items: center;
    justify-content: center;
    order: 5;
}

.three-card-deck-stack {
    position: relative;
    width: var(--three-card-deck-width);
    aspect-ratio: var(--tarot-card-ratio, 1109 / 1920);
    isolation: isolate;
}

.three-card-deck-layer {
    position: absolute;
    inset: 0;
    z-index: var(--deck-z);
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 5px 12px rgba(72, 48, 20, 0.22);
    transform:
        translate(var(--rest-x), var(--rest-y))
        rotate(var(--rest-rotate));
    transition:
        opacity 0.25s,
        transform 0.25s;
    transform-origin: center;
}

.three-card-deck-stack.is-shuffling .three-card-deck-layer {
    animation: tarot-deck-shuffle var(--shuffle-duration) ease-in-out infinite;
    animation-delay: var(--shuffle-delay);
}

@keyframes tarot-deck-shuffle {
    0%,
    100% {
        transform:
            translate(var(--rest-x), var(--rest-y))
            rotate(var(--rest-rotate));
    }

    25% {
        transform:
            translate(var(--move-1-x), var(--move-1-y))
            rotate(var(--move-1-rotate))
            scale(var(--shuffle-card-scale));
    }

    50% {
        transform:
            translate(var(--move-2-x), var(--move-2-y))
            rotate(var(--move-2-rotate))
            scale(var(--shuffle-card-scale));
    }

    75% {
        transform:
            translate(var(--move-3-x), var(--move-3-y))
            rotate(var(--move-3-rotate))
            scale(var(--shuffle-card-scale));
    }
}

.three-card-stage {
    position: relative;
    z-index: 1;
    display: flex;
    min-height: 252px;
    margin: 0 auto;
    padding: 10px 12px 6px;
    align-items: flex-start;
    justify-content: center;
    gap: clamp(22px, 7vw, 64px);
    order: 5;
}

.three-card-stage::before {
    position: absolute;
    top: var(--three-card-line-top, 56%);
    right: var(--three-card-line-right, 14%);
    left: var(--three-card-line-left, 14%);
    z-index: 0;
    height: 4px;
    content: "";
    background-color: #e1bf62;
    border-radius: 999px;
    opacity: 0.8;
}

.three-card-slot {
    position: relative;
    z-index: 1;
    display: flex;
    flex: 0 1 var(--three-card-card-width);
    flex-direction: column;
    align-items: center;
    min-width: 0;
    gap: 5px;
}

.slot-label {
    margin: 0;
    padding: 4px 8px;
    color: #2b1609;
    font-size: clamp(0.7rem, 2.2vw, 0.84rem);
    font-weight: bold;
    line-height: 1.25;
    white-space: nowrap;
    background-color: rgba(255, 253, 247, 0.94);
    border: 1px solid #9f7442;
}

.three-card-wrap {
    position: relative;
}

.three-card-back {
    display: block;
    width: var(--three-card-card-width);
    height: auto;
    aspect-ratio: var(--tarot-card-ratio, 1109 / 1920);
    object-fit: contain;
    border-radius: 6px;
    box-shadow: 0 5px 12px rgba(72, 48, 20, 0.24);
}

.slot-number {
    position: absolute;
    top: 50%;
    left: 50%;
    display: grid;
    width: 28px;
    height: 28px;
    place-items: center;
    color: #4a321d;
    font-weight: bold;
    background-color: #fffdf7;
    border: 1px solid #c89b3c;
    border-radius: 50%;
    transform: translate(-50%, -50%);
}

.button-area {
    position: relative;
    z-index: 10;
    display: flex;
    justify-content: center;
    min-height: 52px;
    margin-top: 10px;
    order: 6;
}

.button-area button,
.retry-button,
.retry-confirm-button,
.retry-cancel-button {
    padding: 12px 24px;
    color: #211008;
    font-size: 1.05rem;
    font-weight: bold;
    cursor: pointer;
    border: 2px solid #70401f;
    border-radius: 10px;
    transition:
        transform 0.2s,
        box-shadow 0.2s;
}

.button-area button,
.retry-button,
.retry-confirm-button {
    background: linear-gradient(180deg, #ffd7b9, #f2b785);
    box-shadow: 0 3px 0 #a9673b;
}

.button-area button {
    min-width: 150px;
}

.button-area button:not(:disabled):hover,
.retry-button:hover,
.retry-confirm-button:hover {
    box-shadow: 0 5px 0 #a9673b;
    transform: translateY(-2px);
}

.button-area button:not(:disabled):active,
.retry-button:active,
.retry-confirm-button:active {
    box-shadow: 0 1px 0 #a9673b;
    transform: translateY(2px);
}

.button-area button:disabled {
    color: #907866;
    cursor: not-allowed;
    background: #ead9cc;
    border-color: #b9a18d;
    box-shadow: 0 3px 0 #a88c75;
}

.reading-result {
    position: relative;
    z-index: 2;
    display: none;
    width: min(100%, 620px);
    margin: -42px auto 0;
    padding: 28px 24px;
    align-self: center;
    order: 7;
    color: #1f1008;
    text-align: left;
    background-color: #fffaf0;
    border: 1px solid #d7b45b;
    border-radius: 12px;
    box-shadow: 0 6px 14px rgba(72, 48, 20, 0.12);
}

.reading-result-title {
    margin: 0;
    padding-bottom: 14px;
    color: #1f1008;
    font-size: clamp(1.5rem, 3vw, 1.9rem);
    text-align: center;
    border-bottom: 2px solid #d7b45b;
}

.reading-theme-name {
    margin: 16px 0 24px;
    color: #804003;
    font-size: 1.04rem;
    font-weight: bold;
    text-align: center;
}

.reading-cards {
    display: grid;
    gap: 18px;
}

.reading-card {
    padding: 18px 16px;
    background-color: #fffdf7;
    border: 1px solid #d9ba77;
    border-left: 6px solid #c89b3c;
    border-radius: 8px;
}

.reading-position {
    margin: 0 0 12px;
    color: #241107;
    font-size: 1.08rem;
    font-weight: bold;
}

.reading-card-name {
    margin: 0;
    color: #1f1008;
    font-size: 1.05rem;
    font-weight: bold;
}

.reading-keyword-label {
    margin: 16px 0 6px;
    color: #804003;
    font-size: 1rem;
    font-weight: bold;
    letter-spacing: 0.03em;
}

.reading-keywords {
    margin: 0;
    color: #4d2a12;
    font-size: 1.02rem;
    font-weight: 500;
}

.reading-meaning {
    margin: 0;
    color: #241107;
    font-size: 1.02rem;
    font-weight: 500;
    line-height: 1.85;
}

.reading-section-title {
    margin: 18px 0 8px;
    color: #804003;
    font-size: 1rem;
    font-weight: bold;
    letter-spacing: 0.03em;
}

.reading-detail-block {
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid rgba(199, 150, 65, 0.5);
}

.reading-detail-block h4 {
    margin: 0 0 8px;
    color: #804003;
    font-size: 1rem;
    font-weight: bold;
    letter-spacing: 0.03em;
}

.reading-interpretation {
    margin: 0;
    color: #241107;
    font-size: 1.02rem;
    font-weight: 500;
    line-height: 1.85;
}

.reading-interpretation-branch-title {
    margin: 18px 0 6px;
    color: #804003;
    font-size: 1rem;
    font-weight: bold;
    letter-spacing: 0.03em;
}

.reading-detail-block h4 + .reading-interpretation-branch-title {
    margin-top: 0;
}

.reading-actions {
    margin-top: 24px;
    text-align: center;
}

.retry-confirm-dialog {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    padding: 16px;
    place-items: center;
    background-color: rgba(54, 34, 18, 0.58);
}

.retry-confirm-content {
    width: min(100%, 420px);
    padding: 28px 24px 24px;
    text-align: center;
    background-color: #fffdf7;
    border: 3px solid #c89b3c;
    border-radius: 14px;
    box-shadow: 0 12px 28px rgba(35, 20, 8, 0.35);
}

.retry-confirm-content h2 {
    margin: 0 0 14px;
    color: #1f1008;
    font-size: 1.35rem;
}

.retry-confirm-content p {
    margin: 0;
    color: #241107;
    font-size: 1rem;
    font-weight: 500;
    line-height: 1.8;
}

.retry-confirm-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 24px;
}

.retry-cancel-button {
    background-color: #fffaf0;
}

@media (min-width: 768px) {
    .three-card-page {
        background-attachment: fixed;
    }
}

@media (max-width: 767px) {
    .three-card-page {
        --three-card-card-width: clamp(76px, 24vw, 102px);
        --three-card-deck-width: min(31vw, 110px);

        padding: 16px 10px;
        background-image: none;
        background-color: #07142d;
    }

    .three-card-panel {
        padding: 178px 20px 28px;
    }

    .spread-heading {
        width: min(88%, 420px);
        padding: 13px 14px 15px;
    }

    .spread-heading-description {
        font-size: 0.94rem;
        line-height: 1.7;
        letter-spacing: 0;
    }

    .heading-description--pc,
    .lead-copy--pc {
        display: none;
    }

    .heading-description--sp,
    .lead-copy--sp {
        display: block;
    }

    .heading-description--sp > span,
    .lead-line {
        display: block;
    }

    .back-to-menu-button {
        min-width: 180px;
        margin-top: 10px;
        margin-bottom: 18px;
        font-size: 1rem;
    }

    .three-card-lead {
        min-height: 76px;
        padding-right: 14px;
        padding-left: 14px;
        font-size: 1rem;
        letter-spacing: 0;
        text-align: left;
    }

    .three-card-lead-action {
        display: block;
        margin-top: 8px;
        text-align: left;
    }

    .mobile-line-break {
        display: inline;
    }

    .theme-selector {
        padding-right: 8px;
        padding-left: 8px;
        white-space: nowrap;
    }

    .theme-selector legend {
        font-size: 1rem;
    }

    .theme-selector label {
        margin: 0 2px;
        font-size: 1rem;
        white-space: nowrap;
    }

    .theme-selector input[type="radio"] {
        width: 1.08rem;
        height: 1.08rem;
        margin: 0 4px 0 0;
        vertical-align: -0.12em;
    }

    .three-card-status {
        min-height: 3.7em;
        font-size: 1rem;
        letter-spacing: 0;
        line-height: 1.8;
    }

    .three-card-deck-area {
        min-height: 268px;
    }

    .three-card-deck-stack.is-shuffling {
        transform: scale(0.9);
    }

    .three-card-stage {
        min-height: 232px;
        gap: 16px;
        padding: 10px 0 6px;
    }

    .slot-label {
        padding: 3px 5px;
        font-size: 0.65rem;
    }

    .slot-number {
        width: 22px;
        height: 22px;
        font-size: 0.75rem;
    }

    .button-area button {
        min-width: 130px;
        font-size: 1rem;
    }

    .reading-result {
        margin-top: -42px;
        padding: 22px 16px;
    }

    .reading-result-title {
        font-size: 1.45rem;
    }

    .reading-theme-name,
    .reading-position,
    .reading-card-name,
    .reading-keywords,
    .reading-keyword-label,
    .reading-meaning,
    .reading-section-title,
    .reading-detail-block h4,
    .reading-interpretation,
    .reading-interpretation-branch-title {
        font-size: 1rem;
    }

    .reading-card {
        padding: 16px 14px;
    }

    .reading-meaning {
        line-height: 1.8;
    }

    .retry-confirm-content {
        padding: 24px 16px 20px;
    }

    .retry-confirm-content h2 {
        font-size: 1.28rem;
    }

    .retry-confirm-content p {
        text-align: left;
    }

    .retry-confirm-actions {
        flex-direction: column;
    }

    .retry-confirm-button,
    .retry-cancel-button {
        width: 100%;
        font-size: 1rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .three-card-deck-stack.is-shuffling .three-card-deck-layer {
        animation: none;
    }

    *,
    *::before,
    *::after {
        scroll-behavior: auto;
        transition-duration: 0.01ms !important;
    }
}