:root {
    --bg:        #0e1220;
    --bg-2:      #161c31;
    --panel:     #1b2238;
    --border:    #2b3554;
    --text:      #e6ebff;
    --muted:     #8b97bd;
    --accent:    #5b7cfa;
    --accent-2:  #22d3a7;
    --danger:    #ff6b6b;
    --warn:      #ffc857;
    --radius:    14px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    background: radial-gradient(1200px 800px at 20% -10%, #1c2547 0%, var(--bg) 55%);
    color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

/* ── Top bar ─────────────────────────────────────────────── */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 22px;
    background: rgba(14, 18, 32, .8);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 50;
}

.brand { font-size: 20px; font-weight: 700; letter-spacing: .5px; }
.brand span { background: linear-gradient(90deg, #5b7cfa, #22d3a7); -webkit-background-clip: text; background-clip: text; color: transparent; }

.userbox { display: flex; align-items: center; gap: 12px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--border); }
.uname { font-weight: 600; }
.pill { background: var(--bg-2); border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px; font-size: 14px; }

/* ── Layout ──────────────────────────────────────────────── */
.layout {
    display: grid;
    grid-template-columns: 240px minmax(360px, 1fr) 340px;
    gap: 16px;
    padding: 16px 22px 40px;
    align-items: start;
}

@media (max-width: 1100px) {
    .layout { grid-template-columns: 1fr; }
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, .25);
}

.panel h2 { margin: 0 0 12px; font-size: 16px; letter-spacing: .3px; }
.muted { color: var(--muted); font-size: 13px; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
    border: 1px solid var(--border);
    background: var(--bg-2);
    color: var(--text);
    padding: 9px 16px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: .15s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.primary { background: linear-gradient(135deg, #5b7cfa, #7c5bfa); border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.wide { width: 100%; justify-content: center; margin-top: 12px; }

/* ── Palette ─────────────────────────────────────────────── */
.palette-list { display: flex; flex-direction: column; gap: 8px; }

.pal-block {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    border: none;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: .15s;
    text-align: left;
}
.pal-block:hover { transform: translateX(3px); filter: brightness(1.12); }
.pal-block .picon { font-size: 16px; }

.c-blue   { background: linear-gradient(135deg, #3b6ef5, #2f56c9); }
.c-green  { background: linear-gradient(135deg, #17b98a, #0e8f6a); }
.c-purple { background: linear-gradient(135deg, #8b5bfa, #6a3fd1); }
.c-amber  { background: linear-gradient(135deg, #e8a33d, #c6842a); }

/* ── Stage ───────────────────────────────────────────────── */
.stage-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.stage-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.brief { color: var(--muted); font-size: 14px; margin: 6px 0 16px; line-height: 1.5; }

.board-wrap {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 340px;
    padding: 16px;
    background: #0b0f1c;
    border: 1px solid var(--border);
    border-radius: 12px;
}

.board { position: relative; }

.cell {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, .04);
    background: #121a2e;
    border-radius: 4px;
}
.cell.wall  { background: #2b3554; box-shadow: inset 0 0 0 2px #1d2540; }
.cell.goal  { background: rgba(34, 211, 167, .14); }
.cell.item  { background: rgba(255, 200, 87, .12); }

.robot {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #7cc9ff;
    text-shadow: 0 0 14px rgba(91, 124, 250, .9);
    transition: left .12s linear, top .12s linear;
    z-index: 5;
    pointer-events: none;
}

/* ── Status ──────────────────────────────────────────────── */
.status { margin-top: 14px; min-height: 22px; font-size: 14px; font-weight: 600; }
.status.info    { color: var(--muted); }
.status.success { color: var(--accent-2); }
.status.error   { color: var(--danger); }
.status.warn    { color: var(--warn); }

/* ── Program ─────────────────────────────────────────────── */
.program { min-height: 160px; }

.blocklist {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.block {
    border-radius: 10px;
    padding: 8px 10px;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
}

.block-head { display: flex; align-items: center; gap: 8px; }
.blabel { flex: 1; }

.barg {
    width: 54px;
    padding: 3px 6px;
    border-radius: 6px;
    border: none;
    background: rgba(0, 0, 0, .3);
    color: #fff;
    font-weight: 700;
    font-size: 13px;
}

.btools { display: flex; gap: 4px; }
.tbtn {
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 6px;
    background: rgba(0, 0, 0, .3);
    color: #fff;
    font-size: 11px;
    cursor: pointer;
    line-height: 1;
}
.tbtn:hover { background: rgba(0, 0, 0, .55); }

.dropzone {
    border: 1px dashed var(--border);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 12px;
    color: var(--muted);
    text-align: center;
    cursor: pointer;
    transition: .15s;
}
.dropzone:hover { border-color: var(--accent); color: var(--text); }
.dropzone.active { border-color: var(--accent-2); color: var(--accent-2); background: rgba(34, 211, 167, .08); }

/* ── Tabs ────────────────────────────────────────────────── */
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tab {
    flex: 1;
    padding: 8px;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
}
.tab.active { background: var(--bg-2); color: var(--text); border-color: var(--accent); }

.tabpane { display: none; }
.tabpane.active { display: block; }

/* ── Task list ───────────────────────────────────────────── */
.tasklist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.taskitem {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--bg-2);
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 14px;
    transition: .15s;
}
.taskitem:hover { border-color: var(--accent); }
.taskitem.current { border-color: var(--accent); background: rgba(91, 124, 250, .12); }
.taskitem.done { opacity: .65; }
.tnum {
    width: 24px; height: 24px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%;
    background: var(--panel);
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}
.taskitem.done .tnum { background: var(--accent-2); color: #06231a; }

/* ── Leaderboard ─────────────────────────────────────────── */
.leaderboard { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.lrow {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 10px;
    background: var(--bg-2);
    font-size: 14px;
}
.lrow.me { border: 1px solid var(--accent); }
.lrank { width: 26px; text-align: center; font-weight: 700; }
.lname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lscore { font-weight: 700; color: var(--warn); }

/* ── Overlay ─────────────────────────────────────────────── */
.overlay {
    position: absolute;
    inset: 0;
    background: rgba(11, 15, 28, .85);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    z-index: 20;
    color: var(--muted);
    font-size: 14px;
}
.overlay.hidden { display: none; }

.spinner {
    width: 38px; height: 38px;
    border: 4px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Login ───────────────────────────────────────────────── */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 44px 40px;
    width: min(420px, 92vw);
    text-align: center;
    box-shadow: 0 30px 70px rgba(0, 0, 0, .45);
}
.login-logo { font-size: 54px; }
.login-card h1 { margin: 8px 0 6px; font-size: 28px; }
.login-card .muted { margin-bottom: 26px; }

.btn.google {
    background: #fff;
    color: #1f1f1f;
    border: none;
    width: 100%;
    justify-content: center;
    padding: 12px;
    font-size: 15px;
}
.btn.google:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(0, 0, 0, .35); }

.alert {
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 13px;
    text-align: left;
    line-height: 1.5;
}
.alert.error { background: rgba(255, 107, 107, .12); color: #ffb3b3; border: 1px solid rgba(255, 107, 107, .3); }
.alert code { background: rgba(0, 0, 0, .35); padding: 1px 5px; border-radius: 4px; }
/* ── Guest badge & banner ────────────────────────────────── */
.guest-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-2);
    color: var(--muted);
    font-size: 15px;
}
.guest-name { color: var(--warn); }

.badge-guest {
    background: rgba(255, 200, 87, .12);
    border-color: rgba(255, 200, 87, .4);
    color: var(--warn);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .5px;
    text-transform: uppercase;
}

.guest-banner {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    align-items: center;
    justify-content: center;
    padding: 10px 22px;
    background: linear-gradient(90deg,
        rgba(255, 200, 87, .10),
        rgba(255, 200, 87, .04));
    border-bottom: 1px solid rgba(255, 200, 87, .25);
    color: #ffd98a;
    font-size: 13px;
    text-align: center;
}
.guest-banner a {
    color: var(--accent-2);
    font-weight: 600;
    text-decoration: underline;
}

/* ── Login page guest extras ─────────────────────────────── */
.or-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 20px 0 16px;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 2px;
}
.or-divider::before,
.or-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.btn.guest {
    width: 100%;
    justify-content: center;
    padding: 12px;
    font-size: 15px;
    background: linear-gradient(135deg, #8b5bfa, #5b7cfa);
    border: none;
    color: #fff;
}
.btn.guest:hover { transform: translateY(-2px); }

.login-note {
    margin: 18px 0 0;
    font-size: 12px;
    line-height: 1.6;
    text-align: left;
}