* { box-sizing: border-box; }
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  background: #070914;
  color: #fff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
}
canvas {
  display: block;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: radial-gradient(circle at center, #121834 0%, #070914 75%);
  touch-action: none;
}
.panel {
  position: absolute;
  background: rgba(10, 14, 32, 0.88);
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.45);
  backdrop-filter: blur(12px);
}
.center {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(420px, calc(100vw - 28px));
  padding: 30px;
  text-align: center;
}
h1 {
  margin: 0 0 8px;
  font-size: 44px;
  letter-spacing: -0.04em;
}
.tagline {
  margin: 0 0 22px;
  color: #cdd5ff;
}
input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(255,255,255,0.08);
  color: white;
  font-size: 16px;
  outline: none;
}
.modeSelect {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 12px;
  padding: 4px;
  border-radius: 10px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.12);
}
button {
  width: 100%;
  margin-top: 12px;
  padding: 14px 16px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, #6a5cff, #39d8ff);
  color: white;
  font-weight: 800;
  font-size: 16px;
  cursor: pointer;
}
button:hover { filter: brightness(1.08); }
.shareBtn {
  background: rgba(255,255,255,0.10);
  border: 1px solid rgba(255,255,255,0.18);
  color: #dce4ff;
}
.shareBtn.compact {
  width: auto;
  min-width: 72px;
  margin-top: 0;
  padding: 10px 13px;
  border-radius: 10px;
  pointer-events: auto;
}
.shareStatus {
  min-height: 18px;
  margin-top: 10px;
  color: #f8ff65;
  font-size: 12px;
}
.modeBtn {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: transparent;
  color: #bec8ef;
  font-size: 14px;
}
.modeBtn.active {
  background: linear-gradient(135deg, #ff566e, #39d8ff 52%, #f8ff65);
  color: #06101d;
}
.hint {
  margin-top: 16px;
  color: #9aa5d8;
  font-size: 13px;
  line-height: 1.45;
}
.hidden { display: none !important; }
.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}
.topbar {
  position: absolute;
  left: 18px;
  right: 18px;
  top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.topbar > div,
.bottombar > div,
.leaderboard {
  background: rgba(9, 13, 30, 0.72);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  padding: 10px 14px;
  backdrop-filter: blur(8px);
}
.topbar > .shareBtn {
  flex: 0 0 auto;
}
.topbar > div:empty {
  display: none;
}
.zoneStatus {
  color: #f8ff65;
  min-width: 150px;
  text-align: center;
}
.zoneStatus.warn {
  color: #ffd36b;
  box-shadow: 0 0 22px rgba(255, 211, 107, 0.18);
}
.zoneStatus.closing,
.zoneStatus.danger {
  color: #ff8fca;
  border-color: rgba(255, 94, 170, 0.38);
  box-shadow: 0 0 24px rgba(255, 94, 170, 0.18);
}
.bottombar {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
}
#shapeCard {
  min-width: 240px;
}
#cooldowns {
  text-align: right;
  min-width: 220px;
}
.feed {
  position: absolute;
  left: 18px;
  top: 76px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  pointer-events: none;
  width: min(240px, calc(100vw - 36px));
  z-index: 3;
}
.feedItem {
  display: inline-block;
  max-width: 100%;
  background: rgba(11, 15, 34, 0.82);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 8px 10px;
  text-align: left;
  color: #dce4ff;
  font-size: 13px;
  line-height: 1.25;
  overflow-wrap: anywhere;
  animation: fadeUp 3.2s ease forwards;
}
@keyframes fadeUp {
  0% { opacity: 0; transform: translateX(-10px); }
  12% { opacity: 1; transform: translateY(0); }
  80% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateX(-10px); }
}
.leaderboard {
  position: absolute;
  right: 18px;
  top: 74px;
  width: 270px;
  line-height: 1.55;
  z-index: 4;
}
.leaderboard h3 {
  margin: 0 0 8px;
  font-size: 12px;
  color: #9aa5d8;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.leaderRow {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
}
.leaderRow span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.deadText {
  color: #ff9cab;
  font-weight: 700;
}

.mobileControls {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}
.touchStick,
.touchAttack,
.touchDodge {
  position: absolute;
  display: none;
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.touchStick {
  left: calc(env(safe-area-inset-left) + 22px);
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  width: 108px;
  height: 108px;
  border-radius: 50%;
  background: rgba(9, 13, 30, 0.58);
  border: 1px solid rgba(255,255,255,0.20);
  box-shadow: inset 0 0 24px rgba(255,255,255,0.05), 0 14px 34px rgba(0,0,0,0.28);
  backdrop-filter: blur(8px);
}
.touchStickKnob,
.touchAttackKnob {
  position: absolute;
  left: 50%;
  top: 50%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: transform 80ms ease;
}
.touchStickKnob {
  width: 44px;
  height: 44px;
  background: rgba(220, 228, 255, 0.82);
  border: 1px solid rgba(255,255,255,0.52);
  box-shadow: 0 0 18px rgba(255,255,255,0.22);
}
.touchAttack {
  right: calc(env(safe-area-inset-right) + 20px);
  bottom: calc(env(safe-area-inset-bottom) + 22px);
  width: 116px;
  height: 116px;
  margin: 0;
  padding: 0;
  border-radius: 50%;
  background: rgba(255, 86, 110, 0.22);
  border: 1px solid rgba(255,255,255,0.26);
  color: #fff;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  box-shadow: inset 0 0 28px rgba(255,86,110,0.18), 0 14px 34px rgba(0,0,0,0.30);
  backdrop-filter: blur(8px);
}
.touchAttack span {
  position: relative;
  z-index: 1;
}
.touchAttackKnob {
  width: 38px;
  height: 38px;
  background: rgba(255,255,255,0.22);
  border: 1px solid rgba(255,255,255,0.35);
  box-shadow: 0 0 16px rgba(255,255,255,0.16);
}
.touchAttack.active {
  border-color: rgba(255,255,255,0.58);
  box-shadow: inset 0 0 34px rgba(255,86,110,0.32), 0 0 24px rgba(255,86,110,0.24), 0 14px 34px rgba(0,0,0,0.30);
}
.touchDodge {
  right: calc(env(safe-area-inset-right) + 144px);
  bottom: calc(env(safe-area-inset-bottom) + 34px);
  width: 70px;
  height: 70px;
  margin: 0;
  padding: 0;
  border-radius: 50%;
  background: rgba(248, 255, 101, 0.18);
  border: 1px solid rgba(248,255,101,0.34);
  color: #f8ff65;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  box-shadow: inset 0 0 22px rgba(248,255,101,0.12), 0 12px 28px rgba(0,0,0,0.26);
  backdrop-filter: blur(8px);
}
.touchDodge:active {
  filter: brightness(1.2);
}
@media (max-width: 700px) {
  .topbar { font-size: 12px; }
  .bottombar { font-size: 12px; }
  #shapeCard, #cooldowns { min-width: auto; }
  .leaderboard { width: min(270px, calc(100vw - 36px)); font-size: 12px; }
}

@media (pointer: coarse), (max-width: 760px) {
  html, body, canvas {
    touch-action: none;
  }
  .center {
    width: min(390px, calc(100vw - 24px));
    padding: 22px;
    border-radius: 14px;
  }
  h1 {
    font-size: 34px;
    letter-spacing: 0;
  }
  .hint {
    font-size: 12px;
  }
  .topbar {
    left: calc(env(safe-area-inset-left) + 8px);
    right: calc(env(safe-area-inset-right) + 8px);
    top: calc(env(safe-area-inset-top) + 7px);
    gap: 5px;
    align-items: center;
    justify-content: center;
    flex-wrap: nowrap;
  }
  .topbar > div,
  .bottombar > div,
  .leaderboard {
    border-radius: 10px;
    padding: 7px 9px;
    backdrop-filter: blur(7px);
  }
  #status {
    display: none;
  }
  #timer,
  #alive,
  #zoneStatus {
    font-size: 10px;
    min-width: 0;
    white-space: nowrap;
  }
  .zoneStatus {
    text-align: center;
    max-width: 112px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .shareBtn.compact {
    display: none;
  }
  .feed {
    left: 8px;
    top: calc(env(safe-area-inset-top) + 44px);
    width: min(150px, 39vw);
    max-height: 78px;
    gap: 4px;
    overflow: hidden;
  }
  .feedItem {
    padding: 5px 7px;
    border-radius: 8px;
    font-size: 10px;
    line-height: 1.15;
    animation-duration: 2.35s;
  }
  .feedItem:nth-child(n+4) {
    display: none;
  }
  .bottombar {
    left: calc(env(safe-area-inset-left) + 8px);
    right: auto;
    bottom: calc(env(safe-area-inset-bottom) + 132px);
    gap: 8px;
  }
  #shapeCard {
    min-width: 0;
    max-width: 168px;
    font-size: 10px;
    line-height: 1.2;
    padding: 6px 8px;
  }
  #cooldowns {
    display: none;
  }
  .leaderboard {
    right: 8px;
    top: calc(env(safe-area-inset-top) + 42px);
    width: min(220px, calc(100vw - 16px));
    font-size: 11px;
  }
  .leaderRow {
    font-size: 11px;
  }
  .mobileControls:not(.hidden) .touchStick,
  .mobileControls:not(.hidden) .touchAttack,
  .mobileControls:not(.hidden) .touchDodge {
    display: block;
  }
}

@media (pointer: coarse) and (max-width: 380px) {
  .touchStick {
    left: calc(env(safe-area-inset-left) + 14px);
    width: 96px;
    height: 96px;
  }
  .touchAttack {
    right: calc(env(safe-area-inset-right) + 14px);
    width: 104px;
    height: 104px;
  }
  .touchDodge {
    right: calc(env(safe-area-inset-right) + 126px);
    width: 60px;
    height: 60px;
    font-size: 10px;
  }
}

@media (pointer: coarse) and (min-width: 381px) {
  .touchStick {
    width: 102px;
    height: 102px;
  }
  .touchAttack {
    width: 108px;
    height: 108px;
  }
  .touchDodge {
    right: calc(env(safe-area-inset-right) + 132px);
    width: 62px;
    height: 62px;
    font-size: 10px;
  }
}
