:root {
  color-scheme: dark;
  --panel: rgba(9, 14, 22, 0.86);
  --line: rgba(190, 226, 255, 0.24);
  --text: #f7fbff;
  --muted: #9cb6c7;
  --gold: #ffcf4a;
  --cyan: #45e4ff;
  --rose: #ff4f89;
  --green: #75ff8b;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #05080d;
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.playing,
body.playing #game,
body.playing .hud,
body.playing .mobile-controls {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  touch-action: none;
  user-select: none;
}

button,
input,
select {
  font: inherit;
}

#game {
  display: block;
  width: 100vw;
  height: 100vh;
  image-rendering: pixelated;
  touch-action: none;
  outline: none;
  -webkit-user-drag: none;
  background: #05080d;
}

#game:focus,
#game:focus-visible {
  outline: none;
}

.hud {
  position: fixed;
  inset: 14px 16px auto 16px;
  display: grid;
  grid-template-columns: minmax(190px, auto) 1fr minmax(104px, auto);
  align-items: start;
  gap: 12px;
  pointer-events: none;
  z-index: 5;
}

.brand,
.net-status,
.score-pill {
  border: 1px solid var(--line);
  background: rgba(3, 7, 12, 0.72);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(10px);
}

.brand {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  gap: 10px;
  padding: 0 13px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand-mark {
  width: 18px;
  height: 18px;
  display: inline-block;
  background:
    linear-gradient(45deg, transparent 0 30%, var(--gold) 30% 55%, transparent 55%),
    linear-gradient(135deg, transparent 0 36%, var(--rose) 36% 62%, transparent 62%),
    var(--cyan);
  clip-path: polygon(50% 0, 100% 42%, 68% 100%, 32% 100%, 0 42%);
}

.scoreboard {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.score-pill {
  display: grid;
  grid-template-columns: 10px minmax(32px, 108px) auto;
  align-items: center;
  min-height: 42px;
  gap: 8px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 12px;
  white-space: nowrap;
}

.score-color {
  width: 10px;
  height: 22px;
  border-radius: 3px;
  box-shadow: 0 0 10px currentColor;
}

.score-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 750;
}

.score-value {
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  font-weight: 850;
}

.net-status {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 13px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-align: center;
}

.net-status.connected {
  color: var(--green);
}

.net-status.offline {
  color: var(--rose);
}

.join-panel {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(circle at 50% 35%, rgba(89, 225, 255, 0.12), transparent 36%),
    rgba(0, 0, 0, 0.38);
  z-index: 10;
}

.join-panel.hidden {
  display: none;
}

.join-card {
  width: min(420px, 100%);
  max-height: calc(100dvh - 28px);
  overflow-y: auto;
  border: 1px solid rgba(252, 227, 118, 0.34);
  border-radius: 8px;
  padding: 20px;
  background: rgba(7, 11, 18, 0.92);
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.48),
    inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.title-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.crest {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  background:
    linear-gradient(90deg, transparent 0 43%, #fff2a8 43% 57%, transparent 57%),
    linear-gradient(45deg, transparent 0 28%, #ff4f89 28% 55%, transparent 55%),
    #35d7ff;
  clip-path: polygon(50% 0, 95% 32%, 78% 100%, 22% 100%, 5% 32%);
  filter: drop-shadow(0 0 14px rgba(69, 228, 255, 0.32));
}

h1 {
  margin: 0;
  font-size: clamp(25px, 7vw, 38px);
  line-height: 0.95;
  letter-spacing: 0;
}

.field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.field input,
.field select {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  outline: none;
  background: rgba(0, 0, 0, 0.42);
  color: var(--text);
  font-size: 16px;
}

.field input:focus,
.field select:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(69, 228, 255, 0.16);
}

.toggle-field {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.045);
  color: var(--text);
  font-size: 13px;
  font-weight: 850;
}

.toggle-field input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--gold);
}

.join-grid {
  display: grid;
  grid-template-columns: 1fr 104px;
  gap: 10px;
  margin-top: 12px;
}

.lobby-field {
  margin-top: 12px;
}

.code-row {
  display: grid;
  grid-template-columns: 1fr 62px;
  gap: 8px;
}

.secondary-button {
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font-size: 13px;
  font-weight: 850;
}

.secondary-button:active {
  transform: translateY(1px);
}

.secondary-button.active {
  border-color: rgba(255, 207, 74, 0.52);
  color: var(--gold);
}

.join-actions {
  display: grid;
  grid-template-columns: minmax(92px, 0.72fr) 1fr;
  gap: 10px;
  margin-top: 12px;
}

.options-button {
  width: 100%;
}

.options-panel {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  border: 1px solid rgba(190, 226, 255, 0.16);
  border-radius: 6px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.035);
}

.options-panel[hidden] {
  display: none;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 8px;
  margin: 14px 0 0;
}

.swatch {
  height: 34px;
  border: 2px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}

.swatch.selected {
  border-color: #ffffff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.18);
}

.primary-button {
  width: 100%;
  height: 46px;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  background: linear-gradient(90deg, #ffcf4a, #ff7f50 48%, #ff4f89);
  color: #16080e;
  font-weight: 900;
}

.primary-button:active {
  transform: translateY(1px);
}

.key-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.key-row span {
  min-width: 34px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  font-size: 12px;
  font-weight: 800;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 94px;
  transform: translateX(-50%);
  min-height: 34px;
  max-width: min(520px, calc(100vw - 32px));
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  opacity: 0;
  pointer-events: none;
  background: rgba(5, 8, 13, 0.84);
  color: var(--text);
  font-size: 13px;
  font-weight: 750;
  transition: opacity 160ms ease;
  z-index: 8;
}

.toast.visible {
  opacity: 1;
}

.mobile-controls {
  position: fixed;
  inset: 0;
  display: none;
  pointer-events: none;
  z-index: 6;
  touch-action: none;
}

.joystick {
  position: absolute;
  left: max(20px, env(safe-area-inset-left));
  bottom: max(22px, env(safe-area-inset-bottom));
  width: 116px;
  height: 116px;
  display: grid;
  place-items: center;
  pointer-events: auto;
  touch-action: none;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 207, 74, 0.08), transparent 30%),
    rgba(7, 11, 18, 0.2);
  box-shadow:
    inset 0 0 0 18px rgba(255, 255, 255, 0.025),
    0 12px 34px rgba(0, 0, 0, 0.28);
  opacity: 0.44;
  transition:
    opacity 120ms ease,
    border-color 120ms ease,
    box-shadow 120ms ease;
}

.joystick-ring {
  position: absolute;
  width: 70px;
  height: 70px;
  border: 1px dashed rgba(255, 255, 255, 0.2);
  border-radius: 50%;
}

.joystick-ring::before,
.joystick-ring::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.34);
}

.joystick-ring::before {
  left: -26px;
}

.joystick-ring::after {
  right: -26px;
}

.joystick-thumb {
  position: relative;
  width: 48px;
  height: 48px;
  border: 2px solid rgba(255, 255, 255, 0.34);
  border-radius: 50%;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.16), transparent),
    rgba(5, 8, 13, 0.72);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.34);
  transition:
    border-color 120ms ease,
    box-shadow 120ms ease;
}

.mobile-flap {
  position: absolute;
  left: 50%;
  bottom: max(43px, calc(env(safe-area-inset-bottom) + 23px));
  width: 46px;
  height: 46px;
  border: 2px solid var(--gold);
  border-radius: 50%;
  opacity: 0;
  transform: translateX(-50%) scale(0.8);
  transition:
    opacity 90ms ease,
    transform 150ms ease;
}

body.joystick-active .joystick {
  border-color: var(--gold);
  opacity: 0.78;
  box-shadow:
    inset 0 0 0 18px rgba(255, 207, 74, 0.04),
    0 0 24px rgba(255, 207, 74, 0.2),
    0 12px 34px rgba(0, 0, 0, 0.34);
}

body.turn-left .joystick-thumb,
body.turn-right .joystick-thumb {
  border-color: var(--gold);
  box-shadow:
    0 0 18px rgba(255, 207, 74, 0.26),
    0 8px 24px rgba(0, 0, 0, 0.34);
}

body.flapping .mobile-flap {
  opacity: 0.46;
  transform: translateX(-50%) scale(1.1);
}

@media (hover: none), (pointer: coarse) {
  body.playing .mobile-controls {
    display: block;
  }

  .key-row {
    display: none;
  }
}

@media (max-width: 760px) {
  body.playing .mobile-controls {
    display: block;
  }

  .hud {
    inset: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) auto max(8px, env(safe-area-inset-left));
    grid-template-columns: 34px minmax(0, 1fr) minmax(64px, auto);
    align-items: center;
    gap: 6px;
  }

  .brand {
    width: 34px;
    min-width: 34px;
    min-height: 32px;
    justify-content: center;
    padding: 0;
  }

  .brand span:last-child {
    display: none;
  }

  .brand-mark {
    width: 16px;
    height: 16px;
  }

  .scoreboard {
    grid-column: auto;
    grid-row: auto;
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow: hidden;
    max-height: 32px;
    gap: 5px;
  }

  .score-pill {
    grid-template-columns: 7px minmax(0, 48px) auto;
    min-height: 32px;
    max-width: 92px;
    gap: 5px;
    padding: 0 7px;
    font-size: 11px;
  }

  .score-pill:nth-child(n + 4) {
    display: none;
  }

  .score-color {
    width: 7px;
    height: 16px;
    border-radius: 2px;
  }

  .net-status {
    min-height: 32px;
    padding: 0 8px;
    font-size: 10px;
  }

  .key-row {
    display: none;
  }

  .join-panel {
    padding: 10px;
    place-items: center;
  }

  .join-card {
    padding: 14px;
    max-height: calc(100dvh - 20px);
  }

  .title-lockup {
    gap: 10px;
    margin-bottom: 8px;
  }

  .crest {
    width: 34px;
    height: 34px;
  }

  h1 {
    font-size: 28px;
  }

  .field {
    gap: 5px;
    font-size: 11px;
  }

  .field input,
  .field select {
    height: 40px;
    padding: 0 10px;
  }

  .lobby-field,
  .join-actions,
  .options-panel {
    margin-top: 10px;
  }

  .code-row {
    grid-template-columns: 1fr 58px;
    gap: 7px;
  }

  .secondary-button,
  .primary-button {
    height: 40px;
    font-size: 12px;
  }

  .swatches {
    gap: 6px;
    margin-top: 10px;
  }

  .swatch {
    height: 28px;
    border-radius: 5px;
  }

  .toggle-field {
    min-height: 38px;
    font-size: 12px;
  }

  .toast {
    bottom: max(64px, calc(env(safe-area-inset-bottom) + 54px));
  }

  .joystick {
    left: max(14px, env(safe-area-inset-left));
    bottom: max(14px, env(safe-area-inset-bottom));
    width: 96px;
    height: 96px;
  }

  .joystick-ring {
    width: 58px;
    height: 58px;
  }

  .joystick-thumb {
    width: 40px;
    height: 40px;
  }
}

@media (max-width: 380px) {
  .hud {
    grid-template-columns: 32px minmax(0, 1fr) minmax(56px, auto);
  }

  .brand {
    width: 32px;
    min-width: 32px;
  }

  .score-pill {
    grid-template-columns: 6px minmax(0, 38px) auto;
    max-width: 76px;
    padding: 0 6px;
    font-size: 10px;
  }

  .net-status {
    padding: 0 7px;
  }
}

@media (max-width: 430px) {
  .join-grid {
    grid-template-columns: 1fr;
  }
}
