* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --cyan: #4df0ff;
  --red: #ff4d6d;
  --gold: #ffd24d;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: #07070f;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  position: fixed;
  width: 100%;
}

canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #07070f;
  touch-action: none;
}

/* ===== Overlays ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 15, 0.9);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #fff;
  gap: 16px;
  text-align: center;
  padding: calc(var(--sat) + 16px) calc(var(--sar) + 24px) calc(var(--sab) + 16px) calc(var(--sal) + 24px);
  z-index: 10;
}
.hidden { display: none !important; }

.title {
  font-size: clamp(56px, 16vw, 84px);
  letter-spacing: 0.28em;
  margin-left: 0.28em; /* kompensera letter-spacing */
  font-weight: 800;
  color: var(--cyan);
  text-shadow: 0 0 24px var(--cyan), 0 0 70px rgba(77, 240, 255, 0.35);
  animation: titlepulse 2.6s ease-in-out infinite;
}
@keyframes titlepulse {
  0%, 100% { text-shadow: 0 0 24px var(--cyan), 0 0 70px rgba(77,240,255,0.35); }
  50%      { text-shadow: 0 0 36px var(--cyan), 0 0 110px rgba(77,240,255,0.55); }
}

h2 { font-size: 34px; letter-spacing: 4px; color: var(--cyan); text-shadow: 0 0 18px rgba(77,240,255,0.6); }

.sub  { color: #8899cc; font-size: 16px; max-width: 440px; line-height: 1.6; }
.keys { color: #ccd; font-size: 14px; line-height: 2; }
.keys b { background: #1e1e3a; border-radius: 4px; padding: 1px 8px; margin: 0 2px; font-family: monospace; }
.menu-best { color: var(--gold); font-size: 16px; min-height: 1.2em; }
.score  { font-size: 26px; color: var(--gold); }
.record { font-size: 18px; color: var(--cyan); animation: titlepulse 1.2s ease-in-out infinite; }

/* ===== Knappar ===== */
.btnrow { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.btnrow.small button { font-size: 14px; padding: 9px 20px; }

button {
  background: #1e1e3a;
  color: #ccd;
  border: 1px solid #333366;
  border-radius: 8px;
  padding: 13px 30px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.06s;
}
button:active { transform: scale(0.96); }

button.primary {
  background: var(--cyan);
  color: #002;
  border: none;
  padding: 14px 44px;
  box-shadow: 0 0 20px rgba(77, 240, 255, 0.4);
}
button.reward {
  background: var(--gold);
  color: #210;
  border: none;
  box-shadow: 0 0 20px rgba(255, 210, 77, 0.4);
}
button.ghost { background: transparent; border-color: #2a2a4d; color: #8899cc; }
button.toggle { min-width: 96px; padding: 9px 16px; font-size: 15px; }
button.toggle.on { background: #103a44; border-color: var(--cyan); color: var(--cyan); }

.iconbtn {
  position: fixed;
  top: calc(var(--sat) + 10px);
  right: calc(var(--sar) + 12px);
  z-index: 5;
  width: 44px;
  height: 44px;
  padding: 0;
  font-size: 18px;
  line-height: 44px;
  border-radius: 50%;
  background: rgba(30, 30, 58, 0.55);
  border: 1px solid rgba(77, 240, 255, 0.25);
  color: #8899cc;
}

/* ===== Namndialog & topplista ===== */
#nameInput {
  background: #12122a;
  border: 1px solid #333366;
  border-radius: 8px;
  color: #fff;
  font-family: inherit;
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  padding: 12px 16px;
  width: min(280px, 75vw);
  outline: none;
}
#nameInput:focus { border-color: var(--cyan); box-shadow: 0 0 12px rgba(77,240,255,0.3); }
.err { color: var(--red); font-size: 14px; min-height: 1.2em; }
.rank { color: var(--cyan); font-size: 17px; }

.boardlist {
  width: min(340px, 85vw);
  max-height: 55vh;
  overflow-y: auto;
  text-align: left;
}
.boardlist h3 {
  color: #8899cc; font-size: 13px; letter-spacing: 2px; text-transform: uppercase;
  margin: 14px 0 6px;
}
.boardrow {
  display: flex; gap: 10px; align-items: baseline;
  color: #ccd; font-size: 16px; padding: 4px 2px;
}
.boardrow .pos { color: #556; width: 26px; text-align: right; }
.boardrow .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.boardrow .pts { color: var(--gold); font-weight: 700; }
.boardrow.me .name { color: var(--cyan); font-weight: 700; }
.boardrow.empty { color: #556; font-style: italic; }

/* ===== Inställningsrader ===== */
.setrow {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: min(320px, 80vw);
  font-size: 17px;
  color: #ccd;
}
