html, body {
  margin: 0;
  height: 100%;
  background: #111;
  color: #eee;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  font: 12px/1.35 ui-monospace, Menlo, Consolas, monospace;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none; /* no scroll, pinch-zoom or pull-to-refresh while swiping */
}

/* Bottom-left, so the top of the screen stays clear for the rack and labels. */
#hud {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 12px);
  left: calc(env(safe-area-inset-left) + 8px);
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.55);
  white-space: pre;
  pointer-events: none;
}

#tune-btn {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 8px);
  right: calc(env(safe-area-inset-right) + 8px);
  padding: 6px 12px;
  border: 1px solid #555;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.6);
  color: #eee;
  font: inherit;
}

#tune {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 44px);
  left: 8px;
  right: 8px;
  max-height: 55vh;
  overflow-y: auto;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(20, 20, 20, 0.92);
  touch-action: pan-y;
}

#tune[hidden] { display: none; }

#tune label {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  margin-bottom: 8px;
}

#tune input { grid-column: 1 / -1; width: 100%; }

.tune-buttons { display: flex; gap: 8px; flex-wrap: wrap; }

.tune-buttons button {
  flex: 1;
  padding: 8px;
  border: 1px solid #555;
  border-radius: 6px;
  background: #2a2a2a;
  color: #eee;
  font: inherit;
}

#results {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(300px, calc(100vw - 32px));
  box-sizing: border-box;
  padding: 18px 20px;
  border-radius: 12px;
  background: rgba(16, 16, 16, 0.94);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
  text-align: center;
  font-family: system-ui, sans-serif;
}

#results[hidden] { display: none; }

.results-title { font-size: 13px; letter-spacing: 0.12em; color: #aaa; }
.results-time { margin: 4px 0; font: bold 44px ui-monospace, Menlo, Consolas, monospace; color: #fff; }
.results-time.negative { color: #7dffb0; }
.results-best { margin-bottom: 12px; font-weight: bold; color: #ffd54f; }

#results table { width: 100%; margin-bottom: 14px; border-collapse: collapse; font-size: 14px; }
#results td { padding: 3px 0; color: #ccc; }
#results td:last-child { text-align: right; color: #fff; }

#results button {
  width: 100%;
  padding: 12px;
  border: 0;
  border-radius: 8px;
  background: #ffd54f;
  color: #111;
  font: bold 16px system-ui, sans-serif;
}

#qr {
  position: fixed;
  right: 16px;
  bottom: 16px;
  padding: 12px;
  border-radius: 10px;
  background: #fff;
  color: #111;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

#qr svg { display: block; margin: 0 auto 6px; }

#results button.to-home {
  margin-top: 8px;
  padding: 10px;
  background: transparent;
  border: 1px solid #555;
  color: #ddd;
  font-weight: normal;
}

#home-btn {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 8px);
  left: calc(env(safe-area-inset-left) + 8px);
  padding: 6px 12px;
  border: 1px solid #555;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.6);
  color: #eee;
  font: inherit;
}

#home-btn[hidden], #tune-btn[hidden], #hud[hidden] { display: none; }

/* Menu over today's level, which keeps drifting behind it. */
#home {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 0 32px;
  background: rgba(10, 30, 55, 0.35);
  font-family: system-ui, sans-serif;
}

#home[hidden] { display: none; }

.home-title {
  margin-bottom: 18px;
  font: 900 min(44px, 11vw)/1 system-ui, sans-serif; /* shrinks to fit narrow phones */
  letter-spacing: 0.06em;
  color: #fff;
  text-shadow: 0 3px 0 #c62828, 0 6px 18px rgba(0, 0, 0, 0.35);
}

#home button {
  width: min(280px, 100%);
  border: 0;
  border-radius: 12px;
  font-family: inherit;
}

.home-play {
  padding: 16px;
  background: #ffd54f;
  color: #111;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.08em;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.home-play span {
  display: block;
  margin-top: 2px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  opacity: 0.7;
}

.home-best { margin-top: -6px; font-weight: 700; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); }

.home-practice {
  padding: 12px;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  font-size: 16px;
}
