:root {
  --bg: #131b33;
  --ink: #f4f6ff;
  --muted: #9aa3c7;
  --gold: #ffd166;
  --drum: #e2574c;
  --row: #2e9edb;
  --nation: #d81f2a;
  --nation2: #ffffff;
  --panel: rgba(13, 19, 42, 0.88);
  --card: rgba(255, 255, 255, 0.07);
  --radius: 18px;
  --display: 'Bungee', 'Arial Black', sans-serif;
  --body: 'Inter', -apple-system, system-ui, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#app { position: fixed; inset: 0; overflow: hidden; }

#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: calc(10px + env(safe-area-inset-top));
  left: 12px; right: 12px;
  display: flex; align-items: flex-start; gap: 10px;
  pointer-events: none;
  z-index: 5;
}
.hud-box {
  background: rgba(10, 15, 35, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 8px 14px;
  font-family: var(--display);
  font-size: clamp(18px, 5vw, 28px);
  backdrop-filter: blur(6px);
}
.hud-dist { color: var(--gold); }
.hud-dist small { font-size: 0.55em; color: var(--muted); }
.hud-time { margin-left: auto; }
.hud-time.low { color: #ff6b6b; animation: pulse 0.5s infinite alternate; }
.hud-combo { color: #7bed9f; font-size: clamp(14px, 4vw, 22px); }
@keyframes pulse { to { transform: scale(1.12); } }

/* ---------- Feedback + countdown ---------- */
#feedback {
  position: absolute;
  top: 26%;
  left: 0; right: 0;
  text-align: center;
  font-family: var(--display);
  font-size: clamp(26px, 9vw, 56px);
  pointer-events: none;
  z-index: 6;
  opacity: 0;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}
#feedback.show { animation: fbPop 0.55s ease-out; }
@keyframes fbPop {
  0% { opacity: 0; transform: scale(0.5); }
  20% { opacity: 1; transform: scale(1.15); }
  70% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1) translateY(-14px); }
}
#feedback.perfect { color: var(--gold); }
#feedback.good { color: #7bed9f; }
#feedback.okay { color: #cfd6f4; }
#feedback.miss { color: #ff6b6b; }

#countdown {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-family: var(--display);
  font-size: clamp(72px, 26vw, 190px);
  color: var(--gold);
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.35);
  z-index: 7;
  pointer-events: none;
}

/* ---------- Tap buttons ---------- */
#controls {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  gap: 10px;
  padding: 10px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 5;
}
.tap-btn {
  flex: 1;
  min-height: max(19vh, 120px);
  border: none;
  border-radius: 22px;
  font-family: var(--display);
  color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.35), inset 0 2px 0 rgba(255, 255, 255, 0.25);
  transition: transform 0.05s;
}
.tap-btn:active, .tap-btn.pressed { transform: translateY(4px) scale(0.985); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35); }
#btnDrum { background: linear-gradient(180deg, #ef6a5e, #c43e34); }
#btnRow { background: linear-gradient(180deg, #3fb0ea, #1f7ec0); }
.tap-ico { font-size: clamp(34px, 9vw, 58px); line-height: 1; }
.tap-label { font-size: clamp(15px, 4vw, 24px); letter-spacing: 0.06em; }

/* ---------- Panels ---------- */
.panel {
  position: absolute; inset: 0;
  z-index: 10;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: linear-gradient(180deg, rgba(10, 14, 34, 0.55) 0%, var(--panel) 34%);
  backdrop-filter: blur(3px);
  padding: calc(14px + env(safe-area-inset-top)) 18px calc(26px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center;
  gap: 16px;
}
.panel::-webkit-scrollbar { display: none; }
/* children must keep their natural height — the panel itself scrolls */
.panel > * { flex-shrink: 0; }

.panel-top {
  width: 100%;
  max-width: 560px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
#langSel, #soundBtn {
  background: var(--card);
  color: var(--ink);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  padding: 7px 10px;
  font-family: var(--body);
  font-size: 14px;
  cursor: pointer;
}

.brand { text-align: center; }
.brand-emoji { font-size: clamp(30px, 8vw, 44px); letter-spacing: 0.15em; }
.brand h1 {
  font-family: var(--display);
  font-size: clamp(28px, 6.4vw, 64px);
  white-space: nowrap;
  line-height: 1;
  background: linear-gradient(180deg, #ffe9a3, var(--gold) 55%, #e8912e);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 0 rgba(0, 0, 0, 0.35));
}
.subtitle { color: var(--muted); font-weight: 600; margin-top: 4px; }
.world-total {
  margin-top: 8px;
  display: inline-block;
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  padding: 5px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--gold);
}
.my-totals { margin-top: 6px; color: #7bed9f; }
.lb-link {
  margin-top: 8px;
  margin-left: 6px;
  font-family: var(--body);
  font-weight: 600;
  border-color: rgba(255, 209, 102, 0.55);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* standalone leaderboard mode (opened from the start screen) */
.lb-head { display: none; }
.lb-only .lb-head {
  display: flex;
  width: 100%; max-width: 560px;
  align-items: center;
  justify-content: space-between;
}
.lb-head h2 { font-family: var(--display); font-size: 20px; color: var(--gold); }
.lb-head button {
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--ink);
  border-radius: 10px;
  width: 38px; height: 38px;
  font-size: 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.lb-only .result-hero,
.lb-only .res-stats,
.lb-only #submitBlock,
.lb-only #shareBtn { display: none !important; }

.howto {
  width: 100%; max-width: 560px;
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  padding: 16px 18px;
  text-align: center;
}
.howto h2 { font-family: var(--display); font-size: 17px; color: var(--gold); margin-bottom: 8px; }
.howto p { color: #d7dcf2; font-size: 14.5px; line-height: 1.5; }
.keys-hint { color: var(--muted) !important; font-size: 12.5px !important; margin-top: 8px; }
@media (pointer: coarse) { .keys-hint { display: none; } }

.howto-beats { display: flex; justify-content: center; gap: 14px; margin: 6px 0 10px; font-size: 34px; }
.beat { animation: beatPulse 1.8s infinite; opacity: 0.45; }
.beat.b1 { animation-delay: 0s; }
.beat.b2 { animation-delay: 0.45s; }
.beat.b3 { animation-delay: 0.9s; }
@keyframes beatPulse {
  0%, 30% { transform: scale(1); opacity: 0.45; }
  8% { transform: scale(1.35); opacity: 1; }
}

.pick-title { font-family: var(--display); font-size: 19px; margin-top: 4px; }

#nationSearch, #nameInput, #resNameInput {
  width: 100%; max-width: 560px;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  padding: 12px 14px;
  outline: none;
}
#nationSearch:focus, #nameInput:focus, #resNameInput:focus { border-color: var(--gold); }

#nationGrid {
  width: 100%; max-width: 560px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(102px, 1fr));
  gap: 8px;
  /* fill whatever height is left so the whole start screen fits on one screen */
  flex: 1 1 240px;
  min-height: 120px;
  max-height: 42vh;
  align-content: start;
  overflow-y: auto;
  padding: 2px;
  border-radius: 12px;
  -webkit-overflow-scrolling: touch;
}
.nation-btn {
  background: var(--card);
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  color: var(--ink);
  font-family: var(--body);
  font-size: 12px;
  font-weight: 600;
  padding: 9px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.nation-btn .nf { font-size: 26px; line-height: 1.1; }
.nation-btn.sel {
  border-color: var(--gold);
  background: rgba(255, 209, 102, 0.16);
  box-shadow: 0 0 0 1px var(--gold);
}

.big-btn {
  width: 100%; max-width: 560px;
  border: none;
  border-radius: 20px;
  padding: 18px;
  font-family: var(--display);
  font-size: clamp(24px, 7vw, 34px);
  color: #1d1503;
  background: linear-gradient(180deg, #ffe9a3, var(--gold) 60%, #f0a832);
  box-shadow: 0 6px 0 #9c6410, 0 10px 24px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.05s;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #9c6410; }
.big-btn:disabled { filter: grayscale(0.8) brightness(0.6); box-shadow: none; cursor: default; }

.mid-btn {
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 14px;
  color: var(--ink);
  font-family: var(--display);
  font-size: 15px;
  padding: 12px 18px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.mid-btn:disabled { opacity: 0.5; cursor: default; }

/* ---------- Result ---------- */
.result-hero { text-align: center; }
.res-flag { font-size: 44px; }
.result-hero p { color: var(--muted); font-weight: 600; }
.res-dist {
  font-family: var(--display);
  font-size: clamp(56px, 19vw, 110px);
  line-height: 1.05;
  color: var(--gold);
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}
.res-dist small { font-size: 0.35em; color: var(--muted); }
.best-badge {
  display: inline-block;
  margin-top: 6px;
  background: #7bed9f;
  color: #0c3b1e;
  font-family: var(--display);
  font-size: 15px;
  border-radius: 999px;
  padding: 6px 16px;
  animation: pulse 0.6s infinite alternate;
}
.res-your-best { font-size: 13px; margin-top: 6px; }

.res-stats {
  width: 100%; max-width: 560px;
  display: flex; gap: 8px;
}
.res-stats > div {
  flex: 1;
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 10px 6px;
  text-align: center;
  display: flex; flex-direction: column; gap: 2px;
}
.res-stats b { font-family: var(--display); font-size: 20px; }
.res-stats span { color: var(--muted); font-size: 11.5px; }

#submitBlock {
  width: 100%; max-width: 560px;
  display: flex; flex-direction: column; gap: 8px;
}
#submitRow { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
#submitRow #resNameInput { flex: 1; min-width: 170px; max-width: none; }
#rankMsg { width: 100%; text-align: center; color: var(--gold); font-weight: 600; font-size: 14.5px; }

.lb-tabs {
  width: 100%; max-width: 560px;
  display: flex; gap: 8px;
}
.lb-tabs button {
  flex: 1;
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  color: var(--muted);
  font-family: var(--display);
  font-size: 13px;
  padding: 11px 6px;
  cursor: pointer;
}
.lb-tabs button.active { color: #1d1503; background: var(--gold); border-color: var(--gold); }

.lb-list {
  width: 100%; max-width: 560px;
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  padding: 6px 12px;
  min-height: 120px;
}
.lb-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 14.5px;
}
.lb-row:last-child { border-bottom: none; }
.lb-row .pos { width: 30px; font-family: var(--display); font-size: 14px; color: var(--muted); }
.lb-row .fl { font-size: 20px; }
.lb-row .nm { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row .sub { color: var(--muted); font-size: 11.5px; font-weight: 400; display: block; }
.lb-row .val { font-family: var(--display); font-size: 15px; color: var(--gold); }
.lb-row.me { background: rgba(255, 209, 102, 0.12); border-radius: 10px; }
.lb-row.lb-x { cursor: pointer; }
.runs { color: var(--muted); font-weight: 400; font-size: 12px; }
.lb-sub {
  padding: 2px 6px 10px 42px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
[dir="rtl"] .lb-sub { padding: 2px 42px 10px 6px; }
.lb-subrow {
  display: flex; justify-content: space-between; align-items: center;
  color: var(--muted); font-size: 13px; padding: 3px 2px;
}
.lb-subrow b { color: var(--gold); font-family: var(--display); font-weight: 400; font-size: 13px; }
.lb-msg { color: var(--muted); text-align: center; padding: 24px 8px; font-size: 14px; }

#confetti {
  position: fixed; inset: 0;
  z-index: 40;
  pointer-events: none;
}

#shareBtn { border-color: rgba(255, 209, 102, 0.6); color: var(--gold); }
#shareBtn.pulse { animation: sharePulse 1s infinite alternate; }
@keyframes sharePulse {
  from { box-shadow: 0 0 0 0 rgba(255, 209, 102, 0.5); }
  to { box-shadow: 0 0 0 8px rgba(255, 209, 102, 0); transform: scale(1.04); }
}

.promo {
  width: 100%; max-width: 560px;
  border-radius: var(--radius);
  padding: 16px 18px;
  text-align: center;
  background: linear-gradient(135deg, rgba(255, 77, 148, 0.18), rgba(64, 224, 208, 0.18));
  border: 1px solid rgba(255, 77, 148, 0.45);
}
.promo-title { font-family: var(--display); font-size: 16px; color: #ff8fb8; }
.promo p:not(.promo-title) { color: #d7dcf2; font-size: 14px; margin-top: 4px; }
.promo a {
  display: inline-block;
  margin-top: 10px;
  background: linear-gradient(90deg, #ff4d94, #40e0d0);
  color: #10131f;
  font-family: var(--display);
  font-size: 14px;
  text-decoration: none;
  border-radius: 999px;
  padding: 10px 22px;
}

.res-actions {
  width: 100%; max-width: 560px;
  display: flex; gap: 10px; align-items: stretch;
}
.res-actions .big-btn { flex: 1; }

/* discreet Klikk signature — bare chevron + wordmark asset, like the nettsider footers */
.made-by {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  align-self: center;
  color: #f4f6ff;
  text-decoration: none;
  opacity: 0.4;
  padding: 4px 8px;
}
.made-by:hover { opacity: 0.85; }
.made-by svg { height: 12px; width: auto; display: block; }  /* chevron = K cap height */
.made-by img { height: 12px; width: auto; display: block; }

/* Compact layout: everything on one screen on phones / short windows */
@media (max-width: 640px), (max-height: 780px) {
  .panel { gap: 10px; padding-top: calc(8px + env(safe-area-inset-top)); }
  .panel-top {
    position: absolute;
    top: calc(8px + env(safe-area-inset-top));
    right: 12px;
    width: auto;
  }
  [dir="rtl"] .panel-top { right: auto; left: 12px; }
  #langSel, #soundBtn { padding: 5px 8px; font-size: 13px; }
  .brand { margin-top: 34px; }
  .brand-emoji { font-size: 22px; }
  .brand h1 { font-size: clamp(24px, 6.8vw, 40px); }
  .subtitle { font-size: 13px; margin-top: 2px; }
  .world-total { margin-top: 5px; font-size: 12px; padding: 4px 12px; }
  .howto { padding: 10px 14px; }
  .howto h2 { font-size: 14px; margin-bottom: 4px; }
  .howto-beats { font-size: 24px; gap: 10px; margin: 4px 0 6px; }
  .howto p { font-size: 12.5px; line-height: 1.4; }
  .pick-title { font-size: 15px; margin-top: 0; }
  #nationSearch, #nameInput, #resNameInput { padding: 9px 12px; }
  #nationGrid { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 6px; }
  .nation-btn { padding: 6px 3px; font-size: 11px; }
  .nation-btn .nf { font-size: 20px; }
  .big-btn { padding: 13px; font-size: clamp(20px, 5.5vw, 26px); border-radius: 16px; }
}

/* RTL tweaks */
[dir="rtl"] .hud-time { margin-left: 0; margin-right: auto; }
