html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    overflow-x: hidden;
    overflow-y: hidden;
    overscroll-behavior: none;
    overscroll-behavior-x: none;
    overscroll-behavior-y: none;
    -webkit-overflow-scrolling: auto;
    background-color: #121212;
    color: #fff;
    touch-action: none;
}

:root {
    --theme-glow-color: #4a4d52;
    /* Ominous chrome-grey default; API updates RGB on divination */
    --theme-glow-rgb: 74, 77, 82;
    --keyboard-offset: 0px;
    /* Move ball + prompt block down without scroll */
    --layout-shift-down: 15vh;
}

.app-shell {
    position: relative;
    isolation: isolate;
    height: 100dvh;
    max-height: 100dvh;
    min-height: 0;
    width: 100%;
    max-width: 100vw;
    overflow: hidden;
    box-sizing: border-box;
    background: transparent;
}

/* Ominous chrome radial: cool grey center → deep charcoal edge */
.mystic-background {
    width: 100%;
    height: 100%;
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    transition: background 2s ease-in-out;
    background: radial-gradient(ellipse 203% 156% at 50% 63%,
            rgba(120, 122, 128, 0.22) 0%,
            rgba(var(--theme-glow-rgb), 0.42) 12%,
            rgba(var(--theme-glow-rgb), 0.22) 32%,
            rgba(28, 30, 34, 0.88) 62%,
            rgba(10, 10, 12, 0.98) 100%);
}

.noise {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background: url('https://raw.githubusercontent.com/pixelass/noise-filter/master/noise.png');
    opacity: 0.04;
    pointer-events: none;
    z-index: 40;
}

.fate-text {
    text-shadow: 0 0 10px rgba(34, 211, 238, 0.8), 0 0 20px rgba(34, 211, 238, 0.4);
    filter: blur(0.5px);
}

.fate-omen {
    font-family: "Press Start 2P", system-ui;
    font-weight: 400;
    font-size: 0.85rem;
    letter-spacing: 0.01em;
    color: #22d3ee;
    max-width: min(74vw, 420px);
    line-height: 1.6;
}

.dare-line {
    font-size: 0.75rem;
    font-weight: 300;
    font-style: italic;
    color: #fff;
    margin-top: 0.5rem;
    max-width: min(74vw, 420px);
    line-height: 1.35;
}

#display-window {
    width: 260px;
    height: 220px;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -48%);
}

#magic-8-ball {
    height: 64%;
    width: 100%;
    max-height: min(68vh, 950px);
    transition: transform 0.28s ease, height 0.28s ease, max-height 0.28s ease;
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 0.28rem;
    width: 100%;
}

#destiny-input {
    box-sizing: border-box;
    flex: 1;
    min-width: 0;
    line-height: 1.2;
    padding: 1.08rem 0;
    font-family: "Avenir Next", "Inter", "Helvetica Neue", Arial, sans-serif;
    font-size: 1.3rem;
    letter-spacing: 0.01em;
    text-align: center;
    color: #fff;
    border: 0;
    border-bottom: 2px solid rgba(255, 255, 255, 0.42);
    background: transparent;
    outline: none;
    transition: border-color 0.25s ease;
}

.ask-submit {
    flex-shrink: 0;
    align-self: flex-end;
    margin-bottom: 0.38rem;
    padding: 0.54rem 0.9rem;
    font-family: "Avenir Next", "Inter", "Helvetica Neue", Arial, sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.95);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.14) 0%, rgba(255, 255, 255, 0.06) 100%);
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.12);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.ask-submit:hover {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.2) 0%, rgba(255, 255, 255, 0.1) 100%);
    border-color: rgba(138, 180, 248, 0.55);
}

.ask-submit:active {
    background: rgba(255, 255, 255, 0.12);
    transform: translateY(1px);
}

#destiny-input:focus {
    border-bottom-color: #8ab4f8;
}

#destiny-input::placeholder {
    color: transparent;
}

/* Hide model-viewer AR utility controls for a seamless page feel. */
#magic-8-ball::part(ar-button),
#magic-8-ball::part(default-ar-button) {
    display: none !important;
}

.ritual-intro {
    position: absolute;
    top: 2rem;
    left: 0;
    z-index: 30;
    width: 100%;
    color: rgba(255, 255, 255, 0.88);
    font-family: "IBM Plex Mono", monospace;
    max-width: min(52vw, 50rem);
    padding: 0.39rem 1rem;
    text-align: left;
}

/* Desktop default (1150px+): original sizes — perfect at full width */
.intro-title {
    font-size: clamp(1.35rem, 2vw, 1.75rem);
    font-weight: bolder;
    line-height: 1.3;
    margin-bottom: 0.84rem;
    color: #c9f8ff;
    text-shadow: 0 0 8px rgba(34, 211, 238, 0.35);
}

.intro-content {
    font-size: clamp(1.16rem, 1.49vw, 1.41rem);
    line-height: 1.4;
    margin-bottom: 1.4rem;
    color: rgba(230, 240, 255, 0.9);
}

.choose-fate-copy {
    font-family: "IBM Plex Mono", monospace;
    font-size: clamp(1.32rem, 1.58vw, 1.64rem);
    font-weight: 700;
    text-transform: uppercase;
    line-height: 1.2;
    color: rgba(255, 255, 255, 0.82);
    text-shadow: 0 0 8px rgba(34, 211, 238, 0.22);
    margin-top: 0.96rem;
}

.rules-container {
    max-width: 42rem;
    font-size: clamp(1.32rem, 1.58vw, 1.64rem);
    line-height: 1.4;
    margin: 0;
}

.rule {
    font-size: clamp(0.89rem, 1.09vw, 1.13rem);
    line-height: 1.35;
    margin-bottom: 1rem;
    opacity: 0;
    animation: reveal 0.8s ease-out forwards;
}

.rule-1 {
    animation-delay: 0.5s;
}

.rule-2 {
    animation-delay: 1.2s;
}

.rule-3 {
    animation-delay: 2.5s;
}

@keyframes reveal {
    from {
        opacity: 0;
        transform: translateY(10px);
        filter: blur(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
        filter: blur(0);
    }
}

.ball-stage {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: calc(18vh + var(--layout-shift-down));
    padding-bottom: 20vh;
    z-index: 30;
}

.prompt-area {
    position: fixed;
    bottom: max(0.75rem,
            calc(4.3rem + 12vh - var(--layout-shift-down) + env(safe-area-inset-bottom) + var(--keyboard-offset)));
    left: 50%;
    transform: translateX(-50%);
    /* 10% narrower line: was 74vw / 660px → ×0.8 */
    width: min(59.2vw, 528px);
    text-align: center;
    z-index: 30;
    box-sizing: border-box;
}

.input-shell {
    position: relative;
    width: 100%;
}

.prompt-overlay {
    position: absolute;
    left: 0;
    right: 4.35rem;
    top: 50%;
    transform: translateY(-50%);
    margin: 0;
    pointer-events: none;
    color: rgba(255, 255, 255, 0.74);
    font-family: "Avenir Next", "Inter", "Helvetica Neue", Arial, sans-serif;
    font-size: 1.04rem;
    letter-spacing: 0.01em;
    text-align: center;
    padding: 0 0.25rem;
    box-sizing: border-box;
}

.terminal-cursor {
    animation: blink-cursor 0.8s steps(1, end) infinite;
}

@keyframes blink-cursor {
    50% {
        opacity: 0;
    }
}

.keyboard-open #magic-8-ball {
    transform: scale(0.9);
}

/* Small desktop window (769–1149px): ~2× font sizes for legibility when minimized */
@media (min-width: 769px) and (max-width: 1149px) {
    .intro-title {
        font-size: clamp(2.0rem, 2.5vw, 2.5rem);
    }

    .intro-content {
        font-size: clamp(1.7rem, 2.0vw, 2.0rem);
    }

    .rule {
        font-size: clamp(1.3rem, 1.5vw, 1.6rem);
    }

    /* ball + form + choose-fate-copy shifted ~20% right of center */
    .ball-stage {
        justify-content: flex-end;
        padding-right: 10vw;
    }

    #display-window {
        left: 70vw;
    }

    .prompt-area {
        left: 70vw;
    }

    .mystic-background {
        background: radial-gradient(ellipse 203% 156% at 70% 58%,
                rgba(120, 122, 128, 0.22) 0%,
                rgba(var(--theme-glow-rgb), 0.42) 12%,
                rgba(var(--theme-glow-rgb), 0.22) 32%,
                rgba(28, 30, 34, 0.88) 62%,
                rgba(10, 10, 12, 0.98) 100%);
    }
}

/* Min desktop: ball fills ~40% vertical, centered */
@media (min-width: 769px) {
    #magic-8-ball {
        height: 100%;
        max-height: min(80vh, 1140px);
    }

    /* top: 48% centers omen+dare on the ball's rendered face (3D model renders slightly above geometric center).
       height: auto + translate(-50%,-50%) keeps both texts contained together on the ball face. */
    #display-window {
        top: 35%;
        height: auto;
        transform: translate(-50%, -50%);
        z-index: 40;
    }
}

/* Large desktop: ball + form column centered at 75vw (~20% right of prior 63vw position) */
@media (min-width: 1150px) {

    /* padding-right positions ball center at 75vw: 100 - 5 - 20 = 75 */
    .ball-stage {
        justify-content: flex-end;
        padding-right: 5vw;
    }

    /* ball +20% larger: 33vw → 40vw, max-height +20% */
    #magic-8-ball {
        height: 180%;
        max-height: min(94vh, 1176px);
        width: 40vw;
        max-width: 648px;
        padding-bottom: 15rem;
    }

    /* display window centered at 75vw, vertically on ball face */
    #display-window {
        left: 75vw;
        top: 35%;
        transform: translate(-50%, -50%);
    }

    /* prompt area centered at 75vw, width matches ball column */
    .prompt-area {
        left: 75vw;
        width: min(40vw, 648px);
        bottom: max(2rem, calc(2.5rem + env(safe-area-inset-bottom)));
    }

    /* gradient origin at 75%, ellipse +20% larger */
    .mystic-background {
        background: radial-gradient(ellipse 108% 158% at 75% 58%,
                rgba(120, 122, 128, 0.22) 0%,
                rgba(var(--theme-glow-rgb), 0.42) 12%,
                rgba(var(--theme-glow-rgb), 0.22) 32%,
                rgba(28, 30, 34, 0.88) 62%,
                rgba(10, 10, 12, 0.98) 100%);
    }
}

@media (max-width: 768px) {

    /* near-zero padding lets title span full phone width */
    .ritual-intro {
        max-width: 100%;
        width: 100%;
        padding: 0.16rem 0.2rem;
        top: 0.35rem;
        max-height: 54vh;
        overflow: hidden;
        pointer-events: none;
    }

    /* aligned left with content/rules; font keeps 2-line target */
    .intro-title {
        font-size: clamp(0.95rem, 2.1vw, 0.95rem);
        line-height: 1.25;
        margin-top: 1.53rem;
        margin-left: 0.6rem;
        margin-right: 0.6rem;
        margin-bottom: 0.9rem;
    }

    .intro-content {
        font-size: clamp(0.68rem, 1.75vw, 0.68rem);
        line-height: 1.3;
        margin-top: 0.9rem;
        margin-left: 0.6rem;
        margin-right: 0.6rem;
        margin-bottom: 0.4rem;
        padding-bottom: 0.5rem;
    }

    /* rules font -10% (mobile only) */
    .rule {
        font-size: clamp(0.68rem, 1.45vw, 1.03rem);
        line-height: 1.35;
        margin-top: 0.4rem;
        margin-left: 0.6rem;
        margin-right: 0.6rem;
        margin-bottom: 0.12rem;
    }

    /* overlay ON TOP of ball; top tracks ball window face with larger ball */
    #display-window {
        width: min(76.8vw, 300px);
        height: auto;
        min-height: 120px;
        top: calc(37vh + var(--layout-shift-down));
        left: 50%;
        transform: translate(-50%, -50%);
        padding: 0.35rem 0.5rem;
        box-sizing: border-box;
        overflow: visible;
        z-index: 50;
    }

    .fate-omen {
        font-size: 1.125rem;
        max-width: min(76.8vw, 300px);
    }

    .dare-line {
        max-width: min(76.8vw, 300px);
    }

    /* ball +30% more; bottom padding keeps it clear of input */
    .ball-stage {
        padding-top: calc(17vh + var(--layout-shift-down));
        padding-bottom: 15vh;
    }

    #magic-8-ball {
        height: 85%;
        max-height: min(90vh, 1040px);
    }

    .input-row {
        gap: 0.22rem;
    }

    /* 10% shorter input line (96vw×0.8); block shifted down with --layout-shift-down */
    .prompt-area {
        width: 76.8vw;
        max-width: 76.8vw;
        bottom: max(0.75rem,
                calc(2.4rem + env(safe-area-inset-bottom) + var(--keyboard-offset)));
        padding-left: 0;
        padding-right: 0;
    }

    /* input ~10% smaller */
    #destiny-input {
        font-size: 1.08rem;
        line-height: 1.1;
        padding: 0.6rem 0;
    }

    .prompt-overlay {
        font-size: 1rem;
        line-height: 1.2;
        right: 3.35rem;
        left: 0;
        text-align: center;
        padding-right: 0.1rem;
    }

    /* sized to guarantee single line within 76.8vw container */
    .choose-fate-copy {
        margin-top: 0.4rem;
        font-size: 1.0rem;
        white-space: nowrap;
    }

    .shake-hint {
        font-size: 0.48rem;
        margin-top: 0.35rem;
    }

    /* button ~10% wider horizontally */
    .ask-submit {
        font-size: 0.74rem;
        padding: 0.46rem 0.73rem;
    }

    html,
    body {
        overflow-x: hidden;
        overflow-y: hidden;
        overscroll-behavior-x: none;
        overscroll-behavior-y: none;
        max-width: 100vw;
    }
}