/* ─── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Covers the areas behind the iOS status bar / Safari chrome */
html { background-color: #080b18; }

body {
  font-family: 'Courier New', monospace;
  background: radial-gradient(ellipse at center, #1e2245 0%, #080b18 100%) #080b18;
  color: #c8c4e8;
  min-height: 100vh;
  min-height: 100dvh; /* dynamic viewport — correct on iOS Safari */
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-x: hidden;
  /* extend content behind iOS notch / home indicator */
  padding-top:    env(safe-area-inset-top,    0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left:   env(safe-area-inset-left,   0px);
  padding-right:  env(safe-area-inset-right,  0px);
}

/* ─── Screens ──────────────────────────────────────────────────────────────── */
.screen         { display: none; width: 100%; }
.screen.active  { display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.screen.hidden  { display: none !important; }
.hidden         { display: none !important; }

/* ─── Typography ───────────────────────────────────────────────────────────── */
h1 {
  font-size: 2.4rem;
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, #a78bfa, #60a5fa, #34d399);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
}

.subtitle {
  color: #7c78a8;
  font-size: 0.82rem;
  text-align: center;
  letter-spacing: 0.05em;
}

/* ─── Inputs ───────────────────────────────────────────────────────────────── */
input[type="text"] {
  width: 100%;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(167,139,250,0.3);
  border-radius: 8px;
  padding: 0.55rem 1rem;
  color: #e2dff8;
  font-family: inherit;
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}
input[type="text"]:focus   { border-color: #a78bfa; }
input[type="text"]::placeholder { color: #4e4a72; }

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.55rem 1.4rem;
  border-radius: 8px;
  border: 1px solid rgba(167,139,250,0.4);
  background: rgba(255,255,255,0.05);
  color: #c8c4e8;
  font-family: inherit;
  font-size: 0.92rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: rgba(167,139,250,0.12); border-color: #a78bfa; }
.btn.primary {
  background: linear-gradient(135deg, #7c3aed, #3b82f6);
  border: none;
  color: #fff;
  font-weight: 700;
}
.btn.primary:hover:not(:disabled) { box-shadow: 0 0 18px rgba(124,58,237,0.5); }
.btn.small   { padding: 0.32rem 0.85rem; font-size: 0.8rem; }
.btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  filter: grayscale(0.4);
}

/* ─── Home screen ──────────────────────────────────────────────────────────── */
#home-section {
  max-width: 440px;
  width: 100%;
  padding: 2rem 1.5rem;
}

.account-display {
  font-size: 0.85rem;
  color: #7c78a8;
  text-align: center;
}
.account-display strong { color: #a78bfa; font-size: 1rem; }

.login-prompt {
  font-size: 0.85rem;
  color: #7c78a8;
  text-align: center;
  padding: 0.6rem 1rem;
  border: 1px solid rgba(255,100,100,0.25);
  border-radius: 8px;
  background: rgba(255,70,70,0.05);
}
.login-prompt a { color: #a78bfa; text-decoration: underline; }

/* Create/join area */
.room-actions { width: 100%; display: flex; flex-direction: column; gap: 0.65rem; }

.create-row { display: flex; align-items: center; gap: 0.75rem; }
.create-row .btn { flex: 1; }

.private-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: #7c78a8;
  cursor: pointer;
  white-space: nowrap;
}
.private-label input { accent-color: #a78bfa; cursor: pointer; }

.divider { text-align: center; color: #4e4a72; font-size: 0.78rem; letter-spacing: 0.05em; }

.join-row { display: flex; gap: 0.5rem; }
.join-row input { flex: 1; text-transform: uppercase; letter-spacing: 0.15em; }

#status-msg { min-height: 1.1em; font-size: 0.82rem; text-align: center; color: #aaa8cc; }

/* Open rooms list */
.rooms-section { width: 100%; }

.rooms-title {
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #5e5a82;
  margin-bottom: 0.5rem;
  text-align: center;
}

.room-list { display: flex; flex-direction: column; gap: 0.4rem; min-height: 2.5rem; }

.rooms-empty { text-align: center; font-size: 0.82rem; color: #4e4a72; padding: 0.5rem; }

.room-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(167,139,250,0.15);
  border-radius: 8px;
  padding: 0.45rem 0.75rem;
  font-size: 0.82rem;
}
.room-row-host  { flex: 1; font-weight: 600; color: #c8c4e8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-row-count { color: #7c78a8; white-space: nowrap; }
.room-row-code  { font-weight: 700; letter-spacing: 0.12em; color: #a78bfa; width: 3em; text-align: center; }

/* ─── Lobby screen ─────────────────────────────────────────────────────────── */
#lobby-section {
  max-width: 500px;
  width: 100%;
  padding: 2rem 1.5rem;
}

.lobby-top { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 0.75rem; }

.room-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(167,139,250,0.2);
  border-radius: 12px;
  padding: 0.55rem 1rem;
  width: 100%;
}

.room-code-block { display: flex; align-items: center; gap: 0.5rem; flex: 1; min-width: 0; }
.room-label { font-size: 0.72rem; color: #7c78a8; letter-spacing: 0.08em; text-transform: uppercase; flex-shrink: 0; }

.room-code {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: #a78bfa;
  cursor: pointer;
  border-radius: 4px;
  padding: 0 0.2em;
  transition: background 0.15s;
}
.room-code:hover { background: rgba(167,139,250,0.12); }

.private-badge {
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #ff9f7f;
  border: 1px solid rgba(255,159,127,0.4);
  border-radius: 4px;
  padding: 0.1em 0.4em;
}

/* Player slots */
.player-slots {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
}

.slot {
  height: 60px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.85rem;
  position: relative;
  overflow: hidden;
}

.slot-filled {
  background: rgba(255,255,255,0.05);
  border: 1.5px solid var(--color, #a78bfa);
  box-shadow: 0 0 10px -4px var(--color, #a78bfa);
}

/* Player currently in the running game */
.slot-ingame {
  background: rgba(105,255,71,0.06);
  box-shadow: 0 0 12px -4px var(--color, #69ff47);
}

.slot-empty {
  border: 2px dashed rgba(167,139,250,0.3);
  background: rgba(167,139,250,0.03);
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.slot-empty:hover { background: rgba(167,139,250,0.08); border-color: #a78bfa; }

.slot-passive {
  border: 2px dashed rgba(255,255,255,0.07);
  justify-content: center;
}

.slot-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--color, #888);
  box-shadow: 0 0 5px var(--color, #888);
  flex-shrink: 0;
}

.slot-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: #e2dff8;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slot-remove {
  background: rgba(255,70,70,0.14);
  border: 1px solid rgba(255,70,70,0.3);
  color: #ff7070;
  border-radius: 6px;
  padding: 0.18rem 0.42rem;
  font-size: 0.72rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}
.slot-remove:hover { background: rgba(255,70,70,0.3); }

.slot-add-btn {
  background: none;
  border: none;
  color: #7c78a8;
  font-family: inherit;
  font-size: 0.86rem;
  cursor: inherit;
  letter-spacing: 0.03em;
  transition: color 0.15s;
}
.slot-empty:hover .slot-add-btn { color: #a78bfa; }

.slot-empty-label { color: #2e2c4a; font-size: 1rem; }

/* Complexity selector */
.complexity-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.82rem;
  color: #7c78a8;
  width: 100%;
}
.complexity-label { flex-shrink: 0; }
.complexity-select {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(167,139,250,0.3);
  border-radius: 6px;
  padding: 0.28rem 0.6rem;
  color: #c8c4e8;
  font-family: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
}
.complexity-select:focus { border-color: #a78bfa; }

.lobby-msg { font-size: 0.82rem; color: #5e5a82; text-align: center; min-height: 1.2em; }

.lobby-actions {
  display: flex;
  gap: 0.75rem;
  width: 100%;
}
.lobby-actions .btn { flex: 1; }

/* ─── Game screen ──────────────────────────────────────────────────────────── */
#game-section {
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  padding: 1rem;
}

#game-header { display: flex; justify-content: center; width: 100%; }

#player-stats { display: flex; flex-wrap: wrap; gap: 0.4rem; justify-content: center; }

.stat-chip {
  display: flex;
  align-items: center;
  gap: 0.32rem;
  padding: 0.22rem 0.55rem;
  border-radius: 20px;
  border: 1px solid var(--player-color, #888);
  font-size: 0.76rem;
  background: rgba(255,255,255,0.04);
  transition: opacity 0.3s;
}
.stat-chip.dead   { opacity: 0.28; text-decoration: line-through; filter: grayscale(0.8); }
.chip-dot         { width: 7px; height: 7px; border-radius: 50%; background: var(--player-color,#888); box-shadow: 0 0 4px var(--player-color,#888); }
.chip-name        { font-weight: 700; color: var(--player-color, #fff); }
.chip-info        { color: #7c78a8; font-size: 0.7rem; }

#game-canvas {
  border: 2px solid rgba(167,139,250,0.22);
  border-radius: 8px;
  box-shadow: 0 0 28px rgba(124,58,237,0.18);
  display: block;
  max-width: 100%;
}

.controls-hint { font-size: 0.7rem; color: #4e4a72; text-align: center; letter-spacing: 0.03em; }

/* ─── Leaderboards (lobby section) ─────────────────────────────────────────── */
.leaderboard {
  width: 100%;
  background: rgba(255,255,255,0.025);
  border: 1px solid rgba(167,139,250,0.14);
  border-radius: 12px;
  padding: 0.7rem 1rem;
}

.lb-title {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #5e5a82;
  margin-bottom: 0.5rem;
  text-align: center;
}

.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.lb-table tr { border-bottom: 1px solid rgba(255,255,255,0.04); }
.lb-table tr:last-child { border-bottom: none; }
.lb-table td { padding: 0.27rem 0.3rem; color: #c8c4e8; }
.lb-table td:last-child {
  text-align: right;
  color: #a78bfa;
  font-weight: 700;
  white-space: nowrap;
}
/* Gold for 1st, silver for 2nd */
.lb-table tr:first-child td { color: #ffd700; }
.lb-table tr:nth-child(2) td { color: #c0c0c0; }
.lb-table tr:first-child td:last-child { color: #ffd700; }

.lb-loading { text-align: center; font-size: 0.78rem; color: #4e4a72; padding: 0.35rem; }

/* ─── Touch controls (game section) ────────────────────────────────────────── */
#touch-controls {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  width: 100%;
  max-width: 600px;
  padding: 0.6rem 0.25rem 0;
  gap: 1rem;
  user-select: none;
  -webkit-user-select: none;
}

.touch-dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.dpad-row {
  display: flex;
  gap: 4px;
  align-items: center;
}

.dpad-center {
  width: 60px;
  height: 60px;
}

.touch-btn {
  width: 60px;
  height: 60px;
  border-radius: 12px;
  border: 2px solid rgba(167,139,250,0.4);
  background: rgba(167,139,250,0.1);
  color: #c8c4e8;
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: background 0.08s, transform 0.05s;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  font-family: inherit;
}

.touch-btn:active { background: rgba(167,139,250,0.32); transform: scale(0.92); }

.touch-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.action-btn { font-size: 1.5rem; }

.touch-label {
  display: block;
  font-size: 0.48rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #7c78a8;
  line-height: 1;
}

.bomb-btn {
  background: rgba(255,160,0,0.1);
  border-color: rgba(255,160,0,0.4);
}
.bomb-btn:active { background: rgba(255,160,0,0.32); }

.special-btn {
  background: rgba(105,255,71,0.08);
  border-color: rgba(105,255,71,0.35);
}
.special-btn:active { background: rgba(105,255,71,0.28); }

/* ─── Result screen ────────────────────────────────────────────────────────── */
#result-section {
  max-width: 380px;
  padding: 3rem 2rem;
  text-align: center;
  gap: 0.75rem;
}

#result-title {
  font-size: 2rem;
  background: linear-gradient(135deg, #a78bfa, #60a5fa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#result-subtitle { color: #7c78a8; font-size: 0.88rem; }

.result-scores {
  width: 100%;
  max-width: 280px;
  margin: 0 auto;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  align-items: center;
  width: 100%;
}
.result-actions .btn { min-width: 160px; }
