/* Intentional, finite motion. Load after home-modern.css. */
:root {
    --rr-motion-out: cubic-bezier(.16, 1, .3, 1);
    --rr-motion-in-out: cubic-bezier(.4, 0, .2, 1);
}

.rm-fortune-panel.is-opening,
.fortune-dialog.is-opening {
    animation: rr-panel-enter 240ms var(--rr-motion-out) both;
}
.fortune-result.is-revealed {
    animation: rr-result-enter 280ms var(--rr-motion-out) both;
}
.fortune-result.is-revealed .fortune-numbers > * {
    animation: rr-number-settle 320ms var(--rr-motion-out) both;
}
.fortune-result.is-revealed .fortune-numbers > :nth-child(2) {
    animation-delay: 55ms;
}

/* A compact writing surface for a complete dream, including long Thai text. */
.dream-form {
    display: block;
}
.dream-form .dream-input {
    display: block;
    width: 100%;
    min-height: 142px;
    margin: 0;
    padding: 11px 12px;
    resize: vertical;
    border: 1px solid #b8d0be;
    border-radius: 11px;
    background: #fff;
    color: #214a36;
    font: inherit;
    font-size: 16px;
    line-height: 1.75;
    overflow-wrap: anywhere;
}
.dream-input::placeholder {
    color: #6a7e6e;
    opacity: 1;
}
.dream-input:focus-visible {
    outline: 3px solid #b88e34;
    outline-offset: 3px;
    border-color: #67967a;
}
.dream-form.is-pending .dream-input {
    background: #f3f6f0;
    color: #4e6755;
}
.dream-form .dream-counter {
    min-height: 18px;
    margin: 4px 1px 0;
    color: #647966;
    font-size: 11px;
    line-height: 1.6;
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.dream-form .dream-privacy {
    margin: 6px 0 12px;
    color: #59715f;
    font-size: 12px;
    line-height: 1.65;
}
.dream-form .dream-submit {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    width: 100%;
    min-height: 48px;
    padding: 10px 12px;
    border: 1px solid #107657;
    border-radius: 11px;
    background: #107657;
    color: #fff;
    font-size: 15px;
    font-weight: 500;
}
.dream-form .dream-submit:not(:disabled):hover {
    background: #0b6549;
    border-color: #0b6549;
}
.dream-form.is-pending .dream-submit {
    opacity: .9;
    cursor: progress;
}
.dream-form.is-pending .dream-submit::after {
    content: '';
    flex: 0 0 24px;
    width: 24px;
    height: 5px;
    background: radial-gradient(circle, currentColor 2px, transparent 2.5px) 0 50% / 8px 5px repeat-x;
    opacity: .65;
    animation: rr-dream-pending 1200ms ease-in-out 25 both;
}
.dream-form .dream-status {
    min-height: 66px;
    margin: 9px 0 0;
    padding: 8px 9px;
    border: 1px solid transparent;
    border-radius: 9px;
    color: #755035;
    font-size: 12px;
    line-height: 1.65;
    overflow-wrap: anywhere;
}
.dream-form .dream-status:not(:empty) {
    border-color: #e4dcc8;
    background: #faf6ec;
}
.dream-form.is-pending .dream-status {
    border-color: #dbe6d6;
    background: #eef4e9;
    color: #45624a;
}
.fortune-result .dream-source-label {
    margin: 0 0 6px;
    color: #5a725f;
    font-size: 12px;
    font-weight: 500;
}
.fortune-result .dream-source-text {
    margin: 0 0 17px;
    padding: 10px 12px;
    border-left: 3px solid #b6c8aa;
    border-radius: 0 9px 9px 0;
    background: #eaf1e5;
    color: #45624a;
    font-size: 13px;
    line-height: 1.75;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.fortune-result[data-tool=dream] > p:not([class]) {
    font-size: 15px;
    line-height: 1.85;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.fortune-result .dream-ai-label {
    margin: 14px 0 5px;
    color: #5d755f;
    font-size: 12px;
    line-height: 1.65;
}

/* Real digit updates happen in JS; the short travel eases into a stable result. */
#numberDisplay {
    position: relative;
    isolation: isolate;
}
#numberDisplay::after {
    content: '';
    position: absolute;
    z-index: -1;
    inset: 18% 20% 0;
    border-radius: 50%;
    background: radial-gradient(ellipse, #bbd7af55, transparent 70%);
    pointer-events: none;
    opacity: 0;
}
#numberDisplay.is-rolling #selectedNumber {
    animation: rr-number-roll 720ms linear both;
}
#numberDisplay.is-revealed #selectedNumber {
    animation: rr-number-settle 300ms var(--rr-motion-out) both;
}
#numberDisplay.is-revealed::after {
    animation: rr-result-light 500ms ease-out both;
}
#numberDisplay.is-revealed ~ .rm-numbers > button {
    animation: rr-option-enter 250ms var(--rr-motion-out) both;
}
#numberDisplay.is-revealed ~ .rm-numbers > button:nth-child(n+6) {
    animation-delay: 45ms;
}

/* Two actual card faces, so only the chosen card turns over. */
.tarot-deck {
    perspective: 850px;
    overflow: visible;
}
.tarot-deck .tarot-back {
    position: relative;
    display: block;
    min-width: 0;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    -webkit-appearance: none;
    appearance: none;
    transition: opacity 220ms ease, transform 220ms var(--rr-motion-out);
}
.tarot-deck .tarot-back:hover {
    background: transparent;
}
.tarot-deck .tarot-back:disabled {
    opacity: 1;
}
.tarot-inner {
    position: absolute;
    inset: 0;
    display: block;
    border-radius: inherit;
    transform-style: preserve-3d;
}
.tarot-back .tarot-face {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 5px;
    border: 1px solid #c6ae72;
    border-radius: inherit;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}
.tarot-face-back {
    color: #e9d9ad;
    background: radial-gradient(ellipse at 50% 35%, #34765b 0, #164e3a 74%);
    box-shadow: inset 0 0 0 4px #164e3a, inset 0 0 0 5px #bfa76b;
}
.tarot-face-back::after {
    content: '';
    position: absolute;
    inset: 9px;
    border: 1px solid #dfce9b38;
    border-radius: 5px;
    pointer-events: none;
}
.tarot-face-front {
    transform: rotateY(180deg);
    color: #34634b;
    background: radial-gradient(ellipse at 50% 35%, #fffef5, #eee6ce);
    box-shadow: inset 0 0 0 4px #f4eedc, inset 0 0 0 5px #ccb987;
}
.tarot-back .tarot-face-front .mu-art {
    width: 46px;
    height: 46px;
}
.tarot-back .tarot-face-front span:not(.mu-art) {
    max-width: 100%;
    font-size: 10px;
    line-height: 1.4;
    text-align: center;
    overflow-wrap: anywhere;
}
.tarot-deck.is-selecting .tarot-back.is-muted {
    opacity: .42;
    transform: scale(.96);
}
.tarot-deck.is-selecting .tarot-back.is-selected {
    z-index: 2;
}
.tarot-back.is-selected .tarot-inner {
    animation: rr-card-turn 680ms var(--rr-motion-in-out) both;
}
@media (hover: hover) and (pointer: fine) {
    .tarot-deck:not(.is-selecting) .tarot-back:hover {
        transform: translateY(-3px);
    }
}

/* Keep the artwork anchored; a separate bamboo stick leaves the cup. */
.fortune-ritual {
    min-height: 190px;
    isolation: isolate;
}
.fortune-ritual::before {
    content: '';
    position: absolute;
    width: 128px;
    height: 17px;
    left: calc(50% - 64px);
    bottom: 14px;
    border-radius: 50%;
    background: radial-gradient(ellipse, #345a3921, transparent 72%);
    pointer-events: none;
}
.fortune-ritual.is-running::after {
    content: none;
    animation: none;
}
.siamsi-scene .siamsi-cup {
    position: absolute;
    z-index: 2;
    width: 142px;
    height: 142px;
    bottom: 15px;
    left: calc(50% - 71px);
    transform-origin: 50% 88%;
}
.siamsi-scene .siamsi-stick {
    position: absolute;
    z-index: 1;
    width: 11px;
    height: 94px;
    left: calc(50% - 5.5px);
    bottom: 42px;
    border: 1px solid #bc9258;
    border-radius: 5px 5px 2px 2px;
    background: linear-gradient(90deg, #c19c61, #f0d398 42%, #d9b77a);
    box-shadow: inset 1px 0 #fff2c66b;
    transform-origin: 50% 90%;
    opacity: 0;
}
.siamsi-scene .siamsi-stick::after {
    content: '';
    position: absolute;
    top: 10px;
    left: 3px;
    width: 3px;
    height: 14px;
    border-radius: 2px;
    background: #88794b;
    opacity: .55;
}
.fortune-ritual.siamsi-scene.is-running .siamsi-cup {
    animation: rr-cup-shake 650ms ease-in-out both;
}
.siamsi-scene.is-revealed .siamsi-cup {
    animation: rr-cup-rest 200ms var(--rr-motion-out) both;
}
.siamsi-scene.is-revealed .siamsi-stick {
    animation: rr-stick-eject 350ms cubic-bezier(.18, .7, .3, 1) both;
}

/* The incense illustration never drifts: ember and smoke are independent layers. */
.incense-scene .incense-smoke {
    position: absolute;
    z-index: 2;
    width: 142px;
    height: 142px;
    bottom: 10px;
    left: calc(50% - 71px);
}
.fortune-ritual.incense-scene.is-running .incense-smoke,
.fortune-ritual.incense-scene.is-revealed .incense-smoke {
    animation: none;
    transform: none;
}
.incense-ember {
    position: absolute;
    z-index: 3;
    width: 5px;
    height: 5px;
    bottom: 102px;
    left: calc(50% - 2px);
    border-radius: 50%;
    background: #f7bf68;
    box-shadow: 0 0 0 3px #d8893c33, 0 0 12px 3px #e9a34566;
    opacity: 0;
}
.incense-curl {
    --curl-x: -9px;
    --curl-drift: -16px;
    position: absolute;
    z-index: 3;
    width: 22px;
    height: 44px;
    left: calc(50% - 11px);
    bottom: 104px;
    border-left: 2px solid #6d8c736b;
    border-top: 1px solid transparent;
    border-radius: 48% 0 0 52%;
    transform-origin: 50% 100%;
    pointer-events: none;
    opacity: 0;
}
.incense-curl::after {
    content: '';
    position: absolute;
    width: 15px;
    height: 39px;
    top: -25px;
    left: -3px;
    border-right: 1px solid #a1b19b8c;
    border-radius: 0 65% 55% 0;
}
.incense-curl:nth-last-child(2) {
    --curl-x: 5px;
    --curl-drift: 11px;
    height: 38px;
    border-left-color: #9aa48d80;
}
.incense-curl:last-child {
    --curl-x: 14px;
    --curl-drift: 23px;
    height: 32px;
    border-left-color: #7d998866;
}
.incense-scene:is(.is-running, .is-revealed) .incense-ember {
    animation: rr-ember-light 1200ms ease-in-out both;
}
.incense-scene:is(.is-running, .is-revealed) .incense-curl {
    animation: rr-incense-rise 1120ms cubic-bezier(.24, .4, .42, 1) both;
}
.incense-scene:is(.is-running, .is-revealed) .incense-curl:nth-last-child(2) {
    animation-delay: 60ms;
}
.incense-scene:is(.is-running, .is-revealed) .incense-curl:last-child {
    animation-delay: 120ms;
}

@keyframes rr-panel-enter {
    from { opacity: 0; transform: translateY(7px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes rr-dream-pending {
    0%, 100% { opacity: .45; }
    50% { opacity: 1; }
}
@keyframes rr-result-enter {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes rr-number-roll {
    0% { transform: translateY(2px); opacity: .65; }
    14%, 36% { transform: translateY(-2px); opacity: .8; }
    24%, 49% { transform: translateY(2px); opacity: .8; }
    66% { transform: translateY(-1px); opacity: .9; }
    82% { transform: translateY(1px); opacity: .95; }
    100% { transform: translateY(0); opacity: 1; }
}
@keyframes rr-number-settle {
    from { opacity: .45; transform: translateY(9px) scale(.96); }
    70% { opacity: 1; transform: translateY(-1px) scale(1.015); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes rr-result-light {
    0% { opacity: 0; transform: scale(.85); }
    45% { opacity: 1; }
    100% { opacity: 0; transform: scale(1.15); }
}
@keyframes rr-option-enter {
    from { opacity: .2; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes rr-card-turn {
    0% { transform: translateY(0) rotateY(0); }
    20% { transform: translateY(-6px) rotateY(-12deg); }
    78% { transform: translateY(-6px) rotateY(180deg); }
    100% { transform: translateY(-3px) rotateY(180deg); }
}
@keyframes rr-cup-shake {
    0%, 100% { transform: translateX(0) rotate(0); }
    13% { transform: translateX(-3px) rotate(-7deg); }
    29% { transform: translateX(3px) rotate(7deg); }
    45% { transform: translateX(-3px) rotate(-6deg); }
    62% { transform: translateX(2px) rotate(5deg); }
    80% { transform: translateX(-1px) rotate(-3deg); }
}
@keyframes rr-cup-rest {
    from { transform: translateY(1px); }
    to { transform: translateY(0); }
}
@keyframes rr-stick-eject {
    0% { opacity: 0; transform: translate(0, 0) rotate(0); }
    15% { opacity: 1; }
    62% { opacity: 1; transform: translate(14px, -43px) rotate(12deg); }
    100% { opacity: 1; transform: translate(26px, -38px) rotate(20deg); }
}
@keyframes rr-ember-light {
    0% { opacity: 0; transform: scale(.4); }
    18% { opacity: 1; transform: scale(1.25); }
    40% { opacity: .75; transform: scale(.95); }
    74% { opacity: 1; transform: scale(1.1); }
    100% { opacity: .3; transform: scale(.8); }
}
@keyframes rr-incense-rise {
    0% { opacity: 0; transform: translate(var(--curl-x), 16px) scale(.55, .6) rotate(-4deg); }
    22% { opacity: .75; }
    68% { opacity: .6; }
    100% { opacity: 0; transform: translate(var(--curl-drift), -27px) scale(1.15, 1.1) rotate(8deg); }
}

@media (max-width: 380px) {
    .tarot-back .tarot-face { padding: 8px 4px; gap: 5px; }
    .tarot-back .tarot-face .mu-art { width: 43px; height: 43px; }
    .fortune-ritual { min-height: 182px; }
}

/* No control is needed; both device preference and the shared JS flag are honored. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
    .tarot-back.is-selected .tarot-inner { transform: rotateY(180deg); }
    .incense-curl, .incense-ember, .siamsi-stick { display: none; }
}
html[data-reduced-motion=true] *,
html[data-reduced-motion=true] *::before,
html[data-reduced-motion=true] *::after {
    animation: none !important;
    transition: none !important;
}
html[data-reduced-motion=true] .tarot-back.is-selected .tarot-inner { transform: rotateY(180deg); }
html[data-reduced-motion=true] :is(.incense-curl, .incense-ember, .siamsi-stick) { display: none; }
