/* Riff Rush - layout.
   Portrait is the first screen it meets. Landscape is not a lesser version. */

:root {
  --lane-0: #20e3a2;
  --lane-1: #ff9e2c;
  --lane-2: #3fa9ff;
  --lane-3: #ff4fa3;
  --ink: #f2eefc;
  --dim: #a49cc4;
  --bg: #07060d;
  --panel: rgba(18, 15, 32, 0.92);
  --edge: rgba(150, 130, 255, 0.22);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#app {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  padding: max(6px, env(safe-area-inset-top)) 8px max(6px, env(safe-area-inset-bottom));
  gap: 6px;
}

/* ---------------- HUD ---------------- */
#hud {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(30, 22, 56, 0.85), rgba(14, 11, 26, 0.7));
  border: 1px solid var(--edge);
  flex: 0 0 auto;
}

.hud-cell {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.hud-mid { align-items: center; margin: 0 auto; }
.hud-right { align-items: flex-end; }

.hud-label {
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dim);
  font-weight: 700;
}

.hud-value {
  font-size: clamp(15px, 4.6vw, 22px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  line-height: 1.1;
}

#score { color: #fff; }
#streak { color: #ffd93d; }
#acc { color: #8be0ff; }
#streak-mult {
  margin-left: 3px;
  font-size: 0.68em;
  color: #ffd93d;
  opacity: 0.85;
}
.hud-value { white-space: nowrap; }

.icon-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--edge);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  font-size: 17px;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.icon-btn:active { transform: scale(0.94); }

/* pause exists only while a run is live, and it has to exist on a phone,
   where there is no Escape key to press */
#pause-btn { display: none; position: relative; }
body.playing #pause-btn { display: grid; }
.pause-bars { display: flex; gap: 4px; }
.pause-bars i {
  display: block;
  width: 3.5px;
  height: 13px;
  border-radius: 1.5px;
  background: currentColor;
}

/* muted is struck through, not just dimmed */
#sound-off { display: none; }
body.muted #sound-on { display: none; }
body.muted #sound-off { display: inline; }
body.muted #sound { color: #6c6488; }
body.muted #sound::after {
  content: "";
  position: absolute;
  left: 22%;
  right: 22%;
  top: 50%;
  height: 2px;
  border-radius: 2px;
  background: #8f6fd8;
  transform: rotate(-38deg);
}

/* ---------------- progress ---------------- */
#progress {
  flex: 0 0 auto;
  height: 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
#progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--lane-0), var(--lane-2), var(--lane-3));
  transition: width 0.12s linear;
}

/* ---------------- stage ---------------- */
#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--edge);
  background: radial-gradient(120% 80% at 50% 0%, #1a1330 0%, #0a0814 70%);
}

#board {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#keys {
  flex: 0 0 auto;
  text-align: center;
  color: var(--dim);
  font-size: 11px;
  letter-spacing: 0.06em;
  padding-bottom: 2px;
}
#keys b {
  display: inline-block;
  min-width: 22px;
  padding: 1px 5px;
  margin: 0 1px;
  border-radius: 5px;
  border: 1px solid var(--edge);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  font-weight: 700;
}

/* ---------------- overlays ---------------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(5, 4, 12, 0.82);
  backdrop-filter: blur(7px);
  z-index: 10;
  overflow: auto;
}
.overlay.hidden { display: none; }

.panel {
  width: min(100%, 430px);
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 20px;
  padding: 20px 18px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  margin: auto;
}
.panel-small { width: min(100%, 320px); }

.logo {
  margin: 0 0 4px;
  font-size: clamp(30px, 10vw, 46px);
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1;
  background: linear-gradient(92deg, #ff9e2c, #ff4fa3 45%, #3fa9ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.logo span { display: block; }

.tagline {
  margin: 6px 0 14px;
  color: var(--dim);
  font-size: 13px;
  line-height: 1.45;
}

h2 { margin: 0 0 6px; font-size: 24px; }

.big-btn {
  width: 100%;
  padding: 15px;
  margin-top: 10px;
  border: none;
  border-radius: 14px;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #12091f;
  background: linear-gradient(180deg, #ffe066, #ff9e2c);
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(255, 158, 44, 0.28);
}
.big-btn:active { transform: translateY(1px) scale(0.99); }

.mini-btn {
  padding: 9px 16px;
  margin-top: 10px;
  border-radius: 11px;
  border: 1px solid var(--edge);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.mini-btn:active { transform: scale(0.97); }

.btn-row {
  display: flex;
  gap: 10px;
  align-items: center;
}
.btn-row .big-btn { margin-top: 10px; }
.btn-row .mini-btn { flex: 0 0 auto; margin-top: 10px; }

.fine {
  margin: 12px 0 0;
  font-size: 11.5px;
  color: var(--dim);
  line-height: 1.5;
}
.fine b {
  color: var(--ink);
  padding: 0 3px;
}

/* empty until the viewer is known, so it must not reserve space */
.who-line {
  margin: 8px 0 0;
  font-size: 12px;
  color: #8be0ff;
  font-weight: 700;
  min-height: 0;
}
.who-line:empty { display: none; }

/* shown only when the browser refused to copy, so the address is still reachable */
.share-url {
  width: 100%;
  margin-top: 9px;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid var(--edge);
  background: rgba(0, 0, 0, 0.38);
  color: var(--ink);
  font-size: 12px;
  text-align: center;
  font-family: ui-monospace, Menlo, monospace;
}
.share-url.hidden { display: none; }

.controls-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--dim);
  cursor: pointer;
}
.switch input { accent-color: #ff9e2c; width: 16px; height: 16px; }

/* ---------------- leaderboard ---------------- */
.board {
  margin-top: 14px;
  text-align: left;
  border: 1px solid var(--edge);
  border-radius: 12px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.25);
}
.board-head {
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--dim);
  font-weight: 700;
  padding: 7px 12px;
  background: rgba(255, 255, 255, 0.04);
}
.board ol {
  list-style: none;
  margin: 0;
  padding: 0;
}
.board li {
  display: flex;
  gap: 10px;
  padding: 6px 12px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}
.board li .rank { color: var(--dim); width: 18px; flex: 0 0 auto; font-weight: 700; }
.board li .who {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.board li .val { font-weight: 800; color: #ffd93d; }
.board li.mine .who { color: #8be0ff; font-weight: 700; }
.board li.board-empty {
  color: var(--dim);
  font-style: italic;
  display: block;
}

/* ---------------- results ---------------- */
.grade {
  font-size: clamp(46px, 16vw, 74px);
  font-weight: 900;
  line-height: 1;
  margin-bottom: 2px;
  background: linear-gradient(180deg, #fff, #ffd93d);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.result-score {
  font-size: clamp(30px, 10vw, 44px);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.result-sub {
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--dim);
  font-weight: 700;
  margin-bottom: 12px;
}
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}
.stat {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--edge);
  border-radius: 10px;
  padding: 7px 4px;
}
.stat span {
  display: block;
  font-size: 8.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
  font-weight: 700;
}
.stat b {
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

/* ---------------- landscape ---------------- */
/* Same vertical lanes, given a sane width for the height on offer, with the
   readouts moved beside the board instead of stealing its height. */
/* Short screens get a compact one-line HUD. It stays in the normal flow on
   purpose: an overlaid HUD collides with the left lane as soon as the window
   narrows, and the lanes must never be covered. */
@media (orientation: landscape) and (max-height: 620px) {
  #app { padding: 4px 8px; gap: 4px; }
  #hud { flex-direction: row; align-items: center; padding: 3px 8px; gap: 10px; }
  .hud-label { font-size: 8px; }
  .hud-value { font-size: 14px; }
  .hud-mid { margin: 0 auto; }
  .icon-btn { width: 30px; height: 30px; font-size: 14px; }
  #keys { display: none; }
  #stage { border-radius: 12px; }
  .panel { width: min(100%, 560px); padding: 14px; }
  .logo { font-size: 30px; }
  .tagline { margin: 4px 0 10px; }
  .stat-grid { grid-template-columns: repeat(6, 1fr); }
  .big-btn { padding: 12px; margin-top: 8px; }
}

/* Below this the four HUD cells cannot all hold their widest value; the streak
   number stays, the multiplier goes, and the canvas still shows it large. */
@media (max-width: 380px) {
  .hud-label { font-size: 8px; }
  #keys { font-size: 10px; }
  #streak-mult { display: none; }
  #hud { gap: 6px; padding: 5px 6px; }
}
