:root {
  --ink: #1d2433;
  --panel: rgba(255, 255, 255, 0.92);
  --chip: rgba(18, 28, 48, 0.62);
  --chip-ink: #f4f7ff;
  --accent: #ff8a00;
  --accent-ink: #fff;
  --muted: #5b6475;
  --error: #c62828;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: #7ec8f2;
  color: var(--ink);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  user-select: none;
}
#game, #game canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

.panel {
  position: fixed;
  background: var(--panel);
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
  padding: 20px 24px;
}
.center {
  top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(420px, calc(100vw - 32px));
  max-height: calc(100vh - 32px); overflow: auto;
}
h1 { margin: 0 0 4px; font-size: 32px; letter-spacing: -0.5px; }
h2 { margin: 0 0 12px; font-size: 20px; }
.sub { color: var(--muted); margin: 6px 0 14px; }
label { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 0; font-weight: 600; }
input, select {
  font: inherit; padding: 8px 10px; border: 1px solid #c9d0dc; border-radius: 8px; min-width: 0; flex: 1; max-width: 240px;
}
button {
  font: inherit; font-weight: 700; padding: 10px 18px; border-radius: 10px; border: 0; cursor: pointer;
}
button.primary { background: var(--accent); color: var(--accent-ink); width: 100%; margin-top: 8px; font-size: 17px; }
button.primary:hover { filter: brightness(1.08); }
.error { color: var(--error); min-height: 1.2em; margin: 6px 0 0; }
details { margin-top: 10px; }
summary { cursor: pointer; font-weight: 600; }
.controls { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 14px; }
.controls td { padding: 4px 0; vertical-align: top; }
.controls td:first-child { font-weight: 600; padding-right: 12px; white-space: nowrap; }

#lobby-list, #board-list { margin: 0; padding: 0; list-style: none; }
#lobby-list li, #board-list li { display: flex; align-items: center; gap: 8px; padding: 5px 0; }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.15); }
.tag { font-size: 12px; color: var(--muted); }
#board-list .pts { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 700; }
#board-list .last { font-size: 12px; color: var(--muted); min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; }

#board { top: 12px; right: 12px; width: 230px; padding: 12px 14px; }
#board h2 { font-size: 15px; margin-bottom: 6px; }

#results-table { width: 100%; border-collapse: collapse; }
#results-table td { padding: 6px 4px; border-bottom: 1px solid #e6e9ef; font-variant-numeric: tabular-nums; }
#results-table td.num { text-align: right; font-weight: 700; }
#results-table tr.me td { background: #fff4e0; }

#hud { position: fixed; inset: 0; pointer-events: none; color: var(--chip-ink); }
.chip { position: absolute; background: var(--chip); border-radius: 10px; padding: 8px 12px; backdrop-filter: blur(4px); }
.k { opacity: 0.75; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
#round-label { top: 12px; left: 12px; font-weight: 700; }
#gauges { left: 12px; bottom: 12px; display: grid; gap: 2px; min-width: 170px; font-variant-numeric: tabular-nums; }
#wind { left: 12px; top: 56px; display: flex; align-items: center; gap: 8px; }
#wind .dial { fill: rgba(255, 255, 255, 0.12); stroke: rgba(255, 255, 255, 0.5); }
#wind path { fill: #ffd23f; }
#minimap { position: absolute; right: 12px; bottom: 12px; background: var(--chip); border-radius: 10px; }
#mode { left: 50%; bottom: 16px; transform: translateX(-50%); font-weight: 700; }
#mode:empty { display: none; }
#items { left: 50%; bottom: 60px; transform: translateX(-50%); display: flex; gap: 10px; font-weight: 700; }
#items span { display: inline-flex; align-items: center; gap: 5px; }
#items i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
#items img { width: 22px; height: 22px; }
#items .slot { padding: 2px 8px 2px 3px; border-radius: 999px; background: rgba(255, 255, 255, 0.18); outline: 2px solid rgba(255, 255, 255, 0.7); }
#items kbd { font: 800 12px system-ui, sans-serif; padding: 1px 5px; border-radius: 4px; background: #fff; color: #1d2433; }
/* Gauntlet: the defender's trap cards */
#traps { position: absolute; left: 50%; bottom: 60px; transform: translateX(-50%); display: flex; gap: 8px; pointer-events: auto; }
#traps button {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border: 0; border-radius: 999px;
  font: 800 15px system-ui, sans-serif; color: #fff; background: var(--c); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  cursor: pointer; touch-action: none;
}
#traps button:disabled { opacity: 0.45; cursor: default; }
#traps .shots { display: inline-flex; align-items: center; padding: 8px 14px; border-radius: 999px; font: 800 15px system-ui, sans-serif; color: #fff; background: rgba(20, 28, 44, 0.8); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3); }
#traps .shots.off { opacity: 0.45; }
#traps kbd { font: 800 12px system-ui, sans-serif; padding: 1px 5px; border-radius: 4px; background: #fff; color: #1d2433; }
body.replaying #traps { display: none !important; }
/* Gauntlet shop: over the fly-by before each round */
#shop {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); width: min(900px, calc(100% - 32px));
  max-height: calc(100% - 76px); overflow-y: auto; pointer-events: auto; padding: 12px 14px;
  background: rgba(18, 28, 48, 0.86); border-radius: 14px; backdrop-filter: blur(6px); box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}
#shop .shop-head { display: flex; align-items: center; gap: 14px; font-size: 18px; flex-wrap: wrap; }
#shop-cash { font-weight: 900; color: #7ee081; font-variant-numeric: tabular-nums; }
#shop-time { opacity: 0.8; font-size: 14px; white-space: nowrap; }
#shop-round { font-size: 13px; opacity: 0.85; flex: 1 1 200px; }
#shop-ready { padding: 8px 22px; width: auto; flex: 0 0 auto; margin: 0; }
body.shopping #touch { display: none !important; }
#shop h3 { margin: 10px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px; }
#shop h3 small { text-transform: none; letter-spacing: 0; font-weight: 400; opacity: 0.75; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 6px; }
.shop-grid button {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 6px; text-align: left; padding: 7px 9px; border: 0; border-radius: 9px;
  background: rgba(255, 255, 255, 0.08); border-left: 5px solid var(--c); color: inherit; font: inherit; cursor: pointer;
}
.shop-grid button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.18); }
.shop-grid button:disabled { opacity: 0.4; cursor: default; }
.shop-grid button.owned { opacity: 0.85; outline: 2px solid var(--c); }
.shop-grid button.strong b::after { content: ' ★'; color: #ffd23f; }
.shop-grid b { font-size: 14px; }
.shop-grid kbd { font: 800 10px system-ui, sans-serif; padding: 0 4px; border-radius: 3px; background: #fff; color: #1d2433; }
.shop-grid .price { font-weight: 800; color: #7ee081; font-variant-numeric: tabular-nums; }
.shop-grid small { grid-column: 1 / -1; font-size: 11.5px; line-height: 1.3; opacity: 0.8; }
#shop-own { margin-top: 10px; display: grid; gap: 4px; font-size: 13px; }
#shop-own .k { display: inline-block; min-width: 76px; }
#shop-own i { opacity: 0.7; }
.chip-own { border: 0; border-radius: 999px; padding: 2px 10px; margin: 0 4px 2px 0; font: 700 12px system-ui, sans-serif; color: #fff; background: var(--c); cursor: pointer; }
.chip-own:disabled { cursor: default; opacity: 0.75; }
#board-list .cash { font-size: 12px; color: #2e9e4f; font-weight: 700; font-variant-numeric: tabular-nums; }
#results-table .cash { color: #2e9e4f; font-weight: 700; }
body.replaying #shop { display: none !important; }
#in-items { flex: 0 0 auto; width: 22px; height: 22px; }
#big {
  position: absolute; left: 0; right: 0; top: 28%; text-align: center;
  font-size: clamp(42px, 9vw, 96px); font-weight: 900; text-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}
#intro-card {
  position: absolute; left: 0; right: 0; top: 13%; text-align: center; padding: 0 16px;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.45); animation: intro-in 0.7s ease-out;
}
#ic-round { font-size: clamp(15px, 2.4vw, 22px); font-weight: 800; letter-spacing: 0.2em; text-transform: uppercase; opacity: 0.9; }
#ic-map { font-size: clamp(38px, 8vw, 84px); font-weight: 900; line-height: 1.05; }
#ic-blurb { font-size: clamp(15px, 2.4vw, 22px); font-weight: 700; margin-top: 6px; }
/* While a replay plays, our own flight's readouts and messages are hidden. */
body.replaying #gauges, body.replaying #mode, body.replaying #items, body.replaying #big, body.replaying #touch { display: none !important; }
#replay-card { position: absolute; left: 0; right: 0; top: 6%; text-align: center; padding: 0 16px; text-shadow: 0 4px 20px rgba(0, 0, 0, 0.5); animation: intro-in 0.5s ease-out; pointer-events: none; }
#rc-tag { display: inline-block; font-size: clamp(13px, 2vw, 18px); font-weight: 800; letter-spacing: 0.2em; text-transform: uppercase; background: #d8262f; padding: 4px 12px; border-radius: 6px; }
#rc-who { font-size: clamp(26px, 5vw, 52px); font-weight: 900; margin-top: 6px; }
#rc-skip { font-size: 14px; opacity: 0.75; margin-top: 4px; }
@keyframes intro-in { from { opacity: 0; transform: translateY(-14px); } to { opacity: 1; transform: none; } }
#toast {
  position: absolute; left: 0; right: 0; top: 62%; text-align: center;
  font-size: clamp(20px, 4vw, 34px); font-weight: 800; text-shadow: 0 3px 12px rgba(0, 0, 0, 0.4);
}

@media (max-width: 640px) {
  #board { width: 170px; font-size: 13px; }
  #minimap { width: 120px; height: 160px; }
  #gauges { min-width: 0; font-size: 13px; }
}

#touch { position: fixed; inset: auto 0 0 0; height: 0; display: none; }
#stick {
  position: fixed; left: 24px; bottom: 24px; width: 140px; height: 140px; border-radius: 50%;
  background: rgba(18, 28, 48, 0.35); border: 2px solid rgba(255, 255, 255, 0.5); touch-action: none;
}
#knob {
  position: absolute; left: 45px; top: 45px; width: 50px; height: 50px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.85); pointer-events: none;
}
#btn-wings {
  position: fixed; right: 24px; bottom: 36px; width: 110px; height: 110px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink); font-size: 18px; touch-action: none;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}
/* Alter Reality: the world's colours turn inside out for the rest of the round. */
#game canvas.altered { filter: invert(1); }
#btn-y {
  position: fixed; right: 150px; bottom: 120px; width: 76px; height: 76px; border-radius: 50%;
  background: #ffd23f; color: #1d2433; font-size: 13px; touch-action: none; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}
#btn-use {
  position: fixed; right: 150px; bottom: 30px; width: 76px; height: 76px; border-radius: 50%;
  background: #fff; color: #1d2433; font-size: 15px; touch-action: none; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}
@media (pointer: coarse) {
  #touch:not(.hidden) { display: block; }
  #gauges { bottom: auto; top: 140px; }
  #minimap { display: none; }
  #mode { bottom: auto; top: 12px; left: auto; right: 12px; transform: none; font-size: 13px; max-width: 48vw; }
  #items { bottom: 200px; left: 12px; transform: none; font-size: 13px; }
  #traps { bottom: auto; top: 56px; left: 12px; right: 12px; transform: none; flex-wrap: wrap; }
  #traps kbd { display: none; }
  #shop { top: 50px; bottom: 12px; max-height: none; z-index: 5; }
  #shop .shop-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  body.shopping #board { display: none; }
  #board { top: auto; bottom: 170px; right: 12px; width: 150px; padding: 8px 10px; font-size: 12px; }
}

#ic-song { margin-top: 8px; font-size: 15px; font-weight: 700; color: #ffd23f; }
#ic-song:empty { display: none; }

/* Alter Reality: a purple fade while time stands still */
#alter-fade { position: fixed; inset: 0; z-index: 30; pointer-events: none; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 50%, rgba(155, 77, 255, 0.55), rgba(40, 0, 80, 0.97)); opacity: 0; }
#alter-fade.on { animation: alter-in 0.7s ease-out forwards; }
#alter-fade.out { animation: alter-out 0.8s ease-in forwards; }
@keyframes alter-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes alter-out { from { opacity: 1; } to { opacity: 0; } }
#alter-text { font: 900 clamp(26px, 5vw, 56px) system-ui, sans-serif; color: #f3e6ff; text-shadow: 0 0 24px #b07bff; letter-spacing: 1px;
  animation: alter-wobble 1.6s ease-in-out infinite; }
@keyframes alter-wobble { 0%, 100% { transform: scale(1) rotate(-1deg); } 50% { transform: scale(1.06) rotate(1deg); } }

/* Victory emotes: the touch button, and the final results moving aside so the winner's celebration shows. */
#btn-emote {
  position: fixed; right: 150px; bottom: 210px; width: 64px; height: 64px; border-radius: 50%;
  background: #ff7ab8; color: #fff; font-size: 26px; touch-action: none; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}
#emote-hint kbd { font-size: 12px; }
@media (min-width: 900px) {
  #results.final { left: 24px; transform: translate(0, -50%); }
}
@media (max-width: 899px) {
  #results.final { top: auto; bottom: 16px; transform: translate(-50%, 0); max-height: 55vh; }
}

/* Character select (lobby): a spinning 3D preview beside a grid of portraits. */
#pick h3 { margin: 12px 0 6px; font-size: 15px; }
#pick-row { display: flex; gap: 10px; align-items: center; }
#pick-preview { width: 120px; height: 120px; flex: none; border-radius: 12px; background: radial-gradient(circle at 50% 40%, #e9f4ff, #c9def3); }
#pick-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; flex: 1; }
#pick-grid button {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 2px; min-width: 0;
  border: 2px solid transparent; border-radius: 10px; background: #f1f4f9; font-size: 11px; color: #1d2433; cursor: pointer;
}
#pick-grid button img { width: 36px; height: 36px; image-rendering: auto; }
#pick-grid button[aria-checked="true"] { border-color: var(--accent); background: #fff4e0; font-weight: 700; }
#pick-name { margin: 4px 0 0; }
#pick-stats { display: grid; grid-template-columns: auto 1fr; gap: 3px 8px; align-items: center; margin-top: 4px; font-size: 13px; }
#pick-stats .bar { position: relative; height: 7px; border-radius: 4px; background: #dfe8f1; overflow: hidden; }
#pick-stats .bar i { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 4px; }
#pick-stats .bar::after { content: ''; position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: #0005; }
#pick-stats b.up { color: #1a8f3a; }
#pick-stats b.down { color: #b4442c; }
.pet { width: 22px; height: 22px; flex: none; }
.pet.emoji { font-size: 18px; line-height: 22px; text-align: center; }

/* Dailies and accounts */
#daily { margin: 12px 0 6px; padding: 12px 14px; border-radius: 12px; background: #fff7ea; border: 1px solid #ffd9a6; }
#daily h3, h3.friends { margin: 0; font-size: 16px; }
h3.friends { margin-top: 14px; }
.daily-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
#daily-fx { margin: 8px 0 4px; padding: 0; list-style: none; font-size: 14px; }
#daily-fx li { padding: 2px 0; }
#daily-fx b { color: #b35a00; }
#daily-maps { margin: 4px 0 8px; }
#account { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0 4px; }
#account .who { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; font-weight: 700; }
#account .who img { width: 28px; height: 28px; border-radius: 50%; }
#account .who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#account button.link { padding: 4px 8px; background: none; color: var(--muted); font-weight: 600; text-decoration: underline; }
.discord { display: block; width: 100%; text-align: center; padding: 10px 18px; border-radius: 10px; background: #5865f2; color: #fff; font-weight: 700; text-decoration: none; }
.discord:hover { filter: brightness(1.08); }
.xpbar { position: relative; flex-basis: 100%; height: 16px; border-radius: 8px; background: #f0dcc0; overflow: hidden; font-size: 11px; font-weight: 700; }
.xpbar i { position: absolute; inset: 0 auto 0 0; background: var(--accent); }
.xpbar span { position: relative; display: block; text-align: center; line-height: 16px; color: #4a2a00; }
.looks { display: flex; gap: 8px; flex-basis: 100%; }
.looks label { flex: 1; margin: 0; font-size: 13px; gap: 6px; }
.looks select { padding: 4px 6px; font-size: 13px; }
#daily-board, #daily-mboard { margin: 6px 0 0; padding-left: 22px; font-size: 14px; }
#daily-board li, #daily-mboard li { padding: 2px 0; }
#daily-board .pts, #daily-mboard .pts { float: right; font-weight: 700; font-variant-numeric: tabular-nums; }
#daily-board li.me, #daily-mboard li.me { color: #b35a00; font-weight: 700; }
#daily-multi { margin-top: 10px; }
.lv { font-size: 11px; font-weight: 700; color: #fff; background: #5865f2; border-radius: 6px; padding: 1px 5px; }
#daily-done { text-align: center; margin: 8px 0; }
#daily-done .big { font-size: 40px; font-weight: 800; color: #b35a00; line-height: 1.1; }
#daily-done .xpbar { margin: 10px 0 6px; }
#daily-done .up { color: #1a8f3a; font-weight: 700; }

/* A daily's themed finale: why today's map is what it is, over the fly-by. */
#ic-theme { max-width: 640px; margin: 14px auto 0; padding: 12px 18px; border-radius: 12px; background: rgba(18, 28, 48, 0.62); color: var(--chip-ink);
  font-size: clamp(14px, 2vw, 18px); font-weight: 600; line-height: 1.45; text-shadow: none; }
#ic-theme:empty { display: none; }
#ic-theme b { display: block; color: #ffd23f; font-size: 1.15em; margin-bottom: 4px; }

/* Names that open a player's profile page. */
a.plink { color: inherit; text-decoration: none; }
a.plink:hover { text-decoration: underline; }
#account a.link { margin-left: auto; margin-right: 10px; font-size: 14px; color: var(--muted); }
