body {
    font-family: 'Plus Jakarta Sans', sans-serif;
    background: radial-gradient(circle at center, #0f172a 0%, #020617 100%);
}

/* 家庭用ゲーム風のタイトル・モード選択画面。 */
.title-ui-screen {
    position: relative;
    isolation: isolate;
    width: min(100%, 1500px, calc(177.78vh - 80px));
    width: min(100%, 1500px, calc(177.78dvh - 80px));
    aspect-ratio: 1672 / 941;
    overflow: hidden;
    justify-content: flex-start;
    padding: clamp(0.4rem, 1.2vw, 1.1rem) clamp(1rem, 5vw, 5rem) clamp(1rem, 3vw, 2.5rem);
    border: 3px solid rgba(255, 255, 255, 0.78);
    border-radius: clamp(1.2rem, 2.5vw, 2.6rem);
    background-image: linear-gradient(rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.03)), url('title_ui_background.png');
    background-position: center;
    background-size: cover;
    box-shadow: 0 22px 70px rgba(59, 130, 246, 0.35), inset 0 0 40px rgba(255, 255, 255, 0.2);
}

#title-screen:not(.hidden) {
    display: flex;
}

#title-screen.hidden {
    display: none;
}

.title-ui-logo {
    position: relative;
    z-index: 2;
    width: min(78%, 1180px);
    margin-top: 0.2%;
    object-fit: contain;
    filter: drop-shadow(0 12px 5px rgba(67, 20, 116, 0.28));
    animation: title-ui-logo-float 3.5s ease-in-out infinite;
}

.title-ui-prompt {
    position: relative;
    z-index: 2;
    margin: clamp(-0.7rem, -0.6vw, -0.2rem) 0 clamp(0.2rem, 0.7vw, 0.7rem);
    padding: clamp(0.3rem, 0.55vw, 0.55rem) clamp(1rem, 2.6vw, 2.4rem);
    border: 3px solid rgba(255, 255, 255, 0.9);
    border-radius: 999px;
    background: linear-gradient(#ff78bd, #e82d83);
    color: white;
    font-size: clamp(0.7rem, 1.25vw, 1.15rem);
    font-weight: 900;
    letter-spacing: 0.05em;
    text-shadow: 0 2px 0 #9d174d;
    box-shadow: 0 5px 0 #a4145d, 0 9px 18px rgba(157, 23, 77, 0.3);
}

.title-ui-prompt span {
    color: #fef08a;
}

.title-ui-menu {
    position: relative;
    z-index: 2;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: min(72%, 1050px);
    gap: clamp(0.1rem, 0.7vw, 0.65rem) clamp(0.4rem, 1.3vw, 1.2rem);
    margin: auto;
}

.title-ui-mode-button {
    position: relative;
    min-width: 0;
    border: 0;
    background: transparent;
    padding: 0;
    cursor: pointer;
    transform: scale(0.98);
    transform-origin: center;
    transition: transform 180ms ease, filter 180ms ease;
    filter: brightness(0.9) saturate(0.92) drop-shadow(0 10px 8px rgba(67, 20, 116, 0.22));
}

.title-ui-mode-button img {
    display: block;
    width: 100%;
    height: auto;
    pointer-events: none;
}

.title-ui-mode-button:hover,
.title-ui-mode-button:focus-visible,
.title-ui-mode-button.is-default {
    z-index: 3;
    transform: translateY(-4px) scale(1.055);
    filter: brightness(1.08) saturate(1.12) drop-shadow(0 0 8px white) drop-shadow(0 13px 9px rgba(67, 20, 116, 0.28));
    outline: none;
}

.title-ui-menu:has(.title-ui-mode-button:hover) .title-ui-mode-button.is-default:not(:hover),
.title-ui-menu:has(.title-ui-mode-button:focus-visible) .title-ui-mode-button.is-default:not(:focus-visible) {
    z-index: auto;
    transform: scale(0.98);
    filter: brightness(0.9) saturate(0.92) drop-shadow(0 10px 8px rgba(67, 20, 116, 0.22));
}

.title-ui-cursor {
    position: absolute;
    z-index: 5;
    left: -4%;
    top: 50%;
    color: #facc15;
    font-size: clamp(1.5rem, 3.4vw, 3.2rem);
    line-height: 1;
    opacity: 0;
    transform: translate(-70%, -50%);
    -webkit-text-stroke: 3px white;
    filter: drop-shadow(0 4px 0 #b45309) drop-shadow(0 0 10px white);
    transition: opacity 150ms ease;
    animation: title-ui-cursor-bounce 650ms ease-in-out infinite alternate;
}

.title-ui-mode-button:hover .title-ui-cursor,
.title-ui-mode-button:focus-visible .title-ui-cursor,
.title-ui-mode-button.is-default .title-ui-cursor {
    opacity: 1;
}

.title-ui-menu:has(.title-ui-mode-button:hover) .title-ui-mode-button.is-default:not(:hover) .title-ui-cursor,
.title-ui-menu:has(.title-ui-mode-button:focus-visible) .title-ui-mode-button.is-default:not(:focus-visible) .title-ui-cursor {
    opacity: 0;
}

.title-ui-counter {
    position: absolute;
    z-index: 4;
    top: 9%;
    right: 4%;
    display: flex;
    width: 27%;
    height: 20%;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: clamp(0.55rem, 1.18vw, 1.05rem);
    font-weight: 1000;
    line-height: 1;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.75);
    white-space: nowrap;
}

.title-ui-counter img {
    width: auto;
    height: 72%;
    margin-right: 0.18em;
    object-fit: contain;
    filter: drop-shadow(0 1px 2px rgba(57, 24, 0, 0.7));
}

.title-ui-coin-counter {
    right: 4.5%;
    width: 30%;
    font-size: clamp(0.5rem, 1.05vw, 0.95rem);
}

.title-ui-coin-counter img {
    transform: translateX(-0.45em);
}

.title-ui-book-counter {
    right: -2%;
    width: 25%;
    font-size: clamp(0.5rem, 1.05vw, 0.95rem);
}

@keyframes title-ui-logo-float {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-5px) scale(1.01); }
}

@keyframes title-ui-cursor-bounce {
    from { margin-left: 0; }
    to { margin-left: 0.45rem; }
}

@media (max-width: 640px) {
    .title-ui-screen {
        min-height: calc(100vh - 2rem);
        aspect-ratio: auto;
        padding: 0.75rem 0.65rem 1.2rem;
        background-position: center;
    }

    .title-ui-logo {
        width: 98%;
        margin-top: 0.5rem;
    }

    .title-ui-prompt {
        margin: 0.2rem 0 0.8rem;
        border-width: 2px;
    }

    .title-ui-menu {
        grid-template-columns: 1fr;
        width: min(94%, 430px);
        gap: 0.1rem;
        margin: 0 auto;
    }

    .title-ui-mode-button {
        width: 100%;
    }

    .title-ui-mode-button:hover,
    .title-ui-mode-button:focus-visible,
    .title-ui-mode-button.is-default {
        transform: translateY(-2px) scale(1.025);
    }

    .title-ui-cursor {
        left: 5%;
        font-size: 2rem;
        transform: translate(-45%, -50%);
        -webkit-text-stroke-width: 2px;
    }

    .title-ui-counter {
        font-size: clamp(0.6rem, 3.5vw, 0.95rem);
    }
}

.gacha-preview-stage {
    background:
        radial-gradient(circle at 50% 40%, rgba(250, 204, 21, 0.2), transparent 34%),
        linear-gradient(145deg, rgba(88, 28, 135, 0.28), rgba(15, 23, 42, 0.75));
}

.gacha-preview-capsule {
    position: relative;
    display: grid;
    width: 150px;
    height: 150px;
    place-items: center;
    overflow: hidden;
    border: 5px solid rgba(253, 224, 71, 0.85);
    border-radius: 50%;
    background: linear-gradient(to bottom, rgba(244, 114, 182, 0.95) 0 49%, rgba(255, 255, 255, 0.95) 51% 100%);
    box-shadow: 0 0 35px rgba(250, 204, 21, 0.35);
}

.gacha-preview-capsule::after {
    content: '';
    position: absolute;
    inset: 47% 0 auto;
    height: 8px;
    background: #facc15;
}

.gacha-preview-capsule span {
    position: relative;
    z-index: 1;
    display: grid;
    width: 54px;
    height: 54px;
    place-items: center;
    border: 4px solid #facc15;
    border-radius: 50%;
    background: #0f172a;
    color: #fde68a;
    font-size: 30px;
    font-weight: 900;
}

.gacha-machine-stage {
    position: relative;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    border: 2px solid rgba(250, 204, 21, 0.35);
    border-radius: 20px;
    background: #020617;
    box-shadow: 0 0 32px rgba(236, 72, 153, 0.18);
}

.gacha-machine-background {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    user-select: none;
}

.gacha-chamber-window {
    position: absolute;
    left: 30.2%;
    top: 29.5%;
    width: 39.7%;
    height: 44%;
    overflow: hidden;
    border-radius: 46% 46% 36% 36%;
}

#gacha-capsule-canvas {
    width: 100%;
    height: 100%;
}

.gacha-glass-shine {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(112deg, transparent 14%, rgba(255, 255, 255, 0.13) 24%, transparent 33%),
        radial-gradient(circle at 50% 45%, transparent 48%, rgba(103, 232, 249, 0.13) 82%, rgba(255, 255, 255, 0.22));
}

.gacha-machine-button {
    position: absolute;
    z-index: 5;
    border: 2px solid #fde68a;
    border-radius: 999px;
    background: linear-gradient(180deg, #fef08a, #f59e0b);
    padding: clamp(5px, 0.8vw, 11px) clamp(10px, 1.5vw, 22px);
    color: #451a03;
    font-size: clamp(10px, 1.25vw, 18px);
    font-weight: 900;
    letter-spacing: 0.08em;
    box-shadow: 0 0 18px rgba(250, 204, 21, 0.8);
    animation: gacha-button-pulse 1.25s ease-in-out infinite;
}

.gacha-machine-button:hover {
    transform: scale(1.06);
    filter: brightness(1.12);
}

.gacha-insert-button {
    left: 15.7%;
    top: 61.5%;
}

.gacha-push-button {
    right: 7.2%;
    top: 61.5%;
}

.gacha-flying-coin {
    position: absolute;
    z-index: 7;
    left: 46%;
    top: 79%;
    width: 10%;
    pointer-events: none;
}

.gacha-flying-coin.is-inserting {
    display: block;
    animation: gacha-coin-insert 900ms cubic-bezier(0.22, 0.8, 0.25, 1) forwards;
}

.gacha-machine-stage.is-mixing {
    animation: gacha-machine-shake 140ms linear 12;
}

.gacha-machine-stage.is-mixing .gacha-machine-background {
    filter: brightness(1.12) saturate(1.18);
}

.gacha-machine-flash {
    position: absolute;
    z-index: 4;
    left: 39%;
    top: 30%;
    width: 23%;
    aspect-ratio: 1;
    border-radius: 50%;
    pointer-events: none;
    opacity: 0;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.95), rgba(236, 72, 153, 0.55) 30%, transparent 68%);
    mix-blend-mode: screen;
}

.gacha-machine-stage.is-mixing .gacha-machine-flash {
    animation: gacha-core-flash 420ms ease-in-out infinite;
}

.gacha-ejected-capsule {
    position: absolute;
    z-index: 8;
    left: 46%;
    top: 59%;
    width: 8%;
    pointer-events: none;
}

.gacha-ejected-capsule.is-ejecting {
    display: block;
    animation: gacha-capsule-eject 1050ms cubic-bezier(0.2, 0.75, 0.25, 1) forwards;
}

.gacha-status-message {
    position: absolute;
    z-index: 6;
    left: 50%;
    bottom: 2.4%;
    transform: translateX(-50%);
    width: min(72%, 620px);
    border: 1px solid rgba(103, 232, 249, 0.55);
    border-radius: 999px;
    background: rgba(2, 6, 23, 0.88);
    padding: clamp(5px, 0.7vw, 10px) 16px;
    color: #cffafe;
    font-size: clamp(9px, 1.15vw, 15px);
    font-weight: 900;
    box-shadow: 0 0 15px rgba(34, 211, 238, 0.25);
}

.gacha-reveal-overlay {
    position: absolute;
    z-index: 12;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: rgba(2, 6, 23, 0.82);
    backdrop-filter: blur(4px);
}

.gacha-reveal-overlay.hidden,
.gacha-character-result.hidden {
    display: none;
}

.gacha-reveal-glow {
    position: absolute;
    width: 56%;
    aspect-ratio: 1;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.95), rgba(236, 72, 153, 0.68) 18%, rgba(34, 211, 238, 0.28) 46%, transparent 70%);
    opacity: 0.7;
    animation: gacha-reveal-pulse 1.4s ease-in-out infinite;
}

.gacha-capsule-open-button {
    position: relative;
    z-index: 2;
    width: min(30%, 290px);
    aspect-ratio: 1;
    border: 0;
    background: transparent;
    filter: drop-shadow(0 0 24px rgba(236, 72, 153, 0.65));
}

.gacha-capsule-shell {
    position: absolute;
    inset: 0;
    overflow: hidden;
    transition: transform 650ms cubic-bezier(0.22, 0.9, 0.25, 1), opacity 500ms ease;
}

.gacha-capsule-shell img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.gacha-capsule-shell-top {
    clip-path: inset(0 0 49% 0);
}

.gacha-capsule-shell-bottom {
    clip-path: inset(50% 0 0 0);
}

.gacha-capsule-open-button.is-open .gacha-capsule-shell-top {
    transform: translateY(-68%) rotate(-18deg);
    opacity: 0;
}

.gacha-capsule-open-button.is-open .gacha-capsule-shell-bottom {
    transform: translateY(68%) rotate(14deg);
    opacity: 0;
}

.gacha-open-label {
    position: absolute;
    left: 50%;
    top: 106%;
    transform: translateX(-50%);
    width: 190%;
    color: #fef3c7;
    font-size: clamp(11px, 1.4vw, 18px);
    font-weight: 900;
    text-shadow: 0 2px 8px #020617;
    animation: gacha-button-pulse 1.2s ease-in-out infinite;
}

.gacha-capsule-open-button.is-open .gacha-open-label {
    opacity: 0;
}

.gacha-character-result {
    position: absolute;
    z-index: 5;
    inset: 3% 5%;
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(260px, 0.9fr);
    align-items: center;
    gap: 4%;
}

.gacha-character-result img {
    justify-self: center;
    width: auto;
    height: 520px;
    max-height: 90%;
    max-width: 100%;
    object-fit: contain;
    filter: brightness(6) saturate(0) drop-shadow(0 0 28px rgba(255, 255, 255, 0.95));
    opacity: 0;
    transform: scale(0.55);
}

.gacha-character-result.is-revealing img {
    animation: gacha-character-materialize 1400ms cubic-bezier(0.2, 0.9, 0.2, 1) forwards;
}

.gacha-result-text {
    align-self: center;
    max-height: 90%;
    overflow-y: auto;
    border: 1px solid rgba(244, 114, 182, 0.5);
    border-radius: 22px;
    background: rgba(15, 23, 42, 0.85);
    padding: clamp(16px, 2.4vw, 32px);
    box-shadow: 0 0 30px rgba(236, 72, 153, 0.25);
    opacity: 0;
    transform: translateX(30px);
}

.gacha-character-result.is-revealing .gacha-result-text {
    animation: gacha-result-text-in 600ms 900ms ease-out forwards;
}

@keyframes gacha-button-pulse {
    0%, 100% { box-shadow: 0 0 12px rgba(250, 204, 21, 0.55); }
    50% { box-shadow: 0 0 28px rgba(250, 204, 21, 0.95); }
}

@keyframes gacha-coin-insert {
    0% { left: 48%; top: 78%; transform: scale(1) rotate(0); opacity: 1; }
    58% { left: 18.5%; top: 47%; transform: scale(0.65) rotate(540deg); opacity: 1; }
    100% { left: 18.5%; top: 55%; transform: scale(0.18) rotate(780deg); opacity: 0; }
}

@keyframes gacha-machine-shake {
    0%, 100% { transform: translate(0, 0); }
    25% { transform: translate(-3px, 2px); }
    50% { transform: translate(3px, -2px); }
    75% { transform: translate(-2px, -1px); }
}

@keyframes gacha-core-flash {
    0%, 100% { opacity: 0.2; transform: scale(0.85); }
    50% { opacity: 0.95; transform: scale(1.18); }
}

@keyframes gacha-capsule-eject {
    0% { left: 47%; top: 60%; transform: scale(0.4) rotate(0); opacity: 0; }
    25% { left: 47%; top: 72%; transform: scale(0.55) rotate(100deg); opacity: 1; }
    58% { left: 42%; top: 77%; transform: scale(0.82) rotate(230deg); opacity: 1; }
    100% { left: 45%; top: 70%; transform: scale(1.35) rotate(360deg); opacity: 0; }
}

@keyframes gacha-reveal-pulse {
    0%, 100% { transform: scale(0.85); opacity: 0.48; }
    50% { transform: scale(1.1); opacity: 0.9; }
}

@keyframes gacha-character-materialize {
    0% { opacity: 0; transform: scale(0.55); filter: brightness(7) saturate(0) blur(8px) drop-shadow(0 0 32px white); }
    40% { opacity: 1; transform: scale(0.82); filter: brightness(5) saturate(0) blur(1px) drop-shadow(0 0 32px white); }
    72% { opacity: 1; transform: scale(1.04); filter: brightness(1.8) saturate(0.45) drop-shadow(0 0 24px rgba(244, 114, 182, 0.9)); }
    100% { opacity: 1; transform: scale(1); filter: brightness(1) saturate(1) drop-shadow(0 18px 20px rgba(0, 0, 0, 0.6)); }
}

@keyframes gacha-result-text-in {
    to { opacity: 1; transform: translateX(0); }
}

@media (max-width: 700px) {
    .gacha-reveal-overlay {
        position: fixed;
        z-index: 90;
        inset: 0;
        min-height: 100dvh;
        padding: max(16px, env(safe-area-inset-top)) 14px max(16px, env(safe-area-inset-bottom));
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .gacha-capsule-open-button {
        width: min(68vw, 300px);
    }

    .gacha-open-label {
        width: 150%;
        font-size: 15px;
    }

    .gacha-reveal-glow {
        position: fixed;
        width: min(92vw, 440px);
    }

    .gacha-character-result {
        position: relative;
        inset: auto;
        display: grid;
        width: min(100%, 430px);
        min-height: calc(100dvh - 32px);
        grid-template-columns: 1fr;
        grid-template-rows: minmax(230px, 48dvh) auto;
        align-content: center;
        gap: 10px;
        padding: 8px 0;
    }

    .gacha-character-result img {
        width: 100%;
        height: 100%;
        max-height: 48dvh;
    }

    .gacha-result-text {
        width: 100%;
        max-height: none;
        overflow: visible;
        padding: 10px;
    }

    .gacha-result-text h3 {
        font-size: 18px;
    }

    .gacha-result-text p {
        font-size: 11px;
    }

    .gacha-result-text button {
        padding: 9px 12px;
        font-size: 11px;
    }
}

@media (max-width: 700px) and (max-height: 620px) {
    .gacha-character-result {
        grid-template-rows: minmax(180px, 40dvh) auto;
    }

    .gacha-character-result img {
        max-height: 40dvh;
    }
}

.character-book-layout {
    display: grid;
    grid-template-columns: minmax(230px, 0.72fr) minmax(360px, 1.6fr) minmax(300px, 1fr);
    gap: 18px;
}

.character-book-card-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
}

.character-book-card {
    position: relative;
    aspect-ratio: 0.82;
    overflow: hidden;
    border: 2px solid #334155;
    border-radius: 12px;
    background: linear-gradient(145deg, #172033, #080d19);
}

.character-book-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: 50% 8%;
}

.character-book-card.is-selected {
    border-color: #f472b6;
    box-shadow: 0 0 16px rgba(244, 114, 182, 0.65), inset 0 0 12px rgba(236, 72, 153, 0.25);
}

.character-book-card.is-locked {
    color: #64748b;
    cursor: not-allowed;
}

.character-book-card-number,
.character-book-card-star {
    position: absolute;
    z-index: 2;
    font-size: 11px;
    font-weight: 900;
    text-shadow: 0 1px 4px #020617;
}

.character-book-card-number {
    top: 5px;
    left: 7px;
}

.character-book-card-star {
    right: 6px;
    bottom: 4px;
    color: #f9a8d4;
}

.character-book-lock {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: 25px;
    filter: grayscale(1);
    opacity: 0.55;
}

.character-book-viewer-panel,
.character-book-profile {
    border: 1px solid rgba(129, 140, 248, 0.3);
    border-radius: 20px;
    background: rgba(15, 23, 42, 0.75);
    padding: 14px;
}

.character-book-viewer {
    display: flex;
    min-height: 590px;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 1px solid rgba(103, 232, 249, 0.2);
    border-radius: 16px;
    background-color: #0b1730;
    background-image:
        linear-gradient(rgba(59, 130, 246, 0.07) 1px, transparent 1px),
        linear-gradient(90deg, rgba(59, 130, 246, 0.07) 1px, transparent 1px),
        radial-gradient(circle at center, rgba(37, 99, 235, 0.17), transparent 58%);
    background-size: 32px 32px, 32px 32px, auto;
    cursor: grab;
    touch-action: none;
}

.character-book-viewer.is-dragging {
    cursor: grabbing;
}

.character-book-viewer img {
    width: auto;
    height: min(560px, 68vh);
    max-width: 92%;
    object-fit: contain;
    transform-origin: center;
    will-change: transform;
    user-select: none;
    pointer-events: none;
    filter: drop-shadow(0 20px 22px rgba(0, 0, 0, 0.55));
}

.character-book-toolbar {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
}

.character-book-variant-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.character-book-variant-button {
    border: 1px solid #475569;
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.85);
    padding: 7px 14px;
    color: #cbd5e1;
    font-size: 12px;
    font-weight: 900;
    transition: border-color 150ms ease, background-color 150ms ease, color 150ms ease;
}

.character-book-variant-button:not(:disabled) {
    cursor: pointer;
}

.character-book-variant-button:not(:disabled):hover,
.character-book-variant-button.is-selected {
    border-color: #f472b6;
    background: rgba(80, 7, 36, 0.8);
    color: #fbcfe8;
}

.character-book-variant-button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.character-book-toolbar button {
    display: flex;
    min-width: 0;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    border: 1px solid #334155;
    border-radius: 10px;
    background: #0f172a;
    padding: 7px 2px;
    color: #cbd5e1;
    font-size: 18px;
}

.character-book-toolbar button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.character-book-toolbar button:not(:disabled) {
    cursor: pointer;
    transition: border-color 150ms ease, background-color 150ms ease, color 150ms ease;
    touch-action: none;
}

.character-book-toolbar button:not(:disabled):hover {
    border-color: #67e8f9;
    background: #172554;
    color: #ecfeff;
}

.character-book-toolbar button:not(:disabled):active {
    border-color: #f472b6;
    background: #500724;
}

.character-book-toolbar span {
    font-size: 9px;
    font-weight: 800;
}

.character-book-profile {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.character-book-profile section {
    border: 1px solid #334155;
    border-radius: 14px;
    background: rgba(2, 6, 23, 0.55);
    padding: 13px;
}

.character-book-profile h4 {
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 900;
}

.character-book-profile p,
.character-book-profile li {
    font-size: 12px;
    line-height: 1.8;
    color: #cbd5e1;
}

.character-book-profile ul {
    list-style: disc;
    padding-left: 18px;
}

@media (max-width: 1050px) {
    .character-book-layout {
        grid-template-columns: minmax(180px, 0.7fr) minmax(360px, 1.5fr);
    }

    .character-book-profile {
        grid-column: 1 / -1;
    }
}

@media (max-width: 700px) {
    .character-book-layout {
        grid-template-columns: 1fr;
    }

    .character-book-card-grid {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }

    .character-book-viewer {
        min-height: 430px;
    }

    .character-book-viewer img {
        height: 410px;
    }

    .character-book-toolbar {
        grid-template-columns: repeat(3, 1fr);
    }
}

canvas {
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* 会話画面の立ち絵。最大値を変えると全キャラクターをまとめて調整できる。 */
.dialogue-portrait {
    position: relative;
    width: clamp(160px, 30vw, 280px);
    height: clamp(240px, 43vh, 380px);
    overflow: hidden;
    filter: drop-shadow(0 18px 20px rgba(0, 0, 0, 0.55));
}

.dialogue-portrait-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: 50% 0%;
    transform: scale(1);
    transform-origin: 50% 50%;
    transition: opacity 130ms ease;
}

/* 会話中は話していない側を暗くし、現在の話者を判別しやすくする。 */
#dialogue-hero-group,
#dialogue-opponent-group {
    filter: brightness(1) saturate(1);
    opacity: 1;
    transition: filter 180ms ease, opacity 180ms ease;
}

#dialogue-hero-group.is-dialogue-inactive,
#dialogue-opponent-group.is-dialogue-inactive {
    filter: brightness(0.55) saturate(0.72);
    opacity: 0.82;
}

/* ハード初回クリア時のあいもげコイン獲得演出。 */
#story-coin-reward {
    transition: opacity 300ms ease;
}

#story-coin-reward.is-showing {
    opacity: 1;
}

.story-coin-reward-rays {
    position: absolute;
    width: min(85vw, 680px);
    aspect-ratio: 1;
    border-radius: 50%;
    background: repeating-conic-gradient(from 0deg, rgba(253, 224, 71, 0.32) 0deg 7deg, transparent 7deg 15deg);
    mask-image: radial-gradient(circle, black 0 20%, transparent 68%);
    animation: story-coin-rays-spin 9s linear infinite;
}

.story-coin-reward-card {
    width: min(92vw, 620px);
    transform: scale(0.45) translateY(60px);
    opacity: 0;
    transition: transform 650ms cubic-bezier(0.2, 1.4, 0.35, 1), opacity 250ms ease;
}

.story-coin-reward-card.is-showing {
    transform: scale(1) translateY(0);
    opacity: 1;
}

.story-coin-reward-image-wrap {
    position: relative;
    width: clamp(180px, 36vw, 310px);
    margin: 1rem auto 0;
    filter: drop-shadow(0 0 18px rgba(253, 224, 71, 0.9)) drop-shadow(0 0 55px rgba(249, 115, 22, 0.65));
}

.story-coin-reward-image {
    width: 100%;
    animation: story-coin-get 1.25s cubic-bezier(0.2, 1, 0.3, 1) both;
}

.story-coin-reward-get {
    margin-top: -0.25rem;
    background: linear-gradient(90deg, #fef08a, #fff, #f59e0b);
    background-clip: text;
    color: transparent;
    font-size: clamp(2.7rem, 9vw, 5.5rem);
    font-weight: 1000;
    line-height: 1;
    letter-spacing: 0.04em;
    filter: drop-shadow(0 4px 0 rgba(146, 64, 14, 0.85));
    animation: story-coin-get-label 700ms 450ms both;
}

.story-coin-reward-sparkles span {
    position: absolute;
    left: 50%;
    top: 46%;
    color: #fef08a;
    font-size: clamp(1.5rem, 5vw, 3.5rem);
    text-shadow: 0 0 14px #facc15;
    animation: story-coin-sparkle 1.6s ease-out infinite;
}

.story-coin-reward-sparkles span:nth-child(1) { --x: -260px; --y: -170px; animation-delay: 0ms; }
.story-coin-reward-sparkles span:nth-child(2) { --x: 250px; --y: -155px; animation-delay: 180ms; }
.story-coin-reward-sparkles span:nth-child(3) { --x: -290px; --y: 20px; animation-delay: 360ms; }
.story-coin-reward-sparkles span:nth-child(4) { --x: 285px; --y: 35px; animation-delay: 540ms; }
.story-coin-reward-sparkles span:nth-child(5) { --x: -210px; --y: 190px; animation-delay: 720ms; }
.story-coin-reward-sparkles span:nth-child(6) { --x: 220px; --y: 175px; animation-delay: 900ms; }
.story-coin-reward-sparkles span:nth-child(7) { --x: -70px; --y: -245px; animation-delay: 1080ms; }
.story-coin-reward-sparkles span:nth-child(8) { --x: 90px; --y: 235px; animation-delay: 1260ms; }

@keyframes story-coin-rays-spin {
    to { transform: rotate(360deg); }
}

@keyframes story-coin-get {
    0% { transform: translateY(90px) scale(0.15) rotate(-540deg); opacity: 0; }
    65% { transform: translateY(-12px) scale(1.12) rotate(18deg); opacity: 1; }
    100% { transform: translateY(0) scale(1) rotate(0); opacity: 1; }
}

@keyframes story-coin-get-label {
    0% { transform: scale(2.4); opacity: 0; }
    70% { transform: scale(0.9); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

@keyframes story-coin-sparkle {
    0% { transform: translate(-50%, -50%) scale(0) rotate(0); opacity: 0; }
    30% { opacity: 1; }
    100% { transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) scale(1.25) rotate(150deg); opacity: 0; }
}

.dialogue-portrait-fallback {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dialogue-portrait.is-overflowing {
    overflow: visible;
}

/* マス選択型スキル中は、盤面を覆わず外枠だけをゆっくり発光させる。 */
#game-board-frame.skill-targeting-board {
    border-color: #ec4899;
    animation: skill-targeting-glow 1.8s ease-in-out infinite;
}

#game-board-frame.skill-targeting-board #game-canvas {
    cursor: crosshair;
}

#game-board-frame.pirate-x-slash-impact {
    animation: pirate-x-slash-impact 0.48s ease-out;
}

@keyframes pirate-x-slash-impact {
    0%, 100% { transform: translate(0, 0); }
    18% { transform: translate(-5px, 3px); }
    36% { transform: translate(5px, -3px); }
    54% { transform: translate(-3px, -2px); }
    72% { transform: translate(3px, 2px); }
}

@keyframes skill-targeting-glow {
    0%, 100% {
        box-shadow: 0 0 12px rgba(236, 72, 153, 0.35);
    }
    50% {
        box-shadow: 0 0 22px rgba(236, 72, 153, 0.65);
    }
}

.neon-glow-red {
    box-shadow: 0 0 15px rgba(244, 63, 94, 0.4);
}

.neon-glow-blue {
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.4);
}

.neon-glow-green {
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.4);
}

.neon-glow-yellow {
    box-shadow: 0 0 15px rgba(234, 179, 8, 0.4);
}

.neon-glow-pink {
    box-shadow: 0 0 15px rgba(236, 72, 153, 0.4);
}

/* スキルボタンのネオングロー（色名ベースの汎用クラス） */
.neon-glow-ruby {
    box-shadow: 0 0 15px rgba(236, 72, 153, 0.4);
}

.neon-glow-sapphire {
    box-shadow: 0 0 15px rgba(234, 179, 8, 0.4);
}

.neon-glow-emerald {
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.4);
}

.neon-glow-topaz {
    box-shadow: 0 0 15px rgba(244, 63, 94, 0.4);
}
@keyframes barrel-drop-impact {
    0%, 100% { transform: translateY(0); }
    25% { transform: translateY(7px); }
    50% { transform: translateY(-3px); }
    75% { transform: translateY(3px); }
}

.barrel-drop-impact {
    animation: barrel-drop-impact 0.42s ease-out;
}
