:root {
  color-scheme: dark;
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    system-ui,
    sans-serif;
  background: #111;
  color: #fff7eb;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 0%, rgba(120, 73, 42, 0.34), transparent 34rem),
    linear-gradient(135deg, #101010, #211a16 52%, #0e0d0c);
}

.game-shell {
  width: min(100vw, 1440px);
  height: 100vh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: clamp(10px, 1.8vw, 22px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
}

h1 {
  margin: 0;
  font-size: clamp(26px, 3.6vw, 46px);
  line-height: 1;
  letter-spacing: 0;
}

.stat-strip {
  display: flex;
  align-items: center;
  gap: 10px;
}

.stat-strip div {
  min-width: 112px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(8, 8, 8, 0.58);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.stat-strip span {
  color: #d9c5a5;
  font-size: 14px;
  font-weight: 700;
}

.stat-strip strong {
  color: #fff7eb;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.stage-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: #0d0d0c;
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.52),
    0 24px 60px rgba(0, 0, 0, 0.34);
}

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

.pedal-controls {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 3;
  display: flex;
  gap: 10px;
}

.pedal-key {
  min-width: 92px;
  width: 92px;
  min-height: 72px;
  height: 72px;
  padding: 7px 8px 15px;
  border: 0;
  border-radius: 0;
  background: linear-gradient(180deg, #34312d 0%, #171614 64%, #0b0a09 100%);
  color: #fff7eb;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 5px 0 #050505;
  clip-path: polygon(8% 0, 92% 0, 100% 50%, 66% 58%, 66% 100%, 34% 100%, 34% 58%, 0 50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 16px;
  line-height: 1.15;
  user-select: none;
  touch-action: none;
}

.pedal-key small {
  color: rgba(255, 247, 235, 0.68);
  font-size: 11px;
  line-height: 1;
}

.pedal-key.expected {
  background: linear-gradient(180deg, #7a5a2d 0%, #3f2b17 64%, #1a110b 100%);
  box-shadow: inset 0 1px 0 rgba(255, 225, 166, 0.58), 0 5px 0 #3b2415;
}

.pedal-key.active {
  transform: translateY(5px);
  background: linear-gradient(180deg, #f5cb78 0%, #c88834 66%, #6e4327 100%);
  color: #1b1715;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.56), 0 1px 0 #6e4327;
}

.pedal-key.active small {
  color: rgba(27, 23, 21, 0.7);
}

.modal-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.34);
  opacity: 1;
  pointer-events: auto;
  transition: opacity 180ms ease;
  z-index: 5;
}

.modal-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.leaderboard-overlay {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: grid;
  place-items: center;
  padding: 14px;
  background: rgba(0, 0, 0, 0.7);
  opacity: 1;
  pointer-events: auto;
  transition: opacity 180ms ease;
}

.leaderboard-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.leaderboard-card {
  width: min(430px, calc(100vw - 28px));
  max-height: calc(100% - 20px);
  overflow: hidden;
  padding: 18px 22px 20px;
  border: 1px solid rgba(240, 192, 103, 0.5);
  border-radius: 8px;
  background: rgba(19, 17, 15, 0.97);
  color: #fff7eb;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.58);
  text-align: center;
}

.leaderboard-card h2 {
  margin: 0;
  color: #fff7eb;
  font-size: 26px;
  letter-spacing: 0;
}

.leaderboard-card > p {
  margin: 5px 0 12px;
  color: #d8bd95;
  font-size: 14px;
}

.leaderboard-form {
  margin: 0 0 12px;
  text-align: left;
}

.leaderboard-form label {
  display: block;
  margin-bottom: 6px;
  color: #d8bd95;
  font-size: 13px;
}

.leaderboard-form > div {
  display: flex;
  gap: 8px;
}

.leaderboard-form input {
  min-width: 0;
  flex: 1;
  padding: 9px 10px;
  border: 1px solid rgba(240, 192, 103, 0.5);
  border-radius: 5px;
  background: #0f0d0b;
  color: #fff7eb;
  font: inherit;
}

.leaderboard-card .leaderboard-form button {
  min-width: 92px;
}

.leaderboard-heading,
.leaderboard-row {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) 72px;
  align-items: center;
  column-gap: 8px;
}

.leaderboard-heading {
  min-height: 27px;
  padding: 0 10px;
  color: #a99578;
  font-size: 12px;
  text-align: left;
}

.leaderboard-heading span:last-child,
.leaderboard-row span:last-child {
  text-align: right;
}

.leaderboard-rows {
  max-height: min(390px, 48vh);
  margin: 0 0 14px;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.leaderboard-row {
  min-height: 31px;
  padding: 0 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  color: #e7d8c2;
  font-size: 14px;
  text-align: left;
}

.leaderboard-row.player {
  min-height: 36px;
  border: 1px solid rgba(255, 210, 113, 0.62);
  background: linear-gradient(90deg, rgba(151, 98, 30, 0.58), rgba(66, 42, 20, 0.52));
  color: #ffe4a3;
  font-weight: 900;
}

.leaderboard-rank {
  color: #b8a488;
  font-weight: 800;
}

.leaderboard-row.player .leaderboard-rank {
  color: #ffd271;
}

.leaderboard-card button {
  min-width: 156px;
}

.modal-card {
  width: min(380px, calc(100vw - 40px));
  padding: 24px;
  border: 1px solid rgba(255, 247, 235, 0.18);
  border-radius: 8px;
  background: rgba(15, 13, 11, 0.9);
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.56),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  text-align: center;
}

.modal-card h2 {
  margin: 0;
  font-size: 30px;
  letter-spacing: 0;
}

.modal-copy {
  margin: 12px 0 20px;
}

.modal-copy p {
  margin: 0;
  color: #dcc7a8;
  line-height: 1.6;
}

#modalScoringHint {
  margin-top: 4px;
}

.modal-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 16px;
}

button {
  min-width: 126px;
  min-height: 44px;
  padding: 0 20px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: #f0c067;
  color: #1b1715;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 7px 0 #8c5530;
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    filter 120ms ease;
}

button:hover {
  filter: brightness(1.08);
}

button:active {
  transform: translateY(5px);
  box-shadow: 0 2px 0 #8c5530;
}

button:focus-visible {
  outline: 3px solid #fff1b8;
  outline-offset: 4px;
}

button[hidden] {
  display: none;
}

@media (max-width: 760px) {
  .topbar {
    min-height: 88px;
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .stat-strip {
    width: 100%;
  }

  .stat-strip div {
    flex: 1;
  }

  .pedal-controls {
    right: 12px;
    bottom: 12px;
  }

  .pedal-key {
    width: 92px;
    height: 72px;
    font-size: 16px;
  }

  .leaderboard-card {
    padding: 14px 14px 16px;
  }

  .leaderboard-card h2 {
    font-size: 22px;
  }

  .leaderboard-card > p {
    margin-bottom: 8px;
  }

  .leaderboard-heading,
  .leaderboard-row {
    grid-template-columns: 44px minmax(0, 1fr) 64px;
  }

  .leaderboard-row {
    min-height: 29px;
  }
}
