/* Runaway Ball. The game canvas fills the screen; everything here is the flat overlay UI. */
:root {
  --ink: #05030d;
  --panel: #0b0716;
  --violet: #b04dff;
  --pink: #ff5ad1;
  --amber: #ffc233;
  --ice: #58e6ff;
  --red: #ff2a3c;
  --text: #f3eeff;
  --dim: #a99fc4;
  --notch: 10px;
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  background: var(--ink);
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  font-family: 'Saira Semi Condensed', system-ui, sans-serif;
  font-weight: 600;
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.rb {
  position: fixed;
  inset: 0;
  height: 100dvh;
  touch-action: none;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
#stage { display: block; width: 100%; height: 100%; touch-action: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
[hidden] { display: none !important; }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }

/* ---- buttons: a notched slab, flat, no glow ---- */
.btn {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 52px;
  padding: 8px 22px;
  border: 0;
  background: var(--violet);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  clip-path: polygon(var(--notch) 0, 100% 0, 100% calc(100% - var(--notch)), calc(100% - var(--notch)) 100%, 0 100%, 0 var(--notch));
  isolation: isolate;
}
.btn::before {
  content: '';
  position: absolute;
  inset: 2px;
  z-index: -1;
  background: var(--panel);
  clip-path: polygon(calc(var(--notch) - 1px) 0, 100% 0, 100% calc(100% - var(--notch) + 1px), calc(100% - var(--notch) + 1px) 100%, 0 100%, 0 calc(var(--notch) - 1px));
}
.btn:hover::before, .btn:focus-visible::before, .btn[aria-pressed='true']::before { background: var(--violet); }
.btn:hover, .btn:focus-visible, .btn[aria-pressed='true'] { color: var(--ink); outline: none; }
.btn:active { transform: translateY(1px); }
.btn.small { min-height: 44px; font-size: 16px; padding: 6px 16px; }
.btn.ghost { background: #4a3d6b; color: var(--dim); }
.btn.hot { background: var(--red); }
.btn.hot:hover::before, .btn.hot:focus-visible::before { background: var(--red); }

/* ---- panels ---- */
.panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: calc(16px + var(--sat)) calc(16px + var(--sar)) calc(44px + var(--sab)) calc(16px + var(--sal));
  background: rgb(5 3 13 / 0.72);
  text-align: center;
  overflow-y: auto;
  touch-action: pan-y;
}
.menu { background: rgb(5 3 13 / 0.55); }
.back {
  position: absolute;
  top: calc(10px + var(--sat));
  left: calc(14px + var(--sal));
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  color: var(--dim);
  font-size: 15px;
  text-decoration: none;
}
.back:hover, .back:focus-visible { color: var(--text); }
h1 {
  margin: 0 0 4px;
  font-size: clamp(44px, 11vw, 104px);
  font-weight: 800;
  line-height: 0.9;
  letter-spacing: 0.04em;
  color: var(--amber);
}
h1 span { color: var(--pink); }
h2 { margin: 0; font-size: clamp(34px, 8vw, 64px); font-weight: 800; letter-spacing: 0.08em; color: var(--amber); }
.name input {
  width: min(280px, 72vw);
  min-height: 44px;
  padding: 6px 12px;
  border: 2px solid var(--violet);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-size: 18px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  user-select: text;
  -webkit-user-select: text;
}
.name input:focus-visible { outline: 2px solid var(--ice); outline-offset: 2px; }
.name input::placeholder { color: #6f6590; }
.name-note, .tip, .board-note { max-width: 34ch; margin: 0; font-size: 12px; font-weight: 500; line-height: 1.35; letter-spacing: 0.04em; text-transform: none; color: var(--dim); }
.modes { display: grid; gap: 10px; width: min(420px, 88vw); }
.mode { grid-template-columns: 1fr; gap: 0; min-height: 64px; }
.mode b { font-size: 26px; font-weight: 800; letter-spacing: 0.12em; line-height: 1.05; }
.mode span { font-size: 11px; font-weight: 600; letter-spacing: 0.14em; opacity: 0.8; }
.mode i { position: absolute; right: 14px; top: 8px; font-style: normal; font-size: 11px; color: var(--amber); }
.mode:hover i, .mode:focus-visible i { color: var(--ink); }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.over-label { margin: 6px 0 0; font-size: 14px; color: var(--dim); }
.over-score { margin: 0; font-size: clamp(64px, 16vw, 120px); font-weight: 800; line-height: 0.95; color: var(--text); }
.over-best, .over-save { margin: 0; min-height: 1.2em; font-size: 14px; color: var(--amber); }
.over-save { color: var(--ice); text-transform: none; letter-spacing: 0.04em; }
.over .btn, .pause .btn { width: min(300px, 78vw); }

/* ---- HUD ---- */
.hud { position: absolute; inset: 0; pointer-events: none; }
.hud > * { position: absolute; margin: 0; }
.hud-score { top: calc(8px + var(--sat)); left: 50%; translate: -50% 0; font-size: clamp(40px, 9vw, 64px); font-weight: 800; line-height: 1; color: var(--amber); }
.hud-speed { top: calc(14px + var(--sat)); left: calc(16px + var(--sal)); font-size: clamp(16px, 3.6vw, 26px); font-weight: 700; }
.hud-speed b { display: inline-block; min-width: 2.2ch; font-weight: 800; }
.icon-btn {
  top: calc(8px + var(--sat));
  right: calc(10px + var(--sar));
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border: 2px solid var(--violet);
  background: rgb(11 7 22 / 0.7);
  color: var(--text);
  cursor: pointer;
  pointer-events: auto;
}
.icon-btn svg { width: 24px; height: 24px; fill: currentColor; }
.icon-btn:hover, .icon-btn:focus-visible { background: var(--violet); color: var(--ink); outline: none; }
.callouts { top: calc(68px + var(--sat)); right: calc(10px + var(--sar)); padding: 0; list-style: none; display: grid; gap: 6px; justify-items: end; }
.callouts li {
  position: relative;
  padding: 3px 14px 3px 8px;
  background: rgb(5 3 13 / 0.6);
  border-right: 4px solid var(--ice);
  font-size: clamp(12px, 2.8vw, 17px);
  font-weight: 700;
  white-space: nowrap;
  animation: callout 1.7s linear forwards;
}
.callouts li[data-type='speed'] { border-color: var(--amber); }
.callouts li[data-type='near'] { border-color: var(--pink); }
@keyframes callout { 0% { opacity: 0; translate: 12px 0; } 8% { opacity: 1; translate: 0 0; } 80% { opacity: 1; } 100% { opacity: 0; } }
.hint { top: calc(74px + var(--sat)); left: 50%; translate: -50% 0; width: max-content; max-width: 90vw; font-size: clamp(14px, 3.4vw, 22px); font-weight: 700; text-align: center; white-space: pre-line; line-height: 1.35; }
.modetag { bottom: calc(30px + var(--sab)); left: 50%; translate: -50% 0; font-size: 15px; font-weight: 800; letter-spacing: 0.2em; color: var(--dim); }
.modetag[data-mode='turbo'] { color: var(--red); }
.nowplaying { bottom: calc(30px + var(--sab)); right: calc(12px + var(--sar)); display: flex; align-items: center; gap: 8px; padding: 4px 10px; background: rgb(5 3 13 / 0.6); font-size: 12px; font-weight: 600; }
.nowplaying b { font-weight: 700; color: var(--ice); }
.disc { width: 16px; height: 16px; border-radius: 50%; border: 5px solid var(--ice); }
.slowtip { bottom: calc(64px + var(--sab)); left: 50%; translate: -50% 0; min-height: 44px; padding: 6px 14px; border: 2px solid var(--amber); background: var(--panel); color: var(--amber); font: inherit; font-size: 13px; text-transform: none; letter-spacing: 0.03em; pointer-events: auto; cursor: pointer; }

/* ---- settings and leaderboard sheets ---- */
.sheet {
  width: min(560px, calc(100vw - 20px));
  max-height: calc(100dvh - 20px);
  padding: 18px 16px 16px;
  border: 2px solid var(--violet);
  background: var(--panel);
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  overscroll-behavior: contain;
}
.sheet[open] { display: flex; flex-direction: column; gap: 12px; }
.sheet::backdrop { background: rgb(5 3 13 / 0.8); overflow: hidden; overscroll-behavior: contain; }
.sheet h2 { font-size: clamp(28px, 7vw, 44px); text-align: center; }
.sheet h3 { margin: 14px 0 4px; font-size: 15px; font-weight: 700; letter-spacing: 0.14em; color: var(--pink); }
.sheet-body { overflow-y: auto; min-height: 0; padding-right: 4px; touch-action: pan-y; }
.sheet form { display: grid; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 44px; font-size: 14px; letter-spacing: 0.04em; }
.field span { flex: 1 1 auto; text-align: left; }
.field input[type='range'] { flex: 0 1 220px; min-width: 120px; height: 28px; accent-color: var(--violet); }
.field input[type='checkbox'] { flex: none; }
.field input[type='checkbox'] { width: 26px; height: 26px; accent-color: var(--violet); }
.presets { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 6px; }
.presets .btn { flex: 1 1 0; padding-inline: 8px; }
.tabs { display: flex; gap: 6px; }
.tab { flex: 1 1 0; min-height: 40px; padding: 4px 2px; border: 2px solid #4a3d6b; background: transparent; color: var(--dim); font: inherit; font-size: 13px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; cursor: pointer; }
.tab[aria-pressed='true'] { border-color: var(--violet); background: var(--violet); color: var(--ink); }
.scores { width: 100%; border-collapse: collapse; font-size: 16px; font-variant-numeric: tabular-nums; }
.scores th { padding: 6px 4px; font-size: 12px; color: var(--dim); text-align: left; border-bottom: 1px solid #4a3d6b; }
.scores td { padding: 7px 4px; border-bottom: 1px solid #1c1530; }
.scores th:last-child, .scores td:last-child { text-align: right; }
.scores td:first-child { width: 3.5em; color: var(--dim); }
.scores tr.me td { color: var(--amber); }
.board-note { max-width: none; padding: 10px 0; text-align: center; }
.pager { display: flex; align-items: center; justify-content: center; gap: 16px; }
.pager .btn { min-width: 52px; font-size: 22px; }

/* ---- the credit and privacy link stay on screen, play included ----
   Small and in the bottom center, away from the thumbs that hold the left and right of the screen to steer. */
.credit {
  position: absolute;
  left: 50%;
  translate: -50% 0;
  bottom: calc(3px + var(--sab));
  margin: 0;
  display: flex;
  gap: 5px;
  width: max-content;
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: none;
  color: var(--dim);
}
.credit a { display: inline-block; padding: 2px 0; color: var(--text); text-decoration: none; }
.credit a:hover, .credit a:focus-visible { color: var(--amber); }
.nojs { position: absolute; inset: 40% 0 auto; text-align: center; }

/* on a narrow screen the hint sits under the callouts instead of beside them */
@media (max-width: 620px) {
  .hint { top: calc(150px + var(--sat)); }
}
@media (max-height: 520px) {
  .panel { gap: 7px; justify-content: flex-start; padding-top: calc(8px + var(--sat)); }
  h1 { font-size: clamp(30px, 9vh, 56px); }
  .modes { grid-template-columns: repeat(3, 1fr); width: min(720px, 94vw); }
  .mode { min-height: 56px; }
  .mode b { font-size: 20px; }
  .name-note { max-width: 70ch; }
  .over-score { font-size: clamp(44px, 20vh, 90px); }
  .over .btn, .pause .btn { min-height: 42px; }
  .nowplaying { bottom: calc(6px + var(--sab)); }
  .modetag { bottom: calc(20px + var(--sab)); font-size: 13px; }
}
@media (prefers-reduced-motion: reduce) {
  .callouts li { animation-duration: 1.7s; animation-timing-function: step-end; }
}
