:root {
  color-scheme: dark;
  --bg: #090806;
  --panel: #16110f;
  --panel-strong: #241814;
  --text: #fff3dd;
  --muted: #c9a984;
  --bp: #e03225;
  --amber: #f2b13f;
  --green: #62d27f;
  --blue: #63b7ff;
  --shadow: rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(224, 50, 37, 0.22), transparent 34rem),
    linear-gradient(180deg, #16100d 0%, var(--bg) 60%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  display: grid;
  place-items: center;
  padding: 20px;
  overscroll-behavior: none;
}

button {
  appearance: none;
  border: 0;
  border-radius: 8px;
  background: var(--bp);
  color: white;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  min-width: 132px;
  padding: 12px 20px;
  box-shadow: 0 10px 24px var(--shadow);
}

button:hover,
button:focus-visible {
  background: #ff4437;
  outline: 2px solid rgba(255, 255, 255, 0.8);
  outline-offset: 3px;
}

.game-shell {
  width: min(100%, 1080px);
}

.hud {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.hud > div {
  background: rgba(22, 17, 15, 0.92);
  border: 1px solid rgba(255, 243, 221, 0.14);
  border-radius: 8px;
  padding: 10px 12px;
  min-width: 0;
}

.hud-label {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
  text-transform: uppercase;
}

.hud strong {
  color: var(--text);
  display: block;
  font-size: clamp(18px, 4vw, 28px);
  line-height: 1.1;
  margin-top: 4px;
  overflow-wrap: anywhere;
}

.audio-control {
  min-width: 230px;
}

.audio-row {
  align-items: center;
  display: flex;
  gap: 8px;
  margin-top: 5px;
}

.mute-button {
  border: 1px solid rgba(255, 243, 221, 0.16);
  box-shadow: none;
  flex: 0 0 64px;
  font-size: 13px;
  min-width: 0;
  padding: 8px 10px;
  width: auto;
}

.mute-button[aria-pressed="true"] {
  background: var(--panel-strong);
  color: var(--muted);
}

#volumeSlider {
  accent-color: var(--amber);
  flex: 1 1 72px;
  min-width: 64px;
}

.volume-value {
  color: var(--text);
  flex: 0 0 4ch;
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
  text-align: right;
}

.stage-wrap {
  aspect-ratio: 16 / 9;
  background: #100c0b;
  border: 1px solid rgba(255, 243, 221, 0.18);
  border-radius: 8px;
  box-shadow: 0 20px 60px var(--shadow);
  overflow: hidden;
  position: relative;
  width: 100%;
}

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

.blind-overlay {
  background: white;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  position: absolute;
  transition: opacity 140ms ease;
  z-index: 2;
}

.blind-overlay.active {
  opacity: 0.88;
}

.touch-controls {
  align-items: center;
  display: none;
  gap: 12px;
  justify-content: space-between;
  margin-top: 10px;
  pointer-events: none;
  width: 100%;
}

.touch-button {
  align-items: center;
  background: rgba(22, 17, 15, 0.76);
  border: 1px solid rgba(255, 243, 221, 0.28);
  border-radius: 8px;
  box-shadow: 0 10px 26px var(--shadow);
  color: var(--text);
  display: flex;
  height: 58px;
  justify-content: center;
  min-width: 0;
  padding: 0;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.touch-button:hover,
.touch-button:focus-visible {
  background: rgba(36, 24, 20, 0.88);
}

.touch-button.is-pressed {
  background: rgba(224, 50, 37, 0.86);
  border-color: rgba(255, 243, 221, 0.7);
  transform: translateY(1px);
}

.touch-button-move {
  flex: 0 0 76px;
  font-size: 44px;
  font-weight: 900;
  line-height: 1;
}

.touch-button-dash {
  background: rgba(224, 50, 37, 0.82);
  flex: 0 0 104px;
  font-size: 16px;
  letter-spacing: 0;
}

.screen {
  align-items: center;
  background: rgba(9, 8, 6, 0.7);
  display: flex;
  flex-direction: column;
  gap: 12px;
  inset: 0;
  justify-content: center;
  padding: 20px;
  position: absolute;
  text-align: center;
  z-index: 3;
}

.screen.hidden {
  display: none;
}

.eyebrow {
  color: var(--amber);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
  margin: 0;
  text-transform: uppercase;
}

.screen h1 {
  color: white;
  font-size: clamp(40px, 10vw, 110px);
  line-height: 0.9;
  margin: 0;
  max-width: 920px;
  text-shadow: 0 8px 0 #5e130e, 0 18px 36px var(--shadow);
}

.screen p:not(.eyebrow) {
  color: var(--text);
  font-size: clamp(16px, 3vw, 24px);
  line-height: 1.35;
  margin: 0;
  max-width: 620px;
}

.creator-credit {
  align-items: center;
  background: rgba(22, 17, 15, 0.72);
  border: 1px solid rgba(255, 243, 221, 0.14);
  border-radius: 8px;
  display: none;
  gap: 10px;
  justify-content: space-between;
  margin-top: 18px;
  max-width: 640px;
  padding: 6px 8px;
  text-align: left;
  transform: translateY(2px);
  width: min(100%, 640px);
}

body[data-mode="over"] .creator-credit {
  display: flex;
}

.creator-credit > div {
  align-items: center;
  display: flex;
  gap: 10px;
  min-width: 0;
}

.creator-avatar {
  background: rgba(22, 17, 15, 0.96);
  border: 2px solid rgba(242, 177, 63, 0.78);
  border-radius: 50%;
  box-shadow: 0 10px 24px var(--shadow);
  display: grid;
  flex: 0 0 auto;
  height: 38px;
  overflow: hidden;
  place-items: center;
  width: 38px;
}

.creator-avatar img,
.youtube-link img {
  display: block;
  object-fit: contain;
}

.creator-avatar img {
  height: 100%;
  width: 100%;
}

.screen .creator-credit p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  margin: 0;
  max-width: none;
}

.screen .creator-credit strong {
  color: white;
  display: block;
  font-size: 14px;
  line-height: 1.1;
}

.youtube-link {
  align-items: center;
  background: rgba(255, 243, 221, 0.08);
  border: 1px solid rgba(255, 243, 221, 0.22);
  border-radius: 8px;
  color: var(--text);
  display: inline-flex;
  flex: 0 0 auto;
  font-weight: 900;
  line-height: 1;
  min-height: 30px;
  min-width: 38px;
  padding: 5px 7px;
  text-decoration: none;
}

.youtube-link:hover,
.youtube-link:focus-visible {
  background: rgba(255, 255, 255, 0.14);
  outline: 2px solid rgba(255, 255, 255, 0.8);
  outline-offset: 3px;
}

.youtube-link img {
  height: 17px;
  width: 23px;
}

@media (max-width: 820px) {
  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .audio-control {
    min-width: 0;
  }
}

.hidden {
  display: none !important;
}

/* Name entry */
#nameEntry {
  align-items: center;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

#nameEntry p {
  color: var(--muted);
  font-size: 14px;
  margin: 0;
  max-width: none;
}

.error-text {
  color: var(--bp);
}

.name-inputs {
  display: flex;
  gap: 10px;
}

.nameChar {
  background: var(--panel-strong);
  border: 2px solid rgba(255, 243, 221, 0.3);
  border-radius: 6px;
  caret-color: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 32px;
  font-weight: 900;
  height: 60px;
  text-align: center;
  text-transform: uppercase;
  width: 52px;
}

.nameChar:focus {
  border-color: var(--amber);
  outline: none;
}

/* Global scoreboard */
#scoreboard {
  list-style: none;
  margin: 0;
  max-height: 220px;
  max-width: 380px;
  overflow-y: auto;
  padding: 0;
  width: 100%;
}

#scoreboard li {
  align-items: center;
  border-radius: 4px;
  display: grid;
  gap: 6px;
  grid-template-columns: 2.5rem 3rem 1fr 4rem;
  padding: 4px 8px;
}

#scoreboard li:nth-child(odd) {
  background: rgba(255, 243, 221, 0.04);
}

#scoreboard li.new-score {
  background: rgba(242, 177, 63, 0.14);
  color: var(--amber);
  font-weight: 800;
}

.sb-rank {
  color: var(--muted);
  font-size: 12px;
}

.sb-name {
  font-weight: 900;
  letter-spacing: 0.08em;
}

.sb-score {
  font-size: 13px;
  text-align: right;
}

.sb-date {
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

@media (max-width: 620px) {
  body {
    align-content: start;
    padding: 8px;
  }

  .hud {
    gap: 6px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .hud > div {
    padding: 8px;
  }

  .hud strong {
    font-size: 18px;
  }

  .hud-label {
    font-size: 10px;
  }

  .audio-control {
    grid-column: 1 / -1;
  }

  .audio-row {
    gap: 6px;
  }

  .mute-button {
    flex-basis: 58px;
    font-size: 12px;
    padding: 8px 6px;
    width: auto;
  }

  .volume-value {
    font-size: 12px;
  }

  button {
    width: min(100%, 180px);
  }

  .screen {
    gap: 7px;
    padding: 12px;
  }

  .screen h1 {
    font-size: clamp(34px, 12vw, 62px);
    text-shadow: 0 5px 0 #5e130e, 0 12px 24px var(--shadow);
  }

  .screen p:not(.eyebrow) {
    font-size: 14px;
    line-height: 1.25;
    max-width: 20rem;
  }

  body[data-mode="over"] .stage-wrap {
    aspect-ratio: auto;
    min-height: 312px;
  }

  body[data-mode="over"] .creator-credit {
    flex-direction: row;
    gap: 10px;
    margin-top: 5px;
    padding: 8px;
    transform: none;
  }

  body[data-mode="over"] .creator-credit > div {
    flex: 1 1 auto;
    gap: 10px;
    min-width: 0;
  }

  body[data-mode="over"] .creator-avatar {
    height: 42px;
    width: 42px;
  }

  body[data-mode="over"] .creator-credit p {
    font-size: 12px;
    text-align: left;
  }

  body[data-mode="over"] .creator-credit strong {
    font-size: 14px;
  }

  body[data-mode="over"] .youtube-link {
    flex: 0 0 auto;
    min-height: 32px;
    min-width: 0;
    padding: 6px 8px;
  }

  body[data-mode="over"] .youtube-link img {
    height: 18px;
    width: 24px;
  }

  body[data-mode="over"] .eyebrow {
    display: none;
  }

  body[data-mode="over"] #nameEntry {
    gap: 6px;
  }

  body[data-mode="over"] #nameEntry p {
    font-size: 13px;
  }

  body[data-mode="over"] .name-inputs {
    gap: 8px;
  }

  body[data-mode="over"] .nameChar {
    font-size: 26px;
    height: 48px;
    width: 44px;
  }

  body[data-mode="over"] #nameSubmit {
    font-size: 14px;
    min-width: 0;
    padding: 10px 14px;
    width: 144px;
  }
}

@media (pointer: coarse), (max-width: 720px) {
  body[data-mode="playing"] .touch-controls {
    display: flex;
  }
}

@media (max-width: 420px) {
  .touch-controls {
    gap: 8px;
    margin-top: 8px;
  }

  .touch-button {
    height: 52px;
  }

  .touch-button-move {
    flex-basis: 62px;
    font-size: 38px;
  }

  .touch-button-dash {
    flex-basis: 88px;
    font-size: 14px;
  }

  body[data-mode="over"] .stage-wrap {
    min-height: 326px;
  }
}
