:root {
  color-scheme: dark;
  --bg: #050505;
  --fg: #f4f4f4;
  --muted: #9aa0a6;
  --accent: #79d7ff;
  --hud-h: 4vh;
  --footer-h: 4vh;
  --gap: 3vh;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, sans-serif;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#controller-app {
  width: 100vw;
  height: 100vh;
  position: relative;
}

/* wrapper sizes itself to fit the viewport, accounting for hud bar */
#game-wrapper {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: min(calc(100vw - var(--gap)), calc((100vh - var(--gap) - var(--hud-h) - var(--footer-h)) * 9 / 16));
}

#hud-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--hud-h);
  padding: 0 0.5vh;
  flex-shrink: 0;
}

#hud-bar > * {
  flex: 1;
  min-width: 0;
}

#score {
  font-size: 3vh;
  font-weight: 700;
  text-align: center;
}

#status {
  font-size: 1.5vh;
}

#enemy-name {
  text-align: right;
  color: var(--muted);
  font-size: 1.5vh;
}

#app {
  aspect-ratio: 9 / 16;
  width: 100%;
  position: relative;
  border: 4px solid rgba(255, 255, 255, 0.95);
  border-radius: 2rem;
  overflow: hidden;
  flex-shrink: 0;
}

#footer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--footer-h);
  padding: 0 0.5vh;
  gap: 1rem;
  position: relative;
}

#player-name-wrap,
#footer-ui-reserve {
  flex: 1;
  min-width: 0;
}

#perf-hud {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  color: var(--muted);
  font-size: 1.3vh;
  white-space: nowrap;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

#footer-ui-reserve {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.45rem;
  position: relative;
}

#player-name {
  width: 100%;
  max-width: 20ch;
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.25);
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 1.5vh;
  padding: 0 0 0.15rem;
  outline: none;
}

#player-name::placeholder {
  color: var(--muted);
}

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

#hud-buttons {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

#lobby-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 2vh;
  background: rgba(5, 5, 5, 0.82);
  backdrop-filter: blur(2px);
  pointer-events: auto;
}

#lobby-overlay[hidden] {
  display: none;
}

#lobby-title {
  margin-top: 24%;
  font-size: 5vh;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--fg);
  text-shadow: 0 0 2vh rgba(121, 215, 255, 0.4);
}

#lobby-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1vh;
  width: min(32ch, 80%);
  margin-top: 12%;
}

#online-counter {
  margin-top: 1.5vh;
  color: var(--muted);
  font-size: 1.5vh;
  font-weight: 600;
  text-align: center;
}

#join-queue-btn,
#play-bot-btn {
  pointer-events: auto;
  border: 0;
  border-radius: 999px;
  padding: 1vh 1.8vh;
  font-weight: 700;
  font-size: 1.6vh;
  cursor: pointer;
}

#join-queue-btn {
  background: var(--accent);
  color: #001018;
}

#play-bot-btn {
  background: rgba(255, 255, 255, 0.1);
  color: var(--fg);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

#status, #score, #controller-status, #drag-hint {
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

#rematch, #go-lobby-btn, #controller-rematch {
  pointer-events: auto;
  border: 0;
  border-radius: 999px;
  padding: 1vh 1.8vh;
  font-weight: 700;
  font-size: 1.6vh;
}

#rematch {
  position: absolute;
}

.score-card {
  position: absolute;
  left: 50%;
  width: min(34ch, calc(100% - 2rem));
  padding: 0.8rem 1rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 1rem;
  background: rgba(5, 5, 5, 0.78);
  box-shadow: 0 0.5rem 2rem rgba(0, 0, 0, 0.35);
  text-align: center;
  transform: translateX(-50%);
}

.score-card-label {
  color: var(--muted);
  font-size: 1.2vh;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.score-card-name {
  margin-top: 0.2rem;
  font-size: 2vh;
  font-weight: 800;
}

.score-card-stats {
  margin-top: 0.55rem;
  color: var(--muted);
  font-size: 1.35vh;
  line-height: 1.45;
  white-space: pre-line;
}

#rematch, #controller-rematch {
  background: var(--accent);
  color: #001018;
}

#opponent-score-card {
  top: 25%;
  transform: translate(-50%, -50%);
}

#rematch {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

#go-lobby-btn {
  background: rgba(255, 255, 255, 0.1);
  color: var(--fg);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 0.35vh 1.2vh;
  font-size: 1.4vh;
  cursor: pointer;
}

#player-score-card {
  top: 75%;
  transform: translate(-50%, -50%);
}

#tool-fab {
  position: relative;
  z-index: 5;
  width: 1.55rem;
  height: 1.55rem;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 999px;
  background: rgba(5, 5, 5, 0.84);
  color: var(--fg);
  padding: 0;
  line-height: 1;
  cursor: pointer;
}

.tool-fab-icon {
  display: block;
  width: 0.72rem;
  height: 0.08rem;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 0 -0.2rem 0 currentColor, 0 0.2rem 0 currentColor;
}

#tool-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 0.35rem);
  z-index: 10;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 0.8rem;
  background: rgba(5, 5, 5, 0.94);
  padding: 0.35rem;
}

#tool-menu > button {
  border: 0;
  border-radius: 0.55rem;
  padding: 0.45rem 0.8rem;
  background: rgba(255, 255, 255, 0.12);
  color: var(--fg);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
}

@media (hover: none) and (pointer: coarse) {
  .tool-fab-icon {
    width: 0.64rem;
    box-shadow: 0 -0.18rem 0 currentColor, 0 0.18rem 0 currentColor;
  }
}

.controller {
  touch-action: none;
}

#controller-app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 1rem;
  padding: 1rem;
}

#drag-area {
  border: 2px solid rgba(255,255,255,0.15);
  border-radius: 1.25rem;
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(90deg, transparent 49.5%, rgba(255,255,255,0.15) 50%, transparent 50.5%),
    linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.08));
}

#drag-hint {
  position: absolute;
  inset: 1rem auto auto 1rem;
  color: var(--muted);
}

#drag-thumb {
  position: absolute;
  width: min(18vw, 6rem);
  height: 5rem;
  border-radius: 999px;
  border: 2px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
  transform: translate(-50%, -50%);
  top: 50%;
  left: 50%;
}

#controller-status {
  text-align: center;
  color: var(--muted);
}
