:root {
  --bg: #16122a;
  --arena: #0e0b1e;
  --panel: #201a3c;
  --panel-2: #2b2350;
  --edge: #4d4285;
  --shadow: #0a0815;
  --text: #f3eeff;
  --muted: #aba3cc;
  --lemon: #ffd23f;
  --pink: #ff5fc8;
  --blue: #4d8dff;
  --display: "Russo One", "Arial Black", sans-serif;
  --body: "Chakra Petch", "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.4;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--lemon); outline-offset: 2px; }

/* ---------- Lobby ---------- */
#lobby { position: relative; min-height: 100%; }
#lobbyBg {
  position: fixed; inset: 0; width: 100%; height: 100%;
  opacity: .3; pointer-events: none;
}
.lobby-inner {
  position: relative;
  max-width: 900px;
  margin: 0 auto;
  padding: 44px 20px 72px;
}

.hero h1 {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(3rem, 12vw, 6.6rem);
  line-height: 1;
  margin: 0;
  color: var(--lemon);
  transform: skewX(-8deg);
  transform-origin: left bottom;
  text-shadow: 4px 4px 0 var(--pink), 8px 8px 0 var(--blue);
}
.tagline {
  margin: 22px 0 32px;
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--muted);
  max-width: 36ch;
}

.panel {
  background: var(--panel);
  border: 2px solid var(--edge);
  border-radius: 4px;
  box-shadow: 5px 5px 0 var(--shadow);
  padding: 18px;
  margin-bottom: 22px;
}
.panel-head { margin-bottom: 14px; }
.panel h2 {
  font-family: var(--display);
  font-weight: 400;
  font-size: 1.15rem;
  margin: 0;
  color: var(--lemon);
  transform: skewX(-8deg);
  transform-origin: left bottom;
}
.sub { margin: 6px 0 0; color: var(--muted); font-size: .92rem; max-width: 72ch; }

/* players */
.rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.row {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) 76px 76px 84px 56px;
  gap: 8px;
  align-items: center;
  padding: 5px 8px;
  border: 2px dashed #3a3166;
  border-radius: 3px;
}
.row > * { opacity: .5; }
.row.joined {
  border: 2px solid var(--c);
  background: color-mix(in srgb, var(--c) 10%, var(--panel));
}
.row.joined > * { opacity: 1; }
.dot {
  width: 22px; height: 22px; border-radius: 3px;
  background: var(--c);
  border: 2px solid #fff;
  padding: 0; justify-self: center;
}
.name {
  background: transparent; border: 0; border-bottom: 2px solid transparent;
  font-weight: 700; font-size: 1.05rem; color: var(--c);
  padding: 3px 2px; width: 100%; min-width: 0;
}
.name:hover, .name:focus { border-bottom-color: var(--c); outline: none; }
.key, .join {
  background: var(--bg); border: 2px solid var(--edge); border-radius: 3px;
  padding: 4px; font-weight: 600; font-size: .9rem;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.key { border-bottom-width: 4px; }
.key:disabled { visibility: hidden; }
.key.listening { border-color: var(--lemon); color: var(--lemon); }
.join.on { background: var(--c); color: #16122a; border-color: var(--c); font-weight: 700; }

/* network lobby */
.note { margin: 0 0 18px; padding: 10px 14px; border: 2px solid var(--pink); border-radius: 3px; font-weight: 600; }
span.dot { display: block; }
span.name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.state { font-weight: 700; font-size: .9rem; text-align: center; color: var(--muted); }
.state.on { color: var(--c); }
.role { font-size: .82rem; font-weight: 600; color: var(--muted); text-align: right; }
.net-host { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.net-host .key { width: 38px; }
.net-host b { min-width: 2ch; text-align: center; }
.net-actions { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; margin: 20px 0 4px; }
#readyBtn.on { background: #2ee6a6; box-shadow: 5px 5px 0 var(--blue); }
.linkbtn { margin-top: 14px; padding: 0; background: none; border: 0; color: var(--muted); font-size: .88rem; text-decoration: underline; }
.linkbtn:hover { color: var(--text); }
#netShare b { color: var(--lemon); user-select: all; }
.guest-only, .net-only { display: none; }
.net-guest .guest-only { display: block; }
.net-guest #matchPanel .setting:not(.personal), .net-guest #puLegend { pointer-events: none; opacity: .6; }
.net-game .net-only { display: block; }
.net-game .local-only { display: none; }

/* home screen */
.home-name { display: grid; gap: 5px; max-width: 280px; }
#homeName, #joinCode {
  background: var(--bg); border: 2px solid var(--edge); border-radius: 3px;
  padding: 7px 9px; font-weight: 700; min-width: 0;
}
.home-actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin: 18px 0; }
.home-actions .join, .home-join .join { padding: 9px 14px; }
.home-join { display: flex; gap: 8px; max-width: 280px; }
#joinCode { flex: 1; text-transform: uppercase; letter-spacing: .08em; }
#joinCode::placeholder { text-transform: none; letter-spacing: 0; color: var(--muted); font-weight: 500; }
.home-sub { margin: 22px 0 8px; font-size: .98rem; font-weight: 700; }
.room-row {
  display: grid; grid-template-columns: minmax(0, 1fr) 44px 76px 72px 64px; gap: 8px; align-items: center;
  padding: 6px 8px; border: 2px solid #3a3166; border-radius: 3px;
}
.room-owner { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-speed { text-transform: capitalize; }
.room-row > span:not(.room-owner) { color: var(--muted); font-size: .9rem; }
.room-empty { color: var(--muted); font-size: .92rem; }
.copy { margin-top: 10px; padding: 5px 12px; }
.vis-label { margin-left: 18px; }

/* settings */
.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 14px 24px; }
.setting { display: grid; gap: 5px; }
.setting-label { color: var(--muted); font-size: .92rem; font-weight: 500; }
.seg { display: flex; border: 2px solid var(--edge); border-radius: 3px; overflow: hidden; }
.seg button {
  flex: 1; border: 0; background: var(--bg);
  padding: 7px 6px; font-weight: 600; color: var(--muted);
}
.seg button + button { border-left: 2px solid var(--edge); }
.seg button[aria-pressed="true"] { background: var(--lemon); color: #16122a; font-weight: 700; }

/* legend */
#puLegend { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; }
.cat h3 {
  margin: 0 0 8px; font-size: .98rem; font-weight: 700; color: var(--c);
  display: flex; align-items: center; gap: 8px;
}
.cat h3::before { content: ""; width: 12px; height: 12px; border-radius: 2px; background: var(--c); }
.pu {
  display: grid; grid-template-columns: 34px 1fr; gap: 10px; align-items: center;
  width: 100%; text-align: left;
  background: transparent; border: 0; border-radius: 3px; padding: 4px 6px;
}
.pu:hover { background: var(--panel-2); }
.pu img { width: 34px; height: 34px; display: block; }
.pu .pu-name { font-weight: 700; font-size: .95rem; }
.pu .pu-desc { color: var(--muted); font-size: .84rem; display: block; line-height: 1.25; }
.pu .tag {
  font-size: .68rem; font-weight: 700; color: #16122a; background: var(--lemon);
  border-radius: 2px; padding: 1px 5px; margin-left: 6px; vertical-align: 2px;
}
.pu.off { opacity: .35; }
.pu.off .pu-name { text-decoration: line-through; }

.start-row { display: flex; align-items: center; gap: 22px; margin-top: 28px; flex-wrap: wrap; }
.primary {
  font-family: var(--display); font-size: 1.35rem;
  background: var(--lemon); color: #16122a;
  border: 0; border-radius: 4px; padding: 14px 30px;
  transform: skewX(-8deg);
  box-shadow: 5px 5px 0 var(--pink);
}
.primary:active { transform: skewX(-8deg) translate(3px, 3px); box-shadow: 2px 2px 0 var(--pink); }
.primary:disabled { opacity: .4; cursor: not-allowed; }
.start-hint { color: var(--muted); font-weight: 500; }

/* ---------- Game ---------- */
#game { position: fixed; inset: 0; display: flex; background: var(--bg); }
#arenaWrap {
  flex: 1; min-width: 0; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 12px; overflow: hidden;
}
#arena { display: block; background: var(--arena); border-radius: 2px; }

/* hype train */
#hypeBanner {
  visibility: hidden;
  width: 100%; height: 36px; flex: none; margin-bottom: 10px;
  background: #8b3dff; border: 2px solid #fff; border-radius: 3px;
  overflow: hidden; white-space: nowrap;
  font-family: var(--display); font-size: 1.05rem; line-height: 32px; color: #fff;
}
#game.hype #hypeBanner { visibility: visible; animation: bannerFlash .4s steps(2) infinite; }
.ticker { display: inline-block; transform: skewX(-8deg); }
#game.hype .ticker { animation: ticker 7s linear infinite; }
@keyframes ticker { to { transform: skewX(-8deg) translateX(-50%); } }
@keyframes bannerFlash { 50% { background: #ff3da5; } }
#game.hype #arena { animation: hypeGlow .9s linear infinite; }
@keyframes hypeGlow {
  0%, 100% { box-shadow: 0 0 34px 4px #ff5fc8; }
  33% { box-shadow: 0 0 34px 4px #ffd23f; }
  66% { box-shadow: 0 0 34px 4px #4d8dff; }
}

#overlay, #confirmBox {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: var(--panel);
  border: 2px solid var(--edge); border-radius: 4px;
  box-shadow: 6px 6px 0 var(--shadow);
  padding: 24px 32px; text-align: center; min-width: 290px; max-width: 90%;
}
#overlay h3, #confirmBox h3 { font-family: var(--display); font-weight: 400; font-size: 1.6rem; margin: 0 0 6px; line-height: 1.15; transform: skewX(-8deg); }
#overlay p, #confirmBox p { margin: 8px 0 0; color: var(--muted); font-weight: 500; }
#confirmBox { z-index: 2; border-color: var(--lemon); }
#confirmBox h3 { color: var(--lemon); }
#overlay ol { list-style: none; padding: 0; margin: 14px 0 6px; text-align: left; }
#overlay ol li { display: flex; justify-content: space-between; gap: 24px; padding: 2px 0; font-weight: 700; }
kbd {
  font-family: var(--body); font-size: .85em; font-weight: 700;
  background: var(--bg); border: 2px solid var(--edge); border-bottom-width: 4px;
  border-radius: 3px; padding: 0 6px; color: var(--text);
}

#side {
  width: 296px; flex: none;
  border-left: 2px solid var(--edge);
  background: var(--panel);
  padding: 18px 14px;
  display: flex; flex-direction: column; gap: 14px;
  overflow-y: auto;
}
.brand {
  font-family: var(--display); font-size: 1.5rem; color: var(--lemon);
  transform: skewX(-8deg); transform-origin: left bottom;
  text-shadow: 2px 2px 0 var(--pink);
}
#goal { color: var(--muted); font-size: .92rem; font-weight: 500; margin-top: -8px; }

#hypeMeter { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: center; font-weight: 700; font-size: .9rem; }
.hm-bar { height: 12px; background: var(--bg); border: 2px solid var(--edge); border-radius: 2px; overflow: hidden; }
.hm-bar i { display: block; height: 100%; width: 0; background: var(--pink); }
#game.hype .hm-bar { border-color: #fff; }
#game.hype .hm-bar i { background: var(--lemon); }
#game.hype #hypeMeter > span { color: var(--lemon); }

#board { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
#board li {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center;
  padding: 7px 10px;
  border: 2px solid var(--c); border-radius: 3px;
  background: color-mix(in srgb, var(--c) 10%, var(--panel));
}
#board li.dead { opacity: .45; border-style: dashed; }
#board .pname { font-weight: 700; color: var(--c); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#board .pname small { color: var(--muted); font-weight: 500; }
#board .pname small.boost { color: var(--lemon); font-weight: 700; }
.crown { width: 16px; height: 10px; margin-right: 6px; fill: var(--lemon); vertical-align: baseline; }
#board .pscore { font-family: var(--display); font-size: 1.45rem; grid-row: span 2; align-self: center; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; min-height: 26px; }

.chip {
  position: relative; display: inline-flex; align-items: center; gap: 5px;
  background: var(--bg); border-radius: 3px; padding: 2px 7px 4px 2px;
  font-size: .8rem; font-weight: 700; overflow: hidden;
  font-variant-numeric: tabular-nums;
}
.chip b { min-width: 1.7ch; }
.chip img { width: 20px; height: 20px; display: block; }
.chip i {
  position: absolute; left: 0; bottom: 0; height: 3px;
  width: calc(var(--p, 1) * 100%); background: var(--c);
}
.chip.low { animation: blink .3s steps(2) infinite; }
@keyframes blink { 50% { opacity: .4; } }

#arenaFx { display: flex; flex-wrap: wrap; gap: 6px; min-height: 30px; }
#arenaFx .chip { font-size: .86rem; }

#fastBtn {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 10px; cursor: pointer;
  background: var(--bg); border: 2px solid var(--lemon); border-radius: 3px;
  box-shadow: 3px 3px 0 var(--shadow);
  font-weight: 700; font-size: .92rem; text-align: left;
}
#fastBtn:hover { background: var(--panel-2); }
#fastBtn.on { background: var(--lemon); color: #16122a; }

.keys-hint { margin-top: auto; color: var(--muted); font-size: .88rem; font-weight: 500; display: grid; gap: 6px; }

@media (max-width: 820px) {
  #game { flex-direction: column; }
  #side { width: auto; border-left: 0; border-top: 2px solid var(--edge); max-height: 38%; }
  .row { grid-template-columns: 26px minmax(0, 1fr) 52px 52px 68px 44px; gap: 4px; padding: 4px; }
  .room-row { grid-template-columns: minmax(0, 1fr) 40px 64px 58px; gap: 4px; }
  .room-speed { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .chip.low,
  #game.hype #hypeBanner,
  #game.hype .ticker,
  #game.hype #arena { animation: none; }
}
