:root {
    --k-red: #d93025;
    --k-blue: #1a237e;
    --k-yellow: #f9a825;
    --k-white: #f5f5f5;
    --k-black: #212121;
    --paper-bg: #f4e4bc;
    --wood-frame: #5d4037;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--paper-bg);
    /* Hanji paper texture effect */
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100' height='100' filter='url(%23noise)' opacity='0.15'/%3E%3C/svg%3E");
    color: var(--k-black);
    font-family: 'Nanum Myeongjo', 'GungSeo', 'Batang', serif;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    padding: clamp(1rem, 3vw, 2.5rem) 0;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    width: 100%;
}

.pattern-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0.1;
    background-image: radial-gradient(circle, #000 1px, transparent 1px);
    background-size: 30px 30px;
}

#confetti-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
}

.decoration {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 200px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 320'%3E%3Cpath fill='%231a237e' fill-opacity='0.2' d='M0,224L48,213.3C96,203,192,181,288,181.3C384,181,480,203,576,224C672,245,768,267,864,250.7C960,235,1056,181,1152,165.3C1248,149,1344,171,1392,181.3L1440,192L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-size: cover;
    z-index: 1;
}

/* Sparkles */
.sparkles-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.sparkle {
    position: absolute;
    width: 5px;
    height: 5px;
    background: var(--k-yellow);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--k-yellow), 0 0 20px var(--k-yellow);
    animation: float-sparkle 3s infinite ease-in-out;
    opacity: 0;
}

@keyframes float-sparkle {
    0% {
        transform: translateY(0) scale(0);
        opacity: 0;
    }

    50% {
        opacity: 1;
    }

    100% {
        transform: translateY(-100px) scale(1);
        opacity: 0;
    }
}

/* Snow Effect */
.snow-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.snowflake {
    position: absolute;
    top: -10px;
    color: #fff;
    font-size: 3em;
    /* Increased size */
    opacity: 1;
    /* Increased visibility */
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.8);
    /* Added glow for clarity */
    animation: fall linear infinite;
}

@keyframes fall {
    0% {
        transform: translateY(-10vh) translateX(0);
        opacity: 1;
    }

    100% {
        transform: translateY(110vh) translateX(20px);
        opacity: 0.3;
    }
}

.container {
    position: relative;
    z-index: 10;
    width: min(100%, 1000px);
    padding: 0 1rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
    box-sizing: border-box;
    margin: 0 auto;
}

/* Header */
header {
    background: white;
    padding: 1rem clamp(1rem, 4vw, 3rem);
    border: 4px solid var(--k-black);
    box-shadow: 10px 10px 0 rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
    width: 100%;
    text-align: center;
    box-sizing: border-box;
}

/* Golden Title Effect */
header h1 {
    font-size: clamp(1.8rem, 5vw, 6rem);
    font-weight: 900;
    margin: 0;
    letter-spacing: clamp(0.03rem, 0.5vw, 0.35rem);
    background: linear-gradient(45deg, #FFD700, #B8860B, #FFD700, #DAA520);
    background-size: 200% auto;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    font-family: 'Nanum Myeongjo', serif;
    /* 3D Effect */
    transform: perspective(500px) rotateX(10deg);
    filter: drop-shadow(0px 4px 0px #5d4037) drop-shadow(0px 8px 5px rgba(0, 0, 0, 0.5));
    position: relative;
    overflow: visible;
    white-space: nowrap;
    animation: titleGlow 3s ease-in-out infinite, titleGradient 4s ease-in-out infinite;
    max-width: 100%;
}

@keyframes titleGlow {
    0%, 100% {
        filter: drop-shadow(0px 4px 0px #5d4037) 
                drop-shadow(0px 8px 5px rgba(0, 0, 0, 0.5))
                drop-shadow(0px 0px 10px rgba(255, 215, 0, 0.3));
    }
    50% {
        filter: drop-shadow(0px 4px 0px #5d4037) 
                drop-shadow(0px 8px 5px rgba(0, 0, 0, 0.5))
                drop-shadow(0px 0px 20px rgba(255, 215, 0, 0.6))
                drop-shadow(0px 0px 30px rgba(255, 215, 0, 0.4));
    }
}

@keyframes titleGradient {
    0%, 100% {
        background-position: 0% center;
    }
    50% {
        background-position: 100% center;
    }
}

/* Main Lottery Area - Scroll/Plaque Style */
/* Breathing Box Border */
@keyframes border-pulse {
    0% {
        box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    }

    50% {
        box-shadow: 0 20px 50px rgba(217, 48, 37, 0.5), 0 0 30px rgba(249, 168, 37, 0.3);
    }

    100% {
        box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    }
}

.lottery-frame {
    position: relative;
    padding: clamp(12px, 3vw, 20px);
    background: var(--wood-frame);
    border-radius: 10px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    animation: border-pulse 4s infinite ease-in-out;
    width: 100%;
    box-sizing: border-box;
}

.lottery-box {
    width: 100%;
    height: clamp(260px, 45vh, 400px);
    background: #fff;
    /* Inner paper texture */
    background-image: url("data:image/svg+xml,%3Csvg width='100' height='100' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100' height='100' filter='url(%23noise)' opacity='0.1'/%3E%3C/svg%3E");
    display: flex;
    justify-content: center;
    align-items: center;
    border: 2px solid #d7ccc8;
    position: relative;
    overflow: hidden;
}

/* Traditional corner patterns */
.corner {
    position: absolute;
    width: 50px;
    height: 50px;
    border: 5px solid var(--k-black);
    z-index: 5;
}

.tl {
    top: 10px;
    left: 10px;
    border-right: none;
    border-bottom: none;
}

.tr {
    top: 10px;
    right: 10px;
    border-left: none;
    border-bottom: none;
}

.bl {
    bottom: 10px;
    left: 10px;
    border-right: none;
    border-top: none;
}

.br {
    bottom: 10px;
    right: 10px;
    border-left: none;
    border-top: none;
}

/* Glowing Text Pulse */
@keyframes text-glow {
    0% {
        text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
    }

    50% {
        text-shadow: 0 0 20px var(--k-red), 0 0 40px var(--k-yellow);
        color: var(--k-red);
    }

    100% {
        text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
    }
}

/* Heartbeat Animation */
@keyframes heartbeat {
    0% {
        transform: scale(1);
    }

    15% {
        transform: scale(1.1);
    }

    30% {
        transform: scale(1);
    }

    45% {
        transform: scale(1.1);
    }

    60% {
        transform: scale(1);
    }

    100% {
        transform: scale(1);
    }
}

.name-display {
    font-size: clamp(3.5rem, 16vw, 14rem);
    font-weight: bold;
    color: var(--k-black);
    z-index: 2;
    /* Ink bleed effect simulation */
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
    animation: text-glow 3s infinite ease-in-out, heartbeat 1.2s infinite ease-in-out;
    font-family: 'Yeon Sung', cursive;
    line-height: 1;
    text-align: center;
    padding: 0 1rem;
    word-break: keep-all;
}

.name-display.rolling {
    opacity: 0.5;
    filter: blur(2px);
    animation: none;
}

.name-display.revealing {
    color: var(--k-black);
    animation: none;
}

@keyframes letterReveal {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.name-display.winner {
    color: var(--k-red);
    transform: scale(1.2);
    animation: stamp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    overflow: hidden;
    text-shadow: 
        0 0 10px rgba(217, 48, 37, 0.4),
        0 0 20px rgba(217, 48, 37, 0.3),
        0 0 30px rgba(249, 168, 37, 0.2);
}

.name-display.winner.shimmer {
    animation: stamp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.name-display.winner.shimmer::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 50%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.3) 20%,
        rgba(255, 255, 255, 0.6) 40%,
        rgba(255, 255, 255, 0.8) 50%,
        rgba(255, 255, 255, 0.6) 60%,
        rgba(255, 255, 255, 0.3) 80%,
        transparent 100%
    );
    animation: shine 2.5s infinite ease-in-out;
    pointer-events: none;
    z-index: 1;
    mix-blend-mode: screen;
    filter: blur(1px);
    transform: skewX(-15deg);
}

@keyframes stamp {
    0% {
        transform: scale(3);
        opacity: 0;
    }

    100% {
        transform: scale(1.2);
        opacity: 1;
    }

    25% {
        transform: rotate(-10deg);
    }

    75% {
        transform: rotate(10deg);
    }
}

@keyframes shine {
    0% {
        left: -50%;
        opacity: 0;
    }
    10% {
        opacity: 1;
    }
    90% {
        opacity: 1;
    }
    100% {
        left: 150%;
        opacity: 0;
    }
}

/* Congrats Message (Vertical) */
.congrats-side {
    position: fixed;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 2rem 1rem;
    border: 4px solid var(--k-red);
    border-radius: 20px;
    box-shadow: 0 0 30px rgba(217, 48, 37, 0.5);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.congrats-side.left {
    left: auto;
}

.congrats-side.right {
    right: auto;
}

.congrats-side.hidden {
    opacity: 0;
    pointer-events: none;
}

.congrats-side.left.hidden {
    transform: translate(-100px, -50%);
    opacity: 0;
}

.congrats-side.right.hidden {
    transform: translate(100px, -50%);
    opacity: 0;
}

.congrats-side .text {
    font-size: 3rem;
    font-weight: bold;
    color: var(--k-red);
    font-family: 'Yeon Sung', cursive;
    letter-spacing: 0.5rem;
    writing-mode: vertical-rl;
    text-orientation: upright;
}

.congrats-side .firecracker {
    font-size: 3rem;
    writing-mode: horizontal-tb;
    /* Keep emoji upright */
    animation: shake 1s infinite ease-in-out;
    line-height: 1;
}

@keyframes shake {

    0%,
    100% {
        transform: rotate(0deg);
    }

    25% {
        transform: rotate(-10deg);
    }

    75% {
        transform: rotate(10deg);
    }
}

/* Controls */
.controls {
    display: flex;
    gap: 2rem;
    margin-top: 2rem;
    flex-wrap: wrap;
    justify-content: center;
}

.btn {
    padding: 1rem 3rem;
    font-size: 1.8rem;
    font-family: 'GungSeo', serif;
    font-weight: bold;
    border: 3px solid var(--k-black);
    background: white;
    color: var(--k-black);
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 5px 5px 0 var(--k-black);
}

.start-btn:hover:not(:disabled) {
    background: var(--k-blue);
    color: white;
    transform: translate(-2px, -2px);
    box-shadow: 7px 7px 0 var(--k-black);
}

.stop-btn:hover:not(:disabled) {
    background: var(--k-red);
    color: white;
    transform: translate(-2px, -2px);
    box-shadow: 7px 7px 0 var(--k-black);
}

.btn:active:not(:disabled) {
    transform: translate(2px, 2px);
    box-shadow: 3px 3px 0 var(--k-black);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
    transform: translate(5px, 5px);
}

/* Responsive */
@media (max-width: 768px) {
    body {
        padding: 1.5rem 0;
    }

    header {
        padding: 0.8rem 1.2rem;
    }

    header h1 {
        font-size: clamp(2rem, 7vw, 3.5rem);
        letter-spacing: 0.2rem;
    }

    .lottery-frame {
        padding: 12px;
    }

    .lottery-box {
        height: clamp(200px, 55vh, 320px);
    }

    .name-display {
        font-size: clamp(2.8rem, 18vw, 8rem);
    }

    .controls {
        width: 100%;
        gap: 1rem;
    }

    .btn {
        flex: 1;
        min-width: 140px;
    }

    .congrats-side {
        display: none;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: clamp(1.8rem, 10vw, 2.6rem);
        letter-spacing: 0.1rem;
    }

    .corner {
        width: 35px;
        height: 35px;
        border-width: 4px;
    }

    .name-display {
        font-size: clamp(2.8rem, 20vw, 7rem);
    }

    .btn {
        min-width: 120px;
        padding: 0.8rem 1.5rem;
    }
}