* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --ink: #1c2333;
  --panel: rgba(255, 255, 255, 0.94);
  --accent: #ff4757;
  --accent-dark: #d63447;
  --mustard: #ffd32a;
  --sky-top: #6ec6ff;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: #0d1322;
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
}

#stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#frame {
  position: relative;
  width: min(100vw, calc(100vh * 16 / 9));
  height: min(100vh, calc(100vw * 9 / 16));
}

#cv {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 0;
  cursor: crosshair;
  touch-action: none;
}

.hidden { display: none !important; }

/* ---------- overlays ---------- */
#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
#overlay:empty, #overlay.gone { display: none; }

.panel {
  pointer-events: auto;
  background: var(--panel);
  border-radius: 24px;
  padding: 36px 44px;
  width: min(420px, calc(100vw - 32px));
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45), 0 2px 0 rgba(255,255,255,0.6) inset;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
}

.title {
  font-family: 'Titan One', 'Nunito', sans-serif;
  font-size: 52px;
  line-height: 0.95;
  letter-spacing: 1px;
  color: var(--accent);
  text-shadow: 0 3px 0 var(--accent-dark), 0 8px 18px rgba(214, 52, 71, 0.35);
}
.title::after {
  content: " 🌭";
  font-size: 40px;
  text-shadow: none;
}

.tagline {
  font-weight: 700;
  color: #7a8296;
  font-size: 14px;
}

input {
  font-family: inherit;
  font-weight: 800;
  font-size: 18px;
  text-align: center;
  padding: 13px 16px;
  border-radius: 14px;
  border: 3px solid #dfe4ee;
  background: #f4f6fb;
  color: var(--ink);
  width: 100%;
  outline: none;
  transition: border-color 0.15s;
}
input:focus { border-color: var(--accent); }
input::placeholder { color: #aab2c5; font-weight: 700; }

#codeInput { text-transform: uppercase; letter-spacing: 6px; width: 130px; }

.btn {
  font-family: inherit;
  font-weight: 900;
  font-size: 17px;
  letter-spacing: 0.5px;
  padding: 13px 22px;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--accent-dark), 0 10px 20px rgba(214, 52, 71, 0.3);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-dark); }
.btn:disabled { filter: grayscale(0.7) brightness(0.95); cursor: default; box-shadow: 0 4px 0 #9aa1b1; }
.btn.big { width: 100%; font-size: 20px; padding: 16px 22px; }
.btn.ghost {
  background: #eef1f8;
  color: #55607a;
  box-shadow: 0 3px 0 #d4dae8;
  font-size: 14px;
  padding: 10px 18px;
}
.btn.ghost:active { box-shadow: 0 1px 0 #d4dae8; }

.divider {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #aab2c5;
  font-weight: 700;
  font-size: 13px;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 2px; background: #e6eaf3; border-radius: 2px; }

.joinrow { display: flex; gap: 10px; width: 100%; justify-content: center; }

.error { color: var(--accent-dark); font-weight: 800; font-size: 14px; }
.hint { color: #97a0b5; font-weight: 700; font-size: 13px; }

/* ---------- lobby ---------- */
.lobbylabel { font-weight: 900; font-size: 13px; letter-spacing: 3px; color: #97a0b5; }
#codeBig {
  font-family: 'Titan One', sans-serif;
  font-size: 64px;
  letter-spacing: 14px;
  padding-left: 14px; /* offset letter-spacing */
  color: var(--ink);
  line-height: 1;
}
#playerList { width: 100%; display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.prow {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #f4f6fb;
  border-radius: 12px;
  padding: 10px 16px;
  font-weight: 800;
  font-size: 16px;
}
.pdot { width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 0 3px rgba(0,0,0,0.08) inset; }
.pcrown { margin-left: auto; }

/* ---------- game over ---------- */
#winnerEmoji { font-size: 64px; }
#gameover h2 { font-family: 'Titan One', sans-serif; font-size: 34px; }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }

#topbar {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  pointer-events: none;
}
.chip {
  background: rgba(13, 19, 34, 0.72);
  border-radius: 12px;
  padding: 7px 12px 8px;
  min-width: 108px;
  color: #fff;
  border-top: 3px solid transparent;
  transition: opacity 0.3s;
}
.chip.dead { opacity: 0.45; }
.chip.turn { box-shadow: 0 0 0 2px var(--mustard), 0 6px 18px rgba(0,0,0,0.4); }
.chip .cname { font-weight: 800; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
.chip .hpbar { height: 6px; border-radius: 4px; background: rgba(255,255,255,0.18); margin-top: 5px; overflow: hidden; }
.chip .hpfill { height: 100%; border-radius: 4px; background: #2ed573; transition: width 0.4s ease, background 0.4s; }

#windbox {
  position: absolute;
  top: 74px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(13, 19, 34, 0.72);
  color: #fff;
  border-radius: 999px;
  padding: 6px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 900;
  font-size: 13px;
  pointer-events: none;
}
.windlabel { letter-spacing: 2px; color: #8fa0c4; font-size: 11px; }
#windarrow { font-size: 18px; display: inline-block; color: var(--mustard); }

#timer {
  position: absolute;
  top: 14px;
  right: 18px;
  font-family: 'Titan One', sans-serif;
  font-size: 26px;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0,0,0,0.5);
  pointer-events: none;
}
#timer.low { color: var(--accent); animation: pulse 0.5s infinite alternate; }
@keyframes pulse { to { transform: scale(1.15); } }

#banner {
  position: absolute;
  top: 34%;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Titan One', sans-serif;
  font-size: 44px;
  color: #fff;
  text-shadow: 0 4px 0 rgba(0,0,0,0.35), 0 12px 30px rgba(0,0,0,0.4);
  animation: bannerIn 0.35s cubic-bezier(0.2, 1.6, 0.4, 1);
  pointer-events: none;
  white-space: nowrap;
}
@keyframes bannerIn { from { transform: translateX(-50%) scale(0.4); opacity: 0; } }

#tray {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
}
.wbtn {
  font-family: inherit;
  font-weight: 800;
  font-size: 13px;
  color: #fff;
  background: rgba(13, 19, 34, 0.78);
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-radius: 14px;
  padding: 8px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: transform 0.08s, border-color 0.1s;
}
.wbtn .wicon { font-size: 22px; }
.wbtn .wammo { font-size: 11px; color: #8fa0c4; }
.wbtn:hover { transform: translateY(-2px); }
.wbtn.sel { border-color: var(--mustard); box-shadow: 0 0 14px rgba(255, 211, 42, 0.35); }
.wbtn:disabled { opacity: 0.35; cursor: default; transform: none; }
.wkey { position: absolute; top: -7px; left: -7px; background: var(--mustard); color: #5c4a00; font-size: 10px; font-weight: 900; border-radius: 6px; padding: 1px 5px; }
.wbtn { position: relative; }

#powerwrap {
  position: absolute;
  bottom: 86px;
  left: 50%;
  transform: translateX(-50%);
  width: 300px;
  height: 18px;
  border-radius: 999px;
  background: rgba(13, 19, 34, 0.78);
  border: 2px solid rgba(255,255,255,0.2);
  overflow: hidden;
  pointer-events: none;
}
#powerbar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #2ed573, var(--mustard), var(--accent));
}

#controlshint {
  position: absolute;
  bottom: 16px;
  left: 18px;
  color: rgba(255, 255, 255, 0.75);
  font-weight: 700;
  font-size: 12px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
  pointer-events: none;
}
#controlshint b { color: var(--mustard); }
