:root {
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #10151f;
  color: #f8fafc;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  min-width: 320px;
}

#app {
  position: relative;
  background: #102239;
}

#game-canvas {
  display: block;
  width: 100vw;
  height: 100vh;
  touch-action: none;
}

#hud {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 236px;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(5, minmax(82px, 1fr));
  gap: 8px;
  pointer-events: none;
}

.metric,
#scoreboard,
#restart,
#toast {
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(9, 14, 22, 0.72);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(10px);
}

.metric {
  min-width: 0;
  border-radius: 8px;
  padding: 8px 10px;
}

.metric span,
#scoreboard small {
  display: block;
  color: #b6c4d8;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 2px;
  color: #ffffff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: clamp(1rem, 2.3vw, 1.45rem);
  line-height: 1.05;
  white-space: nowrap;
}

#scoreboard {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 2;
  width: 204px;
  border-radius: 8px;
  padding: 10px;
}

#scoreboard header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: #fff7d6;
  font-weight: 800;
}

#leaders {
  display: grid;
  gap: 6px;
  min-height: 112px;
  margin: 0;
  padding: 0;
  list-style-position: inside;
}

#leaders li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  min-height: 24px;
  border-radius: 6px;
  padding: 5px 7px;
  background: rgba(255, 255, 255, 0.08);
  color: #e8eef8;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.74rem;
}

#restart {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 2;
  min-width: 92px;
  height: 38px;
  border-radius: 8px;
  color: #ffffff;
  font-weight: 800;
  cursor: pointer;
}

#restart:focus-visible {
  outline: 3px solid #ffd84c;
  outline-offset: 2px;
}

#toast {
  position: absolute;
  left: 50%;
  bottom: 28px;
  z-index: 2;
  max-width: min(460px, calc(100vw - 32px));
  min-height: 42px;
  transform: translateX(-50%);
  border-radius: 8px;
  padding: 10px 18px;
  color: #fff7d6;
  font-size: clamp(1rem, 3vw, 1.35rem);
  font-weight: 900;
  text-align: center;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
  opacity: 0;
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, -8px);
}

@media (max-width: 820px) {
  #hud {
    top: 10px;
    left: 10px;
    right: 10px;
    grid-template-columns: repeat(5, minmax(54px, 1fr));
    gap: 5px;
  }

  .metric {
    padding: 6px;
  }

  .metric span {
    font-size: 0.57rem;
  }

  .metric strong {
    font-size: 0.9rem;
  }

  #scoreboard {
    top: auto;
    right: 10px;
    bottom: 62px;
    width: 172px;
    padding: 8px;
  }

  #leaders {
    min-height: 74px;
  }

  #leaders li {
    min-height: 20px;
    padding: 4px 6px;
    font-size: 0.66rem;
  }

  #restart {
    right: 10px;
    bottom: 10px;
    height: 36px;
  }
}
