:root {
    --bg: #fbfdff;
    --surface: #ffffff;
    --surface-soft: #f7fbff;
    --ink: #253044;
    --muted: #65728a;
    --blue: #9bd5ef;
    --blue-strong: #2e90b8;
    --pink: #f8b7cd;
    --pink-strong: #c95b82;
    --mint: #bdebd5;
    --yellow: #ffe49b;
    --border: #e5edf5;
    --shadow: 0 18px 50px rgba(72, 101, 134, 0.16);
    --radius: 28px;
    --focus: 0 0 0 4px rgba(46, 144, 184, 0.28);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
    color: var(--ink);
    font-family: Poppins, Nunito, "Baloo 2", sans-serif;
}

body {
    min-height: 100vh;
    margin: 0;
    background:
        radial-gradient(circle at 16% 8%, rgba(155, 213, 239, 0.32), transparent 28rem),
        radial-gradient(circle at 90% 18%, rgba(248, 183, 205, 0.34), transparent 25rem),
        linear-gradient(180deg, #ffffff 0%, #f8fcff 48%, #fff8fb 100%);
}

button,
input {
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible {
    outline: none;
    box-shadow: var(--focus);
}

noscript {
    display: block;
    margin: 24px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--surface);
}

.app-shell {
    min-height: 100vh;
    padding: 18px;
}

.welcome {
    min-height: calc(100vh - 36px);
    display: grid;
    place-items: center;
}

.welcome__panel {
    width: min(980px, 100%);
    display: grid;
    gap: 28px;
    align-items: center;
    grid-template-columns: 1fr;
    padding: 24px;
    border: 1px solid rgba(229, 237, 245, 0.92);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.82);
    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
}

.welcome__title {
    margin: 0 0 12px;
    font-size: clamp(2.35rem, 12vw, 5.2rem);
    line-height: 0.95;
    letter-spacing: 0;
}

.welcome__subtitle {
    max-width: 38rem;
    margin: 0 0 28px;
    color: var(--muted);
    font-size: 1.02rem;
    line-height: 1.7;
}

.welcome__preview {
    position: relative;
    min-height: 360px;
    border-radius: 24px;
    overflow: hidden;
    background: linear-gradient(135deg, rgba(155, 213, 239, 0.26), rgba(248, 183, 205, 0.28));
}

.welcome__card-img {
    position: absolute;
    inset: 24px;
    width: calc(100% - 48px);
    height: calc(100% - 48px);
    object-fit: contain;
    filter: drop-shadow(0 16px 24px rgba(89, 107, 130, 0.18));
}

.board {
    min-height: calc(100vh - 36px);
    display: grid;
    gap: 18px;
    grid-template-columns: 1fr;
}

.draw-panel,
.history-panel {
    border: 1px solid rgba(229, 237, 245, 0.94);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.88);
    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
}

.draw-panel {
    min-height: 520px;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 18px;
    padding: 18px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.topbar__actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand {
    min-width: 0;
}

.brand__title {
    margin: 0;
    font-size: 1.22rem;
    line-height: 1.15;
}

.brand__meta {
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.88rem;
}

.icon-button {
    width: 46px;
    height: 46px;
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: #fff;
    color: var(--ink);
    cursor: pointer;
    transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.icon-button:hover {
    transform: translateY(-1px);
    border-color: rgba(46, 144, 184, 0.35);
    background: var(--surface-soft);
}

.hero-draw {
    position: relative;
    align-self: stretch;
    display: grid;
    place-items: center;
    min-height: 310px;
    height: 100%;
    border-radius: 24px;
    overflow: hidden;
    background:
        linear-gradient(135deg, rgba(155, 213, 239, 0.24), rgba(248, 183, 205, 0.25)),
        #fff;
}

.draw-image {
    position: relative;
    z-index: 1;
    width: min(88%, 430px);
    height: min(78%, 430px);
    object-fit: contain;
    transform-origin: center;
    filter: drop-shadow(0 24px 30px rgba(71, 91, 115, 0.17));
    transition: transform 220ms ease, opacity 180ms ease, filter 220ms ease;
}

.draw-image.is-rolling {
    transform: scale(0.96) rotate(-1deg);
}

.draw-image.is-revealed {
    animation: reveal-pop 760ms cubic-bezier(0.2, 0.9, 0.18, 1.2);
    filter: drop-shadow(0 22px 32px rgba(46, 144, 184, 0.2)) drop-shadow(0 0 20px rgba(248, 183, 205, 0.42));
}

.progress {
    display: grid;
    gap: 10px;
}

.progress__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--muted);
    font-size: 0.9rem;
}

.progress__track {
    height: 12px;
    overflow: hidden;
    border-radius: 999px;
    background: #eef5fb;
}

.progress__bar {
    width: 100%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--blue), var(--pink), var(--yellow));
    transform: scaleX(0);
    transform-origin: left center;
    transition: transform 420ms ease;
}

.actions {
    display: grid;
    gap: 12px;
}

.primary-button,
.secondary-button,
.danger-button {
    position: relative;
    min-height: 58px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    border: 0;
    border-radius: 999px;
    padding: 14px 22px;
    overflow: hidden;
    cursor: pointer;
    font-weight: 800;
    letter-spacing: 0;
    transition: transform 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

.primary-button {
    background: linear-gradient(135deg, var(--blue-strong), var(--pink-strong));
    color: #fff;
    box-shadow: 0 16px 28px rgba(46, 144, 184, 0.24);
}

.secondary-button {
    border: 1px solid var(--border);
    background: #fff;
    color: var(--ink);
}

.danger-button {
    background: #d84f62;
    color: #fff;
}

.primary-button:hover,
.secondary-button:hover,
.danger-button:hover {
    transform: translateY(-1px);
}

.primary-button:active,
.secondary-button:active,
.danger-button:active {
    transform: translateY(1px) scale(0.99);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.52;
    transform: none;
}

.button-ripple::after {
    content: "";
    position: absolute;
    inset: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.35);
    transform: translate(-50%, -50%);
    transition: width 360ms ease, height 360ms ease, opacity 360ms ease;
    opacity: 0;
}

.button-ripple:active::after {
    width: 280px;
    height: 280px;
    opacity: 1;
    transition: 0s;
}

.status-message {
    min-height: 24px;
    color: var(--muted);
    text-align: center;
    font-size: 0.92rem;
}

.history-panel {
    min-height: 420px;
    padding: 18px;
    overflow: hidden;
}

.history-head {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
}

.history-head h2 {
    margin: 0;
    font-size: 1.1rem;
}

.history-head span {
    color: var(--muted);
    font-size: 0.9rem;
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 8px;
    align-content: start;
    max-height: calc(100vh - 150px);
    overflow: auto;
    padding: 2px 2px 12px;
}

.history-item {
    display: grid;
    place-items: center;
    aspect-ratio: 1;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 8px 22px rgba(67, 86, 110, 0.08);
    transition: transform 360ms ease;
}

.history-item.is-new {
    animation: history-enter 520ms ease both;
}

.history-item img {
    width: 82%;
    height: 82%;
    object-fit: contain;
}

.finish-banner {
    padding: 14px 16px;
    border: 1px solid rgba(46, 144, 184, 0.16);
    border-radius: 18px;
    background: linear-gradient(135deg, rgba(189, 235, 213, 0.4), rgba(255, 228, 155, 0.38));
    color: var(--ink);
    text-align: center;
    font-weight: 700;
}

.particle-layer {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
    overflow: hidden;
}

.particle {
    position: absolute;
    left: 50%;
    top: 48%;
    width: var(--size, 12px);
    height: var(--size, 12px);
    border-radius: 3px;
    background: var(--particle-color, var(--pink));
    clip-path: polygon(50% 0, 61% 34%, 98% 35%, 68% 56%, 79% 91%, 50% 70%, 21% 91%, 32% 56%, 2% 35%, 39% 34%);
    transform: translate(-50%, -50%) scale(0.2);
    filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.9));
    animation: particle-burst 1450ms cubic-bezier(0.12, 0.8, 0.22, 1) forwards;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(32, 43, 60, 0.42);
}

.modal {
    width: min(480px, 100%);
    border-radius: 24px;
    background: #fff;
    box-shadow: 0 24px 70px rgba(26, 39, 55, 0.28);
    padding: 24px;
}

.modal h2 {
    margin: 0 0 10px;
    font-size: 1.3rem;
}

.modal p {
    margin: 0 0 18px;
    color: var(--muted);
    line-height: 1.6;
}

.modal input {
    width: 100%;
    min-height: 52px;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 0 14px;
    color: var(--ink);
}

.modal__actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 18px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (min-width: 860px) {
    .app-shell {
        padding: 24px;
    }

    .welcome__panel {
        grid-template-columns: minmax(0, 0.95fr) minmax(320px, 0.72fr);
        padding: 38px;
    }

    .board {
        grid-template-columns: minmax(420px, 0.88fr) minmax(0, 1.12fr);
    }

    .draw-panel,
    .history-panel {
        min-height: calc(100vh - 48px);
    }

    .draw-panel {
        padding: 24px;
    }

    .hero-draw {
        min-height: 420px;
    }

    .history-panel {
        padding: 24px;
    }

    .history-grid {
        gap: 12px;
        max-height: calc(100vh - 138px);
    }
}

@keyframes reveal-pop {
    0% {
        transform: scale(0.86) rotate(-2deg);
    }
    48% {
        transform: scale(1.08) rotate(1deg);
    }
    72% {
        transform: scale(0.98) rotate(-0.5deg);
    }
    100% {
        transform: scale(1) rotate(0);
    }
}

@keyframes history-enter {
    from {
        opacity: 0;
        transform: scale(0.72);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes particle-burst {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) rotate(0deg) scale(0.2);
    }
    18% {
        opacity: 1;
        transform: translate(calc(-50% + (var(--x) * 0.24)), calc(-50% + (var(--y) * 0.24))) rotate(80deg) scale(1.2);
    }
    68% {
        opacity: 0.95;
    }
    to {
        opacity: 0;
        transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) rotate(var(--spin, 360deg)) scale(0.72);
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 1ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 1ms !important;
    }

    .particle-layer {
        display: none;
    }
}
