/* TOMBOLA CSS — The Poetry Machine
   Realism / depth pass: richer materials, specular highlights, subtle 3D tilt hooks.
*/

/* Page backdrop (only Poëzie page) */
body.word-page {
    background:
        radial-gradient(900px 520px at 50% -10%, rgba(250, 204, 21, 0.12), transparent 55%),
        radial-gradient(760px 520px at 18% 25%, rgba(168, 85, 247, 0.12), transparent 55%),
        radial-gradient(820px 520px at 82% 35%, rgba(59, 130, 246, 0.10), transparent 58%),
        linear-gradient(180deg, #050816 0%, #020617 55%, #020617 100%);
}

/* Container */
.tombola-wrapper {
    --tilt-x: 0deg;
    --tilt-y: 0deg;
    --light-x: 50%;
    --light-y: 22%;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 40px auto 20px;
    max-width: 600px;
    position: relative;
    user-select: none;

    transform-style: preserve-3d;
    transform: perspective(1100px) rotateX(var(--tilt-x)) rotateY(var(--tilt-y));
    will-change: transform;

    filter: drop-shadow(0 24px 46px rgba(0, 0, 0, 0.55));
}

.tombola-wrapper.is-spinning {
    filter:
        drop-shadow(0 18px 38px rgba(250, 204, 21, 0.12))
        drop-shadow(0 28px 52px rgba(0, 0, 0, 0.65));
}

/* The Machine Base */
.machine-base {
    width: 300px;
    height: 120px;
    background:
        radial-gradient(120px 60px at 25% 25%, rgba(255, 255, 255, 0.18), transparent 60%),
        radial-gradient(140px 70px at 70% 35%, rgba(59, 130, 246, 0.18), transparent 65%),
        linear-gradient(135deg, #1e3a8a 0%, #172554 100%);
    border-radius: 20px 20px 44px 44px;
    position: relative;
    box-shadow:
        inset 0 10px 18px rgba(255, 255, 255, 0.18),
        inset 0 -18px 24px rgba(0, 0, 0, 0.55),
        0 12px 26px rgba(0, 0, 0, 0.65);
    border: 1px solid rgba(255, 255, 255, 0.10);
    z-index: 10;
    margin-top: -40px;
}

.machine-base::before {
    content: '';
    position: absolute;
    inset: 10px 12px auto;
    height: 26px;
    border-radius: 18px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.20), rgba(255, 255, 255, 0));
    opacity: 0.55;
    pointer-events: none;
}

.machine-base::after {
    content: '';
    position: absolute;
    left: 18px;
    right: 18px;
    bottom: 12px;
    height: 16px;
    border-radius: 9999px;
    background: radial-gradient(circle at 50% 40%, rgba(0, 0, 0, 0.18), rgba(0, 0, 0, 0.65));
    opacity: 0.65;
    pointer-events: none;
}

/* The Cage */
.cage-container {
    position: relative;
    width: 240px;
    height: 240px;
    z-index: 20;
}

.cage {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 8px solid rgba(226, 232, 240, 0.92);
    background:
        radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.16), rgba(0, 0, 0, 0.55)),
        radial-gradient(circle at 70% 80%, rgba(59, 130, 246, 0.10), transparent 55%);
    position: relative;
    overflow: hidden;
    box-shadow:
        inset 0 0 28px rgba(0, 0, 0, 0.55),
        0 12px 28px rgba(0, 0, 0, 0.45);
}

/* Wire grid */
.cage::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        linear-gradient(90deg, transparent 48%, rgba(226, 232, 240, 0.22) 50%, transparent 52%),
        linear-gradient(0deg, transparent 48%, rgba(226, 232, 240, 0.22) 50%, transparent 52%);
    background-size: 38px 38px;
    border-radius: 50%;
    pointer-events: none;
    opacity: 0.9;
}

/* Glass reflection */
.cage::after {
    content: '';
    position: absolute;
    inset: -2px;
    border-radius: 50%;
    background:
        radial-gradient(circle at var(--light-x) var(--light-y), rgba(255, 255, 255, 0.65), rgba(255, 255, 255, 0) 46%),
        radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.18), transparent 60%);
    opacity: 0.85;
    mix-blend-mode: screen;
    pointer-events: none;
}

.ball-pool {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
}

.ball {
    position: absolute;
    width: 24px;
    height: 24px;
    border-radius: 50%;

    background:
        radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.98) 0%, rgba(255, 255, 255, 0.72) 18%, rgba(226, 232, 240, 0.70) 42%, rgba(71, 85, 105, 0.95) 100%);

    border: 1px solid rgba(255, 255, 255, 0.55);

    box-shadow:
        0 10px 18px rgba(0, 0, 0, 0.34),
        inset 0 -10px 16px rgba(0, 0, 0, 0.25);

    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    color: rgba(15, 23, 42, 0.88);

    will-change: transform;
    transition: transform 320ms cubic-bezier(0.22, 1, 0.36, 1), opacity 320ms ease;
}

.ball::after {
    content: '';
    position: absolute;
    top: 4px;
    left: 5px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0));
    opacity: 0.85;
    pointer-events: none;
}

.cage.spinning .ball {
    transition: none;
}

.cage.spinning {
    animation: cageShake 420ms infinite linear;
}

.cage.spinning .ball-pool {
    animation: drumRotate 900ms linear infinite;
}

/* Handle */
.handle-connect {
    position: absolute;
    right: -20px;
    top: 50%;
    width: 30px;
    height: 10px;
    background: linear-gradient(180deg, rgba(226, 232, 240, 0.65), rgba(71, 85, 105, 0.8));
    z-index: 5;
    border-radius: 9999px;
    box-shadow: inset 0 -6px 10px rgba(0, 0, 0, 0.35);
}

.handle-arm {
    position: absolute;
    right: -54px;
    top: 50%;
    width: 44px;
    height: 8px;
    background: linear-gradient(180deg, rgba(30, 41, 59, 1), rgba(15, 23, 42, 1));
    transform-origin: 0% 50%;
    transform: rotate(0deg);
    transition: transform 0.1s linear;
    z-index: 5;
    border-radius: 9999px;
}

.handle-knob {
    position: absolute;
    right: -12px;
    top: -10px;
    width: 24px;
    height: 24px;
    background:
        radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.25), rgba(0, 0, 0, 0.85)),
        radial-gradient(circle at 50% 70%, rgba(239, 68, 68, 0.8), rgba(127, 29, 29, 0.9));
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.18);
}

.handle-arm.cranking {
    animation: crank 520ms infinite linear;
}

/* The Chute */
.chute {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 42px;
    height: 64px;
    background:
        repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.10) 0 1px, rgba(255, 255, 255, 0) 2px 6px),
        linear-gradient(90deg, #111827, #64748b, #0f172a);
    z-index: 15;
    border-radius: 0 0 12px 12px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: inset 0 -12px 16px rgba(0, 0, 0, 0.55);
}

/* Controls */
.controls-area {
    margin-top: 10px;
    margin-bottom: 18px;
    text-align: center;
    z-index: 30;
}

.spin-btn {
    background: #eab308;
    color: #000;
    font-family: 'Besley', serif;
    font-weight: 900;
    padding: 15px 40px;
    font-size: 1.2rem;
    border-radius: 50px;
    border: 1px solid rgba(0, 0, 0, 0.25);
    cursor: pointer;
    box-shadow:
        0 4px 0 #a16207,
        0 16px 30px rgba(0, 0, 0, 0.45);
    transition: transform 120ms ease, filter 120ms ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.spin-btn:hover {
    filter: brightness(1.05);
}

.spin-btn:active {
    transform: translateY(4px);
    box-shadow:
        0 0 0 #a16207,
        0 10px 18px rgba(0, 0, 0, 0.5);
}

.spin-btn:disabled {
    background: #94a3b8;
    box-shadow: none;
    transform: translateY(4px);
    cursor: not-allowed;
    opacity: 0.9;
}

/* --- PIPE SYSTEM --- */
.pipe-stage {
    width: 100%;
    max-width: 720px;
    margin: 0 auto 60px;
    padding: 0 8px;
}

.pipe-system {
    --light-x: 50%;
    --light-y: 22%;

    position: relative;
    width: min(640px, 100%);
    height: 420px;
    margin: 0 auto;
    border-radius: 18px;

    background:
        radial-gradient(circle at var(--light-x) var(--light-y), rgba(250, 204, 21, 0.08), transparent 55%),
        linear-gradient(180deg, rgba(15, 23, 42, 0.60) 0%, rgba(2, 6, 23, 0.94) 100%);

    border: 1px solid rgba(148, 163, 184, 0.35);

    box-shadow:
        inset 0 0 0 1px rgba(0, 0, 0, 0.55),
        inset 0 0 80px rgba(0, 0, 0, 0.45),
        0 18px 50px rgba(0, 0, 0, 0.55);

    overflow: hidden;
}

.pipe-system::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.035) 0 1px, rgba(255, 255, 255, 0) 2px 8px),
        radial-gradient(circle at 75% 85%, rgba(59, 130, 246, 0.10), transparent 55%);
    opacity: 0.55;
    pointer-events: none;
}

.pipe {
    position: absolute;
    height: 52px;
    width: 88%;

    background:
        repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.07) 0 1px, rgba(255, 255, 255, 0) 2px 7px),
        linear-gradient(180deg, #738197 0%, #2f3a4a 55%, #111827 100%);

    border-radius: 9999px;
    border: 1px solid rgba(226, 232, 240, 0.18);
    box-shadow:
        inset 0 12px 18px rgba(255, 255, 255, 0.08),
        inset 0 -14px 18px rgba(0, 0, 0, 0.46),
        0 12px 30px rgba(0, 0, 0, 0.55);
}

.pipe::after {
    content: '';
    position: absolute;
    inset: 10px 14px;
    border-radius: 9999px;
    background:
        radial-gradient(circle at 40% 30%, rgba(255, 255, 255, 0.08), rgba(0, 0, 0, 0) 55%),
        linear-gradient(180deg, rgba(0, 0, 0, 0.78), rgba(255, 255, 255, 0.05));
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.pipe-1 { top: 28px; left: 4%; }
.pipe-2 { top: 128px; right: 4%; }
.pipe-3 { top: 228px; left: 4%; }
.pipe-4 { top: 328px; right: 4%; }

.pipe-connector {
    position: absolute;
    width: 62px;
    background:
        repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.06) 0 1px, rgba(255, 255, 255, 0) 2px 7px),
        linear-gradient(180deg, #738197 0%, #2f3a4a 55%, #111827 100%);
    border-radius: 9999px;
    border: 1px solid rgba(226, 232, 240, 0.16);
    box-shadow:
        inset 0 10px 18px rgba(255, 255, 255, 0.07),
        inset 0 -10px 18px rgba(0, 0, 0, 0.45);
}

.connector-1 { top: 76px; right: 4%; height: 74px; }
.connector-2 { top: 176px; left: 4%; height: 74px; }
.connector-3 { top: 276px; right: 4%; height: 74px; }

.pipe-exit {
    position: absolute;
    left: 50%;
    bottom: 64px;
    transform: translateX(-50%);
    width: 62px;
    height: 20px;
    border-radius: 9999px;
    background: radial-gradient(circle at 50% 30%, rgba(255, 255, 255, 0.14), rgba(0, 0, 0, 0.88));
    box-shadow: inset 0 10px 16px rgba(0, 0, 0, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.pipe-platform {
    position: absolute;
    left: 50%;
    bottom: 22px;
    transform: translateX(-50%);
    width: 180px;
    height: 28px;
    border-radius: 14px;
    background:
        repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.10) 0 1px, rgba(255, 255, 255, 0) 2px 9px),
        linear-gradient(180deg, rgba(250, 204, 21, 0.95), rgba(161, 98, 7, 0.88));
    border: 1px solid rgba(255, 255, 255, 0.22);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.55);
}

.pipe-platform::after {
    content: '';
    position: absolute;
    inset: 6px 12px;
    border-radius: 10px;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.28), rgba(255, 255, 255, 0.16));
}

.pipe-ball {
    --x: 0px;
    --y: 0px;

    position: absolute;
    left: 0;
    top: 0;
    width: 36px;
    height: 36px;
    transform: translate3d(var(--x), var(--y), 0);
    transition: transform 400ms linear;
    z-index: 30;

    cursor: pointer;
    outline: none;

    pointer-events: none;
}

.pipe-ball::after {
    content: '';
    position: absolute;
    left: 50%;
    bottom: -10px;
    width: 26px;
    height: 12px;
    transform: translateX(-50%);
    background: radial-gradient(circle at 50% 50%, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0));
    filter: blur(3px);
    opacity: 0.7;
    pointer-events: none;
}

.pipe-ball.is-arrived {
    pointer-events: auto;
}

.pipe-ball:focus-visible {
    outline: 3px solid rgba(250, 204, 21, 0.7);
    outline-offset: 4px;
}

.pipe-ball__shell {
    width: 100%;
    height: 100%;
    border-radius: 9999px;

    background:
        radial-gradient(circle at 35% 35%, rgba(255, 255, 255, 1) 0%, rgba(250, 204, 21, 0.95) 40%, rgba(202, 138, 4, 0.98) 100%);

    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.55);
    border: 2px solid rgba(255, 255, 255, 0.78);

    display: grid;
    place-items: center;

    position: relative;
    overflow: hidden;
}

.pipe-ball__spin {
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
}

.pipe-ball__spec {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0) 40%),
        radial-gradient(circle at 65% 70%, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0) 55%);
    opacity: 0.8;
    mix-blend-mode: screen;
    pointer-events: none;
}

.pipe-ball__num {
    font-weight: 900;
    font-size: 12px;
    color: #422006;
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.65);
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

.pipe-ball.is-moving .pipe-ball__spin {
    animation: pipeSpin 340ms linear infinite;
}

.pipe-ball.is-bump .pipe-ball__shell {
    animation: ballSquish 260ms cubic-bezier(0.22, 1, 0.36, 1);
}

.pipe-ball.is-arrived .pipe-ball__shell {
    box-shadow:
        0 0 0 10px rgba(250, 204, 21, 0.18),
        0 16px 28px rgba(0, 0, 0, 0.65);
}

.pipe-ball.is-arrived::after {
    opacity: 0.55;
}

.pipe-hint {
    margin-top: 10px;
    text-align: center;
    color: rgba(226, 232, 240, 0.78);
    font-size: 0.85rem;
}

/* --- MEMO OVERLAY --- */
.poem-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 20px;
    background: rgba(0, 0, 0, 0.80);

    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
}

.poem-overlay.is-open {
    opacity: 1;
    pointer-events: auto;
}

.poem-memo {
    width: min(560px, 100%);
    max-height: 85vh;
    overflow: auto;

    position: relative;
    padding: 22px 22px 26px;

    background:
        linear-gradient(180deg, rgba(0, 0, 0, 0.08), rgba(0, 0, 0, 0.02)),
        #fef9c3;

    border: 1px solid rgba(120, 113, 108, 0.5);
    box-shadow: 0 25px 70px rgba(0, 0, 0, 0.75);
    transform: rotate(-0.6deg);
    border-radius: 14px;
}

.poem-memo::before {
    content: '';
    position: absolute;
    top: -18px;
    left: 50%;
    transform: translateX(-50%);
    width: 140px;
    height: 42px;
    background: rgba(255, 255, 255, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.12);
}

.poem-close-btn {
    position: absolute;
    top: 12px;
    right: 14px;

    border: none;
    background: transparent;
    cursor: pointer;

    font-size: 22px;
    font-weight: 900;
    color: rgba(66, 32, 6, 0.8);
}

.poem-close-btn:hover {
    color: rgba(0, 0, 0, 0.92);
}

.poem-badge {
    display: inline-flex;
    align-items: center;
    gap: 10px;

    padding: 8px 12px;
    border-radius: 9999px;

    background: rgba(0, 0, 0, 0.85);
    color: rgba(255, 255, 255, 0.92);
    font-weight: 900;
    font-size: 0.85rem;

    margin-bottom: 14px;
}

.poem-title {
    margin: 0 0 14px;
    font-family: 'Besley', serif;
    font-weight: 900;
    font-size: 1.6rem;
    color: rgba(0, 0, 0, 0.95);
}

.poem-body {
    white-space: pre-wrap;
    font-family: 'Besley', serif;
    font-size: 1.05rem;
    line-height: 1.65;
    color: rgba(0, 0, 0, 0.82);
}

/* Animations */
@keyframes cageShake {
    0% { transform: rotate(0deg) translate3d(0, 0, 0); }
    20% { transform: rotate(3deg) translate3d(1px, -1px, 0); }
    50% { transform: rotate(-2deg) translate3d(-1px, 1px, 0); }
    80% { transform: rotate(2deg) translate3d(1px, 1px, 0); }
    100% { transform: rotate(0deg) translate3d(0, 0, 0); }
}

@keyframes drumRotate {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes crank {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes pipeSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes ballSquish {
    0% { transform: scale(1); }
    30% { transform: scaleX(1.22) scaleY(0.82); }
    60% { transform: scaleX(0.94) scaleY(1.08); }
    100% { transform: scale(1); }
}

@media (max-width: 420px) {
    .pipe-system {
        height: 390px;
    }

    .pipe {
        height: 48px;
    }

    .pipe-ball {
        width: 34px;
        height: 34px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .tombola-wrapper {
        transform: none !important;
    }

    .cage.spinning,
    .cage.spinning .ball-pool,
    .handle-arm.cranking,
    .pipe-ball.is-moving .pipe-ball__spin {
        animation: none !important;
    }
}
