:root {
  --app-width: 100vw;
  --app-height: 100dvh;
  --app-left: 0px;
  --app-top: 0px;
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #071018;
  color: #f7fbff;
}

* {
  box-sizing: border-box;
}

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

body {
  position: fixed;
  inset: 0;
  background: #071018;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

button {
  font: inherit;
}

#scene {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#game-shell {
  position: fixed;
  top: var(--app-top);
  left: var(--app-left);
  width: var(--app-width);
  height: var(--app-height);
  min-height: 0;
  overflow: hidden;
}

#topbar {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
  text-shadow: 0 2px 10px rgba(2, 8, 16, 0.7);
}

.brand {
  display: grid;
  gap: 3px;
  padding: 2px 0;
}

.brand strong {
  font-size: 17px;
  line-height: 1;
}

.brand span,
#stats {
  color: rgba(247, 251, 255, 0.75);
  font-size: 12px;
}

#crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0.9;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.7));
}

#crosshair::before,
#crosshair::after {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.95);
}

#crosshair::before {
  left: 8px;
  top: 0;
  width: 2px;
  height: 18px;
}

#crosshair::after {
  left: 0;
  top: 8px;
  width: 18px;
  height: 2px;
}

#start-panel,
#pause-panel {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 18px;
  padding: 24px;
  background:
    linear-gradient(rgba(4, 12, 20, 0.28), rgba(4, 12, 20, 0.56)),
    radial-gradient(circle at 50% 30%, rgba(77, 169, 255, 0.18), transparent 42%);
  text-align: center;
}

#pause-panel[hidden] {
  display: none;
}

#start-panel[hidden] {
  display: none;
}

#start-panel h1,
#pause-panel h2 {
  margin: 0;
  font-size: clamp(40px, 7vw, 88px);
  line-height: 0.92;
  text-shadow: 0 12px 36px rgba(0, 0, 0, 0.55);
}

#pause-panel h2 {
  font-size: clamp(32px, 5vw, 58px);
}

#start-panel p {
  margin: 0;
  color: rgba(247, 251, 255, 0.78);
  font-size: 17px;
}

.join-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(110px, 160px));
  gap: 10px;
  width: min(94vw, 340px);
}

.join-form label {
  display: grid;
  gap: 5px;
  color: rgba(247, 251, 255, 0.78);
  font-size: 12px;
  text-align: left;
}

.join-form input {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  padding: 10px 11px;
  color: #f7fbff;
  background: rgba(6, 15, 24, 0.68);
  outline: none;
}

.join-form input:focus {
  border-color: rgba(244, 211, 94, 0.8);
  box-shadow: 0 0 0 2px rgba(244, 211, 94, 0.18);
}

#start-button,
#resume-button,
#reset-button {
  min-width: 132px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  padding: 11px 16px;
  color: #071018;
  background: #f4d35e;
  cursor: pointer;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
}

#reset-button {
  color: #f7fbff;
  background: rgba(8, 20, 30, 0.76);
}

.pause-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

#hotbar {
  position: absolute;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(7, 62px);
  gap: 5px;
  transform: translateX(-50%);
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(6, 13, 20, 0.58);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(8px);
}

.slot {
  position: relative;
  width: 62px;
  height: 58px;
  border: 2px solid rgba(255, 255, 255, 0.17);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.slot.active {
  border-color: #f4d35e;
  box-shadow: 0 0 0 2px rgba(244, 211, 94, 0.32);
}

.slot.locked {
  opacity: 0.78;
}

.swatch {
  width: 24px;
  height: 24px;
  border: 1px solid rgba(0, 0, 0, 0.36);
  border-radius: 3px;
  background: var(--swatch);
  box-shadow:
    inset 0 6px 10px rgba(255, 255, 255, 0.12),
    inset 0 -8px 10px rgba(0, 0, 0, 0.18);
}

.slot-name,
.rarity,
.lock {
  position: absolute;
  left: 3px;
  right: 3px;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slot-name {
  bottom: 15px;
  font-size: 9px;
  color: rgba(247, 251, 255, 0.9);
}

.rarity {
  bottom: 4px;
  font-size: 8px;
  color: rgba(244, 211, 94, 0.9);
}

.lock {
  top: 3px;
  left: auto;
  right: 3px;
  width: 34px;
  border-radius: 4px;
  padding: 1px 2px;
  color: #071018;
  background: #f4d35e;
  font-size: 8px;
  font-weight: 700;
}

.keycap {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 10px;
  color: rgba(247, 251, 255, 0.72);
}

#toast {
  position: absolute;
  left: 50%;
  bottom: 86px;
  min-height: 20px;
  transform: translateX(-50%);
  color: rgba(247, 251, 255, 0.84);
  font-size: 13px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.85);
  pointer-events: none;
}

#multiplayer-status {
  position: absolute;
  top: 52px;
  right: 16px;
  max-width: min(54vw, 260px);
  color: rgba(247, 251, 255, 0.82);
  font-size: 12px;
  text-align: right;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
  pointer-events: none;
}

#player-hud {
  position: absolute;
  left: 16px;
  top: 52px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: min(58vw, 420px);
  color: rgba(247, 251, 255, 0.86);
  font-size: 12px;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.82);
  pointer-events: none;
}

#player-hud span {
  border-radius: 6px;
  padding: 3px 6px;
  background: rgba(6, 13, 20, 0.42);
}

#touch-controls {
  display: none;
}

.touch-pad,
.touch-button {
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
}

@media (hover: none), (pointer: coarse) {
  :root {
    --touch-scale: 1;
  }

  #start-panel p {
    font-size: 15px;
  }

  #touch-controls {
    position: absolute;
    inset: 0;
    display: block;
    pointer-events: none;
  }

  #move-pad {
    position: absolute;
    left: max(18px, env(safe-area-inset-left));
    bottom: max(calc(84px * var(--touch-scale)), calc(env(safe-area-inset-bottom) + 78px));
    width: 124px;
    height: 124px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 50%;
    background: rgba(5, 13, 22, 0.34);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(5px);
    touch-action: none;
    transform: scale(var(--touch-scale));
    transform-origin: left bottom;
  }

  #move-stick {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 54px;
    height: 54px;
    border: 1px solid rgba(255, 255, 255, 0.38);
    border-radius: 50%;
    background: rgba(244, 211, 94, 0.8);
    box-shadow:
      inset 0 5px 10px rgba(255, 255, 255, 0.18),
      0 8px 18px rgba(0, 0, 0, 0.28);
    transform: translate(-50%, -50%);
  }

  #touch-actions {
    position: absolute;
    right: max(14px, env(safe-area-inset-right));
    bottom: max(calc(84px * var(--touch-scale)), calc(env(safe-area-inset-bottom) + 78px));
    display: grid;
    grid-template-columns: repeat(2, 64px);
    gap: 9px;
    pointer-events: none;
    transform: scale(var(--touch-scale));
    transform-origin: right bottom;
  }

  #toast {
    bottom: max(calc(214px * var(--touch-scale)), calc(env(safe-area-inset-bottom) + 202px));
    width: min(74vw, 320px);
    text-align: center;
    line-height: 1.28;
  }

  .touch-button {
    min-width: 0;
    width: 64px;
    height: 52px;
    border: 1px solid rgba(255, 255, 255, 0.24);
    border-radius: 8px;
    color: #f7fbff;
    background: rgba(6, 15, 24, 0.58);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.26);
    backdrop-filter: blur(5px);
    font-size: 13px;
    touch-action: none;
  }

  .touch-button.primary {
    color: #071018;
    background: rgba(244, 211, 94, 0.88);
  }

  .touch-button:active,
  .touch-button.active {
    transform: translateY(1px);
    border-color: rgba(244, 211, 94, 0.72);
  }
}

@media (max-width: 600px) {
  #topbar {
    top: 12px;
    left: 12px;
    right: 12px;
  }

  .join-form {
    grid-template-columns: 1fr;
    width: min(88vw, 280px);
  }

  #multiplayer-status {
    top: 48px;
    right: 12px;
    font-size: 11px;
  }

  #hotbar {
    grid-template-columns: repeat(7, minmax(28px, 1fr));
    width: min(calc(100vw - 20px), 340px);
    bottom: max(14px, env(safe-area-inset-bottom));
    gap: 3px;
    padding: 4px;
  }

  .slot {
    width: 100%;
    height: 38px;
  }

  .swatch {
    width: 22px;
    height: 22px;
  }
}

@media (max-width: 430px) and (hover: none), (max-width: 430px) and (pointer: coarse) {
  :root {
    --touch-scale: 0.9;
  }
}

@media (max-width: 370px) and (hover: none), (max-width: 370px) and (pointer: coarse) {
  :root {
    --touch-scale: 0.82;
  }
}

@media (max-height: 720px) and (hover: none), (max-height: 720px) and (pointer: coarse) {
  :root {
    --touch-scale: 0.86;
  }
}

@media (max-height: 520px) and (hover: none), (max-height: 520px) and (pointer: coarse) {
  #topbar {
    top: 8px;
  }

  .brand strong {
    font-size: 14px;
  }

  .brand span,
  #stats,
  #multiplayer-status {
    font-size: 10px;
  }

  #move-pad {
    bottom: max(56px, calc(env(safe-area-inset-bottom) + 52px));
    width: 104px;
    height: 104px;
  }

  #move-stick {
    width: 46px;
    height: 46px;
  }

  #touch-actions {
    bottom: max(56px, calc(env(safe-area-inset-bottom) + 52px));
    grid-template-columns: repeat(4, 54px);
  }

  .touch-button {
    width: 54px;
    height: 42px;
    font-size: 11px;
  }

  #hotbar {
    height: 38px;
    padding: 3px;
  }

  .slot {
    height: 30px;
  }

  .swatch {
    width: 19px;
    height: 19px;
  }
}

body.touch-device #touch-controls {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: block;
  pointer-events: none;
}

body.touch-device #hotbar {
  z-index: 31;
  width: min(calc(100% - 18px), 294px);
  bottom: calc(env(safe-area-inset-bottom) + 10px);
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 2px;
  padding: 3px;
}

body.touch-device .slot {
  width: auto;
  height: clamp(33px, 9vw, 40px);
}

body.touch-device .swatch {
  width: clamp(15px, 4.8vw, 18px);
  height: clamp(15px, 4.8vw, 18px);
}

body.touch-device .keycap {
  display: none;
}

body.touch-device .slot-name {
  bottom: 13px;
  font-size: 7px;
}

body.touch-device .rarity {
  bottom: 3px;
  font-size: 6px;
}

body.touch-device .lock {
  width: 28px;
  font-size: 6px;
}

body.touch-device #move-pad {
  position: absolute;
  z-index: 32;
  left: max(12px, calc(env(safe-area-inset-left) + 8px));
  bottom: calc(env(safe-area-inset-bottom) + 52px);
  width: min(22vw, 84px);
  height: min(22vw, 84px);
  min-width: 68px;
  min-height: 68px;
  transform: none;
  transform-origin: center;
}

body.touch-device #move-stick {
  width: 46%;
  height: 46%;
}

body.touch-device #touch-actions {
  position: absolute;
  z-index: 32;
  right: max(10px, calc(env(safe-area-inset-right) + 8px));
  bottom: calc(env(safe-area-inset-bottom) + 52px);
  display: grid;
  grid-template-columns: repeat(2, clamp(42px, 12vw, 48px));
  gap: 5px;
  transform: none;
  transform-origin: center;
}

body.touch-device .touch-button {
  width: clamp(42px, 12vw, 48px);
  height: clamp(32px, 9vw, 36px);
  border-radius: 7px;
  font-size: clamp(9px, 2.8vw, 10px);
}

body.touch-device #toast {
  bottom: calc(env(safe-area-inset-bottom) + 138px);
  width: min(78vw, 320px);
  z-index: 33;
}

body.touch-device #topbar {
  z-index: 25;
  top: calc(env(safe-area-inset-top) + 6px);
  left: max(10px, calc(env(safe-area-inset-left) + 8px));
  right: max(10px, calc(env(safe-area-inset-right) + 8px));
}

body.touch-device .brand strong {
  font-size: 12px;
}

body.touch-device .brand span,
body.touch-device #stats {
  display: none;
}

body.touch-device.playing #topbar {
  display: none;
}

body.touch-device #player-hud {
  top: calc(env(safe-area-inset-top) + 6px);
  left: max(8px, calc(env(safe-area-inset-left) + 6px));
  max-width: 62vw;
  gap: 4px;
  font-size: 9px;
  opacity: 0.72;
}

body.touch-device #player-hud span {
  padding: 2px 4px;
}

body.touch-device #multiplayer-status {
  z-index: 25;
  top: calc(env(safe-area-inset-top) + 24px);
  right: max(10px, calc(env(safe-area-inset-right) + 8px));
  max-width: 70vw;
  font-size: 9px;
}

body.touch-device.playing #multiplayer-status {
  top: calc(env(safe-area-inset-top) + 6px);
  opacity: 0.72;
}

@media (orientation: landscape) {
  body.touch-device #hotbar {
    width: min(34vw, 236px);
    bottom: calc(env(safe-area-inset-bottom) + 8px);
  }

  body.touch-device .slot {
    height: clamp(28px, 8vh, 34px);
  }

  body.touch-device .swatch {
    width: clamp(13px, 4.2vh, 17px);
    height: clamp(13px, 4.2vh, 17px);
  }

  body.touch-device #move-pad {
    left: max(10px, calc(env(safe-area-inset-left) + 8px));
    bottom: calc(env(safe-area-inset-bottom) + 12px);
    width: min(21vh, 78px);
    height: min(21vh, 78px);
    min-width: 58px;
    min-height: 58px;
  }

  body.touch-device #touch-actions {
    right: max(10px, calc(env(safe-area-inset-right) + 8px));
    bottom: calc(env(safe-area-inset-bottom) + 12px);
    grid-template-columns: repeat(2, clamp(40px, 8vw, 46px));
    gap: 5px;
  }

  body.touch-device .touch-button {
    width: clamp(40px, 8vw, 46px);
    height: clamp(29px, 9vh, 34px);
    font-size: 9px;
  }

  body.touch-device #toast {
    bottom: calc(env(safe-area-inset-bottom) + 82px);
    width: min(44vw, 240px);
  }

  body.touch-device #topbar {
    max-width: 34vw;
  }

  body.touch-device .brand strong {
    font-size: 11px;
  }

  body.touch-device .brand span,
  body.touch-device #stats,
  body.touch-device #multiplayer-status {
    font-size: 9px;
  }
}
