:root {
  --bg: #10202c;
  --panel: #182f3f;
  --panel-edge: #2e5268;
  --ink: #eef6fa;
  --muted: #9db8c7;
  --accent: #ffc94a;
  --accent-ink: #33240a;
  --bad: #ff7a6b;
  --hp: #58d86c;
  --shield: #5cc8ff;
  --xp: #ffc94a;
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

input, textarea { -webkit-user-select: text; user-select: text; }
textarea {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 2px solid var(--panel-edge);
  background: #0c1a24;
  color: var(--ink);
  resize: none;
  touch-action: auto;
}
#bugDialog { z-index: 30; }
#bugStatus.ok { color: var(--hp); }

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

.hidden { display: none !important; }

button {
  font: inherit;
  color: var(--ink);
  background: var(--panel-edge);
  border: 0;
  border-radius: 12px;
  padding: 10px 16px;
  cursor: pointer;
}
button:hover { filter: brightness(1.12); }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: .5; cursor: default; }

button.big {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
  font-size: 1.25rem;
  padding: 14px 30px;
  letter-spacing: .06em;
}

input {
  font: inherit;
  font-size: 1.2rem;
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid var(--panel-edge);
  background: #0c1a24;
  color: var(--ink);
  text-align: center;
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 18, 26, .62);
  z-index: 20;
  padding: max(8px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.panel {
  background: var(--panel);
  border: 2px solid var(--panel-edge);
  border-radius: 20px;
  padding: 20px 24px;
  width: min(420px, 100%);
  max-height: 100%;
  overflow-y: auto;
  touch-action: pan-y;
  text-align: center;
}
.panel.wide { width: min(720px, 100%); }
.panel h2 { margin: 0 0 10px; }

.logo {
  margin: 0 0 12px;
  font-size: clamp(1.5rem, min(7vh, 8vw), 3rem);
  line-height: .95;
  letter-spacing: .05em;
  color: var(--accent);
}
@media (max-height: 460px) { .logo { margin-bottom: 6px; } }

#tabs { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-bottom: 14px; }
#tabs button { font-weight: 700; font-size: .9rem; letter-spacing: .05em; background: transparent; border: 2px solid var(--panel-edge); }
#tabs button.on { background: var(--panel-edge); }

#onlineNow { margin: 0 0 10px; font-weight: 800; color: var(--hp); }
#modes { margin: 0 0 12px; }
#modes button { display: grid; gap: 2px; min-width: 150px; font-weight: 800; background: #122634; border: 2px solid var(--panel-edge); }
#modes button.on { border-color: var(--accent); color: var(--accent); }
#modes small { font-weight: 400; color: var(--muted); font-size: .76rem; }
#board li.red { color: #ff8d80; }
#board li.blue { color: #7dc4ff; }
#teamLabel.red { color: #ff8d80; }
#teamLabel.blue { color: #7dc4ff; }
#playForm { display: grid; gap: 10px; max-width: 340px; margin: 0 auto; }
.error { color: var(--bad); min-height: 1.1em; margin: 0; font-size: .92rem; }
.hint { color: var(--muted); font-size: .86rem; margin: 10px 0 0; }
.row { display: flex; gap: 10px; justify-content: center; align-items: center; margin-top: 10px; flex-wrap: wrap; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud button { pointer-events: auto; }

#topleft {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  max-width: 55vw;
}
.chip {
  background: rgba(10, 24, 34, .72);
  border-radius: 10px;
  padding: 8px 12px;
  font-weight: 700;
  font-size: .92rem;
  min-height: 38px;
}
.chip.static { display: flex; align-items: center; color: var(--accent); }

#topright {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  width: 150px;
  text-align: right;
  font-size: .82rem;
}
#minimap {
  width: 150px;
  height: 150px;
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, .28);
  background: #0b1822;
  pointer-events: auto;
  cursor: pointer;
  display: block;
}
#online { margin-top: 4px; color: var(--muted); font-weight: 700; text-shadow: 0 1px 2px #000; }
#board { list-style: none; margin: 2px 0 0; padding: 0; }
#board li { display: flex; justify-content: space-between; gap: 6px; padding: 1px 0; text-shadow: 0 1px 2px #000; }
#board li span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#board li.me { color: var(--accent); font-weight: 700; }
#board li.fire { color: #ffa23c; font-weight: 800; }

#bars {
  position: absolute;
  left: 50%;
  bottom: max(10px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(380px, 42vw);
  display: grid;
  gap: 4px;
}
.bar { position: relative; height: 18px; border-radius: 9px; background: rgba(8, 18, 26, .8); overflow: hidden; }
.bar i { position: absolute; inset: 0 auto 0 0; display: block; width: 0; border-radius: 9px; }
.bar span { position: absolute; inset: 0; text-align: center; font-size: .74rem; font-weight: 800; line-height: 18px; text-shadow: 0 1px 2px #000; }
#hpBar i { background: var(--hp); }
#shieldBar i { background: var(--shield); }
#xpBar i { background: var(--xp); }

#evolve {
  position: absolute;
  top: 10vh;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  max-width: calc(100vw - 340px);
}
#evolve button {
  background: rgba(24, 47, 63, .94);
  border: 2px solid var(--accent);
  width: 142px;
  min-height: 118px;
  padding: 10px 8px;
  display: grid;
  gap: 4px;
  justify-items: center;
  text-align: center;
}
#evolve b { color: var(--accent); font-size: 1.05rem; letter-spacing: .04em; }
#evolve small { color: var(--muted); font-size: .76rem; line-height: 1.15; }
#evolve kbd { font: inherit; font-size: .7rem; color: var(--muted); }
#evolve canvas { width: 54px; height: 54px; }

#tutorial {
  position: absolute;
  top: 34%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 24, 34, .8);
  padding: 10px 18px;
  border-radius: 12px;
  font-weight: 700;
  text-align: center;
  max-width: 70vw;
}

#toast {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: var(--accent-ink);
  padding: 8px 18px;
  border-radius: 12px;
  font-weight: 800;
  white-space: nowrap;
}

#diag {
  position: absolute;
  left: 8px;
  top: 60px;
  margin: 0;
  font: 12px/1.3 Consolas, monospace;
  background: rgba(0, 0, 0, .6);
  padding: 6px 8px;
  border-radius: 8px;
}

#banner {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  background: var(--bad);
  color: #2c0c07;
  font-weight: 800;
  padding: 8px 18px;
  border-radius: 12px;
}

#bigmap canvas { width: min(92vh, 92vw); height: min(92vh, 92vw); border-radius: 18px; background: #0b1822; }

#rotate { display: none; z-index: 40; background: var(--bg); }
@media (orientation: portrait) and (pointer: coarse) { #rotate { display: flex; } }

#spree {
  position: absolute;
  top: 22%;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  white-space: nowrap;
  text-shadow: 0 2px 6px #000, 0 0 18px rgba(255, 90, 28, .9);
  animation: spreePop .28s ease-out;
}
#spree small { display: block; font-size: 1.1rem; font-weight: 800; }
#spree b { display: block; font-size: clamp(2rem, 8vh, 4rem); color: #ffb52e; letter-spacing: .04em; line-height: 1; }
@keyframes spreePop { from { transform: translateX(-50%) scale(1.6); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }
#boosts {
  position: absolute;
  left: 50%;
  bottom: 74px;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
}
#boosts span { padding: 4px 12px; border-radius: 10px; font-weight: 800; font-size: .85rem; color: #fff; }
#boosts .speed { background: #1b6fa6; }
#boosts .damage { background: #a02a1c; }
#feed {
  position: absolute;
  top: 104px;
  left: max(8px, env(safe-area-inset-left));
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: .95rem;
  font-weight: 800;
  text-shadow: 0 1px 2px #000;
}
#feed li { padding: 3px 10px; margin-bottom: 3px; border-radius: 8px; background: rgba(10, 24, 34, .72); width: fit-content; }
#feed li.leader { color: var(--accent); border: 1px solid var(--accent); }
#announce {
  position: absolute;
  top: 12%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 24, 34, .85);
  border: 2px solid var(--accent);
  color: var(--accent);
  padding: 8px 18px;
  border-radius: 12px;
  font-weight: 800;
  white-space: nowrap;
}

/* Info */
.info { text-align: left; }
.info h3 { margin: 10px 0 2px; color: var(--accent); font-size: .95rem; }
.info ul { margin: 0; padding-left: 18px; font-size: .86rem; }
.info li { margin: 2px 0; }
.infoTabs { display: flex; gap: 6px; justify-content: center; margin-bottom: 8px; }
.infoTabs button.on { background: var(--accent); color: var(--accent-ink); font-weight: 800; }
.tierTitle { margin: 10px 0 4px; color: var(--muted); font-size: .8rem; font-weight: 800; letter-spacing: .05em; }
.classes { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.classCard { display: grid; grid-template-columns: 54px 1fr; gap: 8px; background: #122634; border-radius: 12px; padding: 8px; }
.classCard canvas { width: 54px; height: 54px; }
.classCard b { color: var(--accent); }
.classCard small { display: block; font-size: .76rem; line-height: 1.15; }
.classCard small.from { color: var(--muted); }
.stat { display: grid; grid-template-columns: 46px 1fr; gap: 4px; align-items: center; font-size: .66rem; color: var(--muted); margin-top: 2px; }
.stat i { display: block; height: 5px; border-radius: 3px; background: var(--accent); }

/* Collection and profile */
.collections { display: grid; gap: 10px; text-align: left; }
.collection { background: #122634; border-radius: 12px; padding: 10px 12px; }
.collection header { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-weight: 800; }
.collection header button { font-size: .8rem; padding: 5px 10px; }
.collection header button.on { background: var(--accent); color: var(--accent-ink); }
.skins { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.skin { background: #0c1a24; border: 2px solid transparent; border-radius: 10px; padding: 4px; width: 84px; font-size: .7rem; text-align: center; line-height: 1.15; }
.skin canvas { width: 54px; height: 54px; display: block; margin: 0 auto 2px; }
.skin.locked { opacity: .45; }
.skin.on { border-color: var(--accent); }
.progress { height: 8px; background: #0c1a24; border-radius: 4px; overflow: hidden; margin-top: 6px; }
.progress i { display: block; height: 100%; background: var(--accent); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin: 8px 0; }
.stats div { background: #122634; border-radius: 10px; padding: 8px; font-size: .8rem; color: var(--muted); }
.stats b { display: block; font-size: 1.15rem; color: var(--ink); }
.code { font: 700 1.3rem Consolas, monospace; letter-spacing: .12em; color: var(--accent); margin: 6px 0; -webkit-user-select: all; user-select: all; }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; text-align: left; }

@media (max-width: 760px) {
  #evolve { top: 200px; max-width: 96vw; width: max-content; gap: 6px; }
  #evolve button { width: 104px; min-width: 0; min-height: 92px; padding: 6px 2px; }
  #evolve b { font-size: .85rem; }
  #evolve small { display: none; }
  #tutorial { top: 58%; }
}

@media (max-height: 480px) {
  #feed { top: 84px; font-size: .74rem; }
  #boosts { bottom: 50px; }
  #spree { top: 16%; }
  #announce { font-size: .8rem; padding: 5px 12px; }
  #topright, #minimap { width: 104px; }
  #minimap { height: 104px; }
  #board li:nth-child(n+5) { display: none; }
  .chip { font-size: .8rem; padding: 6px 9px; min-height: 34px; }
  #bars { width: 30vw; gap: 3px; }
  .bar { height: 14px; }
  .bar span { font-size: .62rem; line-height: 14px; }
  #evolve { top: 44px; max-width: calc(100vw - 230px); width: auto; }
  #tutorial { top: 24%; }
  #evolve button { width: 110px; min-width: 0; min-height: 92px; padding: 6px 2px; }
  #evolve b { font-size: .85rem; }
  #evolve small { display: none; }
  .panel { padding: 12px 16px; }
}
