:root {
  color-scheme: dark;
  --bg: #171512;
  --panel: #24211d;
  --panel-2: #302a23;
  --ink: #fff8e7;
  --muted: #c8bda8;
  --gold: #f4b23b;
  --green: #5fc46a;
  --red: #ef5c45;
  --line: rgba(255, 248, 231, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(244, 178, 59, 0.22), transparent 32rem),
    linear-gradient(145deg, #141411, #1d1815 48%, #121818);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
label {
  -webkit-tap-highlight-color: transparent;
}

.shell {
  width: min(100%, 1180px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  place-items: center;
}

.game-panel {
  width: min(100%, 980px);
  display: grid;
  gap: 10px;
}

.hud,
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 4.8vw, 4.8rem);
  line-height: 0.92;
  letter-spacing: 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(88px, 1fr));
  gap: 8px;
}

.stats div {
  min-width: 88px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(36, 33, 29, 0.82);
}

.stats span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
}

.stats strong {
  font-size: 1.5rem;
}

.board-wrap {
  position: relative;
  width: min(100%, 68vh, 760px);
  aspect-ratio: 1;
  margin: 0 auto;
  border: 1px solid rgba(255, 248, 231, 0.22);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.42);
  background: #211d19;
}

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

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
  background: rgba(20, 18, 15, 0.72);
  backdrop-filter: blur(5px);
}

.overlay.hidden {
  display: none;
}

.overlay h2 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 5vw, 4rem);
  letter-spacing: 0;
}

.overlay.game-over h2 {
  max-width: 92%;
  font-size: clamp(1.35rem, 3.1vw, 2.35rem);
  line-height: 1.08;
}

.overlay p {
  max-width: 28rem;
  margin-bottom: 0;
  color: var(--muted);
}

.overlay.game-over p {
  max-width: min(90%, 34rem);
  font-size: clamp(0.88rem, 1.8vw, 1rem);
}

.game-over-video {
  width: min(74%, 360px);
  aspect-ratio: 16 / 7;
  border: 1px solid rgba(255, 248, 231, 0.22);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.46);
  background: #111;
}

.game-over-video.hidden {
  display: none;
}

.game-over-video video {
  width: 100%;
  height: 143%;
  display: block;
  object-fit: cover;
  transform: translateY(-15%);
}

.bonus-toast {
  width: min(100%, 760px);
  min-height: 48px;
  margin: -2px auto 0;
  border: 1px solid rgba(244, 178, 59, 0.62);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  background: rgba(36, 33, 29, 0.88);
  font-weight: 900;
  text-align: center;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 160ms ease, transform 160ms ease, border-color 160ms ease;
}

.bonus-toast.hidden {
  visibility: hidden;
  opacity: 0;
  transform: translateY(-4px);
}

button,
.upload,
.difficulty {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--ink);
  background: var(--panel);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

input,
.name-modal select {
  min-height: 44px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: rgba(20, 18, 15, 0.82);
  font: inherit;
  font-weight: 800;
  outline: 0;
}

input:focus {
  border-color: rgba(244, 178, 59, 0.8);
}

.name-modal select {
  cursor: pointer;
}

.name-modal option {
  color: #171512;
}

button:hover,
.upload:hover,
.difficulty:hover {
  border-color: rgba(255, 248, 231, 0.36);
  background: var(--panel-2);
}

.difficulty {
  gap: 8px;
  cursor: default;
}

.difficulty span {
  color: var(--muted);
  font-size: 0.82rem;
}

.difficulty select {
  border: 0;
  color: var(--ink);
  background: transparent;
  font: inherit;
  font-weight: 900;
  outline: 0;
  cursor: pointer;
}

.difficulty option {
  color: #171512;
}

.primary {
  min-width: 140px;
  color: #20170a;
  border-color: transparent;
  background: var(--gold);
}

.primary:hover {
  background: #ffc35e;
}

.upload input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.dpad {
  width: 166px;
  height: 148px;
  margin: -2px auto 0;
  display: grid;
  grid-template-areas:
    ". up ."
    "left . right"
    ". down .";
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(3, 48px);
  gap: 2px 8px;
  justify-content: center;
}

.arrow {
  width: 48px;
  height: 48px;
  padding: 0;
  font-size: 1.4rem;
}

.up {
  grid-area: up;
}

.left {
  grid-area: left;
}

.right {
  grid-area: right;
}

.down {
  grid-area: down;
}

.leaderboard-panel {
  width: min(100%, 760px);
  margin: 4px auto 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(36, 33, 29, 0.74);
}

.leaderboard-head,
.leaderboard-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.leaderboard-actions {
  grid-template-columns: minmax(0, 1fr);
}

.leaderboard-head div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(20, 18, 15, 0.42);
}

.leaderboard-head span,
.name-modal span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
}

.leaderboard-head strong {
  display: block;
  overflow: hidden;
  font-size: 1.02rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-list {
  min-height: 44px;
  margin: 10px 0;
  padding: 0;
  display: grid;
  gap: 6px;
  list-style-position: inside;
}

.leaderboard-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.leaderboard-table {
  min-width: 0;
}

.leaderboard-table h3 {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--gold);
  background: rgba(20, 18, 15, 0.42);
  font-size: 0.92rem;
}

.leaderboard-list li {
  border: 1px solid rgba(255, 248, 231, 0.1);
  border-radius: 8px;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  background: rgba(20, 18, 15, 0.3);
}

.leaderboard-list .leaderboard-name {
  min-width: 0;
}

.leaderboard-list .leaderboard-name strong {
  display: block;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-rank {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: rgba(255, 248, 231, 0.08);
  font-size: 0.82rem;
  font-weight: 900;
}

.leaderboard-score {
  color: var(--gold);
  font-weight: 900;
}

.leaderboard-list li.podium-first {
  border-color: rgba(244, 178, 59, 0.58);
  padding-block: 11px;
  background:
    linear-gradient(135deg, rgba(244, 178, 59, 0.22), rgba(95, 196, 106, 0.1)),
    rgba(20, 18, 15, 0.48);
  box-shadow: inset 0 0 0 1px rgba(255, 248, 231, 0.08);
}

.podium-first .leaderboard-rank {
  color: #20170a;
  background: var(--gold);
  font-size: 1.18rem;
}

.podium-first .leaderboard-name strong {
  font-size: 1.08rem;
}

.podium-first .leaderboard-score {
  font-size: 1.18rem;
}

.sync-status {
  min-height: 1.1rem;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(8, 7, 6, 0.76);
  backdrop-filter: blur(7px);
}

.modal-backdrop.hidden {
  display: none;
}

.name-modal {
  width: min(100%, 380px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  display: grid;
  gap: 12px;
  background: #24211d;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.52);
}

.name-modal h2 {
  margin-bottom: 0;
  font-size: 1.7rem;
}

.name-modal p {
  margin-bottom: 0;
  color: var(--muted);
}

.name-modal label {
  display: grid;
  gap: 6px;
}

.consent-bar {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  width: min(calc(100% - 36px), 420px);
  border: 1px solid rgba(255, 248, 231, 0.18);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 10px;
  background: rgba(36, 33, 29, 0.94);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.48);
}

.consent-bar.hidden {
  display: none;
}

.consent-bar p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.consent-bar div {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

@media (min-width: 840px) {
  .game-panel {
    grid-template-columns: minmax(0, 1fr);
    align-items: center;
  }

  .hud,
  .board-wrap,
  .dpad,
  .controls,
  .leaderboard-panel {
    grid-column: 1;
  }
}

@media (max-width: 640px) {
  .shell {
    padding: 14px;
    align-items: start;
  }

  .hud,
  .controls {
    align-items: stretch;
    flex-direction: column;
  }

  .stats,
  .controls {
    width: 100%;
  }

  .controls {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .leaderboard-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  button,
  .upload,
  .difficulty {
    padding-inline: 10px;
    font-size: 0.88rem;
  }
}
