@import url('https://cdn.jsdelivr.net/npm/galmuri/dist/galmuri.css');
@import url('https://fonts.googleapis.com/css2?family=Pretendard:wght@400;600;700;800&display=swap');

:root {
  --bg-dark: #0b0d13;
  --bg-panel: #161926;
  --bg-card: #1f2337;
  --bg-input: #0e111a;
  --primary: #f59e0b;
  --primary-hover: #fbbf24;
  --accent: #ef4444;
  --p1-color: #3b82f6;
  --p2-color: #ec4899;
  --p3-color: #10b981;
  --p4-color: #f59e0b;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --border: #334155;
  --font-pixel: 'Galmuri11', monospace;
  --font-ui: 'Galmuri11', 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

body {
  background-color: var(--bg-dark);
  color: var(--text);
  font-family: var(--font-ui);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow-x: hidden;
  padding: 10px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.game-container {
  width: 100%;
  max-width: 920px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

/* Header */
.game-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: nowrap;
  background: var(--bg-panel);
  border: 2px solid var(--border);
  padding: 8px 14px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  border-radius: 8px;
}

.logo-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 6px;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.header-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  white-space: nowrap;
}

.icon-btn {
  background: var(--bg-card);
  border: 2px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  font-size: 12.5px;
  font-weight: 700;
  font-family: var(--font-ui);
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--primary);
  color: #000;
  border-color: var(--primary-hover);
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: translateY(1px);
}

/* Screens */
.screen {
  width: 100%;
  display: none;
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Lobby Box */
.lobby-box {
  width: 100%;
  max-width: 580px;
  background: var(--bg-panel);
  border: 3px solid var(--border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  border-radius: 12px;
}

.banner {
  text-align: center;
}

.banner h1 {
  font-size: 26px;
  font-weight: 800;
  color: #f59e0b;
  margin-bottom: 6px;
  letter-spacing: 1px;
}

.banner p {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
}

.menu-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.menu-btn {
  background: #2563eb;
  border: 2px solid #3b82f6;
  color: #fff;
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 700;
  padding: 13px 18px;
  cursor: pointer;
  text-align: center;
  border-radius: 8px;
  transition: all 0.15s ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
}

.menu-btn:hover {
  background: #3b82f6;
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(37, 99, 235, 0.3);
}

.menu-btn:active {
  transform: translateY(1px);
}

.menu-btn.accent {
  background: #10b981;
  border-color: #34d399;
}
.menu-btn.accent:hover {
  background: #059669;
  box-shadow: 0 6px 12px rgba(16, 185, 129, 0.3);
}

.menu-btn.secondary {
  background: #334155;
  border-color: #475569;
}
.menu-btn.secondary:hover {
  background: #475569;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

.join-form {
  display: flex;
  gap: 10px;
}

.room-input {
  flex: 1;
  background: var(--bg-input);
  border: 2px solid var(--border);
  color: #fbbf24;
  font-family: var(--font-ui);
  font-size: 16px;
  font-weight: 700;
  padding: 12px 16px;
  text-transform: uppercase;
  text-align: center;
  outline: none;
  border-radius: 8px;
  letter-spacing: 2px;
}

.room-input::placeholder {
  color: #64748b;
  font-size: 13px;
  letter-spacing: normal;
}

.room-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2);
}

/* Room Lobby Screen */
.room-lobby-box {
  width: 100%;
  max-width: 620px;
  background: var(--bg-panel);
  border: 3px solid var(--border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  border-radius: 12px;
}

.room-code-tag {
  background: var(--bg-input);
  border: 2px dashed var(--primary);
  padding: 14px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  border-radius: 8px;
}

.room-code-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 700;
}

.room-code-val {
  font-size: 28px;
  font-weight: 800;
  color: #fbbf24;
  letter-spacing: 4px;
  font-family: var(--font-pixel);
}

.player-slots {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.player-slot {
  background: var(--bg-card);
  border: 2px solid var(--border);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 8px;
}

.player-slot.occupied {
  border-color: var(--primary);
  background: #252b42;
}

.player-avatar {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: #111;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.player-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.player-name {
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.player-status {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
}

/* In-Game Top Nav Control Bar */
.game-top-bar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-panel);
  border: 2px solid var(--border);
  padding: 8px 14px;
  border-radius: 8px;
}

.match-timer-badge {
  font-size: 16px;
  font-weight: 800;
  color: #fbbf24;
  font-family: var(--font-pixel);
  display: flex;
  align-items: center;
  gap: 6px;
}

.game-top-actions {
  display: flex;
  gap: 8px;
}

/* In-Game Top HUD (Players) */
.game-hud {
  width: 100%;
  display: flex;
  gap: 6px;
  background: var(--bg-panel);
  border: 2px solid var(--border);
  padding: 8px;
  border-radius: 8px;
}

.hud-player {
  flex: 1;
  background: var(--bg-card);
  border: 2px solid var(--border);
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  border-radius: 6px;
}

.hud-player.dead {
  opacity: 0.35;
  filter: grayscale(1);
}

.hud-player-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 700;
}

.hud-stats {
  display: flex;
  gap: 6px;
  color: #fbbf24;
  font-size: 10.5px;
  font-weight: 700;
}

/* Canvas Area */
.canvas-wrapper {
  position: relative;
  background: #111;
  border: 4px solid var(--border);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  overflow: hidden;
  border-radius: 8px;
  margin: 12px 0;
}

#gameCanvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background-color: #15803d;
  max-width: 100%;
  height: auto;
}

/* Quick Emote Bar */
.emote-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--bg-panel);
  border: 2px solid var(--border);
  padding: 6px 10px;
  border-radius: 8px;
}

.emote-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 700;
  margin-right: 4px;
}

.emote-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-size: 18px;
  width: 38px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.1s;
}

.emote-btn:hover {
  background: #334155;
  transform: scale(1.15);
}

.emote-btn:active {
  transform: scale(0.95);
}

/* Round overlay */
.round-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(11, 13, 19, 0.88);
  backdrop-filter: blur(4px);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 100;
  text-align: center;
  padding: 24px;
}

.round-overlay.show {
  display: flex;
}

.overlay-title {
  font-size: 28px;
  font-weight: 800;
  color: #fbbf24;
  letter-spacing: 1px;
}

.overlay-subtitle {
  font-size: 15px;
  color: #e2e8f0;
  font-weight: 700;
}

/* Mobile Virtual Controls */
.mobile-controls {
  display: flex;
  width: 100%;
  max-width: 600px;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  touch-action: none;
  background: var(--bg-panel);
  border: 2px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
  margin-top: 4px;
}

.mobile-controls.hidden {
  display: none !important;
}

.dpad {
  position: relative;
  width: 148px;
  height: 148px;
  background: #111420;
  border: 2px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.6);
}

.dpad-center {
  width: 38px;
  height: 38px;
  background: #1e293b;
  border-radius: 50%;
  border: 2px solid #334155;
  pointer-events: none;
}

.dpad-btn {
  position: absolute;
  background: #334155;
  border: 2px solid #64748b;
  color: #fff;
  font-size: 20px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  box-shadow: 0 3px 6px rgba(0,0,0,0.4);
  transition: all 0.08s ease;
  pointer-events: none;
}

.dpad-btn.active {
  background: #f59e0b;
  color: #000;
  border-color: #fbbf24;
  transform: scale(0.92);
  box-shadow: 0 0 12px rgba(245, 158, 11, 0.6);
}

.dpad-up { top: 4px; left: 50px; }
.dpad-down { bottom: 4px; left: 50px; }
.dpad-left { top: 50px; left: 4px; }
.dpad-right { top: 50px; right: 4px; }

.action-btns {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-right: 12px;
}

.action-btn {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  border: 4px solid #f87171;
  color: #fff;
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 800;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  box-shadow: 0 6px 16px rgba(239, 68, 68, 0.4), inset 0 2px 4px rgba(255,255,255,0.3);
  cursor: pointer;
  transition: all 0.08s ease;
}

.action-btn.active, .action-btn:active {
  transform: scale(0.92);
  background: linear-gradient(135deg, #dc2626, #991b1b);
  box-shadow: 0 2px 6px rgba(239, 68, 68, 0.6);
}

/* Instructions footer */
.controls-hint {
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.6;
  background: var(--bg-card);
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.controls-hint b {
  color: #f8fafc;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  border: 2px solid var(--primary);
  color: #fff;
  padding: 12px 20px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 10000;
  display: none;
}

/* ===================================================
   PORTRAIT MOBILE RESPONSIVE MEDIA QUERIES (세로모드 대응)
   =================================================== */
@media (max-width: 600px) {
  body {
    padding: 6px 4px;
    justify-content: flex-start;
  }

  .game-container {
    gap: 6px;
    max-width: 100%;
  }

  .game-header {
    padding: 6px 10px;
    border-radius: 6px;
  }

  .logo-title {
    font-size: 13.5px;
    gap: 4px;
    letter-spacing: 0;
  }

  .icon-btn {
    padding: 5px 8px;
    font-size: 11px;
    border-radius: 4px;
  }

  /* Main Menu */
  .lobby-box {
    padding: 18px 12px;
    gap: 12px;
    border-radius: 8px;
  }

  .banner h1 {
    font-size: 20px;
  }

  .banner p {
    font-size: 11.5px;
  }

  .menu-btn {
    font-size: 13px;
    padding: 11px 14px;
  }

  .room-input {
    font-size: 13.5px;
    padding: 10px;
  }

  .controls-hint {
    font-size: 10.5px;
    padding: 8px 10px;
    line-height: 1.5;
  }

  /* Room Lobby */
  .room-lobby-box {
    padding: 16px 10px;
    gap: 12px;
    border-radius: 8px;
  }

  .room-code-val {
    font-size: 22px;
    letter-spacing: 3px;
  }

  .player-slots {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .player-slot {
    padding: 6px 8px;
    gap: 6px;
    border-radius: 6px;
  }

  .player-avatar {
    width: 28px;
    height: 28px;
    font-size: 13px;
  }

  .player-name {
    font-size: 11px;
  }

  .player-status {
    font-size: 9.5px;
  }

  /* In-Game HUD */
  .game-top-bar {
    padding: 6px 10px;
  }

  .match-timer-badge {
    font-size: 14px;
  }

  .game-hud {
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    padding: 5px;
  }

  .hud-player {
    padding: 4px 5px;
    border-radius: 4px;
  }

  .hud-player-header {
    font-size: 9.5px;
  }

  .hud-stats {
    font-size: 8.5px;
    gap: 3px;
  }

  /* Canvas */
  .canvas-wrapper {
    width: 100%;
    border-width: 3px;
    border-radius: 6px;
  }

  #gameCanvas {
    width: 100% !important;
    height: auto !important;
  }

  /* Emote Bar */
  .emote-bar {
    padding: 4px 6px;
    gap: 4px;
  }

  .emote-label {
    font-size: 10px;
  }

  .emote-btn {
    width: 34px;
    height: 30px;
    font-size: 15px;
  }

  /* Virtual Controls */
  .mobile-controls {
    padding: 8px 10px;
    max-width: 100%;
  }

  .dpad {
    width: 126px;
    height: 126px;
  }

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

  .dpad-btn {
    width: 40px;
    height: 40px;
    font-size: 17px;
  }

  .dpad-up { top: 3px; left: 43px; }
  .dpad-down { bottom: 3px; left: 43px; }
  .dpad-left { top: 43px; left: 3px; }
  .dpad-right { top: 43px; right: 3px; }

  .action-btns {
    padding-right: 4px;
  }

  .action-btn {
    width: 68px;
    height: 68px;
    font-size: 12px;
  }
}

/* Hide Virtual Pad on Desktop/Wide Screens */
@media (min-width: 768px) {
  #mobileControls, #btnToggleVirtualPad {
    display: none !important;
  }
}
