* { box-sizing: border-box; }

:root {
  --ink: #eef0f4;
  --ink-soft: #8b93a5;
  --bg: #0c0e14;
  --panel: #14171f;
  --accent: #ff5a3c;
  --accent-soft: rgba(255, 90, 60, 0.15);
  --good: #3ce089;
  --line: #2a2d38;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Segoe UI', system-ui, sans-serif;
  overflow: hidden;
  touch-action: none;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px;
  position: relative;
}

header {
  display: flex;
  gap: 20px;
  width: 100%;
  max-width: 420px;
  justify-content: space-between;
  background: var(--panel);
  border-radius: 12px;
  padding: 10px 18px;
}

.stat { display: flex; flex-direction: column; align-items: center; }
.label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); }
.value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }

.headerBtns { display: flex; gap: 6px; align-self: center; }
.iconBtn {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 9px;
  font-size: 15px;
  line-height: 1;
  color: var(--ink);
  cursor: pointer;
}
.iconBtn:active { transform: scale(.95); }

#canvasWrap { position: relative; max-width: 100%; }

canvas {
  background: #23262f;
  border-radius: 14px;
  max-width: 100%;
  max-height: 70vh;
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
  touch-action: none;
  display: block;
}

.powerBadge {
  position: absolute;
  top: 14px;
  left: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(12,14,20,.75);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px 6px 10px;
  backdrop-filter: blur(2px);
}
.powerBadge #powerIcon { font-size: 16px; }
.powerBar { width: 54px; height: 5px; border-radius: 999px; background: rgba(255,255,255,.15); overflow: hidden; }
.powerBarFill { height: 100%; background: var(--accent); width: 100%; transform-origin: left; }

#pauseOverlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(12,14,20,.82);
  border-radius: 14px;
}
#pauseOverlay p { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: .04em; }

.legend {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--ink-soft) !important;
  max-width: none !important;
}

#overlay, #gameOver {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(12,14,20,.88);
  text-align: center;
  padding: 20px;
}

#overlay h1 {
  font-size: 56px;
  margin: 0;
  letter-spacing: .05em;
  color: var(--accent);
  text-shadow: 0 0 30px var(--accent-soft);
}

#overlay p, #gameOver p { color: var(--ink-soft); max-width: 32ch; margin: 0; }
#gameOver p.hint, #overlay p.hint { font-size: 12.5px; }

#gameOver h2 { margin: 0; font-size: 32px; }
#finalScore { color: var(--accent); font-weight: 700; }
#newBest { color: var(--good); font-weight: 600; }

button {
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  padding: 14px 28px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #1a0a05;
  cursor: pointer;
}
button:active { transform: scale(.97); }

.hidden { display: none !important; }

/* mode switch (start screen) */
.modeSwitch {
  display: flex;
  gap: 6px;
  background: var(--panel);
  padding: 4px;
  border-radius: 999px;
}
.modeBtn {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
.modeBtn.active { background: var(--accent); color: #1a0a05; }
#modeHint { margin-top: -6px; font-size: 12.5px; }

/* leaderboard */
.board {
  width: 100%;
  max-width: 300px;
  background: var(--panel);
  border-radius: 12px;
  padding: 12px 16px 16px;
  margin-top: 4px;
}
.boardTabs {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}
.boardTab {
  flex: 1;
  padding: 6px 0;
  font-size: 12px;
  font-weight: 600;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
.boardTab.active { background: rgba(255,90,60,.18); color: var(--accent); }
.boardList {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 160px;
  overflow-y: auto;
}
.boardList li {
  display: flex;
  justify-content: space-between;
  font-size: 13.5px;
  padding: 4px 2px;
}
.boardList li .rank { color: var(--ink-soft); width: 20px; }
.boardList li .bname { flex: 1; text-align: left; }
.boardList li .bdist { font-variant-numeric: tabular-nums; font-weight: 600; }
.boardEmpty { color: var(--ink-soft); justify-content: center !important; }

/* name submit */
#submitForm {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 300px;
}
#nameInput {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 15px;
  padding: 12px 14px;
  border-radius: 999px;
  border: 1px solid var(--line, #333);
  background: var(--panel);
  color: var(--ink);
}
#nameInput:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
#submitForm button { padding: 12px 18px; font-size: 14px; white-space: nowrap; }
#submitStatus { min-height: 16px; margin: 0; }
#modeTag { color: var(--accent); font-weight: 600; }

#bootDiag {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: 10px;
  z-index: 999;
  background: rgba(20, 8, 8, .92);
  border: 1px solid #7a2020;
  color: #ffb4b4;
  font-size: 11.5px;
  line-height: 1.4;
  padding: 10px 12px;
  border-radius: 10px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 40vh;
  overflow-y: auto;
}
