:root {
    --bg: #0f1220;
    --bg-card: #1a1e33;
    --bg-card-2: #20264a;
    --text: #eef0fb;
    --text-dim: #9aa1c3;
    --black-color: #7c8cff;
    --red-color: #ff5d7a;
    --gold: #ffd166;
    --silver: #cbd5e1;
    --bronze: #e0a877;
    --radius: 14px;
    --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    background: radial-gradient(circle at top, #171b30, var(--bg) 60%);
    color: var(--text);
    min-height: 100vh;
}

a {
    color: var(--black-color);
    text-decoration: none;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 24px;
    background: rgba(20, 23, 42, .85);
    backdrop-filter: blur(6px);
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: var(--shadow);
}

.brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
}

.topbar nav {
    display: flex;
    align-items: center;
    gap: 18px;
}

.topbar nav a, .link-btn {
    color: var(--text-dim);
    font-weight: 600;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
}

.topbar nav a:hover, .link-btn:hover {
    color: var(--text);
}

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

.inline-form {
    display: inline;
    margin: 0;
}

.page {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 16px 64px;
}

.section-title {
    font-size: 1.1rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: .06em;
    margin: 36px 0 14px;
}

/* Podium */
.podium {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 18px;
    margin: 24px 0;
    min-height: 200px;
}

.podium-spot {
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: podium-rise .6s ease-out backwards;
}

.podium-spot.rank-1 {
    animation-delay: .3s;
}

.podium-spot.rank-2 {
    animation-delay: .1s;
}

.podium-spot.rank-3 {
    animation-delay: .5s;
}

@keyframes podium-rise {
    from {
        opacity: 0;
        transform: translateY(30px) scale(.85);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.medal {
    font-size: 2rem;
}

.podium-name {
    font-weight: 700;
    margin: 4px 0;
    color: var(--text);
}

.podium-score {
    font-weight: 800;
    font-size: 1.4rem;
    color: var(--gold);
}

.podium-pillar {
    width: 90px;
    border-radius: 8px 8px 0 0;
    margin-top: 8px;
    background: linear-gradient(180deg, var(--bg-card-2), var(--bg-card));
}

.rank-1 .podium-pillar {
    height: 100px;
    background: linear-gradient(180deg, var(--gold), var(--bg-card));
}

.rank-2 .podium-pillar {
    height: 68px;
    background: linear-gradient(180deg, var(--silver), var(--bg-card));
}

.rank-3 .podium-pillar {
    height: 44px;
    background: linear-gradient(180deg, var(--bronze), var(--bg-card));
}

/* Period banner */
.period-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 14px 20px;
    margin: 20px 0;
    box-shadow: var(--shadow);
}

.period-name {
    font-weight: 700;
    flex: 1;
}

.countdown {
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 1.1rem;
    color: var(--gold);
}

.period-link {
    color: var(--text-dim);
    font-size: .9rem;
}

.period-range {
    color: var(--text-dim);
    margin: 0 0 12px;
}

/* Branches */
.branches {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}

.branch-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow);
    animation: fade-in-up .4s ease-out backwards;
}

.branch-card h3 {
    margin: 0 0 10px;
    color: var(--text-dim);
    font-size: .95rem;
}

@keyframes fade-in-up {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.child-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-top: 1px solid rgba(255, 255, 255, .06);
}

.child-row:first-of-type {
    border-top: none;
}

.child-name {
    flex: 1;
    font-weight: 600;
    color: var(--text);
}

.mini-score {
    font-weight: 800;
    min-width: 28px;
    text-align: right;
}

.mini-score.positive {
    color: var(--black-color);
}

.mini-score.negative {
    color: var(--red-color);
}

/* Quick actions */
.quick-actions {
    display: flex;
    gap: 6px;
}

.btn {
    border: none;
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: .95rem;
    transition: transform .12s ease, filter .12s ease;
}

.btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.15);
}

.btn:active {
    transform: scale(.94);
}

.btn-black {
    background: var(--black-color);
    color: #0f1220;
}

.btn-red {
    background: var(--red-color);
    color: #0f1220;
}

.btn-reset {
    background: #3a3f5c;
    color: var(--text);
}

.btn-tiny {
    background: #3a3f5c;
    color: var(--text-dim);
    padding: 2px 8px;
    font-size: .8rem;
}

.btn-primary {
    background: var(--gold);
    color: #0f1220;
    font-weight: 700;
    padding: 10px 18px;
}

/* Leaderboard */
.leaderboard {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.leaderboard th, .leaderboard td, .history th, .history td {
    padding: 10px 14px;
    text-align: left;
}

.leaderboard thead, .history thead {
    background: var(--bg-card-2);
    color: var(--text-dim);
    font-size: .8rem;
    text-transform: uppercase;
}

.leaderboard-row {
    animation: fade-in-up .35s ease-out backwards;
}

.leaderboard-row:nth-child(odd) {
    background: rgba(255, 255, 255, .02);
}

.score-cell {
    font-weight: 800;
}

/* Child detail */
.back-link {
    color: var(--text-dim);
    display: inline-block;
    margin-bottom: 12px;
}

.score-tiles {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin: 16px 0 20px;
}

.tile {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
    box-shadow: var(--shadow);
}

.tile-label {
    display: block;
    color: var(--text-dim);
    font-size: .85rem;
    margin-bottom: 6px;
}

.tile-value {
    font-size: 2rem;
    font-weight: 800;
}

.tile-black .tile-value {
    color: var(--black-color);
}

.tile-red .tile-value {
    color: var(--red-color);
}

.history {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.empty-row {
    color: var(--text-dim);
    padding: 20px;
    text-align: center;
}

/* Periods page */
.active-period {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.create-period {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 24px;
}

.period-form {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    align-items: end;
}

.period-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: var(--text-dim);
    font-size: .85rem;
}

.period-form input {
    background: var(--bg-card-2);
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--text);
}

.frozen-period {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 14px;
    box-shadow: var(--shadow);
}

.frozen-results {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.frozen-results li {
    display: flex;
    gap: 10px;
    align-items: center;
}

.frozen-rank {
    font-weight: 700;
    color: var(--text-dim);
    width: 20px;
}

.frozen-name {
    flex: 1;
}

.frozen-score {
    font-weight: 800;
}

.error-msg {
    color: var(--red-color);
    font-weight: 600;
}

.success-msg {
    color: var(--black-color);
    font-weight: 600;
}

.account-link {
    color: var(--text-dim);
    font-weight: 600;
}

.account-link:hover {
    color: var(--text);
}

.account-link.needs-attention {
    color: var(--gold);
}

.hint {
    color: var(--text-dim);
}

.login-page {
    max-width: 360px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.login-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: var(--text-dim);
}

.login-form input {
    background: var(--bg-card-2);
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 8px;
    padding: 10px;
    color: var(--text);
}

[x-cloak] {
    display: none !important;
}

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--gold);
    color: #0f1220;
    font-weight: 700;
    padding: 10px 20px;
    border-radius: 999px;
    box-shadow: var(--shadow);
    z-index: 2000;
}

/* Confetti */
.confetti-piece {
    position: fixed;
    top: -12px;
    width: 8px;
    height: 14px;
    opacity: .9;
    pointer-events: none;
    z-index: 1000;
    animation: confetti-fall linear forwards;
}

@keyframes confetti-fall {
    to {
        transform: translateY(110vh) rotate(540deg);
        opacity: 0;
    }
}
