:root {
    /* --- Dark Mode (Default) --- */
    --bg-base: #050505;
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.6);
    --text-tertiary: rgba(255, 255, 255, 0.35);
    
    --glass-bg: rgba(20, 20, 22, 0.6);
    --glass-border: rgba(255,255,255,0.08);
    --glass-shine: rgba(255, 255, 255, 0.4);
    
    /* Opacity 0.1 */
    --blob-1: #312e81; 
    --blob-2: #581c87; 
    --blob-3: #172554; 
    --blob-opacity: 0.1; 
    
    --num-gradient: linear-gradient(180deg, #FFFFFF 30%, rgba(255,255,255,0.5) 100%);
    
    --btn-bg: rgba(255,255,255,0.1);
    --switch-bg: rgba(0,0,0,0.3);
    --glider-bg: rgba(255,255,255,0.2);
    --icon-active: #fff;

    --ticket-grid-bg: rgba(0,0,0,0.2);
    --ticket-cell-bg: rgba(255,255,255,0.03);
    --ticket-cell-hover: rgba(255,255,255,0.1);
    --ticket-cell-border: rgba(255,255,255,0.05);
    
    /* Physics */
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Light Mode Overrides --- */
[data-theme="light"] {
    --bg-base: #f4f5f7;
    --text-primary: #1a1a1a;
    --text-secondary: rgba(0, 0, 0, 0.6);
    --text-tertiary: rgba(0, 0, 0, 0.35);
    
    --glass-bg: rgba(255, 255, 255, 0.65);
    --glass-border: rgba(0, 0, 0, 0.06);
    --glass-shine: rgba(255, 255, 255, 0.8);
    
    --blob-1: #c7d2fe; 
    --blob-2: #e9d5ff; 
    --blob-3: #bfdbfe; 
    --blob-opacity: 0.6;
    
    --num-gradient: linear-gradient(180deg, #000000 30%, rgba(0,0,0,0.5) 100%);
    
    --btn-bg: rgba(0,0,0,0.05);
    --switch-bg: rgba(0,0,0,0.05);
    --glider-bg: #fff;
    --icon-active: #000;

    --ticket-grid-bg: rgba(0,0,0,0.04);
    --ticket-cell-bg: rgba(255,255,255,0.8);
    --ticket-cell-hover: #ffffff;
    --ticket-cell-border: rgba(0,0,0,0.08);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    outline: none;
}

body {
    margin: 0; padding: 0;
    height: 100vh; height: 100svh; width: 100vw;
    background-color: var(--bg-base);
    font-family: 'Inter', -apple-system, sans-serif;
    color: var(--text-primary);
    overflow: hidden;
    display: flex; flex-direction: column;
    align-items: center;
    transition: background-color 0.8s ease, color 0.5s ease;
    padding-top: 25px; /* Reduced from 40px to match original */
    padding-bottom: 20px;
}

/* --- Animated Background --- */
.aurora-container {
    position: fixed; inset: 0; z-index: -1; overflow: hidden;
    pointer-events: none;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: var(--blob-opacity);
    transition: background 0.8s ease, opacity 0.8s ease;
    animation: float 25s infinite alternate cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}

[data-theme="light"] .blob { mix-blend-mode: multiply; }

.blob-1 {
    width: 70vw; height: 70vw;
    background: var(--blob-1);
    top: -15%; left: -15%;
    animation-delay: 0s;
}

.blob-2 {
    width: 80vw; height: 80vw;
    background: var(--blob-2);
    bottom: -25%; right: -25%;
    animation-delay: -5s;
    animation-duration: 30s;
}

.blob-3 {
    width: 60vw; height: 60vw;
    background: var(--blob-3);
    bottom: 10%; left: 10%;
    animation-delay: -10s;
    animation-duration: 28s;
}

@keyframes float {
    0% { transform: translate3d(0, 0, 0) scale(1); }
    100% { transform: translate3d(40px, 60px, 0) scale(1.05); }
}

.noise {
    position: fixed; inset: 0; opacity: 0.05; pointer-events: none; z-index: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* --- Lighting Effects --- */
.spotlight-wrapper {
    position: relative;
    background: var(--glass-bg);
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
    border: 1px solid var(--glass-border); 
    transition: background 0.3s ease, border 0.3s ease, box-shadow 0.3s ease;
}

.spotlight-wrapper::after {
    content: ""; position: absolute; inset: -1px; border-radius: inherit; padding: 1px;
    background: radial-gradient(150px circle at var(--x, 50%) var(--y, 50%), var(--glass-shine), transparent 60%);
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor; mask-composite: exclude; pointer-events: none;
    opacity: var(--opacity, 0); transition: opacity 0.5s ease; z-index: 5;
}

.bottom-shine {
    box-shadow: 
        inset 0 -1px 0 rgba(255, 255, 255, 0.2), 
        inset 0 1px 20px rgba(0,0,0,0.05),
        0 10px 30px -5px rgba(0,0,0,0.2);
}

.top-shine {
    box-shadow: 
        inset 0 1px 0 rgba(255, 255, 255, 0.2),
        0 20px 50px rgba(0,0,0,0.3);
}

/* --- Main Stage --- */
.stage {
    z-index: 2; display: flex; flex-direction: column;
    align-items: center; justify-content: center; /* Center content vertically */
    width: 100%;
    flex: 1; /* Expand to fill space */
    min-height: 0; /* Allow shrinking */
    transition: opacity 0.5s ease;
    opacity: 0;
    pointer-events: none;
}

.stage.show {
    opacity: 1;
    pointer-events: auto;
}

#stage-game {
    padding: 0 16px; /* Reduced from 16px for better mobile fit */
    display: none; /* Controlled by JS */
}

#stage-game.show {
    display: flex;
}

.number-display-container {
    text-align: center;
    margin-bottom: 0;
    flex-shrink: 0;
}

.stage-label {
    font-size: 13px; text-transform: uppercase; letter-spacing: 0.25em;
    color: var(--text-tertiary); font-weight: 700;
}

#number-display, #number-display-legacy {
    font-family: 'Inter', sans-serif;
    font-size: clamp(8rem, 23vw, 13rem); 
    font-weight: 800;
    letter-spacing: -0.05em;
    line-height: 1.2; /* Increased from 1 to fix 'g' cut-off */
    font-variant-numeric: tabular-nums;
    background: var(--num-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 40px 80px rgba(0,0,0,0.15));
    transform-origin: center bottom;
    will-change: transform, filter;
    padding: 0 0.1em; 
    overflow: visible;
}

/* --- Sleeping Cat Animation --- */
.animal-block {
    display: inline-block;
    position: relative;
    width: clamp(120px, 30vw, 200px);
    height: auto;
    margin: 0 auto;
    -webkit-text-fill-color: initial;
}

.animal-block svg {
    width: 100%;
    height: auto;
    fill: var(--text-secondary);
    opacity: 0.8;
    animation: breathing 6s ease-in-out infinite;
    transform-origin: center bottom;
}

@keyframes breathing {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05, 0.96); }
}

.animal-block svg {
    width: 100%;
    height: auto;
    fill: var(--text-secondary);
    opacity: 0.8;
}

.z, .zz {
    position: absolute;
    color: var(--text-tertiary);
    font-family: 'Inter', sans-serif;
    font-weight: 800;
    opacity: 0;
    -webkit-text-fill-color: var(--text-tertiary);
}

.z {
    font-size: 32px; /* Increased from 24px */
    bottom: 60%;
    right: 15%;
    animation: zzz 4s linear infinite;
}

.zz {
    font-size: 24px; /* Increased from 18px */
    bottom: 55%;
    right: 5%;
    animation: zzz-2 4s linear infinite 2s;
}

@keyframes zzz {
    0% { transform: translate(0, 0) scale(0.5); opacity: 0; }
    20% { transform: translate(-5px, -20px) scale(0.7); opacity: 0.8; }
    50% { opacity: 1; }
    80% { transform: translate(-15px, -60px) scale(1.2); opacity: 0.5; }
    100% { transform: translate(-20px, -80px) scale(1.5); opacity: 0; }
}

@keyframes zzz-2 {
    0% { transform: translate(0, 0) scale(0.5); opacity: 0; }
    20% { transform: translate(5px, -15px) scale(0.7); opacity: 0.8; }
    50% { opacity: 1; }
    80% { transform: translate(15px, -50px) scale(1.2); opacity: 0.5; }
    100% { transform: translate(20px, -70px) scale(1.5); opacity: 0; }
}

@keyframes dot-flashing {
    0% { opacity: 0.2; }
    50% { opacity: 1; }
    100% { opacity: 0.2; }
}
.dots span {
    animation: dot-flashing 1.4s infinite;
    animation-fill-mode: both;
}
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }

#number-display-legacy {
    font-size: calc(clamp(8rem, 23vw, 13rem) + 5px);
}

.animate-bounce { animation: bounceIn 0.6s var(--ease-spring) forwards; }
@keyframes bounceIn {
    0% { transform: scale(0.8) translateY(-50px); filter: blur(10px); opacity: 0; }
    40% { transform: scale(1.15, 0.85) translateY(10px); filter: blur(0); opacity: 1; }
    70% { transform: scale(0.95, 1.05) translateY(-5px); }
    100% { transform: scale(1) translateY(0); }
}

/* --- Control Bar --- */
.control-bar {
    margin: auto auto 15px auto; /* Lowered from 30px */
    display: flex; align-items: center; 
    gap: 6px; 
    padding: 14px 20px;
    border-radius: 100px;
    min-width: 240px; 
    justify-content: center;
    transition: transform 0.3s ease, opacity 0.3s ease, margin 0.3s ease;
    flex-shrink: 0;
    min-height: 72px; /* Increased from 72px to clear shadow */
}

.icon-btn {
    border: none; background: transparent; color: var(--text-secondary);
    width: 44px; height: 44px; 
    border-radius: 50%;
    font-size: 18px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s; position: relative; z-index: 3;
    flex-shrink: 0;
}
.icon-btn:hover { color: var(--text-primary); background: var(--btn-bg); }

/* Switch */
.switch-container {
    position: relative; width: 104px; height: 44px;
    background: var(--switch-bg); border-radius: 22px;
    border: 1px solid var(--glass-border);
    padding: 2px; display: flex; align-items: center; justify-content: space-between;
    z-index: 3; flex-shrink: 0; transition: background 0.3s;
}

.glider {
    position: absolute; top: 2px; left: 2px; width: 48px; height: 38px;
    background: var(--glider-bg); border-radius: 20px;
    transition: transform 0.4s var(--ease-spring), background 0.3s; z-index: 1;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1), inset 0 1px 0 rgba(255,255,255,0.3);
}

.switch-container:not(.auto-active) .glider.popping { animation: gliderBounce 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
@keyframes gliderBounce {
    0% { transform: translateX(50px) scale(1); } 25% { transform: translateX(50px) scale(1.15); } 50% { transform: translateX(50px) scale(0.95); } 100% { transform: translateX(50px) scale(1); }
}

@keyframes springSlideToAuto { 0% { transform: translateX(50px) scale(1); } 30% { transform: translateX(20px) scale(1, 1.3); } 60% { transform: translateX(-13px) scale(0.98); } 100% { transform: translateX(0px) scale(1); } }
@keyframes springSlideToPick { 0% { transform: translateX(0px) scale(1); } 30% { transform: translateX(30px) scale(1, 1.3); } 60% { transform: translateX(63px) scale(0.98); } 100% { transform: translateX(50px) scale(1); } }

.switch-container:not(.auto-active) .glider { transform: translateX(50px); animation: springSlideToPick 0.35s linear forwards; }
.switch-container.auto-active .glider { transform: translateX(0px); animation: springSlideToAuto 0.35s linear forwards; }

.switch-container.auto-active .glider::after {
    content: ''; position: absolute; inset: 0; border-radius: inherit;
    box-shadow: 0 0 15px var(--text-primary); animation: pulseGlow 2s infinite;
}
@keyframes pulseGlow { 0%, 100% { opacity: 0.2; } 50% { opacity: 0.5; } }

.switch-btn {
    width: 48px; height: 38px; border: none; background: transparent;
    color: var(--text-secondary); font-size: 16px; border-radius: 20px;
    cursor: pointer; position: relative; z-index: 2;
    display: flex; align-items: center; justify-content: center;
    transition: color 0.3s; padding: 0;
}
.switch-btn:hover { color: var(--text-primary); }
.switch-container.auto-active .btn-auto { color: var(--icon-active); }
.switch-container.auto-active .btn-pick { color: var(--text-tertiary); pointer-events: auto; }
.switch-container:not(.auto-active) .btn-pick { color: var(--icon-active); }

[data-theme="light"] .switch-container.auto-active .btn-auto { color: #000; }
[data-theme="light"] .switch-container:not(.auto-active) .btn-pick { color: #000; }

.switch-container:not(.auto-active) .btn-pick:hover i { transform: rotate(20deg); }
.btn-pick i { transition: transform 0.4s; }

/* --- Main Layout Components --- */
.history-ticker {
    margin: 0 auto 20px auto; /* Increased from 10px */
    display: flex; /* Always flex to reserve space */
    align-items: center; gap: 10px;
    padding: 0px 20px; border-radius: 100px;
    transition: opacity 0.4s, transform 0.4s var(--ease-smooth), padding 0.3s var(--ease-smooth), gap 0.3s ease;
    cursor: pointer; z-index: 50; overflow: hidden;
    flex-shrink: 0;
    min-height: 40px; /* Ensure space is reserved */
    opacity: 0;
    transform: translateY(-20px);
    pointer-events: none;
}
.history-ticker.show { 
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}
.history-label { font-size: 11px; text-transform: uppercase; color: var(--text-tertiary); margin-right: 2px; font-weight: 700; letter-spacing: 0.1em; white-space: nowrap; flex-shrink: 0;}

#history-preview { display: flex; align-items: center; }

.ticker-group {
    display: flex; align-items: center;
    overflow: hidden; white-space: nowrap;
    max-width: 0; opacity: 0; transform: translateX(-10px);
    transition: max-width 0.4s var(--ease-spring), opacity 0.3s ease, transform 0.4s var(--ease-spring);
}

.ticker-group.visible { max-width: 60px; opacity: 1; transform: translateX(0); }
.ticker-group.instant-show { max-width: 60px; opacity: 1; transform: translateX(0); transition: none; }

.ticker-group:nth-child(n+4) {
    display: none !important;
}

.ticker-num { font-family: 'Inter', sans-serif; font-size: 16px; font-weight: 500; color: var(--text-secondary); }
.ticker-divider { 
    display: inline-block; opacity: 0.3; color: var(--text-tertiary); font-size: 12px; margin: 0 6px 0 8px;
    max-width: 10px; transition: all 0.3s ease;
}

.ticker-group:last-child .ticker-divider,
.ticker-group:nth-child(3) .ticker-divider { 
    opacity: 0; max-width: 0; margin: 0; 
}

.ticker-group:first-child .ticker-num { color: var(--text-primary); font-weight: 700; }

/* --- Modals --- */
#modal-alert {
    z-index: 300;
}

.modal-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(20px);
    z-index: 100; opacity: 0; pointer-events: none;
    transition: opacity 0.3s ease;
    display: flex; align-items: center; justify-content: center;
}
[data-theme="light"] .modal-backdrop { background: rgba(0,0,0,0.2); }
.modal-backdrop.open { opacity: 1; pointer-events: auto; }

.glass-card {
    background: var(--glass-bg);
    border-radius: 24px;
    border: 1px solid var(--glass-border);
    box-shadow: 0 40px 80px rgba(0,0,0,0.4);
    opacity: 0; transform: scale(0.95);
    transition: all 0.3s var(--ease-spring);
}
.modal-backdrop.open .glass-card { opacity: 1; transform: scale(1); }

.settings-card {
    position: absolute; bottom: 120px; left: 50%;
    transform: translateX(-50%) scale(0.95); width: 280px;
    z-index: 20; pointer-events: none; transform-origin: bottom center;
    backdrop-filter: blur(50px);
}
.settings-card.open { opacity: 1; pointer-events: auto; transform: translateX(-50%) scale(1); }
.setting-row { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--glass-border); }
.setting-row:last-child { border-bottom: none; }

.setting-label { font-size: 14px; font-weight: 500; }

.alert-box { width: 280px; text-align: center; overflow: hidden; }
.alert-content { padding: 24px 20px; }
.alert-actions { display: flex; border-top: 1px solid var(--glass-border); }
.alert-btn { flex: 1; padding: 14px; border: none; background: transparent; color: var(--text-primary); font-size: 16px; cursor: pointer; border-right: 1px solid var(--glass-border); }
.alert-btn.destructive { color: #FF453A; font-weight: 600; }

.history-card { 
    width: 360px; height: 60vh; 
    display: flex; flex-direction: column; overflow: hidden; 
}
.card-header { 
    padding: 20px 24px; display: flex; justify-content: space-between; align-items: center; 
    border-bottom: 1px solid var(--glass-border);
    flex-shrink: 0;
}
.card-title { font-size: 16px; font-weight: 600; letter-spacing: 0.02em; }
.card-close { background: none; border: none; color: var(--text-tertiary); cursor: pointer; padding: 4px; font-size: 16px; transition: color 0.2s; }
.card-close:hover { color: var(--text-primary); }

.history-content-wrapper {
    flex: 1; overflow-y: auto; padding: 24px;
    scrollbar-width: thin; scrollbar-color: var(--glass-border) transparent;
}
.history-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }

.hist-ball {
    aspect-ratio: 1; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 600; color: var(--text-secondary);
    background: var(--btn-bg);
    border: 1px solid var(--glass-border);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    position: relative; overflow: hidden; opacity: 0;
}

.hist-ball.latest {
    background: var(--text-primary); color: var(--bg-base); font-weight: 800; border: none;
    box-shadow: 0 0 20px rgba(0,0,0,0.2); transform: scale(1.05); z-index: 2;
}

.hist-ball.animate-in { animation: staggerFadeUp 0.5s var(--ease-spring) forwards; }
.hist-ball.latest.animate-in { animation: popLatest 0.6s var(--ease-spring) forwards; }
@keyframes staggerFadeUp { 0% { opacity: 0; transform: translateY(15px) scale(0.8); } 100% { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes popLatest { 0% { opacity: 0; transform: scale(0.5); } 50% { transform: scale(1.15); } 100% { opacity: 1; transform: scale(1.05); } }

.empty-state {
    grid-column: 1 / -1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 40px 0; color: var(--text-tertiary); gap: 10px;
}
.empty-state i { font-size: 24px; opacity: 0.5; }
.empty-state span { font-size: 13px; }

.toggle { width: 40px; height: 24px; background: rgba(120, 120, 128, 0.3); border-radius: 12px; position: relative; cursor: pointer; transition: background 0.3s; }
.toggle::after { content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; background: #fff; border-radius: 50%; transition: transform 0.3s var(--ease-spring); }
.toggle.active { background: #32d74b; } .toggle.active::after { transform: translateX(16px); }

.stepper { display: flex; align-items: center; background: rgba(120, 120, 130, 0.2); border-radius: 8px; padding: 2px; }
.stepper-btn { width: 28px; height: 28px; border: none; background: transparent; color: var(--text-primary); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.stepper-val { font-size: 13px; font-weight: 600; min-width: 40px; text-align: center; }

/* --- Lobby Styles --- */
#stage-lobby {
    position: fixed; inset: 0; z-index: 200; height: 100vh; height: 100svh; width: 100vw;
    background: rgba(0,0,0,0.7); backdrop-filter: blur(10px);
    display: none; flex-direction: column; align-items: center; justify-content: center;
    opacity: 0; transition: opacity 0.4s ease, backdrop-filter 0.4s ease;
}

#stage-lobby.open { display: flex; opacity: 1; pointer-events: auto; }
#stage-lobby.exiting { opacity: 0; backdrop-filter: blur(0px); }

#stage-lobby .stage-label {
    margin-bottom: 24px;
}

.lobby-card { width: 320px; padding: 0 !important; overflow: hidden; transform-origin: center; }
#stage-lobby.open .lobby-card { animation: lobbyEnter 0.5s var(--ease-spring) forwards; }
#stage-lobby.exiting .lobby-card { animation: lobbyExit 0.4s var(--ease-smooth) forwards; }

@keyframes lobbyEnter { 0% { transform: scale(0.9) translateY(20px); opacity: 0; } 100% { transform: scale(1) translateY(0); opacity: 1; } }
@keyframes lobbyExit { 0% { transform: scale(1) translateY(0); opacity: 1; } 100% { transform: scale(0.9) translateY(20px); opacity: 0; } }

.lobby-header { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--glass-border); background: rgba(255,255,255,0.02); }
.lobby-title { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: 0.05em; }
.lobby-content { padding: 24px; display: flex; flex-direction: column; gap: 20px; }
.lobby-subtitle { margin: 0; font-size: 13px; color: var(--text-secondary); text-align: center; }
.input-group { display: flex; flex-direction: column; gap: 8px; }
.input-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700; color: var(--text-tertiary); }

.fancy-input { width: 100%; background: rgba(255,255,255,0.05); border: 1px solid var(--glass-border); padding: 12px 16px; border-radius: 12px; color: var(--text-primary); font-family: inherit; font-size: 14px; transition: all 0.3s; }
.fancy-input:focus { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.3); box-shadow: 0 0 15px rgba(255,255,255,0.05); }
.code-input { text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700; text-align: center; }
.lobby-actions { display: flex; flex-direction: column; gap: 16px; }

.btn-fancy { width: 100%; border: none; padding: 14px; border-radius: 12px; font-family: 'Inter', sans-serif; font-weight: 700; font-size: 15px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px; transition: all 0.3s; }
.host-btn { background: var(--text-primary); color: var(--bg-base); }
.host-btn:hover { transform: translateY(-2px); box-shadow: 0 10px 20px rgba(255,255,255,0.1); }
.join-btn { background: var(--btn-bg); color: var(--text-primary); border: 1px solid var(--glass-border); }
.join-btn:hover { background: rgba(255,255,255,0.15); }
.divider { display: flex; align-items: center; gap: 12px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--glass-border); }
.divider span { font-size: 10px; font-weight: 800; color: var(--text-tertiary); }
.join-row { display: flex; gap: 10px; align-items: stretch; }
.join-row .code-input { flex: 1; min-width: 0; }
.join-row .join-btn { width: auto; padding: 0 28px; height: auto; white-space: nowrap; }

.player-list { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: -30px; margin-bottom: 10px; }
.player-badge { font-size: 15px; font-weight: 600; padding: 8px 16px; background: var(--glass-bg); border-radius: 100px; border: 1px solid var(--glass-border); color: var(--text-secondary); transition: all 0.5s ease; backdrop-filter: blur(10px); }
.player-badge.winner-glow { background: #32d74b; color: white; border-color: #fff; box-shadow: 0 0 20px rgba(50, 215, 75, 0.6); animation: badgePulse 2s infinite; }
@keyframes badgePulse { 0%, 100% { box-shadow: 0 0 20px rgba(50, 215, 75, 0.6); } 50% { box-shadow: 0 0 40px rgba(50, 215, 75, 0.9); } }

/* --- Ticket Styles --- */
.mode-switch-btn {
    position: fixed; top: 24px; right: 24px;
    padding: 10px 16px; border-radius: 100px; display: flex; align-items: center; gap: 8px;
    cursor: pointer; z-index: 50; transition: transform 0.2s, background 0.2s; font-size: 14px; font-weight: 600;
}
.mode-switch-btn:hover { background: var(--btn-bg); transform: scale(1.02); }
.mode-switch-btn span { display: none; }
@media (min-width: 600px) { 
    .mode-switch-btn { padding: 10px 20px; }
    .mode-switch-btn span { display: inline; } 
}

.ticket-container {
    background: var(--glass-bg); backdrop-filter: blur(40px); border: 1px solid var(--glass-border);
    padding: 24px; border-radius: 24px;
    max-width: 600px; width: 100%;
    overflow: visible; margin: 0 auto;
    transition: opacity 0.4s ease, transform 0.4s var(--ease-smooth);
    position: relative;
    display: flex; flex-direction: column;
    transform-origin: top center;
}

.floating-ticket-btn {
    position: absolute; top: 10px; z-index: 10; width: 36px; height: 36px;
    background: var(--glass-bg); border: 1px solid var(--glass-border);
    backdrop-filter: blur(10px); font-size: 14px; transition: all 0.3s ease;
}
.floating-ticket-btn:disabled { opacity: 0; pointer-events: none; transform: scale(0.8); }
.btn-back { left: 10px; }
.btn-refresh { right: 10px; }

.is-host .ticket-container { 
    /* Scaling handled by media queries now to avoid double scaling */
}

.ticket-grid-view {
    display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px;
    background: var(--ticket-grid-bg); padding: 6px; border-radius: 12px;
    border: 1px solid var(--glass-border); margin-bottom: 12px;
    flex-shrink: 0;
}
.ticket-grid-view:last-child { margin-bottom: 0; }

.ticket-cell {
    aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
    font-family: 'Inter', monospace; font-weight: 700; font-size: clamp(14px, 4vw, 22px);
    color: var(--text-primary); background: var(--ticket-cell-bg);
    border-radius: 6px; cursor: pointer; user-select: none; transition: all 0.2s; border: none;
}
.ticket-cell.empty { background: transparent; cursor: default; pointer-events: none; border: none; }
.ticket-cell:not(.empty):hover { background: var(--ticket-cell-hover); transform: scale(0.92); }
.ticket-cell.marked {
    background: #FF453A; color: white; box-shadow: 0 0 15px rgba(255, 69, 58, 0.5);
    border-color: rgba(255,255,255,0.2); transform: scale(1.05); z-index: 2;
}
.ticket-cell.marked:hover { background: #ff5e55; color: white; transform: scale(0.98); }

.ticket-actions { display: flex; gap: 16px; margin-top: 24px; justify-content: center; }
.btn-primary {
    background: var(--text-primary); color: var(--bg-base); border: none; padding: 12px 24px;
    border-radius: 100px; font-weight: 700; cursor: pointer; display: flex; align-items: center; gap: 8px;
    font-size: 16px; transition: transform 0.2s, opacity 0.2s;
}
.btn-primary:active { transform: scale(0.95); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

@keyframes winnerReveal {
    0% { transform: scale(0.5) translateY(40px); opacity: 0; filter: blur(20px); }
    15% { transform: scale(1.1) translateY(0); opacity: 1; filter: blur(0); }
    80% { transform: scale(1) translateY(0); opacity: 1; filter: blur(0); }
    100% { transform: scale(1.2) translateY(-40px); opacity: 0; filter: blur(30px); }
}
.animate-winner { animation: winnerReveal 6s forwards cubic-bezier(0.23, 1, 0.32, 1); }

/* --- Scaling Logic --- */
@media (max-width: 600px) {
    .number-display-container { margin-bottom: 5px; }
    .ticket-container { padding: 10px; border-radius: 16px; }
    .ticket-grid-view { gap: 3px; padding: 4px; margin-bottom: 6px; border-radius: 8px; }
    .ticket-cell { font-size: clamp(12px, 3.8vw, 18px); border-radius: 4px; }

    .mode-switch-btn {
        padding: 12px 16px; /* Match history pill height */
    }
}