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

:root {
  --bg-deep: #0a0a0f;
  --bg-card: #12121a;
  --bg-glow: #16162a;
  --red-accent: #ff3d57;
  --red-dim: #ff3d5733;
  --cyan-accent: #00e5ff;
  --cyan-dim: #00e5ff22;
  --text-primary: #e8e8f0;
  --text-secondary: #8888a0;
  --text-dim: #555570;
  --border: #1e1e30;
  --green: #50fa7b;
  --orange: #ffb86c;
}

body {
  font-family: 'Space Grotesk', sans-serif;
  background: var(--bg-deep);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  position: fixed; /* Prevent mobile bounce/scroll */
  touch-action: none; /* Prevent pull-to-refresh */
}

/* ===== SCREENS ===== */
.screen {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  display: none;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  z-index: 100;
}
.screen.active { display: flex; }

/* ===== MENU SCREEN ===== */
#menuScreen {
  background: var(--bg-deep);
}
.menu-title {
  font-size: clamp(3rem, 8vw, 6rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 0.5rem;
}
.menu-title .glitch { color: var(--red-accent); }
.menu-sub {
  color: var(--text-secondary);
  font-size: 1.1rem;
  margin-bottom: 2.5rem;
}
.menu-input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.1rem;
  padding: 0.8rem 1.5rem;
  border-radius: 12px;
  width: 280px;
  text-align: center;
  outline: none;
  margin-bottom: 1rem;
  transition: border-color 0.2s;
}
.menu-input:focus {
  border-color: var(--red-accent);
}
.menu-input::placeholder { color: var(--text-dim); }

.btn-play {
  background: var(--red-accent);
  color: #fff;
  border: none;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.1rem;
  font-weight: 600;
  padding: 0.8rem 3rem;
  border-radius: 12px;
  cursor: pointer;
  letter-spacing: 0.05em;
  transition: transform 0.15s, box-shadow 0.15s;
}
.btn-play:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px var(--red-dim);
}
.btn-play:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
/* Mode Selector */
.mode-selector {
  display: flex;
  gap: 12px;
  margin-bottom: 1.2rem;
}
.mode-btn {
  background: var(--bg-card);
  border: 2px solid var(--border);
  color: var(--text-secondary);
  font-family: 'Space Grotesk', sans-serif;
  padding: 14px 20px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  min-width: 140px;
}
.mode-btn:hover { border-color: var(--text-dim); }
.mode-btn.active {
  border-color: var(--red-accent);
  color: var(--text-primary);
  background: var(--red-dim);
}
.mode-btn .mode-icon { font-size: 1.6rem; margin-bottom: 4px; }
.mode-btn .mode-name { font-size: 0.85rem; font-weight: 600; margin-bottom: 2px; }
.mode-btn .mode-desc { font-size: 0.65rem; color: var(--text-dim); }
.mode-btn.active .mode-desc { color: var(--text-secondary); }

.menu-mode {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 1.5rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

/* ===== ROLE REVEAL ===== */
#roleScreen {
  background: rgba(10, 10, 15, 0.95);
  z-index: 200;
}
.role-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 1rem;
}
.role-name {
  font-size: 3rem;
  font-weight: 700;
  color: var(--cyan-accent);
  margin-bottom: 0.5rem;
}
.role-name.impostor { color: var(--red-accent); }
.role-subtitle {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 1.2rem;
  font-family: 'JetBrains Mono', monospace;
}
.role-tasks {
  color: var(--text-secondary);
  font-size: 0.9rem;
  text-align: left;
  line-height: 2;
}
.role-tasks li {
  list-style: none;
  padding-left: 1.2rem;
  position: relative;
}
.role-tasks li::before {
  content: '>';
  position: absolute;
  left: 0;
  color: var(--cyan-accent);
  font-family: 'JetBrains Mono', monospace;
}

/* ===== GAME CANVAS ===== */
#gameCanvas {
  display: block;
  background: var(--bg-deep);
  touch-action: none; /* Prevent default touch actions like scrolling */
}

/* ===== HUD ===== */
.hud {
  position: fixed;
  top: 0; left: 0; width: 100%;
  pointer-events: none;
  z-index: 50;
}
.hud-top {
  display: flex;
  justify-content: center;
  padding: 12px 20px;
  gap: 20px;
}
.task-bar-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}
.task-bar-label {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  color: var(--text-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
}
.task-bar {
  width: 200px;
  height: 6px;
  background: var(--bg-deep);
  border-radius: 3px;
  overflow: hidden;
}
.task-bar-fill {
  height: 100%;
  background: var(--green);
  border-radius: 3px;
  transition: width 0.3s;
  width: 0%;
}
.timer-display {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ===== TASK LIST ===== */
.task-list {
  position: fixed;
  top: 60px;
  left: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  max-width: 220px;
  z-index: 50;
}
.task-list-title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  color: var(--text-dim);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.task-list ul {
  list-style: none;
}
.task-list li {
  font-size: 0.8rem;
  color: var(--text-secondary);
  padding: 3px 0;
  display: flex;
  align-items: center;
  gap: 6px;
}
.task-list li.completed {
  color: var(--text-dim);
  text-decoration: line-through;
}
.task-list li .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--orange);
  flex-shrink: 0;
}
.task-list li.completed .dot {
  background: var(--green);
}

/* ===== ACTION BUTTONS ===== */
.action-buttons {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
}
.action-btn {
  background: var(--bg-card);
  border: 2px solid var(--border);
  color: var(--text-primary);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 10px 20px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
  display: none;
  pointer-events: auto;
}
.action-btn.visible { display: block; }
.action-btn:hover { transform: translateY(-1px); }

#btnUse {
  border-color: var(--orange);
  color: var(--orange);
}
#btnReport {
  border-color: var(--red-accent);
  color: var(--red-accent);
  background: var(--red-dim);
}
#btnEmergency {
  border-color: var(--red-accent);
  color: #fff;
  background: var(--red-accent);
}
#btnKill {
  border-color: #ff1a1a;
  color: #fff;
  background: #ff1a1a;
  font-weight: 700;
  text-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
#btnKill:hover { background: #ff3333; }
#btnVent {
  border-color: #bd93f9;
  color: #bd93f9;
  background: rgba(189, 147, 249, 0.15);
}
#btnSabotage {
  border-color: var(--orange);
  color: var(--orange);
  background: rgba(255, 184, 108, 0.1);
}

/* Kill Cooldown */
.kill-cooldown {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 55;
}
.cooldown-ring {
  position: relative;
  width: 44px;
  height: 44px;
}
.cooldown-ring svg { width: 100%; height: 100%; }
.cooldown-ring span {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--red-accent);
}

/* ===== TASK PROGRESS OVERLAY ===== */
.task-progress-overlay {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 30px 50px;
  text-align: center;
  z-index: 150;
  display: none;
}
.task-progress-overlay.active { display: block; }
.task-progress-overlay .title {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}
.task-progress-overlay .bar {
  width: 200px;
  height: 8px;
  background: var(--bg-deep);
  border-radius: 4px;
  overflow: hidden;
}
.task-progress-overlay .bar-fill {
  height: 100%;
  background: var(--green);
  border-radius: 4px;
  transition: width 0.1s linear;
}

/* ===== MEETING OVERLAY ===== */
#meetingOverlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(10, 10, 15, 0.92);
  z-index: 200;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 40px;
  touch-action: auto; /* Allow scrolling in meeting overlay */
}
#meetingOverlay.active { display: flex; }

.meeting-header {
  text-align: center;
  margin-bottom: 20px;
}
.meeting-header .alert {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--red-accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}
.meeting-header .detail {
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.meeting-timer {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 16px;
}

/* Chat area */
.chat-area {
  width: 100%;
  max-width: 600px;
  flex: 1;
  display: flex;
  flex-direction: column;
  margin-bottom: 16px;
  min-height: 0;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 10px;
  max-height: 300px;
}
.chat-msg {
  margin-bottom: 8px;
  font-size: 0.85rem;
  line-height: 1.4;
}
.chat-msg .sender {
  font-weight: 600;
  margin-right: 6px;
}
.chat-msg .text {
  color: var(--text-secondary);
}
.chat-input-wrap {
  display: flex;
  gap: 8px;
}
.chat-input {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.85rem;
  padding: 8px 14px;
  border-radius: 10px;
  outline: none;
}
.chat-input:focus { border-color: var(--cyan-accent); }
.chat-send {
  background: var(--cyan-accent);
  color: var(--bg-deep);
  border: none;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: 10px;
  cursor: pointer;
}

/* Vote area */
.vote-area {
  width: 100%;
  max-width: 600px;
  margin-bottom: 20px;
}
.vote-title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  color: var(--text-dim);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 12px;
  text-align: center;
}
.vote-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.vote-btn {
  background: var(--bg-card);
  border: 2px solid var(--border);
  color: var(--text-primary);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 0.8rem;
  padding: 10px 8px;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 8px;
}
.vote-btn:hover { border-color: var(--red-accent); }
.vote-btn.voted { border-color: var(--red-accent); background: var(--red-dim); }
.vote-btn .avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
}
.vote-btn.skip {
  grid-column: 1 / -1;
  justify-content: center;
  border-color: var(--text-dim);
  color: var(--text-dim);
}
.vote-btn.skip:hover { border-color: var(--text-secondary); color: var(--text-secondary); }

/* ===== EJECTION SCREEN ===== */
#ejectionScreen {
  background: rgba(10, 10, 15, 0.95);
  z-index: 250;
}
.ejection-text {
  font-size: 1.6rem;
  font-weight: 600;
  text-align: center;
  max-width: 500px;
  line-height: 1.4;
}
.ejection-role {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-top: 12px;
}

/* ===== GAME OVER ===== */
#gameoverScreen {
  background: rgba(10, 10, 15, 0.95);
  z-index: 300;
}
.gameover-title {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}
.gameover-title.crew { color: var(--cyan-accent); }
.gameover-title.impostor { color: var(--red-accent); }
.gameover-sub {
  color: var(--text-secondary);
  font-size: 1rem;
  margin-bottom: 2rem;
}
.btn-again {
  background: var(--bg-card);
  border: 2px solid var(--border);
  color: var(--text-primary);
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.7rem 2.5rem;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-again:hover {
  border-color: var(--cyan-accent);
  color: var(--cyan-accent);
}

/* ===== KILL OVERLAY ===== */
#killOverlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(255, 61, 87, 0.3);
  z-index: 180;
  display: none;
  justify-content: center;
  align-items: center;
  animation: killFlash 0.8s ease-out forwards;
}
#killOverlay.active { display: flex; }
#killOverlay .kill-text {
  font-size: 2rem;
  font-weight: 700;
  color: var(--red-accent);
  text-transform: uppercase;
}

@keyframes killFlash {
  0% { background: rgba(255, 61, 87, 0.5); }
  100% { background: rgba(255, 61, 87, 0); }
}

/* ===== CONTROLS HINT ===== */
.controls-hint {
  position: fixed;
  bottom: 12px;
  left: 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
  color: var(--text-dim);
  z-index: 50;
  line-height: 1.8;
}
.controls-hint kbd {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.6rem;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ===== VIRTUAL JOYSTICK ===== */
.joystick {
  position: fixed;
  bottom: 24px;
  left: 24px;
  z-index: 60;
  touch-action: none;
  user-select: none;
}
.joystick-base {
  width: 110px;
  height: 110px;
  background: rgba(18, 18, 26, 0.7);
  border: 2px solid var(--border);
  border-radius: 50%;
  position: relative;
  backdrop-filter: blur(8px);
}
.joystick-stick {
  width: 48px;
  height: 48px;
  background: var(--cyan-accent);
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transition: all 0.1s;
  box-shadow: 0 4px 12px rgba(0, 229, 255, 0.4);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 700px) {
  .vote-grid { grid-template-columns: repeat(2, 1fr); }
  .chat-messages { max-height: 200px; }
  .task-list { display: none; }
}

/* ===== MOBILE OPTIMIZATIONS ===== */
@media (max-width: 768px) {
  /* Show joystick on mobile */
  .joystick {
    display: block !important;
    bottom: calc(24px + env(safe-area-inset-bottom));
    left: calc(24px + env(safe-area-inset-left));
  }

  /* Hide desktop controls hint on mobile */
  .controls-hint { display: none !important; }

  /* Make action buttons larger and reposition */
  .action-buttons {
    bottom: calc(24px + env(safe-area-inset-bottom));
    right: calc(24px + env(safe-area-inset-right));
    gap: 12px;
  }
  .action-btn {
    min-height: 50px;
    min-width: 50px;
    padding: 12px 16px;
    font-size: 0.75rem;
  }

  /* Stack mode selector vertically on small screens */
  .mode-selector {
    flex-direction: column;
    gap: 10px;
  }
  .mode-btn {
    width: 100%;
    max-width: 280px;
  }

  /* Make menu inputs full width */
  .menu-input {
    width: 90%;
    max-width: 320px;
  }

  /* Optimize HUD for mobile */
  .hud-top {
    padding: 8px 12px;
    gap: 12px;
    flex-wrap: wrap;
  }
  .task-bar-wrap {
    padding: 5px 12px;
  }
  .task-bar {
    width: 120px;
  }
  .task-bar-label {
    font-size: 0.65rem;
  }
  .timer-display {
    padding: 5px 12px;
    font-size: 0.75rem;
  }

  /* Kill cooldown position */
  .kill-cooldown {
    bottom: 160px;
    left: 69px;
  }

  /* Meeting overlay adjustments */
  #meetingOverlay {
    padding: 20px 16px;
  }
  .meeting-header .alert {
    font-size: 1.4rem;
  }
  .meeting-header .detail {
    font-size: 0.75rem;
  }
  .chat-area {
    max-width: 100%;
    padding: 0 8px;
  }
  .vote-area {
    max-width: 100%;
    padding: 0 8px;
  }
  .chat-input {
    font-size: 16px; /* Prevent iOS zoom */
  }

  /* Vote buttons - larger touch targets */
  .vote-btn {
    min-height: 50px;
    padding: 12px 10px;
    font-size: 0.85rem;
  }
  .chat-send {
    padding: 10px 20px;
    font-size: 0.85rem;
  }

  /* Task progress overlay */
  .task-progress-overlay {
    padding: 24px 36px;
  }
  .task-progress-overlay .bar {
    width: 160px;
  }

  /* Role reveal text sizing */
  .role-name {
    font-size: 2.5rem;
  }
  .role-tasks {
    font-size: 0.85rem;
  }

  /* Game over screen */
  .gameover-title {
    font-size: 2rem;
  }
  .gameover-sub {
    font-size: 0.9rem;
    padding: 0 16px;
  }
}

@media (max-width: 480px) {
  /* Smaller joystick on very small screens */
  .joystick {
    bottom: 16px;
    left: 16px;
  }
  .joystick-base {
    width: 90px;
    height: 90px;
  }
  .joystick-stick {
    width: 40px;
    height: 40px;
  }

  /* Compact action buttons */
  .action-buttons {
    bottom: 16px;
    right: 16px;
    gap: 8px;
  }
  .action-btn {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 12px;
    font-size: 0.7rem;
  }

  /* Kill cooldown position adjustment */
  .kill-cooldown {
    bottom: 130px;
    left: 53px;
  }

  /* Smaller HUD elements */
  .task-bar {
    width: 100px;
  }
  .hud-top {
    padding: 6px 8px;
  }

  /* Menu adjustments */
  .menu-title {
    font-size: 2.5rem;
  }
  .menu-sub {
    font-size: 0.95rem;
  }
  .btn-play {
    padding: 0.7rem 2.5rem;
    font-size: 1rem;
  }
}
