:root {
  --ink: #fffdf6;
  --ink-dim: rgba(255, 253, 246, 0.72);
  --panel: rgba(22, 34, 44, 0.62);
  --panel-edge: rgba(255, 255, 255, 0.16);
  --accent: #ffc94a;
  --accent-ink: #2b2110;
  --green: #5cff7a;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #9fd3f0;
  font-family: 'Fredoka', system-ui, sans-serif;
  color: var(--ink);
  user-select: none;
}
canvas#game { display: block; width: 100vw; height: 100vh; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; text-shadow: var(--shadow); }
.hud-tl, .hud-tc, .hud-tr, .hud-bc { position: absolute; }
.hud-tl { top: 18px; left: 24px; }
.hud-tc { top: 14px; left: 50%; transform: translateX(-50%); text-align: center; }
.hud-tr { top: 18px; right: 24px; text-align: right; }
.hud-bc { bottom: 22px; left: 50%; transform: translateX(-50%); width: min(340px, 80vw); text-align: center; }
.label { font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-dim); }
.big { font-size: 44px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.combo { font-size: 18px; font-weight: 600; color: var(--accent); min-height: 24px; }
.timer { font-size: 34px; font-weight: 600; font-variant-numeric: tabular-nums; }
.sub { font-size: 15px; color: var(--ink-dim); }
.minimap { display: block; width: clamp(140px, 15vw, 210px); height: clamp(140px, 15vw, 210px); margin: 0 0 10px auto; border-radius: 14px; background: rgba(10, 20, 30, 0.38); border: 1px solid rgba(255, 255, 255, 0.18); box-shadow: var(--shadow); }
.pips { display: flex; gap: 6px; justify-content: flex-end; margin: 4px 0 6px; }
.pip { width: 16px; height: 16px; transform: rotate(45deg); border-radius: 3px; background: rgba(255,255,255,0.85); box-shadow: var(--shadow); }
.pip.used { background: #ff5a4f; }
.speed-row { font-weight: 600; }
.speed { font-size: 30px; font-variant-numeric: tabular-nums; }
.unit { font-size: 14px; color: var(--ink-dim); margin-left: 4px; }
.bar { height: 8px; border-radius: 6px; background: rgba(0, 0, 0, 0.28); overflow: hidden; margin: 4px 0 10px; box-shadow: var(--shadow); }
.bar.small { height: 6px; width: 110px; display: inline-block; vertical-align: middle; margin: 0 0 0 8px; }
.fill { height: 100%; width: 0; border-radius: 6px; transition: background 0.2s; }
.speed-fill { background: linear-gradient(90deg, #8fe3ff, #fff, #ffc94a, #ff8a1f); }
.dash-fill { background: #8fe3ff; }
.dash-fill.ready { background: var(--accent); }
.dash-row { font-size: 14px; color: var(--ink-dim); }
.split { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; min-height: 26px; opacity: 0; transition: opacity 0.4s; }
.split.show { opacity: 1; transition: none; }
.split .delta { margin-left: 8px; }
.faster { color: var(--green); }
.slower { color: #ff6a5c; }
.progress { position: absolute; left: 50%; top: 118px; transform: translateX(-50%); width: min(360px, 60vw); height: 4px; background: rgba(0,0,0,0.25); border-radius: 4px; overflow: hidden; }
#progressfill { height: 100%; width: 0; background: rgba(255,255,255,0.85); }

.toasts { position: absolute; left: 50%; top: 32%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 4px; }
.toast { font-weight: 700; font-size: 26px; animation: toast 0.9s ease-out forwards; white-space: nowrap; }
.toast.small { font-size: 20px; }
@keyframes toast {
  0% { opacity: 0; transform: translateY(10px) scale(0.8); }
  15% { opacity: 1; transform: translateY(0) scale(1.08); }
  30% { transform: scale(1); }
  100% { opacity: 0; transform: translateY(-26px); }
}
.center-msg { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); font-size: 92px; font-weight: 700; }
.center-msg.pulse { animation: pulse 0.9s ease-out; }
@keyframes pulse { 0% { transform: translate(-50%, -50%) scale(1.5); opacity: 0; } 25% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 100% { opacity: 0.9; } }
.center-msg.warn { font-size: 30px; color: #ffd9a0; }

/* ---------- Menus ---------- */
/* Menus sit directly on the live world: a black-to-clear gradient over the left half
   of the screen (solid to 60%, clear at its edge), no panel. */
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(10, 20, 30, 0.25); }
.side-menu { position: fixed; inset: 0; pointer-events: none; }
.side {
  pointer-events: auto;
  position: absolute; top: 0; bottom: 0; left: 0;
  width: max(50vw, 380px);
  padding: clamp(28px, 7vh, 80px) 0 clamp(20px, 4vh, 40px) clamp(24px, 4vw, 64px);
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.82) 0%, rgba(0, 0, 0, 0.82) 60%, rgba(0, 0, 0, 0) 100%);
  display: flex; flex-direction: column; gap: clamp(18px, 4vh, 40px);
  overflow-y: auto;
  scrollbar-width: none; /* still scrolls on short screens, without a bar in mid-screen */
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.45);
  animation: side-in 0.45s ease-out;
}
.side::-webkit-scrollbar { display: none; }
.side > * { width: min(100%, max(320px, 30vw)); max-width: calc(100% - 64px); }
/* Shorter windows: tighten the menu so it fits without scrolling. */
@media (max-height: 860px) {
  .side { padding-top: clamp(18px, 4vh, 40px); gap: clamp(10px, 2.2vh, 22px); }
  .side h1 { font-size: clamp(40px, 4.4vw, 64px); }
  .side .menu-body { gap: 10px; }
  .side .tagline { margin-top: 6px; }
}
@keyframes side-in { from { opacity: 0; transform: translateX(-24px); } to { opacity: 1; transform: none; } }
h1 { margin: 0; font-size: clamp(48px, 5.4vw, 84px); line-height: 0.95; letter-spacing: 0.01em; }
h2 { margin: 0; font-size: clamp(36px, 3.6vw, 56px); line-height: 1; }
.tagline { margin: 10px 0 0; color: var(--ink-dim); font-size: 16px; }
.menu-body { display: flex; flex-direction: column; gap: 14px; }
.menu-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; flex-direction: column; gap: 4px; }
.row-label { font-size: 12px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--ink-dim); }

button { font-family: inherit; font-size: 16px; font-weight: 500; color: var(--ink); background: none; border: none; padding: 0; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; text-shadow: inherit; }
button:disabled { opacity: 0.45; cursor: default; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px 22px; }
.tabs button { font-size: 21px; font-weight: 500; color: var(--ink-dim); padding: 4px 0; border-bottom: 2px solid transparent; transition: color 0.15s, border-color 0.15s; }
.tabs button:hover { color: var(--ink); }
.tabs button.selected { color: var(--ink); font-weight: 600; border-bottom-color: var(--accent); }
.link { font-size: 18px; color: var(--ink-dim); padding: 4px 0; transition: color 0.15s, transform 0.15s; }
.link:hover { color: var(--ink); transform: translateX(4px); }
.play { align-self: flex-start; margin-top: 6px; padding: 12px 30px 12px 24px; font-size: 24px; font-weight: 700; color: var(--accent-ink); background: var(--accent); border-radius: 999px; text-shadow: none; box-shadow: 0 6px 24px rgba(255, 201, 74, 0.25); transition: transform 0.15s, background 0.15s; }
.play:hover { background: #ffd673; transform: translateX(4px); }
.key { display: inline-block; min-width: 22px; padding: 1px 6px; margin-right: 4px; border-radius: 6px; font-size: 12px; font-weight: 600; text-align: center; background: rgba(255, 255, 255, 0.16); border: 1px solid rgba(255, 255, 255, 0.25); color: inherit; text-shadow: none; }
.play .key { background: rgba(0, 0, 0, 0.12); border-color: rgba(0, 0, 0, 0.15); }

.seed { display: flex; align-items: center; gap: 16px; }
.seed input { width: 4.6em; font: inherit; font-size: 21px; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink); background: transparent; border: none; border-bottom: 2px solid rgba(255, 255, 255, 0.3); padding: 2px 0; outline: none; }
.seed input:focus { border-bottom-color: var(--accent); }
.seed .link { font-size: 15px; }
.weather-tag { font-size: 13px; padding: 2px 9px; border-radius: 999px; background: rgba(255, 255, 255, 0.12); color: var(--ink-dim); white-space: nowrap; }
.weather-tag:empty { display: none; }
.daily-card { display: grid; gap: 2px; justify-items: start; text-align: left; padding: 10px 14px; border-radius: 14px; border: 1px solid rgba(255, 201, 74, 0.35); background: linear-gradient(90deg, rgba(255, 201, 74, 0.16), rgba(255, 201, 74, 0.02)); transition: border-color 0.15s, transform 0.15s; }
.daily-card:hover { border-color: rgba(255, 201, 74, 0.8); transform: translateX(4px); }
.daily-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.daily-world { font-size: 20px; font-weight: 600; color: var(--ink); }
.daily-meta { font-size: 13px; color: var(--ink-dim); }
.daily-meta b { color: var(--accent); }

.controls { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--ink-dim); }
.invert { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-dim); cursor: pointer; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; color: var(--ink-dim); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; box-shadow: 0 0 8px currentColor; }
.mode-hint { margin: -6px 0 0; font-size: 14px; color: var(--ink-dim); min-height: 18px; }
body.time-attack .score-only { display: none; }
.best { font-size: 15px; color: var(--ink-dim); min-height: 20px; }
.best b { color: var(--accent); }
.result-score { font-size: clamp(56px, 5vw, 80px); font-weight: 700; color: var(--accent); line-height: 1; }
.result-grid { display: grid; grid-template-columns: auto auto; justify-content: start; gap: 4px 24px; font-size: 16px; }
.result-grid span:nth-child(odd) { color: var(--ink-dim); }
.new-best { display: inline-block; margin-top: 10px; padding: 3px 10px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 14px; text-shadow: none; }
.loading { font-size: 22px; font-weight: 500; text-shadow: var(--shadow); }

@media (max-width: 640px) {
  .side { width: 100vw; padding-right: 16px; padding-left: 16px; background: linear-gradient(90deg, rgba(0, 0, 0, 0.82) 0%, rgba(0, 0, 0, 0.82) 70%, rgba(0, 0, 0, 0.35) 100%); }
  .side > * { max-width: 100%; width: 100%; }
  .big { font-size: 32px; }
  .timer { font-size: 26px; }
}

/* ---------- Start, account and multiplayer screens ---------- */
/* 1. Choice Buttons */
.choice {
    display: grid;
    grid-template-columns: 1fr;
    justify-items: start;
    width: 100%;
    text-align: left;
    gap: 4px;
    padding: 16px 18px;
    border-radius: 16px;
    border: 1px solid var(--panel-edge);
    background: rgba(0, 0, 0, 0.2);
    transition: border-color 0.15s, transform 0.15s;
}

.choice:hover {
    border-color: var(--accent);
    transform: translateX(4px);
}

.choice-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--ink);
}

.choice-sub {
    font-size: 14px;
    color: var(--ink-dim);
}

/* .mp-card (same look as .choice but not hoverable) */
.mp-card {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 16px 18px;
    border-radius: 16px;
    border: 1px solid var(--panel-edge);
    background: rgba(0, 0, 0, 0.2);
}

/* 2. Back Button Link */
.back {
    font-size: 15px;
    margin-bottom: 10px;
    display: inline-flex;
}

/* 3. Forms */
.auth-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.field {
    display: grid;
    gap: 4px;
}

.field input {
    font: inherit;
    font-size: 19px;
    color: var(--ink);
    background: transparent;
    border: none;
    border-bottom: 2px solid rgba(255, 255, 255, 0.3);
    padding: 2px 0;
    outline: none;
    width: 100%;
}

.field input::placeholder {
    color: rgba(255, 255, 255, 0.35);
}

.field-hint {
    font-size: 12px;
    color: var(--ink-dim);
}

.field-hint.bad {
    color: #ff8a7a;
}

.field-hint.good {
    color: var(--green);
}

/* 4. Form Error */
.form-error {
    margin: 0;
    min-height: 18px;
    font-size: 14px;
    color: #ff8a7a;
}

/* 5. Code Introduction */
.code-intro {
    margin: 0;
    font-size: 15px;
    color: var(--ink-dim);
}

.code-intro b {
    color: var(--ink);
}

/* 6. Profile Chip */
.profile-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    padding: 4px 12px 4px 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    font-size: 15px;
}

.profile-chip .swatch-dot {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.6);
}

/* 7. Account Line */
.account-line {
    font-size: 14px;
    color: var(--ink-dim);
}

.account-line b {
    color: var(--ink);
}

/* 8. Lobby Components */
.lobby-settings {
    display: grid;
    gap: 12px;
}

.lobby-settings.locked {
    opacity: 0.55;
    pointer-events: none;
}

.player-list {
    list-style: none;
    margin: 6px 0 0;
    padding: 0;
    display: grid;
    gap: 6px;
}

.player {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--panel-edge);
    font-size: 17px;
    animation: player-in 0.35s ease-out;
}

@keyframes player-in {
    from { opacity: 0; transform: translateX(-12px); }
}

.player .swatch-dot {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid #fff;
}

.player .name {
    flex: 1;
}

.badge {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.14);
}

.badge.host {
    background: var(--accent);
    color: var(--accent-ink);
}

.badge.you {
    background: rgba(92, 255, 122, 0.2);
    color: var(--green);
}

/* 9. Lobby Status */
.lobby-status {
    margin: 0;
    font-size: 15px;
    color: var(--ink-dim);
    min-height: 20px;
}

.lobby-status .dots::after {
    content: "";
    animation: dots 1.2s steps(1) infinite;
}

@keyframes dots {
    0% { content: ""; }
    25% { content: "."; }
    50% { content: ".."; }
    75% { content: "..."; }
}

/* 10. Mobile Overrides */
@media (max-width: 640px) {
    .choice-title {
        font-size: 23px;
    }
}
.make-host { margin-left: 4px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--ink-dim); border: 1px solid var(--panel-edge); transition: color 0.15s, border-color 0.15s, background 0.15s; }
.make-host:hover { color: var(--ink); border-color: var(--accent); }
.make-host.confirm { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }

/* ---------------------------------------------------------------- bird select */
#bird-select { z-index: 50; background: rgba(8, 16, 24, 0.55); }
.bird-select-panel { display: flex; flex-direction: column; gap: 16px; width: min(980px, 100%); max-height: calc(100vh - 32px); padding: 22px; border-radius: 20px; background: var(--panel); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid var(--panel-edge); box-shadow: var(--shadow); }
.bird-select-head { display: flex; justify-content: space-between; align-items: center; }
.bird-select-head h2 { margin: 0; font-size: 26px; }
.bird-select-head .link { font-size: 20px; color: var(--ink-dim); padding: 4px 8px; }
.bird-select-head .link:hover { color: var(--ink); }
.bird-select-body { display: grid; grid-template-columns: 1fr 320px; gap: 20px; min-height: 0; flex: 1; }
.bird-grid { list-style: none; margin: 0; padding: 2px; display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; overflow-y: auto; align-content: start; }
.bird-tile { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 6px 10px; border-radius: 14px; background: rgba(255, 255, 255, 0.06); border: 2px solid transparent; transition: transform 0.15s, background 0.15s, border-color 0.15s; }
.bird-tile:hover { background: rgba(255, 255, 255, 0.12); transform: translateY(-2px); }
.bird-tile.selected { border-color: var(--accent); background: rgba(255, 201, 74, 0.12); }
.bird-tile .headshot { width: 64px; height: 64px; }
.bird-tile .bird-name { font-size: 14px; font-weight: 600; }
.headshot { display: block; flex: none; border-radius: 50%; object-fit: cover; border: 2px solid #fff; background: radial-gradient(circle at 50% 35%, #cfe9f5, #6fa9c2); }
.bird-card { display: flex; flex-direction: column; gap: 8px; padding: 16px; border-radius: 16px; background: rgba(0, 0, 0, 0.22); border: 1px solid var(--panel-edge); overflow-y: auto; }
.bird-card-stage { width: 100%; aspect-ratio: 4 / 3; border-radius: 12px; overflow: hidden; background: radial-gradient(ellipse at 50% 40%, rgba(160, 215, 240, 0.35), rgba(0, 0, 0, 0) 70%); }
.bird-card-stage canvas { display: block; width: 100% !important; height: 100% !important; }
.bird-card-name { margin: 0; font-size: 24px; font-weight: 700; }
.bird-card-role { margin: 0; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.12em; color: var(--accent); }
.bird-card-blurb { margin: 0 0 4px; font-size: 14px; color: var(--ink-dim); }
.bird-stats { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.stat { display: grid; grid-template-columns: 86px 1fr 22px; align-items: center; gap: 8px; font-size: 13px; }
.stat-label { color: var(--ink-dim); }
.stat-bar { height: 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.stat-fill { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #7fd3ff, var(--accent)); transition: width 0.35s ease; }
.stat-val { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.bird-ability { margin: 6px 0 0; font-size: 13px; color: var(--ink-dim); }
.ability-label { margin-right: 6px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink); }
#bird-select-pick { margin-top: auto; align-self: stretch; text-align: center; padding: 10px 20px; font-size: 20px; }
#bird-select-pick:hover { transform: none; }
@media (max-width: 720px) {
  .bird-select-panel { overflow-y: auto; padding: 16px; }
  .bird-select-body { grid-template-columns: 1fr; }
  .bird-card { order: -1; overflow: visible; }
  .bird-card-stage { aspect-ratio: 16 / 9; }
  .bird-grid { overflow: visible; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
  .bird-tile .headshot { width: 52px; height: 52px; }
}

/* ---------------------------------------------------------------- lobby: bird, bots, kick */
.bird-button { display: inline-flex; align-self: flex-start; align-items: center; gap: 10px; padding: 6px 14px 6px 6px; border-radius: 999px; font-size: 16px; font-weight: 600; background: rgba(255, 255, 255, 0.08); border: 1px solid var(--panel-edge); transition: border-color 0.15s; }
.bird-button:hover { border-color: var(--accent); }
.bird-button .headshot { width: 34px; height: 34px; }
.bird-button .change { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); }
.player .headshot { width: 30px; height: 30px; }
.kick { margin-left: 4px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--ink-dim); border: 1px solid var(--panel-edge); transition: color 0.15s, border-color 0.15s, background 0.15s; }
.kick:hover { color: #ff8a7a; border-color: #ff8a7a; }
.kick.confirm { color: #fff; background: #ff6b5a; border-color: #ff6b5a; }
.badge.bot { white-space: nowrap; background: rgba(127, 211, 255, 0.18); color: #bfe9ff; }
.bot-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.bot-controls .tabs { gap: 4px 14px; }
.bot-controls .tabs button { font-size: 15px; }
.add-bot { padding: 6px 14px; border-radius: 999px; font-size: 14px; font-weight: 700; color: var(--accent-ink); background: var(--accent); transition: background 0.15s; }
.add-bot:hover { background: #ffd673; }
.add-bot:disabled { opacity: 0.45; cursor: default; }
.profile-chip .headshot { width: 22px; height: 22px; }
