:root {
  --bg: #070b1f;
  --ink: #f4f7ff;
  --cyan: #4de3ff;
  --pink: #ff4fa3;
  --gold: #ffd23f;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }

html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink);
  font-family: var(--font);
  user-select: none; -webkit-user-select: none;
  touch-action: none; overscroll-behavior: none;
}

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; left: 0; right: 0; top: 0; padding: max(14px, env(safe-area-inset-top)) 22px 0;
  display: grid; grid-template-columns: 1fr minmax(120px, 36vw) 1fr; align-items: start; gap: 12px;
  pointer-events: none;
}
#score {
  font-size: clamp(34px, 7vmin, 72px); font-weight: 900; letter-spacing: .02em;
  text-shadow: 0 0 18px rgba(77, 227, 255, .8), 0 3px 0 rgba(0, 0, 0, .5);
  font-variant-numeric: tabular-nums;
}
#timebar {
  margin-top: 16px; height: 16px; border-radius: 10px; background: rgba(255, 255, 255, .14);
  border: 2px solid rgba(255, 255, 255, .35); overflow: hidden;
}
#timebar i { display: block; height: 100%; width: 100%; transform-origin: left; background: linear-gradient(90deg, #35e0a1, #4de3ff); }
#timebar.low i { background: linear-gradient(90deg, #ff9a2e, #ffd23f); }
#combo {
  justify-self: end; text-align: right; font-size: clamp(22px, 4.6vmin, 46px); font-weight: 900;
  color: var(--gold); text-shadow: 0 0 16px rgba(255, 210, 63, .8), 0 3px 0 rgba(0, 0, 0, .5);
}

/* ---------- screens ---------- */
.screen {
  position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(14px, 3.2vmin, 34px); padding: 24px; text-align: center;
}
h1 {
  margin: 0; font-size: clamp(54px, 15vmin, 150px); line-height: .92; font-weight: 900; letter-spacing: .02em;
  text-shadow: 0 0 30px rgba(77, 227, 255, .55), 0 6px 0 rgba(0, 0, 0, .45);
}
h1 b { text-shadow: none; filter: drop-shadow(0 6px 0 rgba(0, 0, 0, .45)) drop-shadow(0 0 22px rgba(255, 176, 46, .45)); color: transparent; background: linear-gradient(180deg, #fff2a8, #ffb02e 55%, #ff4fa3); -webkit-background-clip: text; background-clip: text; }
h2 { margin: 0; font-size: clamp(34px, 8vmin, 80px); font-weight: 900; text-shadow: 0 4px 0 rgba(0, 0, 0, .45); }
h2 small { font-size: .4em; opacity: .6; font-weight: 700; }
.tag { margin: 0; font-size: clamp(18px, 3.4vmin, 34px); opacity: .85; }
#overScore {
  font-size: clamp(70px, 20vmin, 200px); font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums;
  color: var(--gold); text-shadow: 0 0 36px rgba(255, 210, 63, .6), 0 6px 0 rgba(0, 0, 0, .45);
}
#overNote { margin: 0; font-size: clamp(20px, 4vmin, 40px); min-height: 1.3em; color: var(--cyan); font-weight: 800; }
.row { display: flex; gap: clamp(16px, 4vmin, 44px); flex-wrap: wrap; justify-content: center; }

/* ---------- buttons (dwell fills the button; taps work too) ---------- */
.btn {
  position: relative; overflow: hidden; display: inline-flex; align-items: center; justify-content: center; gap: 14px;
  min-width: clamp(190px, 30vmin, 340px); min-height: clamp(76px, 12vmin, 128px); padding: 12px 34px;
  font: 900 clamp(24px, 4.6vmin, 46px)/1 var(--font); letter-spacing: .04em; color: #fff;
  background: linear-gradient(180deg, #5b6bff, #3b2bd6); border: 4px solid rgba(255, 255, 255, .85); border-radius: 999px;
  box-shadow: 0 8px 0 #1a1380, 0 0 28px rgba(91, 107, 255, .55); cursor: pointer;
  touch-action: manipulation;
}
.btn.huge {
  min-width: clamp(280px, 52vmin, 620px); min-height: clamp(110px, 20vmin, 220px); font-size: clamp(40px, 9vmin, 92px);
  background: linear-gradient(180deg, #34e6a0, #12a56c); box-shadow: 0 10px 0 #086a44, 0 0 40px rgba(52, 230, 160, .55);
}
.btn .fill {
  position: absolute; inset: 0; background: rgba(255, 255, 255, .42); transform-origin: left; transform: scaleX(var(--p, 0));
}
.btn span, .btn img { position: relative; }
.btn img[hidden] { display: none; }
.btn img { height: 1.5em; width: 1.5em; object-fit: contain; }
.btn:active { transform: translateY(4px); }

#whoGrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: clamp(12px, 2.6vmin, 28px); }
@media (max-aspect-ratio: 4/5) { #whoGrid { grid-template-columns: repeat(2, 1fr); } }
#whoGrid .btn { flex-direction: column; min-width: 0; min-height: 0; padding: 14px 18px 18px; border-radius: 34px; width: clamp(130px, 20vmin, 230px); }
#whoGrid .btn img { height: clamp(70px, 14vmin, 150px); width: auto; aspect-ratio: 1; }
#whoGrid .btn span { font-size: clamp(18px, 3.2vmin, 32px); }

#scoreList {
  list-style: none; margin: 0; padding: 0; width: min(760px, 92vw);
  display: grid; gap: clamp(3px, .7vmin, 8px);
}
#scores { gap: clamp(10px, 2vmin, 22px); }
#scores h2 { font-size: clamp(30px, 6.5vmin, 64px); }
#scores .btn { min-height: clamp(58px, 9vmin, 96px); }
#scoreList li {
  display: grid; grid-template-columns: 2.2em 1.6em 1fr auto; align-items: center; gap: 14px;
  padding: 4px 22px; border-radius: 16px; background: rgba(255, 255, 255, .1); border: 2px solid rgba(255, 255, 255, .18);
  font-size: clamp(16px, 3.1vmin, 32px); font-weight: 800; text-align: left;
}
#scoreList li.me { background: rgba(255, 210, 63, .22); border-color: var(--gold); }
#scoreList li .n { opacity: .6; }
#scoreList li img { height: 1.5em; width: 1.5em; object-fit: contain; }
#scoreList li .s { font-variant-numeric: tabular-nums; color: var(--gold); }
#scoreList li.empty { opacity: .35; }

/* ---------- parent settings ---------- */
#gear {
  position: fixed; right: max(10px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom));
  width: 54px; height: 54px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .08); color: rgba(255, 255, 255, .4);
  padding: 13px; touch-action: none; z-index: 5;
}
#gear svg { width: 100%; height: 100%; }
#gear .ring {
  position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(var(--cyan) calc(var(--p, 0) * 360deg), transparent 0);
  -webkit-mask: radial-gradient(circle, transparent 60%, #000 62%); mask: radial-gradient(circle, transparent 60%, #000 62%);
}
body.playing #gear { display: none; }

#settings {
  position: fixed; inset: 0; z-index: 10; background: rgba(4, 7, 20, .98); overflow-y: auto; touch-action: pan-y;
  display: flex; padding: 20px;
}
#settings .panel {
  margin: auto; width: min(640px, 100%); display: grid; gap: 18px; text-align: left; font-size: 18px;
}
#settings h2 { font-size: 34px; }
#settings h3 { margin: 6px 0 0; font-size: 20px; opacity: .8; }
#settings label { display: grid; gap: 8px; font-weight: 800; }
#settings label.check { display: flex; align-items: center; gap: 12px; }
#settings .hint { font-weight: 500; font-size: 14px; opacity: .65; }
#settings select, #settings input[type=text] {
  font: 600 18px var(--font); padding: 12px; border-radius: 12px; border: 2px solid rgba(255, 255, 255, .3);
  background: #141a3a; color: #fff; user-select: text; -webkit-user-select: text; touch-action: manipulation;
}
#settings input[type=range] { width: 100%; height: 36px; touch-action: pan-y; }
#settings input[type=checkbox] { width: 28px; height: 28px; }
#nameGrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
#nameGrid label { grid-template-columns: 36px 1fr; align-items: center; }
#nameGrid img { width: 36px; height: 36px; object-fit: contain; }
.plain {
  font: 800 18px var(--font); padding: 14px 24px; border-radius: 14px; border: 2px solid rgba(255, 255, 255, .35);
  background: transparent; color: #fff; touch-action: manipulation;
}
.plain.primary { background: #34e6a0; color: #05281a; border-color: #34e6a0; }
#settings .row { justify-content: space-between; }
