:root {
  color-scheme: dark;
  font: 1rem/1.5 system-ui, sans-serif;
  background: #171311;
  color: #fff2db;
  --accent: #ffba58;
  --muted: #d5bd9f;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-width: 17rem;
  background: radial-gradient(ellipse at 50% 0%, #3c251c 0%, #171311 64%);
}
.cabinet {
  width: min(100rem, 100% - 1.5rem);
  min-height: 100dvh;
  margin: 0 auto;
  padding: clamp(1.25rem, 4vw, 3.2rem) 0 1.5rem;
  display: grid;
  grid-template-rows: auto minmax(21rem, 1fr) auto;
}
.header, footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.header { margin-bottom: 1.25rem; }
h1, h2, p, dl, dd { margin: 0; }
h1 {
  font-family: Impact, "Arial Black", system-ui, sans-serif;
  font-size: clamp(3.5rem, 9vw, 7.4rem);
  line-height: .88;
  letter-spacing: -.045em;
}
h1 em { color: var(--accent); font-style: normal; }
.header p { color: var(--muted); margin-top: .65rem; }
#level { color: var(--accent); font-size: .875rem; font-weight: 750; }
#level + p { margin-top: .2rem; }
.scoreboard { display: flex; flex: 0 0 auto; gap: .55rem; }
.scoreboard div {
  min-width: 6.2rem;
  padding: .55rem .8rem;
  border: 1px solid #6b4e39;
  border-radius: .45rem;
  background: #231a15;
}
dt {
  font: 700 .875rem/1.2 system-ui, sans-serif;
  color: var(--muted);
}
dd {
  font: 750 2rem/1.3 ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}
#time.urgent { color: #ff946f; }
#bonus {
  position: absolute;
  top: .75rem;
  left: .75rem;
  display: flex;
  gap: .65rem;
  align-items: center;
  padding: .35rem .75rem;
  border: 1px solid #f9c365;
  border-radius: .35rem;
  background: #21180dee;
  color: #ffe1a3;
  font-size: .875rem;
  font-weight: 700;
  pointer-events: none;
}
#bonus-time { font-variant-numeric: tabular-nums; }
.arena {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  border: 1px solid #8d6346;
  border-radius: .75rem;
  background: #231811;
  box-shadow: 0 1.5rem 3rem #0c080676, inset 0 0 0 .35rem #3d2a1d;
}
canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: none; }
canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: -5px; }
#conveyor-shadows {
  position: absolute;
  inset: 0;
  pointer-events: none;
  --shadow-fade: calc(100% - var(--shadow-start));
  background: radial-gradient(ellipse var(--shadow-radius-x) var(--shadow-radius-y) at 50% 56%,
    #18191d00 var(--shadow-start),
    #18191d07 calc(var(--shadow-start) + var(--shadow-fade) * .2),
    #18191d22 calc(var(--shadow-start) + var(--shadow-fade) * .4),
    #18191d62 calc(var(--shadow-start) + var(--shadow-fade) * .6),
    #18191dbc calc(var(--shadow-start) + var(--shadow-fade) * .8),
    #18191de9 calc(var(--shadow-start) + var(--shadow-fade) * .92),
    #18191d 100%);
}
#blast {
  position: absolute;
  width: clamp(5rem, 15vw, 11rem);
  aspect-ratio: 1;
  border-radius: 50%;
  translate: -50% -50%;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle, #fff9c7, #ffa744b8 23%, #e852173d 49%, transparent 68%);
  box-shadow: inset 0 0 .45rem .22rem #ffbf68, 0 0 1.6rem #f7792a8a;
}
#crosshair {
  position: absolute;
  width: 1.3rem;
  height: 1.3rem;
  border: 2px solid var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 0 2px #211710;
  pointer-events: none;
  transform: translate(-50%, -50%);
}
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: #17100cbd;
  padding: 1rem;
}
.message {
  width: min(100%, 24rem);
  padding: 1.5rem;
  border: 1px solid #866043;
  border-radius: .6rem;
  background: #271c16;
  text-align: center;
}
.message h2 { font-size: 1.5rem; }
.message p { margin: .4rem 0 0; color: var(--muted); }
button {
  border: 1px solid #846348;
  padding: .55rem .9rem;
  min-height: 2.75rem;
  border-radius: .4rem;
  background: #2d2119;
  color: inherit;
  font: 700 1rem/1.2 system-ui, sans-serif;
  cursor: pointer;
}
button:hover:enabled { border-color: var(--accent); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
button:disabled { opacity: .55; cursor: default; }
#start, #play-again { margin-top: 1rem; background: var(--accent); color: #241609; }
.overlay:has(#leaderboard:not([hidden])) { place-items: start center; overflow-y: auto; }
#leaderboard { margin-top: 1rem; text-align: left; }
#leaderboard h3 { margin: 0 0 .5rem; font-size: 1.1rem; }
#score-form label { display: block; margin-bottom: .25rem; font-size: .875rem; color: var(--muted); }
.score-entry { display: flex; gap: .5rem; }
.score-entry input {
  flex: 1;
  min-width: 0;
  border: 1px solid #846348;
  border-radius: .4rem;
  background: #171311;
  color: inherit;
  font: inherit;
  padding: .45rem .6rem;
}
.score-entry input:focus-visible { outline: 2px solid var(--accent); }
#save-score { flex: 0 0 auto; }
#score-status { min-height: 1.4em; font-size: .875rem; color: var(--accent); }
#leaderboard table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
  font-size: .875rem;
  font-variant-numeric: tabular-nums;
}
#leaderboard th, #leaderboard td { padding: .28rem .35rem; border-bottom: 1px solid #5b422f; }
#leaderboard td { overflow-wrap: anywhere; }
#leaderboard th:last-child, #leaderboard td:last-child { text-align: right; }
footer { margin-top: .9rem; color: var(--muted); align-items: start; }
footer button { flex: 0 0 auto; }
#controls { color: #fff2db; }
.alternate { font-size: .875rem; }
.music-credit a { color: inherit; }
#status { color: var(--accent); min-height: 1.5em; }

@media (max-width: 44rem) {
  .cabinet { width: calc(100% - 1.5rem); grid-template-rows: auto minmax(18rem, 1fr) auto; }
  .header { align-items: start; flex-direction: column; gap: .75rem; margin-bottom: .75rem; }
  .scoreboard { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); width: 100%; gap: .35rem; }
  .scoreboard div { min-width: 0; padding-inline: .35rem; }
  .scoreboard dt { font-size: .75rem; }
  .scoreboard dd { font-size: clamp(1.35rem, 6vw, 2rem); }
}
