:root {
  --ink: #e8f3ef;
  --dim: #8fa8a1;
  --water: #48c7ff;
  --drain: #ff5a54;
  --quake: #ffc94a;
  --panel: rgba(9, 25, 26, 0.86);
  --edge: rgba(120, 220, 210, 0.22);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #05100f;
  color: var(--ink);
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(1200px 700px at 50% 8%, rgba(34, 118, 108, 0.30), transparent 62%),
    radial-gradient(900px 600px at 50% 110%, rgba(14, 58, 82, 0.45), transparent 60%),
    linear-gradient(180deg, #071514 0%, #04100f 100%);
}

#frame {
  position: relative;
  width: min(100vw, calc(100vh * 1000 / 760));
  height: min(100vh, calc(100vw * 760 / 1000));
  margin: 0 auto;
  top: 50%;
  transform: translateY(-50%);
  container-type: size;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-size: clamp(9px, 1.25cqw, 14px);
}

#hud button { pointer-events: auto; }

.brand {
  position: absolute;
  top: 2.2%;
  left: 2.4%;
  display: flex;
  align-items: baseline;
  gap: 0.6em;
  letter-spacing: 0.22em;
}
.brand-mark {
  font-weight: 800;
  font-size: 1.5em;
  letter-spacing: 0.16em;
  color: #d9fbf3;
  text-shadow: 0 0 18px rgba(72, 199, 255, 0.45);
}
.brand-mark .plus { color: var(--quake); }
.brand-sub { font-size: 0.72em; color: var(--dim); letter-spacing: 0.4em; }

.topbar {
  position: absolute;
  top: 2%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 1.5em;
  padding: 0.55em 1.4em;
  background: rgba(4, 18, 17, 0.55);
  border: 1px solid var(--edge);
  border-radius: 0.5em;
  backdrop-filter: blur(4px);
}
.stat { display: flex; flex-direction: column; align-items: center; min-width: 4.2em; }
.stat span { font-size: 0.66em; letter-spacing: 0.24em; color: var(--dim); }
.stat b { font-size: 1.55em; font-variant-numeric: tabular-nums; font-weight: 700; }
.stat.score b { color: #9fffe7; min-width: 4.5em; text-align: center; }

.meter {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 2.9em;
  height: 56%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5em;
}
.meter.quake { left: 1.8%; }
.meter.drain { right: 1.8%; }
.meter-name {
  font-size: 0.62em;
  letter-spacing: 0.22em;
  color: var(--dim);
  writing-mode: vertical-rl;
  transform: rotate(180deg);
}
.meter-track {
  position: relative;
  flex: 1;
  width: 1.5em;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 1em;
  background: rgba(0, 0, 0, 0.45);
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  box-shadow: inset 0 0 12px rgba(0,0,0,0.7);
}
.meter-fill {
  width: 100%;
  height: 0%;
  transition: height 90ms linear;
  border-radius: 1em;
}
.quake .meter-fill { background: linear-gradient(180deg, #ffd36b, #e0911f); box-shadow: 0 0 12px rgba(255, 201, 74, 0.55); }
.drain .meter-fill { background: linear-gradient(180deg, #ff8a6e, #d92f42); box-shadow: 0 0 14px rgba(255, 90, 84, 0.65); }
.drain .meter-track::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(180deg, transparent 0 9%, rgba(0,0,0,0.35) 9% 10%);
  pointer-events: none;
}
.meter-cap { font-size: 0.55em; color: var(--dim); }

#badges {
  position: absolute;
  top: 9.5%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 0.7em;
}
.badge {
  font-size: 0.85em;
  letter-spacing: 0.1em;
  padding: 0.3em 0.7em;
  border-radius: 2em;
  background: rgba(7, 30, 28, 0.7);
  border: 1px solid var(--edge);
  color: #ffe58f;
}
.badge.rainbow {
  display: none;
  background: linear-gradient(90deg, #ff5a5a, #ffb347, #ffe66d, #6dff9c, #5ad1ff, #b57bff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  border-color: rgba(255,255,255,0.3);
  font-weight: 800;
}
.badge.rainbow.on { display: block; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { filter: brightness(1.35); } }

.nextbox {
  position: absolute;
  left: 2%;
  bottom: 3%;
  display: flex;
  flex-direction: column;
  gap: 0.3em;
}
.next-label { font-size: 0.6em; letter-spacing: 0.3em; color: var(--dim); }
#next { width: 6.2em; height: 8.7em; opacity: 0.92; }

.controls {
  position: absolute;
  bottom: 2.4%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 1.1em;
  font-size: 0.62em;
  letter-spacing: 0.14em;
  color: rgba(180, 208, 201, 0.65);
  white-space: nowrap;
}

#leaderboard {
  position: absolute;
  top: 12%;
  right: 7%;
  width: 17em;
  padding: 0.7em 0.8em;
  background: rgba(4, 18, 17, 0.68);
  border: 1px solid var(--edge);
  border-radius: 0.5em;
  pointer-events: auto;
}
.lb-title { font-size: 0.62em; letter-spacing: 0.28em; color: var(--dim); margin-bottom: 0.4em; }
#lbList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.2em; }
#lbList li {
  display: flex;
  justify-content: space-between;
  gap: 0.6em;
  padding: 0.22em 0.4em;
  border-radius: 0.25em;
  cursor: pointer;
  font-size: 0.86em;
}
#lbList li:hover { background: rgba(72, 199, 255, 0.12); }
#lbList li.target { background: rgba(72, 199, 255, 0.22); outline: 1px solid rgba(72,199,255,0.5); }
#lbList li.dead { opacity: 0.35; text-decoration: line-through; }
#lbList li .dot { width: 0.7em; height: 0.7em; border-radius: 50%; display: inline-block; margin-right: 0.45em; }
.lb-hint { margin-top: 0.4em; font-size: 0.6em; color: var(--dim); }

#attackPanel {
  position: absolute;
  right: 6%;
  bottom: 4%;
  width: 17.5em;
  padding: 0.8em;
  background: rgba(4, 18, 17, 0.72);
  border: 1px solid var(--edge);
  border-radius: 0.5em;
  pointer-events: auto;
}
.attack-title { font-size: 0.65em; letter-spacing: 0.2em; color: var(--dim); margin-bottom: 0.5em; }
.attack-title b { color: #9fffe7; font-size: 1.2em; margin-left: 0.4em; }
.attack-title span { float: right; font-size: 0.85em; color: #9fffe7; letter-spacing: 0.08em; }
.atk-meter {
  height: 0.3em;
  margin: 0 0 0.6em;
  border-radius: 1em;
  background: rgba(0, 0, 0, 0.45);
  overflow: hidden;
}
.atk-meter i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #43c8b8, #9fffe7);
  transition: width 90ms linear;
}
.atk-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 0.35em; }
.atk-btns button {
  font: inherit;
  font-size: 0.68em;
  letter-spacing: 0.12em;
  padding: 0.5em 0.2em;
  color: #dff9f1;
  background: rgba(72, 199, 255, 0.10);
  border: 1px solid rgba(72, 199, 255, 0.35);
  border-radius: 0.3em;
  cursor: pointer;
}
.atk-btns button:hover:not(:disabled) { background: rgba(72, 199, 255, 0.25); }
.atk-btns button:disabled { opacity: 0.28; cursor: default; }

#overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: radial-gradient(700px 500px at 50% 45%, rgba(4, 22, 21, 0.78), rgba(2, 8, 8, 0.94));
  backdrop-filter: blur(3px);
  z-index: 20;
}
#overlay.show { display: flex; }

.panel {
  width: min(88%, 34em);
  padding: 2em 2.4em;
  background: var(--panel);
  border: 1px solid rgba(110, 220, 205, 0.28);
  border-radius: 0.8em;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6), inset 0 0 60px rgba(38, 120, 110, 0.08);
  text-align: center;
  max-height: 92%;
  overflow: auto;
}
.panel h1 {
  margin: 0;
  font-size: clamp(2.2em, 6cqw, 4em);
  letter-spacing: 0.12em;
  font-weight: 800;
  color: #dffdf5;
  text-shadow: 0 0 40px rgba(72, 199, 255, 0.35);
}
.panel h1 span { color: var(--quake); }
.panel h2 {
  margin: 0 0 0.4em;
  font-size: 1.7em;
  letter-spacing: 0.14em;
  font-weight: 700;
}
.tag { font-size: 0.72em; letter-spacing: 0.24em; color: var(--dim); margin: 0.6em 0 1.6em; }
.menu-buttons { display: flex; gap: 0.8em; justify-content: center; flex-wrap: wrap; }

button.big {
  font: inherit;
  font-size: 0.82em;
  letter-spacing: 0.18em;
  font-weight: 700;
  padding: 0.9em 2em;
  color: #05201d;
  background: linear-gradient(180deg, #9fffe7, #43c8b8);
  border: none;
  border-radius: 0.4em;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(67, 200, 184, 0.25);
  transition: transform 80ms ease, filter 120ms ease;
}
button.big:hover:not(:disabled) { filter: brightness(1.12); transform: translateY(-1px); }
button.big:active:not(:disabled) { transform: translateY(1px); }
button.big:disabled { opacity: 0.35; cursor: default; }
button.ghost { background: transparent; color: #bfe8e0; border: 1px solid rgba(140, 220, 208, 0.4); box-shadow: none; }

.help {
  margin: 1.8em 0 0.8em;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35em 1.4em;
  text-align: left;
  font-size: 0.68em;
  color: #a9c6c0;
  line-height: 1.4;
}
.help b { color: #dff9f1; }
.tiny { font-size: 0.62em; color: #78938d; margin: 0.8em 0 0; line-height: 1.5; }

.lobby-form { display: flex; gap: 0.7em; justify-content: center; align-items: flex-end; flex-wrap: wrap; margin-bottom: 1em; }
.lobby-form label { display: flex; flex-direction: column; gap: 0.35em; font-size: 0.62em; letter-spacing: 0.2em; color: var(--dim); text-align: left; }
.lobby-form input {
  font: inherit;
  font-size: 1.5em;
  letter-spacing: 0.06em;
  padding: 0.4em 0.6em;
  width: 8.5em;
  color: #e8f3ef;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(120, 220, 210, 0.3);
  border-radius: 0.3em;
  outline: none;
}
.lobby-form input:focus { border-color: var(--water); }
.lobby-status { font-size: 0.72em; color: #93b3ac; margin: 0.6em 0 1em; min-height: 1.4em; }
.lobby-players { list-style: none; margin: 0 auto 1.2em; padding: 0; width: 100%; max-width: 20em; display: flex; flex-direction: column; gap: 0.3em; }
.lobby-players li {
  display: flex; align-items: center; gap: 0.6em;
  padding: 0.4em 0.7em;
  background: rgba(255,255,255,0.04);
  border-radius: 0.3em;
  font-size: 0.8em;
}
.lobby-players li .dot { width: 0.8em; height: 0.8em; border-radius: 50%; }
.lobby-players li .st { margin-left: auto; font-size: 0.8em; color: var(--dim); letter-spacing: 0.14em; }
.lobby-players li.ready .st { color: #7dffbf; }
.lobby-actions { display: flex; gap: 0.8em; justify-content: center; }

.final-score { display: flex; flex-direction: column; align-items: center; margin: 0.6em 0 1.6em; }
.final-score span { font-size: 0.66em; letter-spacing: 0.3em; color: var(--dim); }
.final-score b { font-size: 2.6em; color: #9fffe7; font-variant-numeric: tabular-nums; }

.hidden { display: none !important; }

#pauseBanner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.6em, 5cqw, 3em);
  font-weight: 800;
  letter-spacing: 0.4em;
  color: rgba(223, 253, 245, 0.85);
  background: rgba(2, 12, 11, 0.45);
  backdrop-filter: blur(2px);
  pointer-events: none;
  z-index: 10;
}

@media (max-aspect-ratio: 4/5) {
  #leaderboard { top: 14%; right: 2%; width: 12em; }
  #attackPanel { width: 12em; right: 2%; }
}
