:root {
    --ink: #f7f1e8;
    --paper: #fff8ed;
    --charcoal: #151316;
    --black: #070607;
    --midnight: #151011;
    --blood: #8f1022;
    --crimson: #d41f3d;
    --gold: #f3c15d;
    --rose: #b51942;
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--ink);
    background:
        radial-gradient(circle at 18% 12%, rgba(212, 31, 61, 0.34), transparent 23rem),
        radial-gradient(circle at 84% 8%, rgba(243, 193, 93, 0.16), transparent 18rem),
        linear-gradient(135deg, #040404 0%, #17080c 44%, #090909 100%);
    overflow-x: hidden;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background:
        linear-gradient(90deg, rgba(212, 31, 61, 0.08), transparent 18%, transparent 82%, rgba(212, 31, 61, 0.08)),
        repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 72px);
    mask-image: linear-gradient(to bottom, #000, transparent 82%);
}

button {
    font: inherit;
}

.table {
    position: relative;
    width: min(1180px, calc(100% - 28px));
    min-height: 100vh;
    margin: 0 auto;
    padding: 24px 0 40px;
}

.stage {
    position: relative;
    display: grid;
    grid-template-columns: 170px 1fr auto;
    gap: 24px;
    align-items: center;
    min-height: 190px;
    padding: 18px;
    border: 1px solid rgba(212, 31, 61, 0.36);
    border-radius: 8px;
    background:
        linear-gradient(135deg, rgba(143, 16, 34, 0.34), rgba(7, 6, 7, 0.74) 52%),
        rgba(255, 255, 255, 0.04);
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.44);
}

.intro h1 {
    margin: 4px 0 10px;
    font-size: clamp(2.1rem, 5vw, 5.2rem);
    line-height: 0.95;
    letter-spacing: 0;
    text-shadow: 0 8px 28px rgba(212, 31, 61, 0.42);
}

.intro p {
    max-width: 680px;
    margin: 0;
    color: rgba(247, 241, 232, 0.82);
    font-size: clamp(1rem, 2vw, 1.2rem);
}

.eyebrow {
    margin: 0;
    color: var(--gold);
    text-transform: uppercase;
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.1em;
}

.magician {
    position: relative;
    width: 150px;
    height: 170px;
    transform-style: preserve-3d;
    perspective: 700px;
}

.hat {
    position: absolute;
    left: 42px;
    top: 10px;
    width: 66px;
    height: 54px;
    background: #111;
    border: 3px solid #31243b;
    transform: rotateX(18deg) rotateZ(-4deg);
    box-shadow: 0 9px 0 #0a0a0b;
}

.hat::before {
    content: "";
    position: absolute;
    left: -28px;
    bottom: -12px;
    width: 122px;
    height: 16px;
    border-radius: 50%;
    background: #0b0b0d;
}

.hat span {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 13px;
    height: 10px;
    background: var(--crimson);
}

.head {
    position: absolute;
    left: 52px;
    top: 68px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #e7b788;
    box-shadow: inset -10px -8px 0 rgba(117, 67, 43, 0.2);
}

.cape {
    position: absolute;
    left: 24px;
    top: 104px;
    width: 105px;
    height: 64px;
    background: linear-gradient(145deg, var(--crimson), #4a0711 68%);
    clip-path: polygon(27% 0, 73% 0, 100% 100%, 0 100%);
    transform: rotateX(16deg);
    box-shadow: 0 24px 32px rgba(0, 0, 0, 0.35);
}

.wand {
    position: absolute;
    right: 8px;
    top: 70px;
    width: 8px;
    height: 96px;
    background: linear-gradient(#f8f3d1 0 18%, #101010 18% 100%);
    transform: rotateZ(34deg);
    transform-origin: bottom;
    animation: wand 2.2s ease-in-out infinite;
}

.spark {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--gold);
    clip-path: polygon(50% 0, 64% 35%, 100% 50%, 64% 65%, 50% 100%, 36% 65%, 0 50%, 36% 35%);
    animation: sparkle 1.8s ease-in-out infinite;
}

.spark-one { right: 6px; top: 40px; }
.spark-two { right: 30px; top: 16px; animation-delay: 0.4s; }
.spark-three { right: 54px; top: 46px; animation-delay: 0.8s; }

.ghost-button,
.primary-button {
    min-height: 44px;
    border: 0;
    border-radius: 8px;
    padding: 0 18px;
    cursor: pointer;
    font-weight: 800;
}

.ghost-button {
    color: var(--ink);
    background: rgba(212, 31, 61, 0.18);
    border: 1px solid rgba(212, 31, 61, 0.55);
}

.primary-button {
    color: #fff8ed;
    background: linear-gradient(135deg, var(--crimson), #7c0919);
    box-shadow: 0 14px 26px rgba(0, 0, 0, 0.34);
}

.round-panel {
    padding-top: 24px;
}

.round-status {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
    color: rgba(247, 241, 232, 0.78);
    font-weight: 800;
}

.meter {
    display: inline-flex;
    gap: 8px;
}

.meter b {
    width: 44px;
    height: 8px;
    border-radius: 99px;
    background: rgba(255, 255, 255, 0.2);
}

.meter .active {
    background: var(--gold);
}

.rows {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
    perspective: 1200px;
}

.row-choice {
    width: 100%;
    min-height: 430px;
    display: grid;
    grid-template-rows: auto 1fr;
    align-items: center;
    justify-items: center;
    gap: 14px;
    padding: 18px;
    color: var(--ink);
    background:
        linear-gradient(180deg, rgba(143, 16, 34, 0.28), rgba(0, 0, 0, 0.58)),
        rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(212, 31, 61, 0.32);
    border-radius: 8px;
    cursor: pointer;
    transform-style: preserve-3d;
    transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}

.row-choice:hover,
.row-choice:focus-visible {
    outline: none;
    border-color: rgba(243, 193, 93, 0.82);
    background:
        linear-gradient(180deg, rgba(212, 31, 61, 0.42), rgba(0, 0, 0, 0.48)),
        rgba(243, 193, 93, 0.08);
    transform: translateY(-4px) rotateY(2deg);
}

.row-choice.is-hovered .card {
    transform: translate(calc(-50% + var(--fan-x)), calc(var(--fan-y) - 8px)) rotate(var(--fan-rot)) rotateX(5deg);
}

.row-label {
    display: grid;
    place-items: center;
    width: 100%;
    min-height: 50px;
    border-radius: 8px;
    color: #fff8ed;
    background: linear-gradient(135deg, #d41f3d, #7a0718);
    border: 1px solid rgba(255, 255, 255, 0.15);
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.card-strip {
    position: relative;
    display: block;
    width: min(150px, 100%);
    height: 340px;
    margin: 0 auto;
    isolation: isolate;
}

.card-strip .card {
    position: absolute;
    left: 50%;
    top: 0;
    width: 102px;
    transform-origin: 50% 115%;
    animation: fanDeal 520ms ease both;
}

.card-strip .card:nth-child(1) { --fan-x: 0px; --fan-y: 0px; --fan-rot: 0deg; z-index: 11; }
.card-strip .card:nth-child(2) { --fan-x: 0px; --fan-y: 34px; --fan-rot: 0deg; z-index: 12; }
.card-strip .card:nth-child(3) { --fan-x: 0px; --fan-y: 68px; --fan-rot: 0deg; z-index: 13; }
.card-strip .card:nth-child(4) { --fan-x: 0px; --fan-y: 102px; --fan-rot: 0deg; z-index: 14; }
.card-strip .card:nth-child(5) { --fan-x: 0px; --fan-y: 136px; --fan-rot: 0deg; z-index: 15; }
.card-strip .card:nth-child(6) { --fan-x: 0px; --fan-y: 170px; --fan-rot: 0deg; z-index: 16; }
.card-strip .card:nth-child(7) { --fan-x: 0px; --fan-y: 204px; --fan-rot: 0deg; z-index: 17; }

.card {
    position: relative;
    display: block;
    aspect-ratio: 2.25 / 3.25;
    min-width: 0;
    border-radius: 8px;
    color: var(--charcoal);
    background:
        linear-gradient(145deg, rgba(255, 255, 255, 0.95), rgba(255, 248, 237, 0.94)),
        var(--paper);
    box-shadow:
        0 16px 28px rgba(0, 0, 0, 0.32),
        inset 0 0 0 2px rgba(21, 19, 22, 0.08);
    transform: translateY(0) rotateY(var(--tilt)) rotateX(0);
    transform-style: preserve-3d;
    transition: transform 220ms ease;
    animation: deal 520ms ease both;
    animation-delay: var(--delay);
}

.card::after {
    content: "";
    position: absolute;
    inset: 8px;
    border: 1px solid rgba(21, 19, 22, 0.14);
    border-radius: 6px;
    pointer-events: none;
}

.card.red {
    color: #bd1836;
}

.card.black {
    color: #151316;
}

.corner {
    position: absolute;
    display: grid;
    gap: 1px;
    width: 46px;
    text-align: center;
    font-weight: 900;
    line-height: 1;
    font-size: clamp(1.45rem, 2.65vw, 1.9rem);
}

.corner b {
    font-size: 1.18em;
}

.corner.top {
    top: 8px;
    left: 8px;
}

.corner.bottom {
    right: 8px;
    bottom: 8px;
    transform: rotate(180deg);
}

.card-strip .corner.top {
    display: flex;
    align-items: center;
    gap: 4px;
    width: auto;
    min-width: 54px;
    top: 7px;
    left: 8px;
    text-align: left;
    font-size: clamp(1.34rem, 2.45vw, 1.72rem);
}

.card-strip .corner.top b {
    font-size: 1.06em;
    line-height: 1;
}

.suit {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: clamp(3.7rem, 8vw, 6.25rem);
    filter: drop-shadow(0 5px 0 rgba(0, 0, 0, 0.08));
}

.reveal-panel {
    display: grid;
    justify-items: center;
    gap: 16px;
    padding: 42px 0 20px;
    text-align: center;
}

.reveal-panel h2 {
    margin: 0;
    font-size: clamp(1.9rem, 4vw, 3.8rem);
}

.reveal-card {
    width: min(260px, 70vw);
    animation: reveal 900ms cubic-bezier(.2, .9, .2, 1.2) both;
}

.reveal-card .corner {
    width: 58px;
    font-size: clamp(1.8rem, 4.8vw, 2.65rem);
}

.reveal-card .suit {
    font-size: clamp(5.4rem, 15vw, 8.5rem);
}

.is-revealed .magician .wand {
    animation-duration: 0.8s;
}

@keyframes deal {
    from {
        opacity: 0;
        transform: translateY(18px) rotateY(34deg) rotateX(18deg);
    }
    to {
        opacity: 1;
        transform: translateY(0) rotateY(var(--tilt)) rotateX(0);
    }
}

@keyframes fanDeal {
    from {
        opacity: 0;
        transform: translate(-50%, 28px) rotate(0deg) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translate(calc(-50% + var(--fan-x)), var(--fan-y)) rotate(var(--fan-rot));
    }
}

@keyframes reveal {
    0% {
        opacity: 0;
        transform: translateY(36px) rotateY(180deg) rotateX(28deg) scale(0.82);
    }
    100% {
        opacity: 1;
        transform: translateY(0) rotateY(0) rotateX(0) scale(1);
    }
}

@keyframes wand {
    0%, 100% { transform: rotateZ(34deg); }
    50% { transform: rotateZ(46deg); }
}

@keyframes sparkle {
    0%, 100% {
        opacity: 0.35;
        transform: scale(0.65) rotate(0deg);
    }
    50% {
        opacity: 1;
        transform: scale(1.35) rotate(90deg);
    }
}

@media (max-width: 820px) {
    .table {
        width: min(100% - 20px, 1180px);
    }

    .stage {
        grid-template-columns: 104px 1fr;
        min-height: 0;
        gap: 14px;
        padding: 14px;
    }

    .restart-form {
        grid-column: 1 / -1;
    }

    .magician {
        width: 110px;
        height: 142px;
        transform: scale(0.8);
        transform-origin: left center;
    }

    .row-choice {
        min-height: 0;
        padding: 12px;
    }

    .row-label {
        min-height: 42px;
    }

    .card-strip {
        width: min(132px, 100%);
        height: 304px;
    }

    .card-strip .card {
        width: 90px;
        top: 0;
    }

    .corner {
        width: 38px;
        font-size: 1.28rem;
    }

    .corner.top {
        top: 8px;
        left: 6px;
    }

    .corner.bottom {
        right: 6px;
        bottom: 8px;
    }
}

@media (max-width: 420px) {
    .rows {
        grid-template-columns: 1fr;
    }

    .row-choice {
        min-height: 260px;
    }

    .card-strip {
        width: min(150px, 100%);
        height: 336px;
    }

    .card-strip .card {
        width: 100px;
        top: 0;
    }

    .card-strip .card:nth-child(1) { --fan-x: 0px; --fan-y: 0px; --fan-rot: 0deg; }
    .card-strip .card:nth-child(2) { --fan-x: 0px; --fan-y: 32px; --fan-rot: 0deg; }
    .card-strip .card:nth-child(3) { --fan-x: 0px; --fan-y: 64px; --fan-rot: 0deg; }
    .card-strip .card:nth-child(4) { --fan-x: 0px; --fan-y: 96px; --fan-rot: 0deg; }
    .card-strip .card:nth-child(5) { --fan-x: 0px; --fan-y: 128px; --fan-rot: 0deg; }
    .card-strip .card:nth-child(6) { --fan-x: 0px; --fan-y: 160px; --fan-rot: 0deg; }
    .card-strip .card:nth-child(7) { --fan-x: 0px; --fan-y: 192px; --fan-rot: 0deg; }
}

@media (max-width: 520px) {
    .table {
        width: min(100% - 14px, 1180px);
        padding-top: 12px;
    }

    .stage {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .magician {
        height: 114px;
        transform: scale(0.68);
    }

    .intro h1 {
        font-size: 2.35rem;
    }

    .intro p {
        font-size: 0.98rem;
    }

    .round-status {
        align-items: flex-start;
        flex-direction: column;
        gap: 10px;
        margin-bottom: 12px;
    }

    .meter {
        width: 100%;
    }

    .meter b {
        flex: 1;
    }

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

    .row-choice {
        grid-template-rows: auto auto;
        padding: 10px;
        min-height: 0;
    }

    .row-choice:hover,
    .row-choice:focus-visible {
        transform: translateY(-2px);
    }

    .row-label {
        min-height: 42px;
        font-size: 0.82rem;
    }

    .card-strip {
        width: min(132px, 100%);
        height: 292px;
    }

    .card-strip .card {
        width: 88px;
        top: 0;
    }

    .card-strip .card:nth-child(1) { --fan-x: 0px; --fan-y: 0px; --fan-rot: 0deg; }
    .card-strip .card:nth-child(2) { --fan-x: 0px; --fan-y: 28px; --fan-rot: 0deg; }
    .card-strip .card:nth-child(3) { --fan-x: 0px; --fan-y: 56px; --fan-rot: 0deg; }
    .card-strip .card:nth-child(4) { --fan-x: 0px; --fan-y: 84px; --fan-rot: 0deg; }
    .card-strip .card:nth-child(5) { --fan-x: 0px; --fan-y: 112px; --fan-rot: 0deg; }
    .card-strip .card:nth-child(6) { --fan-x: 0px; --fan-y: 140px; --fan-rot: 0deg; }
    .card-strip .card:nth-child(7) { --fan-x: 0px; --fan-y: 168px; --fan-rot: 0deg; }
    }

    .card::after {
        inset: 4px;
    }

    .suit {
        font-size: 2.85rem;
    }

    .corner {
        width: 34px;
        font-size: 1.1rem;
    }

    .ghost-button,
    .primary-button {
        width: 100%;
    }
}

@media (max-width: 380px) {
    .table {
        width: min(100% - 10px, 1180px);
    }

    .stage {
        padding: 10px;
    }

    .intro h1 {
        font-size: 2rem;
    }

    .eyebrow {
        font-size: 0.66rem;
    }

    .card-strip {
        width: min(116px, 100%);
        height: 260px;
    }

    .card-strip .card {
        width: 78px;
        top: 0;
    }

    .card-strip .card:nth-child(1) { --fan-x: 0px; --fan-y: 0px; --fan-rot: 0deg; }
    .card-strip .card:nth-child(2) { --fan-x: 0px; --fan-y: 25px; --fan-rot: 0deg; }
    .card-strip .card:nth-child(3) { --fan-x: 0px; --fan-y: 50px; --fan-rot: 0deg; }
    .card-strip .card:nth-child(4) { --fan-x: 0px; --fan-y: 75px; --fan-rot: 0deg; }
    .card-strip .card:nth-child(5) { --fan-x: 0px; --fan-y: 100px; --fan-rot: 0deg; }
    .card-strip .card:nth-child(6) { --fan-x: 0px; --fan-y: 125px; --fan-rot: 0deg; }
    .card-strip .card:nth-child(7) { --fan-x: 0px; --fan-y: 150px; --fan-rot: 0deg; }
    }

    .row-choice {
        padding: 8px;
    }

    .suit {
        font-size: 2.38rem;
    }

    .corner {
        width: 30px;
        font-size: 0.98rem;
    }
}
