body {
    position: relative;
    background-color: #edf3f4;
}

#graticube-page-bg {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    opacity: 0.9;
    filter: saturate(0.94) brightness(1.02);
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: -2;
}

body::after {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: -1;
}

body.bg-theme-cosmic-light {
    background:
        linear-gradient(180deg, #f4f7f7 0%, #ecf3f5 42%, #e9eef4 100%);
}

body.bg-theme-cosmic-light::before {
    background:
        radial-gradient(circle at 20% 18%, rgba(138, 210, 214, 0.22), transparent 26%),
        radial-gradient(circle at 78% 16%, rgba(255, 207, 166, 0.26), transparent 24%),
        radial-gradient(circle at 50% 78%, rgba(182, 174, 230, 0.18), transparent 28%);
}

body.bg-theme-cosmic-light::after {
    background:
        linear-gradient(180deg, rgba(255,255,255,0.62), rgba(255,255,255,0.32)),
        url("cosmic2.png") center/cover no-repeat;
    opacity: 0.46;
    filter: saturate(0.82) blur(1px);
}

body.bg-theme-water-glow {
    background:
        linear-gradient(180deg, #e8fbff 0%, #d8f1f7 42%, #edf8fb 100%);
}

body.bg-theme-water-glow::before {
    background:
        linear-gradient(103deg,
            rgba(255,255,255,0) 8%,
            rgba(255,255,255,0.58) 16%,
            rgba(196,243,250,0.22) 22%,
            rgba(255,255,255,0) 30%),
        linear-gradient(103deg,
            rgba(255,255,255,0) 34%,
            rgba(143,219,233,0.34) 43%,
            rgba(255,255,255,0.16) 49%,
            rgba(255,255,255,0) 58%),
        linear-gradient(103deg,
            rgba(255,255,255,0) 62%,
            rgba(255,255,255,0.5) 71%,
            rgba(167,231,240,0.18) 77%,
            rgba(255,255,255,0) 86%),
        radial-gradient(circle at 18% 22%, rgba(97, 205, 226, 0.24), transparent 18%),
        radial-gradient(circle at 82% 18%, rgba(121, 216, 233, 0.18), transparent 18%),
        radial-gradient(circle at 48% 78%, rgba(96, 186, 208, 0.12), transparent 24%);
}

body.bg-theme-water-glow::after {
    background:
        linear-gradient(180deg, rgba(255,255,255,0.08), rgba(255,255,255,0.01)),
        repeating-linear-gradient(
            92deg,
            rgba(255,255,255,0) 0px,
            rgba(255,255,255,0) 16px,
            rgba(166,230,240,0.16) 18px,
            rgba(255,255,255,0.04) 21px,
            rgba(255,255,255,0) 34px
        );
    opacity: 0.95;
    filter: none;
}

body.bg-theme-spiritfest {
    background:
        linear-gradient(180deg, #f6efe9 0%, #efe6de 44%, #f2ebe4 100%);
}

body.bg-theme-spiritfest::before {
    background:
        radial-gradient(circle at 18% 14%, rgba(255, 255, 255, 0.2), transparent 18%),
        radial-gradient(circle at 82% 18%, rgba(255, 224, 205, 0.16), transparent 20%),
        linear-gradient(180deg, rgba(255,255,255,0.16), rgba(255,255,255,0.05));
}

body.bg-theme-spiritfest::after {
    background:
        linear-gradient(180deg, rgba(255,255,255,0.14), rgba(255,255,255,0.04)),
        url("spiritfest.jpg") center/cover no-repeat;
    opacity: 0.9;
    filter: saturate(0.94) brightness(1.02);
}

body.bg-theme-sunrise-paper {
    background:
        linear-gradient(180deg, #fbf5ee 0%, #f8eee6 44%, #f1ece9 100%);
}

body.bg-theme-sunrise-paper::before {
    background:
        radial-gradient(circle at 18% 14%, rgba(255, 194, 147, 0.28), transparent 24%),
        radial-gradient(circle at 82% 20%, rgba(243, 216, 157, 0.22), transparent 22%),
        radial-gradient(circle at 55% 78%, rgba(221, 194, 233, 0.14), transparent 28%);
}

body.bg-theme-sunrise-paper::after {
    background:
        linear-gradient(180deg, rgba(255,255,255,0.64), rgba(255,255,255,0.22)),
        url("cosmic2.png") center/cover no-repeat;
    opacity: 0.18;
    filter: saturate(0.5) sepia(0.18) hue-rotate(-20deg) blur(1px);
}

body.bg-theme-misty-play {
    background:
        linear-gradient(180deg, #f7f7fb 0%, #eef1fb 48%, #eef5f8 100%);
}

body.bg-theme-misty-play::before {
    background:
        radial-gradient(circle at 16% 18%, rgba(169, 183, 245, 0.22), transparent 24%),
        radial-gradient(circle at 80% 18%, rgba(255, 196, 178, 0.2), transparent 22%),
        radial-gradient(circle at 52% 80%, rgba(169, 226, 228, 0.16), transparent 26%);
}

body.bg-theme-misty-play::after {
    background:
        linear-gradient(180deg, rgba(255,255,255,0.62), rgba(255,255,255,0.24)),
        url("cosmic2.png") center/cover no-repeat;
    opacity: 0.28;
    filter: saturate(0.7) hue-rotate(14deg) blur(1px);
}

#bg-theme-picker {
    position: fixed;
    top: 18px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    z-index: 10;
}

#bg-theme-picker button {
    border: 0;
    border-radius: 999px;
    min-height: 40px;
    padding: 10px 16px;
    background: rgba(255, 255, 255, 0.72);
    color: #243440;
    box-shadow: 0 8px 24px rgba(32, 43, 60, 0.12);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    cursor: pointer;
}

#root-wrapper {
    position: relative;
    width: 100%;
    min-height: 760px;
    margin-top: 56px;
    padding: 24px;
    background: transparent;
    border-radius: 28px;
    overflow: hidden;
    color: #21414d;
    box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.22),
        0 20px 60px rgba(69, 128, 146, 0.12);
}

#root-wrapper::before {
    content: "";
    position: absolute;
    inset: 0;
    background:
        linear-gradient(120deg, rgba(255, 255, 255, 0.08), transparent 26%),
        radial-gradient(circle at 50% 46%, rgba(255, 255, 255, 0.08) 0, rgba(255, 255, 255, 0) 55%);
    pointer-events: none;
}

#root-wrapper[hidden] {
    display: none;
}

#canvas {
    position: relative;
    z-index: 1;
    width: 100%;
    min-height: 680px;
    border-radius: 24px;
    background:
        linear-gradient(180deg, rgba(255,255,255,0.1), rgba(255,255,255,0.03)),
        linear-gradient(103deg, rgba(255,255,255,0.12), rgba(255,255,255,0) 28%);
    box-shadow:
        inset 0 0 0 1px rgba(255, 255, 255, 0.18),
        inset 0 18px 40px rgba(255, 255, 255, 0.08);
}

#canvas[hidden] {
    display: none;
}

#canvas canvas {
    display: block;
    width: 100% !important;
    height: auto !important;
    border-radius: 20px;
}

#loading_text {
    display: none;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 0 16px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-size: 12px;
}

#throw {
    display: none;
}

#throw[hidden] {
    display: none;
}

#control_stack {
    position: absolute;
    top: 12px;
    left: 16px;
    transform: none;
    width: auto;
    z-index: 1001;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

#play_icon,
#gratitude_heart,
#curiosity_bubble,
#gift_icon,
#gratitude_sound_toggle {
    pointer-events: auto;
}

#gratitude_heart {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    width: 34px;
    margin-top: 10px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.78);
    color: #c65f72;
    font-size: 18px;
    line-height: 1;
    box-shadow: 0 10px 28px rgba(87, 71, 57, 0.14);
    cursor: pointer;
}

#play_icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    width: 34px;
    margin-top: 0;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.78);
    color: #5a4e3d;
    font-size: 14px;
    line-height: 1;
    box-shadow: 0 10px 28px rgba(87, 71, 57, 0.14);
    cursor: pointer;
    pointer-events: auto;
}

#curiosity_bubble {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    width: 34px;
    margin-top: 8px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.78);
    color: #5b8fd9;
    font-size: 15px;
    line-height: 1;
    box-shadow: 0 10px 28px rgba(87, 71, 57, 0.14);
    cursor: pointer;
    pointer-events: auto;
}

#gift_icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    width: 34px;
    margin-top: 8px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.78);
    color: #b57b47;
    font-size: 15px;
    line-height: 1;
    box-shadow: 0 10px 28px rgba(87, 71, 57, 0.14);
    cursor: pointer;
    pointer-events: auto;
}

#gratitude_sound_toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    width: 34px;
    margin-top: 8px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.78);
    color: #6c4f71;
    font-size: 15px;
    line-height: 1;
    box-shadow: 0 10px 28px rgba(87, 71, 57, 0.14);
    cursor: pointer;
    pointer-events: auto;
}

#gratitude_heart.is-active {
    animation: graticube-heart-pulse 0.55s ease;
}

#gratitude_feedback {
    margin-top: 10px;
    color: #9b5660;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-align: left;
    opacity: 0;
    transform: translateY(-4px);
    pointer-events: none;
}

#gratitude_feedback.is-active {
    animation: graticube-gratitude-feedback 1.8s ease forwards;
}

#gratitude_burst {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.graticube-gratitude-particle {
    position: absolute;
    left: 50%;
    top: 50%;
    color: #d16a80;
    opacity: 0;
    transform: translate(-50%, 0);
    text-shadow: 0 10px 24px rgba(141, 54, 74, 0.18);
    animation: graticube-gratitude-float 1.5s ease-out forwards;
    animation-delay: var(--gratitude-delay, 0s);
}


#graticube_curiosity_modal {
    position: fixed;
    inset: 0;
    z-index: 2001;
}

#graticube_curiosity_modal[hidden] {
    display: none;
}

#graticube_curiosity_backdrop {
    position: absolute;
    inset: 0;
    border: 0;
    background: rgba(28, 38, 56, 0.42);
    cursor: pointer;
}

#graticube_curiosity_dialog {
    position: absolute;
    inset: 50% auto auto 50%;
    transform: translate(-50%, -50%);
    width: min(90vw, 90vh);
    height: min(90vw, 90vh);
    padding: 56px 24px 24px;
    border-radius: 28px;
    background: linear-gradient(180deg, rgba(234, 245, 253, 0.98), rgba(220, 237, 250, 0.98));
    border: 1px solid rgba(91, 143, 217, 0.2);
    box-shadow: 0 24px 60px rgba(42, 72, 106, 0.2);
    overflow: auto;
}

#graticube_curiosity_close {
    position: absolute;
    top: 12px;
    right: 12px;
    border: 0;
    border-radius: 999px;
    min-height: 34px;
    padding: 0 12px;
    background: rgba(91, 143, 217, 0.12);
    color: #4f78b2;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

#graticube_curiosity_content {
    color: #38506d;
    line-height: 1.55;
}

#graticube_curiosity_content strong {
    display: block;
    margin-bottom: 18px;
    color: #2f4868;
    font-size: clamp(22px, 3vw, 30px);
}

#graticube_curiosity_content p {
    margin: 0;
    color: #4a6787;
    font-size: clamp(18px, 2.2vw, 24px);
}

#graticube_curiosity_content p + p {
    margin-top: 18px;
}

#graticube_gift_modal {
    position: fixed;
    inset: 0;
    z-index: 2002;
}

#graticube_gift_modal[hidden] {
    display: none;
}

#graticube_gift_backdrop {
    position: absolute;
    inset: 0;
    border: 0;
    background: rgba(58, 46, 28, 0.36);
    cursor: pointer;
}

#graticube_gift_dialog {
    position: absolute;
    inset: 50% auto auto 50%;
    transform: translate(-50%, -50%);
    width: min(90vw, 760px);
    height: 90vh;
    padding: 56px 24px 24px;
    border-radius: 28px;
    background: linear-gradient(180deg, rgba(251, 245, 233, 0.98), rgba(246, 236, 214, 0.98));
    border: 1px solid rgba(181, 123, 71, 0.22);
    box-shadow: 0 24px 60px rgba(90, 68, 38, 0.18);
    overflow: auto;
}

#graticube_gift_close {
    position: absolute;
    top: 12px;
    right: 12px;
    border: 0;
    border-radius: 999px;
    min-height: 34px;
    padding: 0 12px;
    background: rgba(181, 123, 71, 0.12);
    color: #9a6b43;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

#graticube_gift_content {
    color: #6a563f;
    line-height: 1.55;
}

#graticube_gift_content strong {
    display: block;
    margin-bottom: 18px;
    color: #8a5d39;
    font-size: clamp(22px, 3vw, 30px);
}

#graticube_gift_content p {
    margin: 0 0 20px;
    color: #735c43;
    font-size: clamp(18px, 2.2vw, 24px);
}

#graticube_gift_content img {
    display: block;
    max-width: 100%;
    max-height: calc(100% - 140px);
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 16px;
    margin: 0 auto;
}

#graticube_play_modal {
    position: fixed;
    inset: 0;
    z-index: 2003;
}

#graticube_play_modal[hidden] {
    display: none;
}

#graticube_play_backdrop {
    position: absolute;
    inset: 0;
    border: 0;
    background: rgba(0, 0, 0, 0.28);
    cursor: pointer;
}

#graticube_play_dialog {
    position: absolute;
    inset: 50% auto auto 50%;
    transform: translate(-50%, -50%);
    width: min(90vw, 760px);
    height: 90vh;
    padding: 56px 24px 24px;
    border-radius: 28px;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.12);
    overflow: auto;
}

#graticube_play_close {
    position: absolute;
    top: 12px;
    right: 12px;
    border: 0;
    border-radius: 999px;
    min-height: 34px;
    padding: 0 12px;
    background: rgba(0, 0, 0, 0.06);
    color: #222;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

#graticube_play_content {
    color: #111;
    line-height: 1.55;
}

#graticube_play_content img {
    display: block;
    width: min(420px, calc(100% - 72px));
    max-width: 100%;
    height: auto;
    margin: 0 auto 8px;
}

#graticube_play_content strong {
    display: block;
    margin-bottom: 10px;
    color: #111;
    font-size: clamp(22px, 3vw, 30px);
}

#graticube_play_content ol {
    margin: 0 0 0 1.2em;
    padding: 0;
    color: #111;
    font-size: clamp(18px, 2.2vw, 24px);
    line-height: 1.55;
}

#graticube_play_content li + li {
    margin-top: 12px;
}

#graticube_play_content .graticube-play-footer {
    margin: 48px 0 0;
    color: #111;
    font-size: clamp(16px, 1.6vw, 18px);
    line-height: 1.5;
}

#graticube_play_content .graticube-play-footer a,
#graticube_play_content .graticube-play-footer a:visited {
    color: #6692cb !important;
    text-decoration: none;
}

#graticube_play_content .graticube-play-footer a:hover,
#graticube_play_content .graticube-play-footer a:focus-visible {
    color: #4b4a9f !important;
    text-decoration: underline;
}

#story_card {
    position: absolute;
    top: 96px;
    right: 24px;
    max-width: 360px;
    max-height: calc(100vh - 48px);
    padding: 24px;
    border-radius: 24px;
    background: rgba(241, 250, 252, 0.78);
    border: 1px solid rgba(120, 187, 200, 0.26);
    backdrop-filter: blur(14px);
    box-shadow: 0 18px 50px rgba(77, 129, 146, 0.18);
    overflow-y: auto;
    overscroll-behavior: contain;
    z-index: 999;
    isolation: isolate;
}

#story_card::before {
    content: "";
    position: absolute;
    inset: 14px;
    border-radius: 18px;
    background-image: var(--story-character-icon, none);
    background-position: center;
    background-repeat: no-repeat;
    background-size: min(78%, 280px);
    opacity: 0.09;
    pointer-events: none;
    z-index: 0;
}

#story_card > * {
    position: relative;
    z-index: 1;
}

#story_card.gratitude-active {
    animation: graticube-card-gratitude 1.2s ease;
}

#story_roll {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
}

#story_roll span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 0 12px;
    border-radius: 999px;
    background: #845f8a;
    color: #fbf5fc;
    font-size: 13.8px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

#story_card_question {
    margin: 0 0 12px;
    font-size: 28px;
    line-height: 1.15;
    color: #4c3427;
}

#story_card_character {
    margin: 0 0 8px;
    color: #9b5660;
    font-size: 21.6px;
    font-style: italic;
}

#story_card_subtext {
    margin: 0 0 16px;
    color: #be5c4c;
    font-size: 1.2em;
    line-height: 1.45;
}

#story_card_hint {
    margin: 0 0 16px;
    padding: 14px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.46);
}

#story_card_hint_text {
    margin: 0;
    color: rgba(33, 65, 77, 0.76);
    line-height: 1.5;
}

#story_card_hint[hidden] {
    display: none;
}

#story_card_hint,
#story_help_toggle,
#story_help_a11y {
    display: none !important;
}

#story_help_a11y {
    display: flex;
    gap: 8px;
    margin: 0 0 16px;
}

#story_actions {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

#story_help_toggle {
    margin: 0;
    border: 0;
    border-radius: 999px;
    min-height: 34px;
    padding: 0 12px;
    background: rgba(255, 255, 255, 0.68);
    color: #25505d;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
}

#story_help_font_down,
#story_help_font_up,
#story_help_close {
    border: 0;
    border-radius: 999px;
    min-height: 34px;
    padding: 0 12px;
    background: rgba(255, 255, 255, 0.72);
    color: #25505d;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.05em;
    cursor: pointer;
}

#story_roll {
    margin-bottom: 18px;
}

#story_next {
    border: 0;
    border-radius: 999px;
    min-height: 34px;
    padding: 0 12px;
    margin: 0 0 0 auto;
    background: #a476ae;
    color: #fff7ff;
    font-weight: 700;
    cursor: pointer;
}

#selector_div {
    display: none;
}

@keyframes graticube-heart-pulse {
    0% { transform: scale(1); }
    35% { transform: scale(1.16); }
    70% { transform: scale(0.96); }
    100% { transform: scale(1); }
}

@keyframes graticube-gratitude-feedback {
    0% { opacity: 0; transform: translateY(-4px); }
    18% { opacity: 1; transform: translateY(0); }
    78% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-8px); }
}

@keyframes graticube-gratitude-float {
    0% {
        opacity: 0;
        transform: translate(-50%, 0) scale(0.7);
    }
    20% {
        opacity: 0.95;
    }
    100% {
        opacity: 0;
        transform: translate(calc(-50% + var(--gratitude-x, 0vw)), var(--gratitude-y, -20vh)) scale(1.3);
    }
}

@keyframes graticube-card-gratitude {
    0% {
        box-shadow: 0 18px 50px rgba(77, 129, 146, 0.18);
        border-color: rgba(120, 187, 200, 0.26);
    }
    35% {
        box-shadow: 0 18px 50px rgba(77, 129, 146, 0.18), 0 0 0 4px rgba(214, 124, 142, 0.18);
        border-color: rgba(198, 95, 114, 0.42);
    }
    100% {
        box-shadow: 0 18px 50px rgba(77, 129, 146, 0.18);
        border-color: rgba(120, 187, 200, 0.26);
    }
}

@media (max-width: 900px) {
    #bg-theme-picker {
        position: static;
        transform: none;
        margin-bottom: 16px;
    }

    #control_stack {
        top: 8px;
        left: 8px;
        width: auto;
    }

    #root-wrapper {
        margin-top: 0;
        min-height: 640px;
        padding: 16px;
    }

    #canvas {
        min-height: 520px;
    }

    #story_card {
        position: fixed;
        left: 12px;
        right: 12px;
        bottom: max(12px, env(safe-area-inset-bottom));
        top: auto;
        max-width: none;
        max-height: min(74vh, 640px);
        margin-top: 0;
        z-index: 999;
        background: rgba(241, 250, 252, 0.7);
    }

    #throw {
        position: static;
        margin-top: 16px;
    }
}
