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

body {
  background: #0a0a1a;
  overflow: hidden;
  font-family: 'Courier New', Courier, monospace;
  color: #ffffff;
  user-select: none;
}

#game-container {
  position: relative;
  width: 100vw;
  height: 100vh;
}

#game-canvas {
  display: block;
  position: absolute;
  top: 0; left: 0;
}

/* ── HUD ── */
#hud {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  pointer-events: none;
  z-index: 10;
}

#stats-bar {
  display: flex;
  gap: 24px;
  padding: 12px 16px;
  font-size: 13px;
  color: #8888bb;
  text-transform: uppercase;
  letter-spacing: 1px;
}

#stats-bar .stat-val {
  color: #ffffff;
  font-size: 15px;
  font-weight: bold;
}

#top-right {
  position: absolute;
  top: 10px;
  right: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

#power-inventory {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}

.power-slot {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  padding: 4px 10px 4px 8px;
}

.power-icon {
  font-size: 18px;
  filter: drop-shadow(0 0 6px currentColor);
}

.power-name {
  font-size: 13px;
  font-family: 'Courier New', monospace;
  font-weight: bold;
  letter-spacing: 1px;
  text-transform: uppercase;
}

#life-bar-wrap {
  width: 180px;
  height: 12px;
  background: rgba(255,255,255,0.08);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.15);
}

#life-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #00ff88, #00cc66);
  border-radius: 6px;
  transition: width 0.3s ease, background 0.5s ease;
}

#active-effects {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.effect-tag {
  font-size: 11px;
  border: 1px solid;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ── Input display ── */
#input-wrap {
  position: absolute;
  bottom: 20px;
  left: 20px;
  pointer-events: none;
  z-index: 10;
}

#input-display {
  font-size: 22px;
  color: #ffffcc;
  letter-spacing: 2px;
  min-width: 4px;
}

#input-display::after {
  content: '|';
  animation: blink 1s step-end infinite;
  color: #ffff88;
}

@keyframes blink {
  50% { opacity: 0; }
}

#input-prefix {
  color: #888;
  font-size: 18px;
  margin-right: 4px;
}

/* ── Level banner ── */
#level-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  font-size: 48px;
  font-weight: 900;
  letter-spacing: 8px;
  color: #ffffff;
  text-shadow: 0 0 30px #aaaaff, 0 0 60px #6666ff;
  opacity: 0;
  pointer-events: none;
  z-index: 20;
  transition: opacity 0.3s, transform 0.3s;
}

#level-banner.visible {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

/* ── Overlay (start / game over) ── */
#game-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 26, 0.85);
  backdrop-filter: blur(4px);
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s;
}

#game-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

#overlay-title {
  font-size: 52px;
  font-weight: 900;
  letter-spacing: 10px;
  color: #fff;
  text-shadow: 0 0 20px #6688ff, 0 0 50px #4466cc;
  margin-bottom: 16px;
}

#overlay-stats {
  font-size: 16px;
  color: #aaaacc;
  text-align: center;
  line-height: 1.9;
  margin-bottom: 32px;
}

#overlay-btn {
  padding: 12px 40px;
  font-size: 16px;
  font-family: 'Courier New', monospace;
  font-weight: bold;
  letter-spacing: 3px;
  text-transform: uppercase;
  background: transparent;
  color: #ffffff;
  border: 2px solid #6688ff;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
}

#overlay-btn:hover {
  background: rgba(102, 136, 255, 0.2);
  box-shadow: 0 0 20px rgba(102, 136, 255, 0.5);
}

/* ── CSS2D Word Labels ── */
.word {
  font-family: 'Courier New', Courier, monospace;
  font-size: 18px;
  font-weight: bold;
  color: #e0e0ff;
  white-space: nowrap;
  letter-spacing: 2px;
  padding: 2px 6px;
  border-radius: 3px;
  transition: color 0.1s;
}

.word--targeted {
  background: rgba(255, 255, 180, 0.08);
  border: 1px solid rgba(255, 255, 180, 0.3);
  color: #ffffcc;
}

.word--targeted .typed {
  color: #88ff88;
  text-decoration: none;
}

/* Power word glows */
.word--power-clear {
  color: #FFD700;
  animation: pulse-glow 1.2s ease-in-out infinite alternate;
  --glow-color: #FFD700;
}

.word--power-ice {
  color: #00FFFF;
  animation: pulse-glow 1.2s ease-in-out infinite alternate;
  --glow-color: #00FFFF;
}

.word--power-slow {
  color: #c084fc;
  animation: pulse-glow 1.2s ease-in-out infinite alternate;
  --glow-color: #9B59B6;
}

.word--power-shorten {
  color: #FF6B35;
  animation: pulse-glow 1.2s ease-in-out infinite alternate;
  --glow-color: #FF6B35;
}

@keyframes pulse-glow {
  from { text-shadow: 0 0 6px var(--glow-color), 0 0 12px var(--glow-color); }
  to   { text-shadow: 0 0 12px var(--glow-color), 0 0 28px var(--glow-color), 0 0 50px var(--glow-color); }
}

/* Portal word */
.word--portal {
  font-size: 20px;
  letter-spacing: 4px;
  padding: 4px 12px;
  border-radius: 6px;
  border: 1px solid rgba(200, 120, 255, 0.5);
  animation: portal-rainbow 2s linear infinite;
}

@keyframes portal-rainbow {
  0%   { color: #ff66ff; text-shadow: 0 0 10px #ff66ff, 0 0 30px #ff66ff; }
  25%  { color: #66ccff; text-shadow: 0 0 10px #66ccff, 0 0 30px #66ccff; }
  50%  { color: #66ffcc; text-shadow: 0 0 10px #66ffcc, 0 0 30px #66ffcc; }
  75%  { color: #ffcc66; text-shadow: 0 0 10px #ffcc66, 0 0 30px #ffcc66; }
  100% { color: #ff66ff; text-shadow: 0 0 10px #ff66ff, 0 0 30px #ff66ff; }
}

/* ── Overlay actions row ── */
#overlay-actions {
  display: flex;
  flex-direction: row;
  gap: 12px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

.overlay-extra-btn {
  padding: 12px 28px;
  font-size: 14px;
  font-family: 'Courier New', monospace;
  font-weight: bold;
  letter-spacing: 3px;
  text-transform: uppercase;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
  display: none;
}

.overlay-extra-btn--portal {
  color: #cc88ff;
  border: 2px solid #cc88ff;
}

.overlay-extra-btn--portal:hover {
  background: rgba(204, 136, 255, 0.2);
  box-shadow: 0 0 20px rgba(204, 136, 255, 0.5);
}

.overlay-extra-btn--scoreboard {
  color: #88aabb;
  border: 2px solid #556677;
}

.overlay-extra-btn--scoreboard:hover {
  background: rgba(85, 102, 119, 0.25);
  box-shadow: 0 0 20px rgba(136, 170, 187, 0.4);
}

#game-overlay.gameover .overlay-extra-btn {
  display: block;
}

/* ── Rank display in stats bar ── */
#rank-display {
  color: #8888bb;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 13px;
}

#stat-rank {
  font-size: 15px;
  font-weight: bold;
  color: #ffffff;
}

#stat-rank.rank-gold {
  color: #FFD700;
  text-shadow: 0 0 8px #FFD700;
}

#stat-rank.rank-silver {
  color: #b0b0cc;
  text-shadow: 0 0 6px #aaaacc;
}

/* ── Username overlay ── */
#username-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 26, 0.92);
  backdrop-filter: blur(4px);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s;
}

#username-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

#username-title {
  font-size: 52px;
  font-weight: 900;
  letter-spacing: 10px;
  color: #fff;
  text-shadow: 0 0 20px #6688ff, 0 0 50px #4466cc;
  margin-bottom: 12px;
}

#username-subtitle {
  font-size: 16px;
  color: #aaaacc;
  margin-bottom: 6px;
  letter-spacing: 1px;
}

#username-twitter-hint {
  font-size: 13px;
  color: #667799;
  margin-bottom: 28px;
  letter-spacing: 1px;
}

#username-input-wrap {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

#username-input {
  background: rgba(10, 10, 30, 0.9);
  border: 2px solid #334466;
  border-radius: 4px;
  color: #ffffff;
  font-family: 'Courier New', monospace;
  font-size: 18px;
  letter-spacing: 2px;
  padding: 10px 16px;
  outline: none;
  width: 260px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#username-input::placeholder {
  color: #445566;
}

#username-input:focus {
  border-color: #6688ff;
  box-shadow: 0 0 14px rgba(102, 136, 255, 0.5);
}

#username-avatar-preview img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid #cc88ff;
}

#username-error {
  font-size: 13px;
  color: #ff5555;
  min-height: 18px;
  margin-bottom: 18px;
  letter-spacing: 1px;
}

#username-btn {
  padding: 12px 40px;
  font-size: 16px;
  font-family: 'Courier New', monospace;
  font-weight: bold;
  letter-spacing: 3px;
  text-transform: uppercase;
  background: transparent;
  color: #ffffff;
  border: 2px solid #6688ff;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
}

#username-btn:hover {
  background: rgba(102, 136, 255, 0.2);
  box-shadow: 0 0 20px rgba(102, 136, 255, 0.5);
}

/* ── Scoreboard overlay ── */
#scoreboard-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 40px 20px 30px;
  background: rgba(10, 10, 26, 0.93);
  backdrop-filter: blur(6px);
  z-index: 45;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s;
  overflow-y: auto;
}

#scoreboard-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

#scoreboard-title {
  font-size: 38px;
  font-weight: 900;
  letter-spacing: 8px;
  color: #fff;
  text-shadow: 0 0 20px #6688ff, 0 0 50px #4466cc;
  margin-bottom: 28px;
  flex-shrink: 0;
}

#scoreboard-list {
  width: 100%;
  max-width: 560px;
  max-height: 60vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 28px;
}

#scoreboard-list::-webkit-scrollbar {
  width: 4px;
}

#scoreboard-list::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.04);
}

#scoreboard-list::-webkit-scrollbar-thumb {
  background: rgba(102, 136, 255, 0.4);
  border-radius: 2px;
}

.score-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 6px;
  padding: 8px 14px;
  transition: background 0.15s;
}

.score-entry:hover {
  background: rgba(102, 136, 255, 0.07);
}

.score-rank {
  font-size: 14px;
  font-weight: bold;
  color: #8888bb;
  min-width: 28px;
  text-align: right;
}

.score-rank.rank-1 { color: #FFD700; text-shadow: 0 0 8px #FFD700; }
.score-rank.rank-2 { color: #C0C0C0; text-shadow: 0 0 6px #C0C0C0; }
.score-rank.rank-3 { color: #CD7F32; text-shadow: 0 0 6px #CD7F32; }

.score-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.score-avatar-placeholder {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #334466, #223355);
  border: 1px solid rgba(102, 136, 255, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: bold;
  color: #aabbdd;
  flex-shrink: 0;
  text-transform: uppercase;
}

.score-username {
  flex: 1;
  font-size: 14px;
  font-weight: bold;
  color: #ccddff;
  letter-spacing: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

a.score-username {
  text-decoration: none;
  color: #cc88ff;
  transition: text-decoration 0.15s;
}

a.score-username:hover {
  text-decoration: underline;
}

.score-val {
  font-size: 18px;
  font-weight: bold;
  color: #ffffff;
  min-width: 70px;
  text-align: right;
}

.score-meta {
  font-size: 11px;
  color: #667799;
  min-width: 80px;
  text-align: right;
  letter-spacing: 0.5px;
  line-height: 1.5;
}

#scoreboard-close {
  padding: 12px 40px;
  font-size: 15px;
  font-family: 'Courier New', monospace;
  font-weight: bold;
  letter-spacing: 3px;
  text-transform: uppercase;
  background: transparent;
  color: #ffffff;
  border: 2px solid #6688ff;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
  flex-shrink: 0;
}

#scoreboard-close:hover {
  background: rgba(102, 136, 255, 0.2);
  box-shadow: 0 0 20px rgba(102, 136, 255, 0.5);
}

/* ── Portal confirmation overlay ── */
#portal-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(10, 0, 26, 0.92);
  backdrop-filter: blur(8px);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

#portal-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

#portal-ring {
  font-size: 80px;
  animation: portal-rainbow 2s linear infinite;
  margin-bottom: 8px;
  filter: drop-shadow(0 0 20px #cc66ff);
}

#portal-title {
  font-size: 32px;
  font-weight: 900;
  letter-spacing: 6px;
  color: #cc88ff;
  text-shadow: 0 0 20px #cc66ff, 0 0 50px #9933cc;
  margin-bottom: 14px;
  font-family: 'Courier New', monospace;
}

#portal-desc {
  font-size: 15px;
  color: #9988bb;
  text-align: center;
  margin-bottom: 36px;
  letter-spacing: 1px;
}

#portal-buttons {
  display: flex;
  gap: 20px;
}

#portal-yes, #portal-no {
  padding: 12px 36px;
  font-size: 14px;
  font-family: 'Courier New', monospace;
  font-weight: bold;
  letter-spacing: 3px;
  text-transform: uppercase;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s;
}

#portal-yes {
  background: transparent;
  color: #cc88ff;
  border: 2px solid #cc88ff;
}

#portal-yes:hover {
  background: rgba(200, 136, 255, 0.2);
  box-shadow: 0 0 24px rgba(200, 136, 255, 0.6);
}

#portal-no {
  background: transparent;
  color: #667799;
  border: 2px solid #445566;
}

#portal-no:hover {
  background: rgba(80, 100, 140, 0.2);
}

/* ── Scoreboard tabs ── */
#scoreboard-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-shrink: 0;
}

.score-tab {
  padding: 8px 28px;
  font-size: 13px;
  font-family: 'Courier New', monospace;
  font-weight: bold;
  letter-spacing: 2px;
  text-transform: uppercase;
  background: transparent;
  color: #556688;
  border: 1px solid #334455;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.score-tab.active {
  color: #aaccff;
  border-color: #6688ff;
  background: rgba(102, 136, 255, 0.12);
}

.score-tab:hover:not(.active) {
  color: #8899bb;
  border-color: #445577;
}

/* ── Tap-to-type hint (mobile only) ── */
#tap-hint {
  position: absolute;
  bottom: 64px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: rgba(136, 136, 187, 0.5);
  letter-spacing: 2px;
  text-transform: uppercase;
  pointer-events: none;
  z-index: 10;
  display: none;
}

/* Show only on touch devices */
@media (hover: none) and (pointer: coarse) {
  #tap-hint { display: block; }
  /* Bigger touch targets for buttons */
  #overlay-btn, .overlay-extra-btn, #username-btn,
  #scoreboard-close, #portal-yes, #portal-no, .score-tab {
    min-height: 48px;
  }
}

/* ── Responsive: small screens ── */
@media (max-width: 600px) {
  #stats-bar {
    gap: 10px;
    padding: 8px 10px;
    font-size: 11px;
    flex-wrap: wrap;
  }
  #stats-bar .stat-val { font-size: 12px; }

  #top-right { top: 6px; right: 10px; gap: 5px; }
  #life-bar-wrap { width: 110px; height: 10px; }
  .power-slot { padding: 3px 7px; }
  .power-name { font-size: 11px; }
  .power-icon { font-size: 14px; }

  .word { font-size: 14px; letter-spacing: 1px; padding: 1px 4px; }
  .word--portal { font-size: 15px; letter-spacing: 2px; padding: 3px 8px; }

  #input-wrap { bottom: 12px; left: 10px; }
  #input-display { font-size: 18px; letter-spacing: 1px; }
  #input-prefix { font-size: 16px; }

  #overlay-title { font-size: 34px; letter-spacing: 6px; margin-bottom: 12px; }
  #overlay-stats { font-size: 14px; margin-bottom: 20px; }
  #overlay-actions { flex-direction: column; align-items: stretch; gap: 10px; }
  #overlay-btn, .overlay-extra-btn { padding: 14px 20px; font-size: 14px; letter-spacing: 2px; }

  #username-title { font-size: 34px; letter-spacing: 6px; }
  #username-subtitle { font-size: 14px; }
  #username-twitter-hint { font-size: 11px; margin-bottom: 20px; }
  #username-input { width: 200px; font-size: 16px; padding: 10px 12px; }
  #username-input-wrap { flex-direction: column; align-items: center; }

  #scoreboard-overlay { padding: 16px 10px 16px; }
  #scoreboard-title { font-size: 26px; letter-spacing: 5px; margin-bottom: 16px; }
  #scoreboard-list { max-height: 52vh; }
  .score-entry { padding: 6px 8px; gap: 8px; }
  .score-rank { min-width: 22px; font-size: 12px; }
  .score-avatar, .score-avatar-placeholder { width: 26px; height: 26px; font-size: 11px; }
  .score-username { font-size: 13px; }
  .score-val { font-size: 14px; min-width: 52px; }
  .score-meta { font-size: 10px; min-width: 52px; }

  #portal-ring { font-size: 56px; }
  #portal-title { font-size: 22px; letter-spacing: 4px; }
  #portal-desc { font-size: 13px; margin-bottom: 24px; }
  #portal-buttons { flex-direction: column; gap: 10px; align-items: stretch; }
  #portal-yes, #portal-no { padding: 14px 20px; text-align: center; }

  #level-banner { font-size: 36px; letter-spacing: 5px; }
}
