:root {
            --primary: #2563eb; --primary-dark: #1d4ed8; --bg: #f8fafc; --card-bg: #ffffff;
            --text-main: #0f172a; --text-muted: #64748b; --success: #10b981; --danger: #ef4444;
            --border-radius: 12px; --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
        }
        * { box-sizing: border-box; margin: 0; padding: 0; }
        body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--text-main); padding-bottom: 80px; }
        a { text-decoration: none; color: inherit; }

        .container { max-width: 800px; margin: 0 auto; padding: 20px; }
        
        /* AUTH MODAL & PLAYER MODAL */
        .modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); z-index: 2000; display: none; justify-content: center; align-items: center; }
        .modal-overlay.open { display: flex; }
        .modal-box { background: white; padding: 25px; border-radius: 16px; width: 90%; max-width: 380px; box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1); position: relative; animation: popIn 0.2s ease-out; }
        @keyframes popIn { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
        .close-modal { position: absolute; top: 15px; right: 15px; background: none; border: none; font-size: 1.5rem; color: #999; cursor: pointer; }
        
        .auth-tabs { display: flex; margin-bottom: 20px; border-bottom: 1px solid #e2e8f0; }
        .auth-tab { flex: 1; text-align: center; padding: 10px; cursor: pointer; font-weight: 600; color: var(--text-muted); }
        .auth-tab.active { color: var(--primary); border-bottom: 2px solid var(--primary); }
        .auth-form { display: none; }
        .auth-form.active { display: block; }
        .form-input { width: 100%; padding: 12px; border: 1px solid #e2e8f0; border-radius: 8px; font-size: 1rem; margin-bottom: 15px; font-family: inherit; }
        .forgot-link { display:block; text-align:right; margin-top:-10px; margin-bottom:15px; font-size:0.85rem; color:var(--primary); cursor:pointer; }
        
        .card { background: var(--card-bg); border-radius: var(--border-radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 20px; }
        .card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
        .card-title { font-weight: 700; font-size: 1.1rem; }
        
        .alert { padding: 12px; border-radius: 8px; margin-bottom: 15px; font-size: 0.9rem; font-weight: 500; text-align: center; }
        .alert-error { background: #fee2e2; color: #b91c1c; }
        .alert-ok { background: #dcfce7; color: #166534; }

        .game-list { list-style: none; }
        .game-item { display: flex; justify-content: space-between; align-items: center; padding: 12px; background: #f8fafc; border-radius: 8px; margin-bottom: 10px; border: 1px solid #e2e8f0; }
        .game-info { flex: 1; cursor: pointer; }
        .game-name { font-weight: 600; color: var(--text-main); }
        .game-meta { font-size: 0.75rem; color: var(--text-muted); display: flex; gap: 10px; align-items: center; }
        .badge { padding: 2px 6px; border-radius: 4px; font-size: 0.7rem; font-weight: bold; text-transform: uppercase; }
        .badge-live { background: #dbeafe; color: var(--primary); }
        .badge-open { background: #dcfce7; color: #166534; }
        
        .btn-action { padding: 8px 14px; border-radius: 6px; font-size: 0.85rem; font-weight: 600; border: none; cursor: pointer; margin-left: 10px; text-decoration: none; display: inline-block; }
        .btn-join { background: var(--success); color: white; }
        .btn-view { background: #e2e8f0; color: var(--text-main); }
        .btn-start { background: var(--primary); color: white; }
        .btn-delete { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: #fee2e2; margin-left: 5px; }
        .btn-toggle-hist { background: #f1f5f9; color: var(--text-muted); font-size: 0.8rem; padding: 6px 12px; border-radius: 20px; border: 1px solid #e2e8f0; cursor: pointer; }

        .form-label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 0.9rem; color: var(--text-muted); }
        .radio-group { display: flex; gap: 10px; margin-bottom: 15px; }
        .radio-label { flex: 1; text-align: center; padding: 10px; background: #f1f5f9; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--text-muted); border: 2px solid transparent; transition: 0.2s; }
        input[type="radio"]:checked + .radio-label { background: #eff6ff; color: var(--primary); border-color: var(--primary); }
        input[type="radio"] { display: none; }
        
        .player-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; max-height: 150px; overflow-y: auto; padding: 5px; border: 1px solid #e2e8f0; border-radius: 8px; background: #f8fafc; margin-bottom: 15px; }
        .player-check { display: none; }
        .player-tile { display: flex; align-items: center; justify-content: center; padding: 8px; background: white; border: 1px solid #e2e8f0; border-radius: 6px; font-size: 0.85rem; font-weight: 500; cursor: pointer; transition: 0.1s; text-align: center; }
        .player-check:checked + .player-tile { background: var(--primary); color: white; border-color: var(--primary); font-weight: 700; }

        .btn-primary { width: 100%; padding: 14px; background: var(--primary); color: white; border: none; border-radius: 8px; font-size: 1rem; font-weight: 700; cursor: pointer; box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.2); transition: background 0.2s; }

        .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin-bottom: 20px; }
        .nav-card { background: var(--card-bg); padding: 15px; border-radius: var(--border-radius); box-shadow: var(--shadow); text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--text-main); font-weight: 600; transition: transform 0.1s; border: 1px solid transparent; height: 100px; }
        .nav-card:active { transform: scale(0.98); background: #f8fafc; }
        .nav-card-icon { font-size: 1.8rem; }
        .nav-card-sub { font-size: 0.7rem; color: var(--text-muted); font-weight: 400; }

        .history-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
        .history-table td { padding: 12px 5px; border-bottom: 1px solid #f1f5f9; }
        .history-table tr:last-child td { border-bottom: none; }
        .section-header td { background: #f8fafc; color: var(--text-muted); font-weight: 800; font-size: 0.75rem; padding: 8px 10px; border-top: 1px solid #e2e8f0; text-transform:uppercase; letter-spacing:0.05em; }

        .shops-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 15px; justify-content: center; padding: 10px 0; }
        .shop-btn { height: 60px; display: flex; align-items: center; justify-content: center; background: white; border: 1px solid #e2e8f0; border-radius: 12px; transition: transform 0.1s, box-shadow 0.1s; }
        .shop-btn:hover { transform: translateY(-2px); box-shadow: 0 4px 6px rgba(0,0,0,0.05); }
        .shop-btn img { max-width: 80%; max-height: 80%; object-fit: contain; }
        
        /* REGISTRATION & CALENDAR BUTTONS */
        .btn-reg { padding: 4px 8px; font-size: 0.75rem; border-radius: 6px; border: none; cursor: pointer; font-weight: 600; margin-left:5px; }
        .btn-reg-join { background: var(--success); color: white; }
        .btn-reg-leave { background: #fee2e2; color: var(--danger); }
        .btn-reg-start { background: var(--primary); color: white; }
        .btn-reg-view { background: #e2e8f0; color: var(--text-main); }
        .reg-count { font-size: 0.75rem; color: var(--text-muted); margin-left: 5px; }
        
        /* BUTTON GROUPS (Radio as Buttons) */
        .btn-group { display: flex; gap: 8px; }
        .btn-check-label { flex:1; text-align:center; padding:10px; background:#f1f5f9; border:1px solid #e2e8f0; border-radius:8px; cursor:pointer; font-weight:600; font-size:0.9rem; transition:0.2s; color:var(--text-muted); }
        .btn-check-input:checked + .btn-check-label { background:var(--primary); color:white; border-color:var(--primary); }
        .btn-check-input { display:none; }

        .ordered-item:hover { border-color: var(--primary) !important; }
        .ordered-item[draggable="true"] { user-select: none; }

        @media(min-width: 768px) {
            .grid-2 { grid-template-columns: repeat(4, 1fr); }
        }

/* Kuvakkeet nav-korteissa: kuva pidetään emoji-kuvakkeen kokoisena */
.nav-card-icon { display: flex; align-items: center; justify-content: center; height: 2.2rem; }
.nav-card-icon img { width: 1.9rem; height: 1.9rem; object-fit: contain; display: block; }

/* Taitettava kortti (Luo uusi turnaus): suljettu oletuksena */
details.collapsible > summary { cursor: pointer; list-style: none; margin-bottom: 0; }
details.collapsible > summary::-webkit-details-marker { display: none; }
details.collapsible > summary::after { content: '▸'; color: var(--primary); font-size: 1.1rem; margin-left: 10px; transition: transform .2s; }
details.collapsible[open] > summary { margin-bottom: 15px; }
details.collapsible[open] > summary::after { transform: rotate(90deg); }

/* Etusivun tilannekortit */
.overview { display: grid; grid-template-columns: 1fr; gap: 12px; margin-bottom: 14px; }
.ov-card { background: var(--card-bg); border-radius: var(--border-radius); box-shadow: var(--shadow); padding: 16px; display: block; color: inherit; text-decoration: none; }
.ov-link:active { transform: scale(0.99); }
.ov-label { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 6px; }
.ov-main { font-weight: 800; font-size: 1.1rem; }
.ov-sub { font-size: 0.85rem; color: var(--text-muted); margin-top: 3px; }
.ov-form { display: flex; gap: 5px; margin-top: 8px; }
.pos-chip { background: #f1f5f9; color: var(--text-muted); border-radius: 6px; padding: 2px 8px; font-size: 0.8rem; font-weight: 700; }
.pos-chip.top3 { background: #dbeafe; color: #1d4ed8; }
.pos-chip.gold { background: #fef3c7; color: #b45309; }
.push-btn { margin-top: 10px; border: 1px solid #e2e8f0; background: #f8fafc; color: var(--text-main); border-radius: 999px; padding: 7px 14px; font: inherit; font-size: 0.85rem; font-weight: 600; cursor: pointer; }
.push-btn.on { background: #dcfce7; border-color: #86efac; color: #166534; }
.push-btn[hidden] { display: none; }
.live-link { display: flex; align-items: center; gap: 12px; background: var(--card-bg); border-radius: var(--border-radius); box-shadow: var(--shadow); padding: 12px 16px; margin-bottom: 20px; color: inherit; text-decoration: none; }
.live-link img { width: 2rem; height: 2rem; object-fit: contain; }
.live-link span { display: flex; flex-direction: column; flex: 1; }
.live-link small { color: var(--text-muted); font-size: 0.78rem; }
.live-link .chev { flex: none; font-size: 1.6rem; color: var(--text-muted); }
@media (min-width: 768px) { .overview { grid-template-columns: repeat(3, 1fr); } }

.ov-me { margin-top: 8px; padding: 6px 10px; background: #eff6ff; color: #1d4ed8; border-radius: 8px; font-size: 0.85rem; }
