* {
    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;
}

.hexagram-page {
    --hexagram-card-width: clamp(82px, 10vw, 110px);
    --hexagram-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;
}

.hexagram-panel {
    position: relative;
    display: flex;
    width: min(100%, 720px);
    margin: 0 auto;
    padding: 180px 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);
}

.hexagram-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(86%, 500px);
    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);
}

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

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

.top-menu-button {
    position: relative;
    z-index: 2;
    display: inline-flex;
    min-width: 190px;
    margin: 16px auto 14px;
    padding: 10px 18px;
    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: #fffaf0;
    border: 1px solid #c89b3c;
    border-radius: 8px;
    box-shadow: 0 2px 0 #d7b45b;
    transition:
        transform 0.2s,
        box-shadow 0.2s;
}

.top-menu-button:hover {
    box-shadow: 0 4px 0 #d7b45b;
    transform: translateY(-2px);
}

.top-menu-button:active {
    box-shadow: 0 1px 0 #d7b45b;
    transform: translateY(1px);
}

.hexagram-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;
}

.hexagram-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;
}

.hexagram-status {
    position: relative;
    z-index: 6;
    min-height: 42px;
    margin: 0;
    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;
}

.hexagram-stage {
    position: relative;
    z-index: 1;
    width: min(100%, 620px);
    height: 770px;
    margin: 0 auto;
    order: 5;
}

.hexagram-stage.is-deck-mode {
    height: 286px;
}

.hexagram-deck-stack {
    position: absolute;
    top: 50%;
    left: 50%;
    width: var(--hexagram-deck-width);
    aspect-ratio: var(--tarot-card-ratio, 1109 / 1920);
    isolation: isolate;
    transform: translate(-50%, -50%);
}

.hexagram-deck-card {
    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;
}

.hexagram-deck-stack.is-shuffling .hexagram-deck-card {
    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));
    }
}

.hexagram-spread {
    position: absolute;
    inset: 0;
}

.hexagram-spread::before {
    position: absolute;
    inset: 54px 9% 24px;
    z-index: 0;
    content: "";
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath d='M50 6 L12 72 H88 Z M50 94 L12 28 H88 Z' fill='none' stroke='%23e1bf62' stroke-width='1.15'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    opacity: 0.85;
    pointer-events: none;
}

.hexagram-slot {
    position: absolute;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    transform: translateX(-50%);
}

.hexagram-slot-1 {
    top: 14px;
    left: 50%;
}

.hexagram-slot-5 {
    top: 150px;
    left: 18%;
}

.hexagram-slot-6 {
    top: 150px;
    left: 82%;
}

.hexagram-slot-7 {
    top: 274px;
    left: 50%;
}

.hexagram-slot-3 {
    top: 404px;
    left: 18%;
}

.hexagram-slot-2 {
    top: 404px;
    left: 82%;
}

.hexagram-slot-4 {
    top: 528px;
    left: 50%;
}

.slot-label {
    position: relative;
    z-index: 3;
    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.96);
    border: 1px solid #9f7442;
}

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

.hexagram-card-back {
    display: block;
    width: var(--hexagram-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-submit,
.retry-confirm-cancel {
    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-submit {
    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-submit:hover {
    box-shadow: 0 5px 0 #a9673b;
    transform: translateY(-2px);
}

.button-area button:not(:disabled):active,
.retry-button:active,
.retry-confirm-submit: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-note {
    margin: -8px 0 22px;
    padding: 12px 14px;
    color: #4d2a12;
    font-size: 0.98rem;
    font-weight: 500;
    line-height: 1.8;
    background-color: rgba(255, 253, 247, 0.78);
    border: 1px solid rgba(199, 150, 65, 0.55);
    border-radius: 8px;
}

.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-box {
    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-box h2 {
    margin: 0 0 14px;
    color: #1f1008;
    font-size: 1.35rem;
}

.retry-confirm-box 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-confirm-cancel {
    background-color: #fffaf0;
}

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

@media (max-width: 767px) {
    .hexagram-page {
        --hexagram-card-width: clamp(72px, 20vw, 82px);
        --hexagram-deck-width: min(31vw, 110px);

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

    .hexagram-panel {
        padding: 202px 20px 28px;
    }

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

    .hexagram-heading-description {
        margin-top: 8px;
        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;
    }

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

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

    .hexagram-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;
    }

    .hexagram-status {
        min-height: 3.5em;
        font-size: 1rem;
        letter-spacing: 0;
        line-height: 1.8;
    }

    .hexagram-stage {
        height: clamp(540px, 150vw, 570px);
    }

    .hexagram-stage.is-deck-mode {
        height: 268px;
    }

    .hexagram-deck-stack.is-shuffling {
        transform: translate(-50%, -50%) scale(0.9);
    }

    .hexagram-spread::before {
        inset: 0;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath d='M50 18 L18 69 H82 Z M50 85 L18 36 H82 Z' fill='none' stroke='%23e1bf62' stroke-width='1.15'/%3E%3C/svg%3E");
        background-size: 100% 100%;
    }

    .hexagram-slot-1 {
        top: 2.8%;
    }

    .hexagram-slot-5,
    .hexagram-slot-6 {
        top: 18.8%;
    }

    .hexagram-slot-7 {
        top: 34.9%;
    }

    .hexagram-slot-2,
    .hexagram-slot-3 {
        top: 51.8%;
    }

    .hexagram-slot-4 {
        top: 68.1%;
    }

    .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 14px;
    }

    .reading-result-title {
        padding-bottom: 12px;
        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,
    .reading-note {
        font-size: 1rem;
    }

    .reading-theme-name {
        margin: 14px 0 20px;
    }

    .reading-note {
        margin-top: -6px;
        margin-bottom: 18px;
        padding: 11px 12px;
    }

    .reading-cards {
        gap: 14px;
    }

    .reading-card {
        padding: 16px 14px;
        border-left-width: 4px;
    }

    .reading-position {
        margin-bottom: 10px;
    }

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

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

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

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

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

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

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

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