:root {
    --bg1: #071224;
    --bg2: #0f2547;
    --glass: rgba(15, 32, 60, 0.72);
    --glass-border: rgba(255, 255, 255, 0.14);
    --text: #f8fafc;
    --muted: #cbd5e1;
    --accent: #ef4444;
    --gold: #facc15;
    --green: #22c55e;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: linear-gradient(170deg, var(--bg1) 0%, var(--bg2) 60%, #102a43 100%);
    color: var(--text);
    overflow-x: hidden;
}

#snow-canvas {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.garland {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-around;
    padding: 2px 6px;
    pointer-events: none;
    z-index: 5;
}

.garland span {
    width: 10px;
    height: 14px;
    border-radius: 50%;
    animation: twinkle 1.6s infinite alternate;
}

.garland span:nth-child(4n+1) { background: #ef4444; box-shadow: 0 0 10px #ef4444; }
.garland span:nth-child(4n+2) { background: #facc15; box-shadow: 0 0 10px #facc15; animation-delay: 0.4s; }
.garland span:nth-child(4n+3) { background: #22c55e; box-shadow: 0 0 10px #22c55e; animation-delay: 0.8s; }
.garland span:nth-child(4n+4) { background: #38bdf8; box-shadow: 0 0 10px #38bdf8; animation-delay: 1.2s; }

@keyframes twinkle {
    from { opacity: 0.45; transform: translateY(0); }
    to { opacity: 1; transform: translateY(2px); }
}

.app-shell {
    position: relative;
    z-index: 2;
    max-width: 480px;
    margin: 0 auto;
    padding: 18px 14px 128px;
}

.glass {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-radius: 18px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center-text { text-align: center; }
.mt-12 { margin-top: 12px; }

/* Topbar */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    padding-top: 4px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-badge {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.25), rgba(250, 204, 21, 0.2));
    border: 1px solid rgba(250, 204, 21, 0.35);
    color: var(--gold);
    display: flex;
    align-items: center;
    justify-content: center;
}

.brand-badge .ico { width: 22px; height: 22px; }
.brand-title { font-weight: 800; font-size: 18px; letter-spacing: 0.2px; }
.brand-sub { font-size: 12px; color: var(--gold); }

.ico {
    width: 18px;
    height: 18px;
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
}

.ico-wrap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
}

.ico-wrap.gold { color: var(--gold); }

.title-with-ico {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.mt-6 { margin-top: 6px; }
.mb-10 { margin-bottom: 10px; }

.hero-icon-badge {
    width: 64px;
    height: 64px;
    margin: 0 auto 12px;
    border-radius: 18px;
    background: rgba(250, 204, 21, 0.14);
    border: 1px solid rgba(250, 204, 21, 0.35);
    color: var(--gold);
    display: flex;
    align-items: center;
    justify-content: center;
}

.hero-icon-badge .ico { width: 32px; height: 32px; }

.spinner-badge {
    width: 64px;
    height: 64px;
    margin: 0 auto 12px;
    border-radius: 50%;
    background: rgba(34, 197, 94, 0.16);
    border: 1px solid rgba(34, 197, 94, 0.4);
    color: #4ade80;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse 1.2s infinite ease-in-out;
}

.spinner-badge .ico { width: 32px; height: 32px; }

.orn-svg {
    width: 28px;
    height: 28px;
    display: block;
}

.wm-ornament-wrap {
    width: 64px;
    height: 64px;
    margin: 0 auto 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--glass-border);
    border-radius: 18px;
}

.wm-ornament-wrap .orn-svg { width: 44px; height: 44px; }

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    vertical-align: middle;
    margin-right: 4px;
}

.status-dot.green { background: #22c55e; box-shadow: 0 0 6px #22c55e; }
.status-dot.gray { background: #94a3b8; }

.rank-medal {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 26px;
    height: 26px;
    padding: 0 6px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 800;
    margin-right: 8px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--muted);
}

.rank-medal.m1 { background: linear-gradient(135deg, #facc15, #ca8a04); color: #0f172a; }
.rank-medal.m2 { background: linear-gradient(135deg, #e2e8f0, #94a3b8); color: #0f172a; }
.rank-medal.m3 { background: linear-gradient(135deg, #fb923c, #c2410c); color: #fff; }

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

.icon-btn {
    background: rgba(255,255,255,0.1);
    border: 1px solid var(--glass-border);
    color: var(--text);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.pill-btn {
    background: rgba(255,255,255,0.12);
    border: 1px solid var(--glass-border);
    color: var(--text);
    padding: 7px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
}

.pill-btn.accent {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    border: none;
}

/* Center cards */
.center-card {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 28px 20px;
    text-align: center;
    margin-top: 40px;
}

.spinner {
    font-size: 46px;
    animation: pulse 1.2s infinite ease-in-out;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

.gate-emoji { font-size: 48px; margin-bottom: 8px; }

/* Buttons */
.primary-btn {
    background: linear-gradient(135deg, #ef4444, #b91c1c);
    color: #fff;
    border: none;
    padding: 13px 18px;
    border-radius: 14px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(239, 68, 68, 0.35);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.primary-btn:active { transform: scale(0.98); }

.secondary-btn {
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    border: 1px solid var(--glass-border);
    padding: 12px 16px;
    border-radius: 14px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.full-btn { width: 100%; }

.share-btn {
    background: linear-gradient(135deg, #facc15, #eab308);
    color: #1e293b;
    border: none;
    padding: 9px 14px;
    border-radius: 12px;
    font-weight: 800;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
}

/* Tree Header & Stage */
.tree-header-card {
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.tree-header-card h1 {
    margin: 0 0 4px;
    font-size: 19px;
}

.level-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
}

.badge {
    background: rgba(250, 204, 21, 0.18);
    color: var(--gold);
    border: 1px solid rgba(250, 204, 21, 0.4);
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
}

.tree-stage {
    position: relative;
    padding: 12px 8px;
    margin-bottom: 12px;
    overflow: hidden;
    min-height: 360px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.christmas-tree-svg {
    width: 100%;
    max-width: 310px;
    height: auto;
    display: block;
}

.ornaments-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.ornament-item {
    position: absolute;
    transform: translate(-50%, -50%);
    pointer-events: auto;
    background: rgba(15, 23, 42, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 21px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    animation: sway 3s ease-in-out infinite;
}

@keyframes sway {
    0%, 100% { transform: translate(-50%, -50%) rotate(-5deg); }
    50% { transform: translate(-50%, -50%) rotate(5deg); }
}

.action-row { margin-bottom: 12px; }

.section-card {
    padding: 16px;
    margin-bottom: 12px;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.section-head h2, .section-head h3 { margin: 0; font-size: 17px; }

/* Wishes */
.wishes-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.wish-card {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 14px;
    padding: 12px;
    cursor: pointer;
}

.wish-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
    font-size: 13px;
}

.wish-card-text {
    font-size: 14px;
    line-height: 1.4;
    color: #f1f5f9;
}

/* Mini-Game */
.record-box {
    text-align: right;
    background: rgba(250, 204, 21, 0.14);
    border: 1px solid rgba(250, 204, 21, 0.3);
    padding: 6px 12px;
    border-radius: 12px;
}

.record-box strong {
    display: block;
    font-size: 18px;
    color: var(--gold);
}

.game-hud {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.hud-pill {
    flex: 1;
    background: rgba(255,255,255,0.08);
    padding: 8px 12px;
    border-radius: 12px;
    text-align: center;
    font-size: 14px;
}

.game-canvas-wrap {
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    background: radial-gradient(circle at top, #132c52, #071224);
    border: 1px solid var(--glass-border);
}

#game-canvas {
    width: 100%;
    height: auto;
    display: block;
    touch-action: none;
}

.game-overlay {
    position: absolute;
    inset: 0;
    background: rgba(7, 18, 36, 0.84);
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 20px;
}

/* Prediction */
.prediction-box {
    text-align: center;
    padding: 14px 10px;
    background: rgba(255,255,255,0.05);
    border-radius: 16px;
}

.prediction-gift { font-size: 52px; margin-bottom: 8px; }
.prediction-text { font-size: 15px; line-height: 1.5; margin: 0 0 12px; }
.prediction-word {
    display: inline-block;
    background: rgba(250, 204, 21, 0.2);
    color: var(--gold);
    border: 1px solid var(--gold);
    padding: 5px 14px;
    border-radius: 999px;
    font-weight: 800;
    margin-bottom: 12px;
}

/* Leaderboard */
.seg-btns {
    display: flex;
    background: rgba(255,255,255,0.08);
    border-radius: 10px;
    padding: 3px;
}

.seg-btn {
    border: none;
    background: transparent;
    color: var(--muted);
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.seg-btn.active {
    background: var(--accent);
    color: #fff;
}

.rank-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.rank-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: rgba(255,255,255,0.06);
    border-radius: 12px;
}

.rank-row.me {
    border: 1px solid var(--gold);
    background: rgba(250, 204, 21, 0.12);
}

/* Admin */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.stat-tile {
    background: rgba(255,255,255,0.06);
    border-radius: 12px;
    padding: 10px;
}

.stat-tile span { font-size: 12px; color: var(--muted); display: block; }
.stat-tile strong { font-size: 20px; color: var(--gold); }

.admin-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.admin-form input, .admin-form textarea, #wish-input {
    width: 100%;
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid rgba(255,255,255,0.18);
    color: #fff;
    padding: 11px 12px;
    border-radius: 12px;
    font-family: inherit;
    font-size: 14px;
}

.two-cols {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.file-label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12px;
    color: var(--muted);
}

.stack-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.admin-item {
    background: rgba(255,255,255,0.06);
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 13px;
}

.admin-item-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

/* WebApp Banner */
.webapp-banner {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 68px;
    width: calc(100% - 24px);
    max-width: 452px;
    z-index: 15;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.webapp-banner img {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    object-fit: cover;
}

.banner-body { flex: 1; min-width: 0; }
.banner-title { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Bottom Nav */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    background: rgba(8, 18, 36, 0.94);
    border-top: 1px solid var(--glass-border);
    backdrop-filter: blur(16px);
    display: flex;
    justify-content: space-around;
    padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
    z-index: 20;
}

.nav-item {
    background: none;
    border: none;
    color: var(--muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    cursor: pointer;
    flex: 1;
}

.nav-ico {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.nav-ico .ico { width: 20px; height: 20px; }

.nav-item small { font-size: 11px; font-weight: 600; }
.nav-item.active { color: var(--gold); }

/* Modals */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-card {
    position: relative;
    width: 100%;
    max-width: 420px;
    padding: 22px 18px;
    max-height: 88vh;
    overflow-y: auto;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(255,255,255,0.12);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.modal-close .ico { width: 16px; height: 16px; }

.wm-emoji { font-size: 46px; text-align: center; }
#wm-author { text-align: center; margin: 6px 0 2px; }
#wm-date { text-align: center; margin: 0 0 12px; }
.wm-message {
    background: rgba(255,255,255,0.08);
    padding: 14px;
    border-radius: 14px;
    line-height: 1.5;
    font-size: 15px;
    white-space: pre-wrap;
}

.ornament-picker {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    margin: 12px 0;
}

.pick-item {
    background: rgba(255,255,255,0.08);
    border: 2px solid transparent;
    border-radius: 12px;
    height: 44px;
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.pick-item.selected {
    border-color: var(--gold);
    background: rgba(250, 204, 21, 0.2);
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 10px 0 14px;
    font-size: 13px;
    color: var(--muted);
}

.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.95);
    border: 1px solid var(--gold);
    color: #fff;
    padding: 10px 16px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    z-index: 60;
    box-shadow: 0 8px 24px rgba(0,0,0,0.45);
}
