:root {
  color-scheme: dark;
  --gold: #ffd84a;
  --cyan: #7af0ff;
  --pink: #ff4d8d;
  --ink: #070910;
  --panel: rgba(8, 10, 18, 0.78);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: #f4f7ff;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

canvas {
  display: block;
  width: 100vw;
  height: 100vh;
  outline: none;
}

#ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.screen {
  display: none;
  pointer-events: auto;
  position: absolute;
  inset: 0;
  place-items: center;
  align-content: center;
  text-align: center;
  padding: 24px 16px;
  background: rgba(5, 7, 12, 0.28);
}

.screen.show { display: grid; }

.card {
  width: min(640px, 94vw);
  padding: 28px 32px 24px;
  border-radius: 24px;
  background: rgba(8, 12, 22, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.eyebrow {
  margin: 0 0 8px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--cyan);
}

h1, h2 {
  margin: 0;
  font-weight: 800;
  letter-spacing: 0.08em;
}

h1 {
  font-size: clamp(56px, 10vw, 112px);
  line-height: 0.9;
  background: linear-gradient(90deg, var(--gold), #fff, var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

h2 { font-size: clamp(36px, 6vw, 68px); }

.twist {
  max-width: 560px;
  margin: 16px auto 22px;
  color: #d5def2;
  font-size: 17px;
  line-height: 1.45;
}

button {
  pointer-events: auto;
  border: 0;
  border-radius: 999px;
  padding: 14px 28px;
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #14120a;
  background: linear-gradient(180deg, #ffe58a, var(--gold));
  cursor: pointer;
  box-shadow: 0 8px 30px rgba(255, 216, 74, 0.25);
}

button:hover { filter: brightness(1.05); }
button:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 16px;
  margin: 22px auto 0;
  color: #c5d0e6;
  font-size: 14px;
}

kbd {
  display: inline-block;
  min-width: 1.4em;
  margin: 0 2px;
  padding: 2px 6px;
  border: 1px solid #3d4d6e;
  border-bottom-width: 3px;
  border-radius: 6px;
  background: #151b2b;
  color: white;
  font-family: inherit;
  font-size: 12px;
}

.roster {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
  color: #9eabc4;
  font-size: 13px;
}

.roster i {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border-radius: 50%;
}

#hud {
  display: none;
  position: absolute;
  inset: 0;
}

#hud.show { display: block; }

.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px 16px 0;
}

.stat-card, #speedBox, #board, #itemSlot, #riftStatus {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.stat-card {
  min-width: 132px;
  padding: 10px 14px 12px;
  border-radius: 16px;
  text-align: left;
}

.stat-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

#place {
  font-size: 40px;
  font-weight: 800;
  line-height: 0.9;
  letter-spacing: -0.03em;
}

#lap, #clock, #speedBox span, #itemWrap small, #riftStatus {
  color: #d5def2;
  letter-spacing: 0.12em;
  font-size: 12px;
}

#lap { margin-top: 6px; }

#clock { margin-top: 2px; font-variant-numeric: tabular-nums; }

#speedBox {
  text-align: right;
  padding: 8px 14px 10px;
  border-radius: 16px;
  min-width: 92px;
}

#speedBox b {
  display: block;
  font-size: 28px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

#board {
  margin: 0;
  padding: 8px 12px;
  list-style: none;
  min-width: 132px;
  border-radius: 14px;
}

#board li {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 3px 0;
  font-size: 14px;
  color: #d5def2;
}

#board li.me { color: var(--gold); font-weight: 700; }

#board b {
  width: 1.2em;
  color: #8ea0c0;
  font-variant-numeric: tabular-nums;
}

#riftStatus {
  position: absolute;
  left: 16px;
  bottom: 16px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(88, 48, 150, 0.72);
  border-color: rgba(192, 132, 252, 0.4);
}

#riftStatus.closed {
  background: rgba(20, 24, 36, 0.72);
  border-color: rgba(255, 255, 255, 0.08);
  color: #9eabc4;
}

#itemWrap {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  text-align: center;
}

#itemSlot {
  width: 76px;
  height: 76px;
  margin: 0 auto 6px;
  display: grid;
  place-items: center;
  align-content: center;
  border-radius: 16px;
  border: 2px solid #31405f;
}

#itemGlyph {
  font-size: 28px;
  line-height: 1;
}

#itemName {
  font-size: 11px;
  letter-spacing: 0.12em;
  color: #d5def2;
}

#driftBar {
  width: 120px;
  height: 8px;
  margin: 0 auto 8px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

#driftFill {
  height: 100%;
  width: 0%;
  background: #fff;
}

#count {
  position: absolute;
  top: 22%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 96px;
  font-weight: 800;
  letter-spacing: -0.04em;
  text-shadow: 0 10px 40px rgba(0, 0, 0, 0.55);
  pointer-events: none;
}

#banner {
  position: absolute;
  top: 118px;
  left: 16px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(8, 10, 18, 0.82);
  border: 1px solid rgba(122, 240, 255, 0.35);
  letter-spacing: 0.16em;
  font-size: 13px;
  font-weight: 800;
}

#wrong {
  position: absolute;
  top: 42%;
  left: 50%;
  transform: translateX(-50%);
  color: #ff5a6a;
  font-size: 42px;
  font-weight: 800;
  letter-spacing: 0.12em;
  animation: pulse 0.4s infinite alternate;
}

@keyframes pulse { to { opacity: 0.45; } }

#resultList {
  list-style: none;
  margin: 18px auto;
  padding: 0;
  width: min(420px, 92vw);
  text-align: left;
}

#resultList li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  margin: 6px 0;
  border-radius: 12px;
  background: rgba(8, 10, 18, 0.72);
}

#resultList li.me {
  outline: 2px solid var(--gold);
}

#pause p, #results p { color: #d5def2; }
