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

:root {
  --bg-dark: #0a0a0f;
  --bg-card: #12121a;
  --bg-card-hover: #1a1a28;
  --bg-surface: #16161f;
  --text-primary: #e8e6e3;
  --text-secondary: #8b8999;
  --text-muted: #5a586a;
  --accent-red: #dc2626;
  --accent-red-glow: rgba(220, 38, 38, 0.3);
  --accent-blue: #3b82f6;
  --accent-blue-glow: rgba(59, 130, 246, 0.3);
  --accent-green: #22c55e;
  --accent-green-glow: rgba(34, 197, 94, 0.3);
  --accent-purple: #a855f7;
  --accent-purple-glow: rgba(168, 85, 247, 0.3);
  --accent-yellow: #eab308;
  --accent-gold: #f59e0b;
  --border: #2a2a3a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-dark);
  color: var(--text-primary);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x pan-y;
}

body {
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(120, 0, 0, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(60, 0, 120, 0.06) 0%, transparent 50%);
}

/* ═══ Screens ═══ */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0; left: 0;
  overflow-y: auto;
  animation: fadeIn 0.4s ease;
}

.screen.active {
  display: flex;
  justify-content: center;
  align-items: center;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes glow {
  0%, 100% { box-shadow: 0 0 5px var(--accent-red-glow); }
  50% { box-shadow: 0 0 20px var(--accent-red-glow), 0 0 40px var(--accent-red-glow); }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes zzzAnim {
  0% { opacity: 0.3; letter-spacing: 4px; }
  50% { opacity: 1; letter-spacing: 12px; }
  100% { opacity: 0.3; letter-spacing: 4px; }
}

/* ═══ Buttons ═══ */
.btn {
  padding: 10px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--text-muted);
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent-red);
  border-color: var(--accent-red);
  color: #fff;
}

.btn-primary:hover {
  background: #b91c1c;
  border-color: #b91c1c;
}

.btn-secondary {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: #fff;
}

.btn-secondary:hover {
  background: #2563eb;
  border-color: #2563eb;
}

.btn-ghost {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-secondary);
}

.btn-ghost:hover {
  border-color: var(--text-secondary);
  color: var(--text-primary);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}

.btn-large {
  padding: 14px 32px;
  font-size: 16px;
}

.btn-toggle {
  min-width: 70px;
}

.btn-toggle.active {
  background: var(--accent-green);
  border-color: var(--accent-green);
  color: #fff;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ═══ Inputs ═══ */
input[type="text"] {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 15px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
  width: 100%;
}

input[type="text"]::placeholder {
  color: var(--text-muted);
}

input[type="text"]:focus {
  border-color: var(--accent-red);
}

/* ═══ Error ═══ */
.error-msg {
  color: var(--accent-red);
  font-size: 13px;
  min-height: 20px;
  text-align: center;
  margin-top: 8px;
}

/* ═══ Landing ═══ */
.landing-container {
  max-width: 400px;
  width: 100%;
  padding: 24px;
  text-align: center;
}

.logo {
  margin-bottom: 40px;
}

.logo-icon {
  font-size: 72px;
  animation: float 3s ease-in-out infinite;
  margin-bottom: 12px;
}

.logo h1 {
  font-size: 42px;
  font-weight: 800;
  letter-spacing: 4px;
  color: var(--accent-red);
  line-height: 1.1;
}

.logo h1 span {
  display: block;
  font-size: 28px;
  color: var(--text-primary);
  letter-spacing: 8px;
  font-weight: 300;
}

.tagline {
  color: var(--text-secondary);
  font-style: italic;
  margin-top: 8px;
  font-size: 14px;
}

.landing-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 13px;
}

.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.join-row {
  display: flex;
  gap: 8px;
}

.join-row input {
  flex: 1;
}

/* ═══ Lobby ═══ */
.lobby-container {
  max-width: 600px;
  width: 100%;
  padding: 24px;
}

.lobby-header {
  text-align: center;
  margin-bottom: 24px;
}

.lobby-header h2 {
  font-size: 14px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 8px;
}

.room-code {
  font-size: 48px;
  font-weight: 800;
  letter-spacing: 12px;
  color: var(--accent-gold);
  font-family: 'Courier New', monospace;
}

#btn-copy-code {
  margin-top: 8px;
}

.lobby-body {
  display: flex;
  gap: 24px;
  margin-bottom: 24px;
}

.lobby-players {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.lobby-players h3 {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.lobby-players ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lobby-players li {
  padding: 10px 14px;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.lobby-players li .host-badge {
  background: var(--accent-gold);
  color: #000;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: auto;
}

.lobby-players li .you-badge {
  background: var(--accent-blue);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
}

.lobby-settings {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.lobby-settings h3 {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.setting-row:last-child {
  border-bottom: none;
}

.setting-row label {
  font-size: 13px;
  color: var(--text-primary);
}

.setting-control {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.btn-large {
  width: 100%;
}

.wait-msg {
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 12px;
  font-style: italic;
}

/* ═══ Role Reveal ═══ */
.role-reveal-container {
  text-align: center;
  padding: 24px;
  animation: fadeIn 0.6s ease;
}

.role-reveal-container h2 {
  color: var(--text-secondary);
  font-size: 16px;
  text-transform: uppercase;
  letter-spacing: 3px;
  margin-bottom: 24px;
}

.role-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  max-width: 360px;
  margin: 0 auto;
  animation: slideDown 0.6s ease;
}

.role-card.vampire {
  border-color: var(--accent-red);
  box-shadow: 0 0 30px var(--accent-red-glow);
}

.role-card.villager {
  border-color: var(--accent-blue);
  box-shadow: 0 0 30px var(--accent-blue-glow);
}

.role-card.doctor {
  border-color: var(--accent-green);
  box-shadow: 0 0 30px var(--accent-green-glow);
}

.role-card.seer {
  border-color: var(--accent-purple);
  box-shadow: 0 0 30px var(--accent-purple-glow);
}

.role-icon {
  font-size: 80px;
  margin-bottom: 16px;
}

.role-card h3 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 12px;
}

.role-card p {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.5;
}

.teammates {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--accent-red);
}

.role-reveal-timer {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 24px;
  animation: pulse 1.5s ease-in-out infinite;
}

/* ═══ Game Screen ═══ */
.game-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.phase-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
}

.phase-icon {
  font-size: 24px;
}

.phase-text {
  font-size: 18px;
  font-weight: 700;
}

.round-badge {
  background: var(--bg-surface);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-secondary);
}

.timer {
  font-size: 32px;
  font-weight: 800;
  font-family: 'Courier New', monospace;
  color: var(--text-primary);
  min-width: 60px;
  text-align: center;
}

.timer.warning {
  color: var(--accent-red);
  animation: pulse 0.5s ease-in-out infinite;
}

.my-role-badge {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.my-role-badge.vampire { background: var(--accent-red); color: #fff; }
.my-role-badge.villager { background: var(--accent-blue); color: #fff; }
.my-role-badge.doctor { background: var(--accent-green); color: #fff; }
.my-role-badge.seer { background: var(--accent-purple); color: #fff; }
.my-role-badge.dead { background: var(--text-muted); color: var(--bg-dark); }

/* ═══ Game Main ═══ */
.game-main {
  flex: 1;
  overflow-y: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px;
}

.game-panel {
  width: 100%;
  max-width: 700px;
  animation: fadeIn 0.4s ease;
}

/* Night: Sleeping */
.sleeping-container {
  text-align: center;
  padding: 60px 20px;
}

.sleeping-container .moon {
  font-size: 80px;
  animation: float 3s ease-in-out infinite;
  margin-bottom: 20px;
}

.sleeping-container h2 {
  font-size: 28px;
  margin-bottom: 8px;
}

.sleeping-container p {
  color: var(--text-secondary);
}

.zzz {
  font-size: 24px;
  color: var(--text-muted);
  margin-top: 20px;
  letter-spacing: 8px;
  animation: zzzAnim 2s ease-in-out infinite;
}

/* Night: Role Actions */
.vampire-container, .doctor-container, .seer-container {
  text-align: center;
  padding: 20px;
}

.vampire-container h2, .doctor-container h2, .seer-container h2 {
  font-size: 24px;
  margin-bottom: 8px;
}

.vampire-container p, .doctor-container p, .seer-container p {
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.mini-info {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
  padding: 8px 12px;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  display: inline-block;
}

/* Target Grid */
.target-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  margin: 16px 0;
}

.target-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.target-card:hover {
  border-color: var(--text-muted);
  background: var(--bg-card-hover);
  transform: translateY(-2px);
}

.target-card.selected {
  border-color: var(--accent-red);
  background: rgba(220, 38, 38, 0.1);
  box-shadow: 0 0 15px var(--accent-red-glow);
}

.target-card.selected-green {
  border-color: var(--accent-green);
  background: rgba(34, 197, 94, 0.1);
  box-shadow: 0 0 15px var(--accent-green-glow);
}

.target-card.selected-purple {
  border-color: var(--accent-purple);
  background: rgba(168, 85, 247, 0.1);
  box-shadow: 0 0 15px var(--accent-purple-glow);
}

.target-card .target-icon {
  font-size: 32px;
  margin-bottom: 6px;
}

.target-card .target-name {
  font-size: 14px;
  font-weight: 600;
}

.target-card .target-vote-count {
  font-size: 11px;
  color: var(--accent-red);
  margin-top: 4px;
}

.votes-info {
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-secondary);
  padding: 10px;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
}

.action-confirm {
  margin-top: 12px;
  font-size: 14px;
  color: var(--accent-green);
  font-weight: 600;
}

/* Seer Result */
.seer-result {
  margin-top: 20px;
  padding: 20px;
  border-radius: var(--radius);
  font-size: 18px;
  font-weight: 700;
  animation: slideDown 0.3s ease;
}

.seer-result.is-vampire {
  background: rgba(220, 38, 38, 0.15);
  border: 2px solid var(--accent-red);
  color: var(--accent-red);
}

.seer-result.not-vampire {
  background: rgba(34, 197, 94, 0.15);
  border: 2px solid var(--accent-green);
  color: var(--accent-green);
}

/* Dead */
.dead-container {
  text-align: center;
  padding: 60px 20px;
  opacity: 0.6;
}

.dead-container h2 {
  font-size: 28px;
  margin-bottom: 8px;
}

.dead-container p {
  color: var(--text-secondary);
}

/* ═══ Day Phase ═══ */
.day-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 80px);
}

.announcement {
  padding: 16px 20px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 15px;
  font-weight: 600;
  animation: slideDown 0.4s ease;
  text-align: center;
}

.announcement.death {
  background: rgba(220, 38, 38, 0.12);
  border: 1px solid var(--accent-red);
  color: var(--accent-red);
}

.announcement.saved {
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid var(--accent-green);
  color: var(--accent-green);
}

.announcement.no-attack {
  background: rgba(59, 130, 246, 0.12);
  border: 1px solid var(--accent-blue);
  color: var(--accent-blue);
}

.players-status {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  justify-content: center;
}

.player-chip {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.player-chip.dead {
  opacity: 0.4;
  text-decoration: line-through;
}

.player-chip.you {
  border-color: var(--accent-blue);
}

/* Chat */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 200px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chat-msg {
  font-size: 13px;
  line-height: 1.4;
  padding: 4px 0;
}

.chat-msg .chat-author {
  font-weight: 700;
  color: var(--accent-blue);
  margin-right: 6px;
}

.chat-msg.system {
  color: var(--text-muted);
  font-style: italic;
  text-align: center;
}

.chat-input-row {
  display: flex;
  border-top: 1px solid var(--border);
}

.chat-input-row input {
  flex: 1;
  border: none;
  border-radius: 0;
  background: var(--bg-surface);
  padding: 12px 16px;
}

.chat-input-row .btn {
  border-radius: 0;
  border: none;
  border-left: 1px solid var(--border);
}

.ready-vote-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  justify-content: center;
}

/* ═══ Voting ═══ */
.voting-container {
  text-align: center;
  padding: 20px;
}

.voting-container h2 {
  font-size: 24px;
  margin-bottom: 8px;
  color: var(--accent-gold);
}

.voting-container > p {
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.voting-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 16px;
}

.voting-live-board {
  margin-top: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.voting-live-board h4 {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-align: center;
}

.vote-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.vote-row:last-child {
  border-bottom: none;
}

.vote-row .voter-name {
  font-weight: 600;
}

.vote-row .vote-target {
  color: var(--accent-red);
  font-weight: 600;
}

.vote-row .vote-target.skip {
  color: var(--text-muted);
  font-style: italic;
}

.vote-row .vote-confirmed {
  color: var(--accent-green);
  font-size: 11px;
  margin-left: 6px;
}

.vote-row .vote-pending {
  color: var(--text-muted);
  font-size: 11px;
  margin-left: 6px;
}

.vote-status {
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

/* ═══ Game Over ═══ */
.gameover-container {
  text-align: center;
  padding: 24px;
  max-width: 500px;
  animation: fadeIn 0.6s ease;
}

.gameover-icon {
  font-size: 100px;
  margin-bottom: 16px;
  animation: float 3s ease-in-out infinite;
}

.gameover-container h2 {
  font-size: 32px;
  font-weight: 800;
  margin-bottom: 8px;
}

.gameover-container h2.vampires-win {
  color: var(--accent-red);
}

.gameover-container h2.villagers-win {
  color: var(--accent-blue);
}

.gameover-subtitle {
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.gameover-roles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  margin-bottom: 24px;
}

.gameover-role-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 8px;
  text-align: center;
}

.gameover-role-card.dead {
  opacity: 0.5;
}

.gameover-role-card .role-emoji {
  font-size: 24px;
  display: block;
  margin-bottom: 4px;
}

.gameover-role-card .player-name {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 2px;
}

.gameover-role-card .player-role {
  font-size: 11px;
  color: var(--text-secondary);
}

.gameover-role-card .player-status {
  font-size: 10px;
  margin-top: 4px;
}

.gameover-role-card .player-status.survived {
  color: var(--accent-green);
}

.gameover-role-card .player-status.eliminated {
  color: var(--accent-red);
}

.gameover-container .btn {
  margin: 4px;
}

/* ═══ Vote Result Overlay ═══ */
.overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  animation: fadeIn 0.3s ease;
}

.overlay-content {
  text-align: center;
  padding: 40px;
  animation: slideDown 0.4s ease;
}

.vote-result-icon {
  font-size: 80px;
  margin-bottom: 16px;
}

.overlay-content h2 {
  font-size: 24px;
  margin-bottom: 8px;
}

.overlay-content p {
  color: var(--text-secondary);
  font-size: 15px;
}

/* ═══ Night Theme Override ═══ */
body.night-theme {
  background-color: #050510;
  background-image:
    radial-gradient(ellipse at 50% 0%, rgba(30, 0, 60, 0.15) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 80%, rgba(80, 0, 0, 0.1) 0%, transparent 40%);
}

body.night-theme .game-header {
  background: #08081a;
  border-color: #1a1a30;
}

/* ═══ Day Theme Override ═══ */
body.day-theme {
  background-color: #0c0c14;
  background-image:
    radial-gradient(ellipse at 50% 0%, rgba(234, 179, 8, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 20% 80%, rgba(59, 130, 246, 0.05) 0%, transparent 40%);
}

/* ═══ Voting Theme Override ═══ */
body.voting-theme {
  background-color: #0c0808;
  background-image:
    radial-gradient(ellipse at 50% 50%, rgba(220, 38, 38, 0.06) 0%, transparent 50%);
}

/* ═══ Scrollbar ═══ */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ═══ Responsive ═══ */
@media (max-width: 600px) {
  .lobby-body {
    flex-direction: column;
  }

  .logo h1 {
    font-size: 32px;
  }

  .logo h1 span {
    font-size: 22px;
  }

  .room-code {
    font-size: 36px;
    letter-spacing: 8px;
  }

  .target-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
  }

  .target-card {
    padding: 12px 8px;
  }

  .game-header {
    padding: 10px 12px;
  }

  .timer {
    font-size: 24px;
  }

  .gameover-roles {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }
}
