/* ── Knowledge Card Unlock Animation ── */
/* ── Knowledge Card Unlock Animation 2.0 ── */
.knowledge-card-overlay {
    position: fixed;
    inset: 0;
    z-index: 9000;
    background: rgba(8, 10, 24, 0.45);
    backdrop-filter: blur(12px) brightness(0.85);
    -webkit-backdrop-filter: blur(12px) brightness(0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    perspective: 1200px;
    cursor: pointer;
}

.knowledge-card-container {
    position: relative;
    width: 290px;
    height: 420px;
    transform-style: preserve-3d;
}

.spirit-unlock-container {
    width: min(92vw, 430px);
    height: auto;
    min-height: 0;
    transform-style: flat;
}

.knowledge-card {
    position: relative;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #201422 0%, #321838 50%, #201422 100%);
    border: 2px solid rgba(251, 191, 36, 0.6);
    border-radius: 24px;
    box-shadow:
        0 30px 70px rgba(0, 0, 0, 0.9),
        inset 0 0 40px rgba(251, 191, 36, 0.14),
        0 0 25px rgba(251, 191, 36, 0.2);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 30px 24px;
    text-align: center;
    animation: knowledge-card-pop 0.7s cubic-bezier(0.34, 1.56, 0.64, 1) forwards,
        knowledge-card-float 4s ease-in-out infinite 0.7s;
    backface-visibility: hidden;
    user-select: none;
}

/* Sparkle Effects */
.card-sparkles {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
}

.card-sparkle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 0 10px #fff, 0 0 20px #fbbf24;
    opacity: 0;
    animation: sparkle-twinkle 3s infinite;
}

.card-sparkle:nth-child(1) {
    top: 15%;
    left: 20%;
    animation-delay: 0.2s;
}

.card-sparkle:nth-child(2) {
    top: 25%;
    right: 15%;
    animation-delay: 0.8s;
}

.card-sparkle:nth-child(3) {
    bottom: 30%;
    left: 15%;
    animation-delay: 1.5s;
}

.card-sparkle:nth-child(4) {
    bottom: 20%;
    right: 25%;
    animation-delay: 2.1s;
}

.card-sparkle:nth-child(5) {
    top: 50%;
    left: 10%;
    animation-delay: 0.5s;
}

.card-sparkle:nth-child(6) {
    top: 60%;
    right: 10%;
    animation-delay: 1.2s;
}

.card-sparkle:nth-child(7) {
    top: 10%;
    right: 40%;
    animation-delay: 2.5s;
}

.card-sparkle:nth-child(8) {
    bottom: 10%;
    left: 40%;
    animation-delay: 1.8s;
}

@keyframes sparkle-twinkle {

    0%,
    100% {
        transform: scale(0);
        opacity: 0;
    }

    50% {
        transform: scale(1.2);
        opacity: 0.8;
    }
}

/* Inner Shine */
.card-inner-shine {
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent 45%, rgba(255, 255, 255, 0.1) 50%, transparent 55%);
    pointer-events: none;
    z-index: 5;
    animation: card-shine-sweep 4s infinite linear;
}

@keyframes card-shine-sweep {
    0% {
        transform: translateX(-10%) translateY(-10%);
    }

    100% {
        transform: translateX(10%) translateY(10%);
    }
}

.card-magic-glow {
    position: absolute;
    inset: -30px;
    background: radial-gradient(circle at center, rgba(139, 92, 246, 0.4) 0%, transparent 70%);
    filter: blur(25px);
    z-index: -1;
    animation: card-glow-pulse 3s ease-in-out infinite;
}

.spirit-unlock-stage {
    position: relative;
    z-index: 0;
    width: 100%;
    min-height: min(86dvh, 620px);
    padding: clamp(24px, 5vw, 38px) clamp(20px, 5vw, 34px) clamp(22px, 5vw, 32px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(14px, 2.8vh, 22px);
    text-align: center;
    color: #fff7ed;
    overflow: visible;
    user-select: none;
    animation: spirit-unlock-enter 0.62s cubic-bezier(0.22, 1.16, 0.38, 1) both;
}

.spirit-unlock-aura {
    position: absolute;
    inset: 5% 0 20%;
    pointer-events: none;
    background:
        radial-gradient(circle at 50% 38%, rgba(255, 244, 179, 0.58) 0%, rgba(251, 191, 36, 0.2) 28%, transparent 58%),
        radial-gradient(circle at 50% 54%, rgba(167, 139, 250, 0.34) 0%, rgba(45, 27, 105, 0.2) 38%, transparent 70%);
    filter: blur(6px);
    opacity: 0.9;
    z-index: 0;
}

.spirit-unlock-stars {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 3;
}

.spirit-unlock-star {
    position: absolute;
    width: 5px;
    height: 5px;
    border-radius: 999px;
    background: #fff7c2;
    box-shadow: 0 0 12px rgba(255, 247, 194, 0.9);
    opacity: 0;
    animation: spirit-star-twinkle 3.4s ease-in-out infinite;
}

.spirit-unlock-star:nth-child(1) {
    top: 14%;
    left: 16%;
    animation-delay: 0.1s;
}

.spirit-unlock-star:nth-child(2) {
    top: 18%;
    right: 18%;
    animation-delay: 0.7s;
}

.spirit-unlock-star:nth-child(3) {
    top: 34%;
    left: 8%;
    animation-delay: 1.2s;
}

.spirit-unlock-star:nth-child(4) {
    top: 37%;
    right: 9%;
    animation-delay: 1.8s;
}

.spirit-unlock-star:nth-child(5) {
    top: 52%;
    left: 18%;
    animation-delay: 2.2s;
}

.spirit-unlock-star:nth-child(6) {
    top: 55%;
    right: 16%;
    animation-delay: 0.4s;
}

.spirit-unlock-star:nth-child(7) {
    bottom: 28%;
    left: 14%;
    animation-delay: 1.5s;
}

.spirit-unlock-star:nth-child(8) {
    bottom: 30%;
    right: 16%;
    animation-delay: 2.6s;
}

.spirit-unlock-star:nth-child(9) {
    bottom: 16%;
    left: 28%;
    animation-delay: 0.9s;
}

.spirit-unlock-star:nth-child(10) {
    bottom: 18%;
    right: 30%;
    animation-delay: 2.9s;
}

.spirit-unlock-kicker {
    position: relative;
    z-index: 2;
    margin: 0;
    padding: 6px 16px;
    border-radius: 999px;
    background:
        linear-gradient(180deg, rgba(255, 252, 232, 0.18), rgba(251, 191, 36, 0.08)),
        rgba(255, 247, 237, 0.1);
    border: 1px solid rgba(253, 230, 138, 0.42);
    color: #fff0a8;
    font-size: clamp(0.86rem, 3.5vw, 1rem);
    font-weight: 900;
    letter-spacing: 0.08em;
    box-shadow:
        0 0 18px rgba(253, 230, 138, 0.16),
        inset 0 1px 0 rgba(255, 255, 255, 0.28);
    text-shadow:
        0 2px 10px rgba(0, 0, 0, 0.5),
        0 0 10px rgba(253, 230, 138, 0.28);
}

.spirit-unlock-hero {
    position: relative;
    z-index: 2;
    width: min(78vw, 330px);
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: visible;
}

.spirit-unlock-hero::after {
    content: "";
    position: absolute;
    left: 16%;
    right: 16%;
    bottom: 8%;
    height: 11%;
    border-radius: 999px;
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.34), transparent 68%);
    filter: blur(8px);
    opacity: 0.36;
    z-index: -1;
}

.spirit-unlock-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter:
        drop-shadow(0 24px 28px rgba(0, 0, 0, 0.36)) drop-shadow(0 0 24px rgba(253, 230, 138, 0.3));
    animation: spirit-unlock-float 3.8s ease-in-out infinite 0.4s;
}

.spirit-unlock-copy {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 9px;
    max-width: 360px;
}

.spirit-unlock-name {
    margin: 0;
    color: #fff3b0;
    font-size: clamp(1.55rem, 7vw, 2.28rem);
    line-height: 1.16;
    font-weight: 950;
    letter-spacing: 0;
    text-shadow:
        0 3px 14px rgba(0, 0, 0, 0.62),
        0 0 18px rgba(251, 191, 36, 0.28);
}

.spirit-unlock-text {
    margin: 0;
    white-space: pre-line;
    color: #fff7ed;
    font-size: clamp(1.02rem, 4.4vw, 1.2rem);
    line-height: 1.62;
    font-weight: 760;
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.66);
}

.spirit-unlock-btn {
    position: relative;
    z-index: 2;
    margin-top: 2px;
    padding: 10px 24px;
    border-radius: 999px;
    border: 1px solid rgba(253, 230, 138, 0.48);
    background: linear-gradient(180deg, #fff2b8, #f6c85f);
    color: #4a2605;
    font-size: 1rem;
    font-weight: 950;
    box-shadow:
        0 10px 24px rgba(0, 0, 0, 0.32),
        inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.spirit-unlock-btn:active {
    transform: scale(0.96);
}

.card-header {
    flex: 1.5;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 10px;
}

.particle-glamour {
    font-size: 130px;
    font-weight: 900;
    color: #fbbf24;
    text-shadow:
        0 10px 30px rgba(0, 0, 0, 0.5),
        0 0 20px rgba(251, 191, 36, 0.4),
        0 0 40px rgba(251, 191, 36, 0.2);
    font-family: "Noto Serif JP", serif;
    line-height: 1;
    animation: particle-float 4s ease-in-out infinite;
}

@keyframes particle-float {

    0%,
    100% {
        transform: scale(1);
        filter: brightness(1);
    }

    50% {
        transform: scale(1.05);
        filter: brightness(1.2);
    }
}

.card-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 12px;
}

.card-topic-tag {
    display: inline-block;
    align-self: center;
    padding: 4px 16px;
    background: rgba(251, 191, 36, 0.15);
    border: 1px solid rgba(251, 191, 36, 0.3);
    border-radius: 99px;
    font-size: 1.1rem;
    font-weight: 900;
    color: #fbbf24;
    letter-spacing: 2px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.card-meaning {
    font-size: 1.2rem;
    color: #e2e8f0;
    line-height: 1.6;
    font-weight: 500;
    max-width: 90%;
    margin: 0 auto;
}

.card-footer {
    margin-top: 20px;
    font-size: 0.8rem;
    font-weight: 800;
    color: rgba(251, 191, 36, 0.6);
    text-transform: uppercase;
    letter-spacing: 4px;
    animation: footer-pulse 2s infinite ease-in-out;
}

@keyframes footer-pulse {

    0%,
    100% {
        opacity: 0.4;
    }

    50% {
        opacity: 0.8;
    }
}

/* Absorption State */
.knowledge-card-overlay.is-absorbing .knowledge-card {
    animation: knowledge-card-absorb 1.1s cubic-bezier(0.45, 0.05, 0.55, 0.95) forwards !important;
}

.knowledge-card-overlay.is-absorbing .spirit-unlock-stage {
    animation: spirit-unlock-absorb 1.1s ease-in forwards !important;
}

/* Keyframes */
@keyframes knowledge-card-pop {
    0% {
        transform: scale(0.3) rotateY(-40deg) rotateX(20deg);
        opacity: 0;
    }

    100% {
        transform: scale(1) rotateY(0) rotateX(0);
        opacity: 1;
    }
}

@keyframes knowledge-card-float {

    0%,
    100% {
        transform: translateY(0) rotate(0);
    }

    50% {
        transform: translateY(-15px) rotate(1deg);
    }
}

@keyframes card-glow-pulse {

    0%,
    100% {
        opacity: 0.3;
        transform: scale(1);
    }

    50% {
        opacity: 0.6;
        transform: scale(1.1);
    }
}

@keyframes knowledge-card-absorb {
    0% {
        transform: translate(0, 0) scale(1) rotate(0);
    }

    25% {
        transform: translate(0, -30px) scale(1.1) rotate(-8deg);
    }

    100% {
        /* Approximate target: bottom right HUD Codex icon area */
        transform: translate(calc(50vw - 80px), calc(50vh - 80px)) scale(0.01) rotate(1080deg);
        opacity: 0;
        filter: brightness(3) blur(5px);
    }
}

@keyframes spirit-unlock-enter {
    0% {
        opacity: 0;
        transform: translateY(18px) scale(0.88);
        filter: blur(6px);
    }

    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
        filter: blur(0);
    }
}

@keyframes spirit-unlock-float {

    0%,
    100% {
        transform: translateY(0) scale(1);
    }

    50% {
        transform: translateY(-10px) scale(1.015);
    }
}

@keyframes spirit-star-twinkle {

    0%,
    100% {
        opacity: 0;
        transform: scale(0.4);
    }

    45% {
        opacity: 0.88;
        transform: scale(1.15);
    }
}

@keyframes spirit-unlock-absorb {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1);
        filter: brightness(1);
    }

    70% {
        opacity: 1;
        transform: translateY(-18px) scale(1.04);
        filter: brightness(1.35);
    }

    100% {
        opacity: 0;
        transform: translateY(-38px) scale(0.72);
        filter: brightness(2.4) blur(8px);
    }
}

.card-absorb-particles {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.card-absorb-particle {
    position: absolute;
    width: 6px;
    height: 6px;
    background: #fbbf24;
    border-radius: 50%;
    box-shadow: 0 0 10px #fbbf24;
    animation: absorb-p-drift 1.1s ease-out forwards;
}

@keyframes absorb-p-drift {
    to {
        transform: translate(var(--dx), var(--dy)) scale(0);
        opacity: 0;
    }
}


/* ==========================================================================
   SPIRIT RESONANCE WHEEL UI
   ========================================================================== */

/* ── Book outer shell ── */
.codex-book {
    background:
        radial-gradient(circle at 18% 12%, rgba(255, 246, 207, 0.42), transparent 34%),
        linear-gradient(175deg, #f5e9c4 0%, #edd89a 65%, #e5cc80 100%);
    border-radius: 10px;
    border: 3px solid #7a4d0f;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.75), inset 0 0 0 1px rgba(255, 246, 205, 0.35);
    overflow: hidden;
    max-height: 75dvh;
}

.codex-book--resonance {
    background:
        radial-gradient(circle at 50% 2%, rgba(255, 255, 255, 0.52), transparent 36%),
        radial-gradient(circle at 18% 38%, rgba(147, 197, 253, 0.22), transparent 34%),
        linear-gradient(180deg, rgba(226, 240, 255, 0.96), rgba(171, 207, 246, 0.95) 52%, rgba(74, 102, 162, 0.92));
    border-color: rgba(214, 230, 255, 0.72);
    box-shadow: 0 24px 70px rgba(14, 23, 52, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.36);
}

.spirit-reward-portrait-wrap {
    width: 178px;
    height: 178px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 28px;
    background:
        radial-gradient(circle at 50% 42%, rgba(255, 247, 210, 0.22), rgba(251, 191, 36, 0.06) 58%, transparent 74%),
        linear-gradient(135deg, rgba(255, 255, 255, 0.08), rgba(15, 23, 42, 0.16));
    border: 1px solid rgba(251, 191, 36, 0.22);
    box-shadow: inset 0 0 28px rgba(251, 191, 36, 0.10), 0 12px 34px rgba(0, 0, 0, 0.36);
    overflow: hidden;
}

.spirit-reward-portrait {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 14px 20px rgba(0, 0, 0, 0.36));
}

.spirit-reward-text {
    white-space: pre-line;
    font-size: 1rem;
}

@media (min-width: 640px) {
    .codex-book {
        max-height: 94dvh;
    }
}

/* ── Monster Codex v1 ── */
.monster-codex-panel {
    max-width: 920px;
    max-height: min(85dvh, 760px);
    overflow: hidden;
    border-radius: 32px;
    border: 1px solid rgba(251, 191, 36, 0.32);
    background:
        radial-gradient(circle at 18% 8%, rgba(251, 191, 36, 0.22), transparent 40%),
        radial-gradient(circle at 86% 78%, rgba(34, 211, 238, 0.12), transparent 40%),
        linear-gradient(145deg, rgba(10, 15, 28, 0.96), rgba(30, 27, 75, 0.85));
    box-shadow:
        0 32px 100px rgba(0, 0, 0, 0.85),
        inset 0 0 0 1px rgba(255, 255, 255, 0.08),
        inset 0 20px 40px rgba(255, 255, 255, 0.02);
    backdrop-filter: blur(32px) saturate(160%);
    -webkit-backdrop-filter: blur(32px) saturate(160%);
}

.monster-codex-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.10);
    background: linear-gradient(90deg, rgba(15, 23, 42, 0.72), rgba(67, 56, 202, 0.20));
}

.monster-codex-mark {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 14px;
    background: rgba(251, 191, 36, 0.14);
    border: 1px solid rgba(251, 191, 36, 0.28);
    box-shadow: inset 0 0 18px rgba(251, 191, 36, 0.10);
}

.monster-codex-title {
    color: #fef3c7;
    font-size: 1.24rem;
    font-weight: 950;
    letter-spacing: 0.12em;
    line-height: 1.1;
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.52);
}

.monster-codex-subtitle {
    color: rgba(253, 230, 138, 0.56);
    font-size: 0.62rem;
    font-weight: 900;
    letter-spacing: 0.28em;
    margin-top: 3px;
}

.monster-codex-body {
    display: grid;
    grid-template-columns: minmax(170px, 0.45fr) minmax(0, 1fr);
    min-height: 0;
    flex: 1;
}

.monster-codex-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    overflow-y: auto;
    padding: 14px;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(2, 6, 23, 0.22);
}

.monster-codex-card {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.04);
    color: rgba(241, 245, 249, 0.9);
    text-align: left;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.monster-codex-card:hover,
.monster-codex-card.is-active {
    transform: translateX(4px);
    border-color: rgba(251, 191, 36, 0.5);
    background: rgba(251, 191, 36, 0.15);
    box-shadow:
        0 4px 15px rgba(0, 0, 0, 0.3),
        inset 0 0 12px rgba(251, 191, 36, 0.1);
}

.monster-codex-card.is-active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 20%;
    bottom: 20%;
    width: 4px;
    background: #fbbf24;
    border-radius: 0 4px 4px 0;
    box-shadow: 0 0 10px rgba(251, 191, 36, 0.6);
}

.monster-codex-card.is-locked {
    color: rgba(148, 163, 184, 0.6);
    background: rgba(15, 23, 42, 0.5);
    border-color: rgba(255, 255, 255, 0.05);
    filter: grayscale(0.5);
}

.monster-codex-card-icon {
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    flex: 0 0 auto;
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.62);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.monster-codex-card-main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.monster-codex-card-main strong {
    font-size: 0.96rem;
    font-weight: 900;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.monster-codex-card-main small {
    color: rgba(203, 213, 225, 0.58);
    font-size: 0.68rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.monster-codex-card-lock {
    color: rgba(253, 230, 138, 0.56);
    font-size: 0.56rem;
    font-weight: 950;
    letter-spacing: 0.12em;
}

@media (min-width: 1024px) {
    .monster-codex-list {
        gap: 8px;
        padding: 16px 14px;
    }

    .monster-codex-card {
        gap: 12px;
        padding: 10px 12px;
        min-height: 50px;
    }

    .monster-codex-card-icon {
        width: 34px;
        height: 34px;
    }

    .monster-codex-card-main strong {
        font-size: 0.94rem;
    }
}

.monster-codex-detail {
    min-height: 0;
    overflow-y: auto;
    padding: 24px 28px;
}

.monster-codex-portrait-wrap {
    display: grid;
    place-items: center;
    min-height: 180px;
    border-radius: 24px;
}

.monster-codex-portrait {
    max-width: min(80%, 280px);
    max-height: 220px;
    object-fit: contain;
    filter: drop-shadow(0 18px 22px rgba(0, 0, 0, 0.48));
}

.monster-codex-portrait,
.codex-wheel-img,
.codex-contract-img,
.spirit-unlock-img,
.spirit-reward-portrait,
.result-spirit-hero img {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
}

.monster-codex-detail-copy {
    margin-top: 12px;
}

.monster-codex-kicker {
    color: rgba(125, 211, 252, 0.78);
    font-size: 0.84rem;
    font-weight: 850;
}

.monster-codex-name {
    margin-top: 4px;
    color: #f8fafc;
    font-size: clamp(1.6rem, 3vw, 2.1rem);
    font-weight: 950;
    letter-spacing: 0.06em;
}

.monster-codex-trait {
    margin-top: 10px;
    color: rgba(226, 232, 240, 0.84);
    font-size: 1.0rem;
    line-height: 1.7;
    white-space: pre-line;
}

.monster-codex-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-top: 20px;
    padding: 16px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.monster-codex-stats div {
    padding: 10px 14px;
    border-radius: 14px;
    background: rgba(15, 23, 42, 0.48);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.monster-codex-stats span {
    display: block;
    color: rgba(148, 163, 184, 0.82);
    font-size: 0.78rem;
    font-weight: 850;
    letter-spacing: 0.1em;
}

.monster-codex-stats strong {
    display: block;
    margin-top: 5px;
    color: #fef3c7;
    font-size: 1.15rem;
    font-weight: 950;
}

.monster-codex-locked-detail {
    min-height: 420px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: rgba(203, 213, 225, 0.68);
}

.monster-codex-unknown {
    display: grid;
    place-items: center;
    width: 132px;
    height: 132px;
    border-radius: 34px;
    background: rgba(15, 23, 42, 0.58);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: rgba(148, 163, 184, 0.48);
    font-size: 4.2rem;
    font-weight: 950;
    margin-bottom: 18px;
}

.monster-codex-locked-detail h3 {
    color: rgba(226, 232, 240, 0.72);
    font-size: 1.6rem;
    font-weight: 950;
}

.monster-codex-locked-detail p {
    max-width: 280px;
    margin-top: 8px;
    font-size: 0.86rem;
    line-height: 1.7;
}

@media (max-width: 640px) {
    .monster-codex-panel {
        height: min(88dvh, calc(100dvh - 1rem));
        max-height: min(88dvh, calc(100dvh - 1rem));
        border-radius: 24px;
    }

    .monster-codex-header {
        padding: 14px 15px;
    }

    .monster-codex-title {
        font-size: 1.28rem;
    }

    .monster-codex-subtitle {
        font-size: 0.8rem;
        letter-spacing: 0.18em;
    }

    .monster-codex-body {
        display: flex;
        flex-direction: column;
        min-height: 0;
        flex: 1 1 auto;
    }

    .monster-codex-list {
        flex: 0 0 auto;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 12px;
        border-right: 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    }

    .monster-codex-card {
        width: 178px;
        flex: 0 0 178px;
    }

    .monster-codex-card-main strong {
        font-size: 1rem;
    }

    .monster-codex-card-main small,
    .monster-codex-card-lock {
        font-size: 0.78rem;
    }

    .monster-codex-detail {
        display: flex;
        flex-direction: column;
        flex: 1 1 auto;
        min-height: 0;
        overscroll-behavior: contain;
        padding: 20px 14px 14px;
    }

    .monster-codex-portrait-wrap {
        min-height: 180px;
    }

    .monster-codex-portrait {
        max-height: 180px;
    }

    .monster-codex-detail-copy {
        display: flex;
        flex: 1 1 auto;
        flex-direction: column;
        margin-top: 12px;
    }

    .monster-codex-kicker {
        font-size: 1.02rem;
    }

    .monster-codex-trait {
        font-size: 1.08rem;
        line-height: 1.58;
    }

    .monster-codex-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        padding: 10px;
        margin-top: clamp(18px, 2.8dvh, 28px);
    }

    .monster-codex-stats div {
        padding: 7px 8px;
    }

    .monster-codex-stats span {
        font-size: 0.9rem;
        letter-spacing: 0.08em;
    }

    .monster-codex-stats strong {
        font-size: 1.12rem;
    }

    .monster-codex-locked-detail {
        min-height: 100%;
    }
}

/* ── Header ── */
.codex-book-header {
    background:
        linear-gradient(90deg, rgba(251, 191, 36, 0.08), transparent 24%, rgba(251, 191, 36, 0.08)),
        linear-gradient(135deg, #5c2e08 0%, #3e1e04 100%);
    border-bottom: 2px solid rgba(122, 77, 15, 0.92);
    box-shadow: inset 0 -1px 0 rgba(252, 228, 160, 0.16), 0 2px 10px rgba(70, 35, 5, 0.18);
}

.codex-book--resonance .codex-book-header {
    position: relative;
    z-index: 4;
    isolation: isolate;
    background:
        linear-gradient(90deg, rgba(255, 255, 255, 0.24), transparent 26%, rgba(147, 197, 253, 0.2)),
        linear-gradient(135deg, rgba(43, 69, 135, 0.92), rgba(82, 112, 181, 0.9));
    border-bottom-color: rgba(219, 234, 254, 0.5);
    box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.22), 0 2px 12px rgba(43, 69, 135, 0.2);
}

.codex-book-title {
    color: #fce4a0;
    font-weight: 900;
    font-size: 1.08rem;
    letter-spacing: 0.08em;
}

.codex-book-subtitle {
    color: rgba(252, 228, 160, 0.62);
    font-size: 0.56rem;
    letter-spacing: 0.32em;
    font-weight: 800;
}

.codex-book--resonance .codex-book-subtitle {
    color: rgba(226, 240, 255, 0.84);
    font-size: 0.68rem;
    font-weight: 900;
    letter-spacing: 0.28em;
}

.codex-close-btn {
    color: rgba(252, 228, 160, 0.55);
    padding: 6px;
    border-radius: 8px;
    transition: all 0.2s;
}

.codex-close-btn:hover {
    color: #fce4a0;
    background: rgba(255, 255, 255, 0.1);
}

.codex-close-btn:active {
    transform: scale(0.88);
}

/* ── Spirit Codex Resonance Wheel Prototype ── */
.codex-resonance-shell {
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background:
        radial-gradient(circle at 50% 18%, rgba(255, 255, 255, 0.26), transparent 34%),
        radial-gradient(circle at 18% 72%, rgba(191, 219, 254, 0.2), transparent 32%),
        radial-gradient(circle at 82% 70%, rgba(252, 211, 77, 0.1), transparent 28%),
        linear-gradient(180deg, rgba(235, 247, 255, 0.72), rgba(180, 213, 247, 0.58) 58%, rgba(77, 105, 168, 0.82));
}

.codex-resonance-overview {
    position: relative;
    display: flex;
    flex: 1;
    min-height: 0;
    flex-direction: column;
    justify-content: center;
    gap: 0.8rem;
    padding: 1.05rem 1rem 1.15rem;
}

.codex-resonance-overview>* {
    position: relative;
    z-index: 1;
}

.codex-wheel-stage {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-height: 300px;
    overflow: visible;
    transform: translateY(-1.6rem);
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
}

.codex-wheel-stage::before {
    content: "";
    position: absolute;
    left: 10%;
    right: 10%;
    bottom: 10%;
    height: 26%;
    border-radius: 50%;
    border: 1px solid rgba(96, 165, 250, 0.34);
    box-shadow: inset 0 0 28px rgba(147, 197, 253, 0.14), 0 0 28px rgba(30, 64, 175, 0.2);
    transform: perspective(620px) rotateX(64deg);
    pointer-events: none;
    display: none;
}

.codex-wheel-stage::after {
    content: "";
    position: absolute;
    left: 6%;
    right: 6%;
    top: 24%;
    height: 44%;
    border-radius: 50%;
    border: 1px solid rgba(96, 165, 250, 0.18);
    background:
        radial-gradient(circle at 50% 0%, rgba(252, 211, 77, 0.12), transparent 8%),
        radial-gradient(circle at 14% 45%, rgba(147, 197, 253, 0.16), transparent 6%),
        radial-gradient(circle at 86% 45%, rgba(147, 197, 253, 0.16), transparent 6%),
        radial-gradient(circle at 50% 50%, transparent 54%, rgba(96, 165, 250, 0.06) 56%, transparent 62%);
    box-shadow: 0 0 30px rgba(96, 165, 250, 0.11);
    pointer-events: none;
    display: none;
}

.codex-resonance-overview::before {
    content: "";
    position: absolute;
    inset: -3%;
    pointer-events: none;
    background:
        linear-gradient(180deg, rgba(239, 248, 255, 0.14), rgba(219, 234, 254, 0.08) 50%, rgba(67, 105, 178, 0.2)),
        radial-gradient(circle at 50% 34%, rgba(255, 255, 255, 0.14), transparent 48%),
        url("../images/bg_home_painterly.webp");
    background-position: center, center, center bottom;
    background-size: cover;
    filter: saturate(0.94) brightness(1.02) blur(0.25px);
    transform: scale(1.02);
    opacity: 0.8;
}

.codex-resonance-overview::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        radial-gradient(circle at 24% 26%, rgba(255, 255, 255, 0.34) 0 1px, transparent 2px),
        radial-gradient(circle at 66% 18%, rgba(219, 234, 254, 0.34) 0 1px, transparent 2px),
        radial-gradient(circle at 78% 38%, rgba(255, 255, 255, 0.24) 0 1px, transparent 2px),
        radial-gradient(circle at 38% 70%, rgba(219, 234, 254, 0.26) 0 1px, transparent 2px),
        linear-gradient(180deg, rgba(255, 255, 255, 0.2) 0 1px, transparent 1px 100%) 50% 18% / min(62vw, 520px) 34% no-repeat,
        linear-gradient(90deg, transparent 0 12%, rgba(255, 255, 255, 0.12) 12% 14%, transparent 14% 25%, rgba(255, 255, 255, 0.1) 25% 27%, transparent 27% 73%, rgba(255, 255, 255, 0.1) 73% 75%, transparent 75% 86%, rgba(255, 255, 255, 0.12) 86% 88%, transparent 88%) 50% 16% / min(72vw, 560px) 36% no-repeat,
        radial-gradient(ellipse at 50% 9%, rgba(255, 255, 255, 0.16), transparent 40%),
        linear-gradient(180deg, transparent 0%, rgba(219, 234, 254, 0.1) 62%, rgba(30, 64, 175, 0.12) 100%);
    opacity: 0.42;
}

.codex-wheel-orbit {
    position: relative;
    width: min(88vw, 660px);
    height: min(50vh, 366px);
    min-height: 282px;
    overflow: visible;
}

.codex-wheel-orbit::before,
.codex-wheel-orbit::after {
    content: "";
    position: absolute;
    pointer-events: none;
    border-radius: 50%;
    display: none;
}

.codex-wheel-orbit::before {
    left: 7%;
    top: 28%;
    width: 86%;
    height: 42%;
    border: 1px solid rgba(59, 130, 246, 0.2);
    box-shadow: inset 0 0 28px rgba(147, 197, 253, 0.1), 0 0 18px rgba(255, 255, 255, 0.14);
}

.codex-wheel-orbit::after {
    left: 12%;
    top: 34%;
    width: 76%;
    height: 30%;
    border: 1px dashed rgba(252, 211, 77, 0.2);
}

.codex-wheel-spirit {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 148px;
    min-height: 208px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 0.34rem;
    border: 0;
    background: transparent;
    color: #fef3c7;
    overflow: visible;
    transition: filter 0.18s ease;
    filter: saturate(0.74) brightness(0.84);
    cursor: pointer;
}

.codex-wheel-spirit.is-selected {
    min-height: calc(132px + 3.35rem);
    padding-bottom: 0;
    filter: saturate(0.86) brightness(0.96);
    z-index: 140;
}

.codex-wheel-spirit.is-selected:not(.is-locked) {
    filter: saturate(0.92) brightness(1.02);
}

.codex-wheel-spirit.is-selected .codex-wheel-img,
.codex-wheel-spirit.is-selected .codex-wheel-particle {
    filter: drop-shadow(0 16px 16px rgba(30, 41, 59, 0.24)) drop-shadow(0 0 6px rgba(255, 255, 255, 0.22));
}

.codex-wheel-spirit.is-selected:not(.is-locked) .codex-wheel-img,
.codex-wheel-spirit.is-selected:not(.is-locked) .codex-wheel-particle {
    filter: drop-shadow(0 14px 14px rgba(30, 58, 95, 0.2)) drop-shadow(0 0 8px rgba(255, 255, 255, 0.34));
    animation: codex-center-breathe 4.6s ease-in-out infinite;
}

.codex-wheel-spirit.is-selected:not(.is-locked) .codex-wheel-ring {
    animation: codex-center-ring-breathe 4.6s ease-in-out infinite;
}

.codex-wheel-spirit.is-midground {
    filter: saturate(0.62) brightness(0.84);
}

.codex-wheel-spirit.is-midground:not(.is-locked) {
    filter: saturate(0.72) brightness(0.9);
}

.codex-wheel-spirit.is-background {
    filter: saturate(0.7) brightness(0.92);
}

.codex-wheel-spirit.is-background:not(.is-locked) {
    filter: saturate(0.78) brightness(0.96);
}

.codex-wheel-spirit.is-foreground:not(.is-selected):not(.is-locked) .codex-wheel-img,
.codex-wheel-spirit.is-foreground:not(.is-selected):not(.is-locked) .codex-wheel-particle {
    animation: codex-orbit-breathe 6.8s ease-in-out infinite;
}

/* Spin composite downgrade: all slots stay in DOM/RAF; no filter/shadow cost while moving */
.codex-wheel-orbit.is-spinning .codex-wheel-spirit {
    transition: none;
    will-change: transform;
    filter: none;
}

.codex-wheel-orbit.is-spinning .codex-wheel-spirit .codex-wheel-img,
.codex-wheel-orbit.is-spinning .codex-wheel-spirit .codex-wheel-particle {
    filter: none;
    animation: none;
}

/* Spin-only sealed badge: hide spirit art, show neutral lock disc (no veil overlay) */
.codex-wheel-orbit.is-spinning .codex-wheel-spirit.is-locked .codex-wheel-img {
    filter: none;
    opacity: 0.46;
}

.codex-wheel-orbit.is-spinning .codex-wheel-spirit.is-locked .codex-wheel-particle {
    filter: none;
    opacity: 0.22;
    color: rgba(203, 213, 225, 0.78);
    background: rgba(51, 65, 85, 0.52);
    border-color: rgba(100, 116, 139, 0.48);
}

.codex-wheel-orbit.is-spinning .codex-wheel-ring {
    box-shadow: none;
    background: radial-gradient(circle, rgba(252, 211, 77, 0.12), transparent 72%);
}

.codex-wheel-orbit.is-spinning .codex-wheel-spirit.is-locked .codex-wheel-ring {
    z-index: 1;
    border: 1px solid rgba(100, 116, 139, 0.22);
    background: transparent;
    box-shadow: none;
    filter: none;
}

.codex-wheel-orbit.is-spinning .codex-wheel-spirit.is-midground .codex-wheel-ring,
.codex-wheel-orbit.is-spinning .codex-wheel-spirit.is-background .codex-wheel-ring {
    background: radial-gradient(circle, rgba(252, 211, 77, 0.14), transparent 72%);
}

.codex-wheel-orbit.is-spinning .codex-wheel-spirit.is-bond-max .codex-wheel-ring {
    box-shadow: none;
}

.codex-wheel-orbit.is-spinning .codex-wheel-name {
    text-shadow: none;
}

.codex-wheel-spirit.is-locked {
    color: rgba(226, 232, 240, 0.66);
    filter: saturate(0.2) brightness(0.72);
}

.codex-wheel-spirit.is-selected.is-locked {
    color: rgba(254, 243, 199, 0.9);
    filter: saturate(0.42) brightness(0.92);
}

.codex-wheel-spirit.is-bond-max .codex-wheel-ring {
    border-color: rgba(252, 211, 77, 0.9);
    box-shadow: 0 0 22px rgba(252, 211, 77, 0.42), inset 0 0 18px rgba(252, 211, 77, 0.18);
}

.codex-wheel-ring {
    position: absolute;
    top: 13px;
    width: 112px;
    height: 112px;
    border-radius: 999px;
    border: 1px solid rgba(252, 211, 77, 0.36);
    background: radial-gradient(circle, rgba(252, 211, 77, 0.13), rgba(79, 38, 8, 0.08) 62%, transparent 70%);
}

.codex-wheel-spirit.is-locked .codex-wheel-ring {
    border-color: rgba(226, 232, 240, 0.32);
    background:
        radial-gradient(circle, rgba(226, 232, 240, 0.16), rgba(129, 140, 248, 0.08) 48%, transparent 68%),
        linear-gradient(135deg, transparent 46%, rgba(226, 232, 240, 0.22) 49%, transparent 52%);
    box-shadow: inset 0 0 14px rgba(226, 232, 240, 0.08), 0 0 12px rgba(129, 140, 248, 0.16);
}

.codex-wheel-spirit.is-midground .codex-wheel-ring {
    border-color: rgba(252, 211, 77, 0.3);
    background: radial-gradient(circle, rgba(252, 211, 77, 0.18), rgba(79, 38, 8, 0.08) 58%, transparent 70%);
}

.codex-wheel-spirit.is-background .codex-wheel-ring {
    border-color: rgba(252, 211, 77, 0.42);
    background: radial-gradient(circle, rgba(252, 211, 77, 0.38), rgba(252, 211, 77, 0.12) 48%, transparent 70%);
    box-shadow: 0 0 14px rgba(252, 211, 77, 0.2);
}

.codex-wheel-img,
.codex-wheel-particle {
    position: relative;
    width: 132px;
    height: 132px;
    object-fit: contain;
    margin-top: 0;
    filter: drop-shadow(0 18px 18px rgba(0, 0, 0, 0.28));
}

/* Prevent native browser image drag (ghost image / no-drop cursor) in the wheel */
.codex-wheel-img {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
}

.codex-wheel-spirit.is-locked .codex-wheel-img {
    opacity: 0.46;
    filter: none;
}

.codex-wheel-spirit.is-selected.is-locked .codex-wheel-img {
    opacity: 0.62;
    filter: none;
}

.codex-wheel-spirit.is-midground .codex-wheel-img,
.codex-wheel-spirit.is-midground .codex-wheel-particle {
    opacity: 0.88;
}

.codex-wheel-spirit.is-background .codex-wheel-img,
.codex-wheel-spirit.is-background .codex-wheel-particle {
    opacity: 0.84;
}

.codex-wheel-spirit.is-background.is-locked .codex-wheel-img {
    opacity: 0.5;
    filter: none;
}

.codex-wheel-particle {
    display: grid;
    place-items: center;
    border-radius: 999px;
    background: rgba(252, 211, 77, 0.12);
    border: 1px solid rgba(252, 211, 77, 0.34);
    font-weight: 900;
    font-size: 2.2rem;
}

.codex-wheel-name {
    max-width: 148px;
    min-height: 2.05rem;
    font-weight: 900;
    font-size: 0.98rem;
    line-height: 1.08;
    text-align: center;
    text-shadow: 0 2px 5px rgba(0, 0, 0, 0.42);
}

.codex-wheel-meta {
    display: none;
}

.codex-wheel-spirit.is-selected .codex-wheel-meta {
    position: absolute;
    left: 50%;
    top: calc(132px + 0.16rem);
    z-index: 6;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.32rem;
    width: max-content;
    max-width: min(166px, 42vw);
    transform: translateX(-50%);
    pointer-events: none;
}

.codex-wheel-spirit.is-selected .codex-wheel-name {
    max-width: 100%;
    min-height: auto;
    color: #fff0b8;
    font-size: 0.96rem;
    line-height: 1.06;
    text-shadow: 0 2px 4px rgba(15, 23, 42, 0.62), 0 0 8px rgba(146, 64, 14, 0.24);
}

.codex-wheel-spirit.is-selected .codex-wheel-state {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-width: 94px;
    height: 24px;
    min-height: 24px;
    padding: 0;
    border-radius: 999px;
    border: 0;
    background: transparent;
    color: #fff7ed;
    font-size: 0.7rem;
    font-weight: 900;
    line-height: 1;
    letter-spacing: 0.01em;
    overflow: visible;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.36);
    box-shadow: none;
}

.codex-wheel-state--affinity {
    --affinity: 0%;
}

.codex-wheel-state--bond {
    --affinity: 100%;
}

.codex-wheel-spirit.is-selected .codex-wheel-state--bond {
    min-width: 104px;
    color: #fffbeb;
}

.codex-wheel-spirit.is-selected .codex-wheel-state--locked {
    width: auto;
    min-width: 64px;
    padding: 0 0.68rem;
    overflow: visible;
    background: rgba(30, 41, 59, 0.58);
    border-color: rgba(148, 163, 184, 0.34);
    color: rgba(226, 232, 240, 0.84);
}

.codex-wheel-affinity-row {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.28rem;
}

.codex-wheel-affinity-heart {
    display: grid;
    place-items: center;
    width: 18px;
    height: 22px;
    background: transparent;
    border: 0;
    color: #f43f5e;
    font-size: 0.96rem;
    line-height: 1;
    text-shadow: 0 1px 2px rgba(30, 41, 59, 0.22), 0 0 7px rgba(244, 114, 182, 0.52), 0 -1px 0 rgba(255, 255, 255, 0.7);
    filter: drop-shadow(0 1px 1px rgba(30, 41, 59, 0.16));
}

.codex-wheel-affinity-meter {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 62px;
    height: 18px;
    border-radius: 8px;
    border: 1px solid rgba(255, 183, 213, 0.42);
    background: rgba(36, 29, 43, 0.68);
    overflow: hidden;
    box-shadow: 0 2px 7px rgba(30, 41, 59, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.14), inset 0 -4px 8px rgba(15, 23, 42, 0.16);
}

.codex-wheel-affinity-meter::after {
    content: "";
    position: absolute;
    left: 8%;
    right: 8%;
    top: 1px;
    height: 34%;
    border-radius: 7px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.42), rgba(255, 255, 255, 0.06));
    pointer-events: none;
    z-index: 1;
}

.codex-wheel-affinity-fill {
    position: absolute;
    inset: 0 auto 0 0;
    width: var(--affinity);
    border-radius: inherit;
    background: linear-gradient(90deg, rgba(244, 114, 182, 0.92), rgba(251, 113, 133, 0.86));
    box-shadow: inset 0 0 8px rgba(255, 255, 255, 0.18);
}

.codex-wheel-state--bond .codex-wheel-affinity-heart {
    background: transparent;
    border: 0;
    color: #f59e0b;
    text-shadow: 0 1px 2px rgba(120, 53, 15, 0.2), 0 0 8px rgba(252, 211, 77, 0.62), 0 -1px 0 rgba(255, 255, 255, 0.75);
}

.codex-wheel-state--bond .codex-wheel-affinity-meter {
    width: 68px;
    border-color: rgba(252, 211, 77, 0.58);
    background: rgba(78, 48, 42, 0.78);
    box-shadow: 0 2px 12px rgba(120, 53, 15, 0.28), 0 0 14px rgba(244, 114, 182, 0.2), inset 0 1px 0 rgba(255, 247, 214, 0.14);
}

.codex-wheel-state--bond .codex-wheel-affinity-fill {
    width: 100%;
    background: linear-gradient(90deg, rgba(252, 211, 77, 0.9), rgba(244, 114, 182, 0.92) 58%, rgba(251, 113, 133, 0.9));
}

.codex-wheel-affinity-text {
    position: relative;
    z-index: 1;
    width: 100%;
    text-align: center;
}

.codex-wheel-state {
    min-height: 1.35rem;
    padding: 0.2rem 0.54rem;
    border-radius: 999px;
    background: rgba(28, 16, 8, 0.62);
    border: 1px solid rgba(252, 211, 77, 0.2);
    color: rgba(254, 243, 199, 0.84);
    font-size: 0.72rem;
    font-weight: 800;
    line-height: 1;
}

.codex-wheel-arrow {
    position: absolute;
    z-index: 220;
    top: 50%;
    display: grid;
    place-items: center;
    width: 42px;
    height: 58px;
    border-radius: 8px;
    border: 1px solid rgba(252, 211, 77, 0.3);
    background: rgba(36, 20, 8, 0.74);
    color: #fde68a;
    font-size: 2.3rem;
    line-height: 1;
    transform: translateY(-50%);
}

.codex-wheel-arrow--left {
    left: 0.2rem;
}

.codex-wheel-arrow--right {
    right: 0.2rem;
}

/* Suppress browser focus outline on pointer/mouse interaction; preserve for keyboard */
.codex-wheel-spirit:focus:not(:focus-visible),
.codex-wheel-arrow:focus:not(:focus-visible) {
    outline: none;
}

@keyframes codex-center-breathe {
    0%,
    100% {
        transform: translateY(0) scale(1);
    }

    50% {
        transform: translateY(-5px) scale(1.025);
    }
}

@keyframes codex-center-ring-breathe {
    0%,
    100% {
        transform: scale(1);
        opacity: 0.92;
    }

    50% {
        transform: scale(1.035);
        opacity: 1;
    }
}

@keyframes codex-orbit-breathe {
    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-2px);
    }
}

.codex-resonance-detail {
    position: relative;
    display: grid;
    grid-template-columns: minmax(220px, 0.78fr) minmax(0, 1.22fr);
    gap: 1rem;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    padding: 1rem;
    color: #16325f;
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    background:
        radial-gradient(ellipse 72% 58% at 24% 44%, rgba(147, 197, 253, 0.2), transparent 58%),
        radial-gradient(circle at 52% 88%, rgba(191, 219, 254, 0.14), transparent 42%),
        radial-gradient(circle at 26% 20%, rgba(255, 255, 255, 0.7), transparent 28%),
        radial-gradient(circle at 78% 28%, rgba(191, 219, 254, 0.34), transparent 34%),
        linear-gradient(180deg, rgba(241, 248, 255, 0.92), rgba(207, 226, 251, 0.88));
}

.codex-detail-back {
    grid-column: 1 / -1;
    justify-self: start;
    min-height: 36px;
    padding: 0.42rem 0.72rem;
    border-radius: 8px;
    border: 1px solid rgba(96, 165, 250, 0.42);
    background: rgba(255, 255, 255, 0.58);
    color: #1d4f91;
    font-size: 0.84rem;
    font-weight: 900;
    box-shadow: 0 8px 22px rgba(37, 99, 235, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.76);
}

.codex-contract-hero {
    position: relative;
    display: grid;
    place-items: center;
    min-height: 280px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    isolation: isolate;
}

.codex-contract-hero::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: min(92%, 360px);
    aspect-ratio: 1;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    pointer-events: none;
    z-index: 0;
    background:
        radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.55) 0%, rgba(191, 219, 254, 0.12) 42%, transparent 62%),
        radial-gradient(circle at 50% 50%, transparent 48%, rgba(96, 165, 250, 0.09) 52%, transparent 58%);
    box-shadow:
        0 0 0 1px rgba(147, 197, 253, 0.14),
        0 0 48px rgba(59, 130, 246, 0.1);
}

.codex-contract-seal {
    position: absolute;
    width: min(52vw, 300px);
    height: min(52vw, 300px);
    max-width: 300px;
    max-height: 300px;
    border-radius: 999px;
    border: 1px solid rgba(147, 197, 253, 0.58);
    z-index: 1;
    background:
        radial-gradient(circle, rgba(255, 255, 255, 0.72), rgba(191, 219, 254, 0.2) 46%, transparent 66%),
        radial-gradient(circle, transparent 52%, rgba(252, 211, 77, 0.16) 53%, transparent 58%);
    box-shadow:
        inset 0 0 32px rgba(96, 165, 250, 0.14),
        0 0 34px rgba(96, 165, 250, 0.18),
        0 0 0 1px rgba(255, 255, 255, 0.22);
}

.codex-contract-img,
.codex-contract-particle {
    position: relative;
    z-index: 2;
    width: min(48vw, 278px);
    height: min(48vw, 278px);
    max-width: 278px;
    max-height: 278px;
    object-fit: contain;
    filter: drop-shadow(0 22px 22px rgba(30, 64, 175, 0.22)) drop-shadow(0 0 10px rgba(255, 255, 255, 0.26));
}

.codex-resonance-detail.is-locked .codex-contract-img {
    opacity: 0.52;
    filter: grayscale(1) brightness(0.38) contrast(1.2);
}

.codex-contract-particle {
    display: grid;
    place-items: center;
    border-radius: 999px;
    border: 1px solid rgba(147, 197, 253, 0.46);
    background: rgba(239, 246, 255, 0.66);
    color: #1d4ed8;
    font-size: 3rem;
    font-weight: 900;
}

.codex-contract-panel {
    width: 100%;
    min-width: 0;
    min-height: 0;
    max-width: 100%;
    box-sizing: border-box;
    align-self: stretch;
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid rgba(147, 197, 253, 0.48);
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.72), rgba(219, 234, 254, 0.44)),
        rgba(239, 246, 255, 0.74);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.82), 0 16px 36px rgba(37, 99, 235, 0.14);
    backdrop-filter: blur(14px);
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.codex-contract-kicker {
    font-size: 0.66rem;
    font-weight: 900;
    letter-spacing: 0.28em;
    color: #174f9c;
    opacity: 0.92;
}

.codex-contract-name {
    margin-top: 0.2rem;
    color: #0c2448;
    font-size: 1.45rem;
    font-weight: 900;
    line-height: 1.12;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.65);
}

.codex-contract-affinity {
    display: grid;
    gap: 0.42rem;
    margin: 0.75rem 0;
}

.codex-contract-affinity span {
    width: max-content;
    max-width: 100%;
    padding: 0.22rem 0.62rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(96, 165, 250, 0.34);
    color: #143d6e;
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.06em;
    line-height: 1.2;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.codex-contract-affinity span.is-full {
    color: #8a5b05;
    border-color: rgba(245, 158, 11, 0.42);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.75),
        0 0 16px rgba(252, 211, 77, 0.2);
}

.codex-contract-affinity .codex-mastery-track {
    border-color: rgba(96, 165, 250, 0.28);
    background: rgba(255, 255, 255, 0.46);
    box-shadow: inset 0 1px 4px rgba(30, 64, 175, 0.12), 0 1px 0 rgba(255, 255, 255, 0.58);
}

.codex-contract-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.62rem;
}

.codex-contract-section {
    min-width: 0;
    padding: 0.72rem;
    border-radius: 8px;
    border: 1px solid rgba(147, 197, 253, 0.32);
    background: rgba(255, 255, 255, 0.5);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.68);
}

.codex-contract-section--wide {
    grid-column: 1 / -1;
}

.codex-contract-section strong {
    display: block;
    margin-top: 0.35rem;
    color: #0a1f3d;
    font-size: 1.25rem;
    font-weight: 900;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}

.codex-contract-section p,
.codex-contract-section li,
.codex-contract-section code,
.codex-contract-locked-text {
    margin-top: 0.35rem;
    color: #1a3a5c;
    font-size: 0.9rem;
    line-height: 1.55;
}

.codex-contract-section code {
    display: block;
    overflow-wrap: anywhere;
    font-family: "Noto Sans JP", sans-serif;
    font-weight: 800;
}

.codex-contract-section .codex-label-mini {
    padding: 0.2rem 0.62rem;
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.06em;
    color: #143d6e;
    border-color: rgba(96, 165, 250, 0.34);
    background: rgba(255, 255, 255, 0.72);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.codex-contract-section ul {
    margin: 0.25rem 0 0;
    padding-left: 1rem;
}

.codex-mastery-track {
    height: 11px;
    overflow: hidden;
    border-radius: 999px;
    border: 1px solid rgba(251, 191, 36, 0.24);
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.58), rgba(15, 23, 42, 0.34));
    box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.52), 0 1px 0 rgba(255, 246, 205, 0.08);
}

.codex-mastery-fill {
    height: 100%;
    border-radius: inherit;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.30), transparent 48%),
        linear-gradient(90deg, #b45309 0%, #fbbf24 48%, #34d399 100%);
    box-shadow: 0 0 12px rgba(251, 191, 36, 0.28), 0 0 14px rgba(52, 211, 153, 0.24);
    transition: width 0.25s ease;
}

.codex-mastery-fill--full {
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35), 0 0 10px rgba(253, 224, 71, 0.35);
}

@media (max-width: 639px) {
    .codex-modal-overlay {
        align-items: stretch !important;
        padding: max(0.34rem, env(safe-area-inset-top)) 0.34rem max(0.34rem, env(safe-area-inset-bottom)) !important;
    }

    .codex-book {
        height: calc(100vh - max(0.68rem, env(safe-area-inset-top)) - max(0.68rem, env(safe-area-inset-bottom)));
        max-height: calc(100vh - max(0.68rem, env(safe-area-inset-top)) - max(0.68rem, env(safe-area-inset-bottom)));
        height: calc(100dvh - max(0.68rem, env(safe-area-inset-top)) - max(0.68rem, env(safe-area-inset-bottom)));
        max-height: calc(100dvh - max(0.68rem, env(safe-area-inset-top)) - max(0.68rem, env(safe-area-inset-bottom)));
    }

    .codex-book-header {
        padding-top: 0.58rem !important;
        padding-bottom: 0.58rem !important;
    }

    .codex-resonance-overview {
        padding: 0.62rem 0.24rem 0.58rem;
        gap: 0.44rem;
        justify-content: flex-start;
        overflow: hidden;
    }

    .codex-resonance-overview::before,
    .codex-resonance-overview::after {
        inset: 0;
    }

    .codex-wheel-stage {
        min-height: min(52vh, 320px);
        transform: translateY(-0.35rem);
        overflow: hidden;
    }

    .codex-wheel-stage::after {
        left: 1%;
        right: 1%;
        top: 26%;
        height: 40%;
    }

    .codex-wheel-orbit {
        width: 100%;
        height: min(48vh, 340px);
        min-height: 264px;
    }

    .codex-wheel-orbit::before {
        left: 5%;
        top: 28%;
        width: 90%;
        height: 40%;
    }

    .codex-wheel-orbit::after {
        left: 12%;
        top: 36%;
        width: 76%;
        height: 28%;
    }

    .codex-wheel-spirit {
        width: 116px;
        min-height: 178px;
    }

    .codex-wheel-ring {
        top: 11px;
        width: 96px;
        height: 96px;
    }

    .codex-wheel-img,
    .codex-wheel-particle {
        width: 112px;
        height: 112px;
    }

    .codex-wheel-name {
        max-width: 116px;
        font-size: 0.92rem;
    }

    .codex-wheel-spirit.is-selected {
        min-height: calc(112px + 3.1rem);
    }

    .codex-wheel-spirit.is-selected .codex-wheel-meta {
        top: calc(112px + 0.12rem);
        max-width: min(136px, 42vw);
        gap: 0.28rem;
    }

    .codex-wheel-spirit.is-selected .codex-wheel-name {
        font-size: 0.82rem;
    }

    .codex-wheel-spirit.is-selected .codex-wheel-state {
        min-width: 88px;
        width: auto;
        height: 22px;
        min-height: 22px;
        padding: 0;
        font-size: 0.64rem;
    }

    .codex-wheel-spirit.is-selected .codex-wheel-state--bond {
        min-width: 98px;
    }

    .codex-wheel-spirit.is-selected .codex-wheel-state--locked {
        width: auto;
        min-width: 58px;
        padding: 0 0.58rem;
    }

    .codex-wheel-state {
        padding: 0.18rem 0.42rem;
        font-size: 0.66rem;
    }

    .codex-wheel-affinity-row {
        gap: 0.24rem;
    }

    .codex-wheel-affinity-heart {
        width: 17px;
        height: 20px;
        font-size: 0.86rem;
    }

    .codex-wheel-affinity-meter {
        width: 58px;
        height: 17px;
        border-radius: 8px;
    }

    .codex-wheel-state--bond .codex-wheel-affinity-meter {
        width: 64px;
    }

    .codex-wheel-arrow {
        width: 34px;
        height: 50px;
        font-size: 1.85rem;
    }

    .codex-book--resonance .codex-book-title {
        font-size: 1.16rem;
    }

    .codex-book--resonance .codex-book-subtitle {
        font-size: 0.76rem;
        font-weight: 900;
        color: rgba(239, 246, 255, 0.92);
        letter-spacing: 0.24em;
    }

    .codex-resonance-detail {
        display: flex;
        flex-direction: column;
        grid-template-columns: none;
        gap: 0.62rem;
        padding: 0.62rem max(0.5rem, env(safe-area-inset-left)) 0.72rem max(0.5rem, env(safe-area-inset-right));
        overflow: hidden;
    }

    .codex-resonance-detail .codex-detail-back {
        flex: 0 0 auto;
        min-height: 38px;
        font-size: 0.92rem;
        max-width: 100%;
        box-sizing: border-box;
    }

    .codex-resonance-detail .codex-contract-hero {
        flex: 0 0 auto;
        min-height: 178px;
        padding: 0 0.12rem;
    }

    .codex-resonance-detail .codex-contract-panel {
        flex: 1 1 auto;
        min-height: 0;
        padding: 0.88rem;
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }

    .codex-contract-hero::before {
        width: min(86%, 260px);
    }

    .codex-contract-seal {
        width: min(68vw, 190px);
        height: min(68vw, 190px);
    }

    .codex-contract-img,
    .codex-contract-particle {
        width: min(64vw, 178px);
        height: min(64vw, 178px);
    }

    .codex-resonance-detail .codex-detail-back {
        grid-column: auto;
    }

    .codex-resonance-detail .codex-contract-kicker {
        font-size: 0.72rem;
    }

    .codex-resonance-detail .codex-contract-name {
        font-size: 1.62rem;
    }

    .codex-resonance-detail .codex-contract-affinity span {
        font-size: 0.84rem;
    }

    .codex-resonance-detail .codex-contract-grid {
        grid-template-columns: 1fr;
        gap: 0.58rem;
    }

    .codex-resonance-detail .codex-contract-section {
        padding: 0.72rem;
    }

    .codex-resonance-detail .codex-contract-section p,
    .codex-resonance-detail .codex-contract-section li,
    .codex-resonance-detail .codex-contract-section code,
    .codex-resonance-detail .codex-contract-locked-text {
        font-size: 1.17rem;
        line-height: 1.58;
    }

    .codex-resonance-detail .codex-contract-section .codex-label-mini {
        font-size: 0.88rem;
        padding: 0.22rem 0.68rem;
    }

    .codex-mastery-track {
        height: 10px;
    }
}

/* ── Mini labels ── */
.codex-label-mini {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 100px;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    flex-shrink: 0;
    white-space: nowrap;
}

.codex-label-mini--rule {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.codex-label-mini--formula {
    background: rgba(34, 211, 238, 0.12);
    color: #67e8f9;
    border: 1px solid rgba(34, 211, 238, 0.25);
}

.codex-label-mini--example {
    background: rgba(16, 185, 129, 0.12);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.25);
}

.codex-label-mini--tip {
    background: rgba(251, 191, 36, 0.10);
    color: #fbbf24;
    border: 1px solid rgba(251, 191, 36, 0.25);
}

/* ── Mobile portrait: stabilize overview wheel layout ── */
@media (max-width: 767px) and (orientation: portrait) {
    .codex-modal-overlay .codex-book--resonance:has(.codex-resonance-overview),
    .codex-modal-overlay .codex-resonance-shell:has(.codex-resonance-overview) {
        overflow: hidden !important;
    }

    .codex-modal-overlay .codex-resonance-overview {
        justify-content: flex-start;
        padding-top: 0.5rem;
        padding-bottom: 0.7rem;
        overflow: hidden;
    }

    .codex-modal-overlay .codex-wheel-stage {
        flex: 1 1 auto;
        min-height: min(50vh, 300px) !important;
        height: auto !important;
        margin-top: 0 !important;
        margin-bottom: 0 !important;
        transform: none !important;
        overflow: hidden !important;
    }

    .codex-modal-overlay .codex-wheel-orbit {
        width: 100% !important;
        margin-left: 0 !important;
        height: min(48vh, 340px) !important;
        min-height: 264px !important;
    }

    .codex-modal-overlay .codex-wheel-arrow {
        top: 50% !important;
    }
}

/* ── Tablet portrait: taller resonance overview (iPad; not iPhone) ── */
@media (min-width: 640px) and (max-width: 1024px) and (orientation: portrait) {
    .codex-modal-overlay .codex-book--resonance:has(.codex-resonance-overview) {
        display: flex;
        flex-direction: column;
        width: min(92vw, 720px);
        min-height: min(78dvh, 820px);
        max-height: min(86dvh, 900px);
        height: auto;
    }

    .codex-modal-overlay .codex-resonance-shell:has(.codex-resonance-overview) {
        flex: 1 1 auto;
        min-height: 0;
        overflow: hidden;
    }

    .codex-modal-overlay .codex-resonance-overview {
        flex: 1 1 auto;
        min-height: 0;
        overflow: hidden;
        justify-content: flex-start;
        padding-bottom: 1.35rem;
    }

    .codex-modal-overlay .codex-resonance-overview::before,
    .codex-modal-overlay .codex-resonance-overview::after {
        inset: 0;
    }

    .codex-modal-overlay .codex-wheel-stage {
        flex: 1 1 auto;
        min-height: min(52vh, 440px);
        height: auto;
        transform: none;
        overflow: hidden;
    }

    .codex-modal-overlay .codex-wheel-orbit {
        width: 100%;
        height: min(48vh, 400px);
        min-height: 300px;
    }
}

@media (max-width: 640px) {
    .codex-wheel-spirit.is-selected .codex-wheel-name {
        color: #3f2a12;
        -webkit-text-stroke: 0.35px rgba(255, 251, 235, 0.76);
        text-shadow:
            0 1px 0 rgba(255, 248, 220, 0.9),
            0 2px 6px rgba(255, 255, 255, 0.52),
            0 0 10px rgba(15, 23, 42, 0.2);
    }
}

/* ── Desktop: extra bottom breathing room so affinity bar clears the modal border ── */
@media (min-width: 768px) {
    .codex-resonance-overview {
        padding-bottom: 2.2rem;
    }
}
