/* ==========================================================================
   SMALL-BOX ARENA // CLEAN MODERN PRIMARY-COLOR DESIGN SYSTEM
   ========================================================================== */

:root {
  /* Slate Neutrals (Light / Base / Dark Tones) */
  --bg-app: #0f172a;
  --bg-surface: #1e293b;
  --bg-surface-alt: #273449;
  --bg-elevated: #334155;
  --border-subtle: rgba(148, 163, 184, 0.22);
  --border-strong: rgba(148, 163, 184, 0.38);

  /* Text */
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;

  /* Clean Primary Colors + Light / Dark Shades */
  --blue: #3b82f6;
  --blue-light: #60a5fa;
  --blue-dark: #1d4ed8;
  --blue-soft: rgba(59, 130, 246, 0.14);

  --red: #ef4444;
  --red-light: #f87171;
  --red-dark: #b91c1c;
  --red-soft: rgba(239, 68, 68, 0.14);

  --yellow: #eab308;
  --yellow-light: #facc15;
  --yellow-dark: #a16207;
  --yellow-soft: rgba(234, 179, 8, 0.14);

  --green: #22c55e;
  --green-light: #4ade80;
  --green-dark: #15803d;
  --green-soft: rgba(34, 197, 94, 0.14);

  --font-display: 'Space Grotesk', 'Inter', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --radius-md: 10px;
  --radius-lg: 14px;
}

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

html, body {
  min-height: 100%;
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* Subtle screen shake on impact */
.shake-active {
  animation: screenShake 0.3s ease-in-out;
}

@keyframes screenShake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-3px, 2px); }
  50% { transform: translate(3px, -2px); }
  80% { transform: translate(-2px, 1px); }
}

/* ==========================================================================
   COMMON BUTTONS & SURFACES
   ========================================================================== */

.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 24px rgba(2, 6, 23, 0.32);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.65rem 1.15rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface-alt);
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.16s ease, border-color 0.16s ease, transform 0.12s ease;
}

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

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

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

.btn-full {
  width: 100%;
}

.btn-sm {
  padding: 0.45rem 0.85rem;
  font-size: 0.82rem;
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
}

.btn-blue {
  background: var(--blue);
  border-color: var(--blue-light);
  color: #ffffff;
}
.btn-blue:hover:not(:disabled) {
  background: var(--blue-dark);
  border-color: var(--blue-light);
}

.btn-red {
  background: var(--red);
  border-color: var(--red-light);
  color: #ffffff;
}
.btn-red:hover:not(:disabled) {
  background: var(--red-dark);
  border-color: var(--red-light);
}

.btn-yellow {
  background: var(--yellow);
  border-color: var(--yellow-light);
  color: #0f172a;
}
.btn-yellow:hover:not(:disabled) {
  background: var(--yellow-dark);
  color: #ffffff;
}

.btn-green {
  background: var(--green);
  border-color: var(--green-light);
  color: #0f172a;
}
.btn-green:hover:not(:disabled) {
  background: var(--green-dark);
  color: #ffffff;
}

.btn-outline-red {
  background: var(--red-soft);
  border-color: rgba(239, 68, 68, 0.45);
  color: var(--red-light);
}
.btn-outline-red:hover:not(:disabled) {
  background: var(--red);
  color: #ffffff;
}

/* ==========================================================================
   INITIAL LANDING SCREEN (HOST OR JOIN)
   ========================================================================== */

.entry-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.25rem;
  background: radial-gradient(circle at top center, #1e293b 0%, #0f172a 65%);
}

.entry-brand {
  text-align: center;
  margin-bottom: 2.25rem;
}

.entry-title {
  font-family: var(--font-display);
  font-size: 2.75rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.entry-title span {
  color: var(--blue-light);
}

.entry-subtitle {
  color: var(--text-muted);
  font-size: 1rem;
  margin-top: 0.35rem;
}

.entry-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 340px));
  gap: 1.5rem;
  width: 100%;
  max-width: 720px;
}

.entry-card {
  padding: 2rem 1.75rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 1.25rem;
}

.entry-card h2 {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.entry-card p {
  color: var(--text-muted);
  font-size: 0.92rem;
}

.code-inputs-container {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
  margin: 0.25rem 0 0.5rem 0;
}

.code-char-input {
  width: 52px;
  height: 54px;
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  background: var(--bg-app);
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 0.15s ease;
}

.code-char-input:focus {
  border-color: var(--blue-light);
}

.entry-error {
  margin-top: 1.25rem;
  padding: 0.65rem 1.1rem;
  border-radius: var(--radius-md);
  background: var(--red-soft);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: var(--red-light);
  font-weight: 600;
  font-size: 0.9rem;
}

/* ==========================================================================
   MAIN DASHBOARD SHELL (HEADER + SIDEBAR + CENTER STAGE)
   ========================================================================== */

.app-container {
  min-height: 100vh;
  max-width: 1520px;
  margin: 0 auto;
  padding: 1rem 1.5rem 1.5rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
}

.header-logo {
  cursor: pointer;
  display: flex;
  align-items: center;
  user-select: none;
}

.logo-title {
  font-family: var(--font-display);
  font-size: 2.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
}

.logo-title .accent-word {
  color: var(--blue-light);
}

.logo-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.04em;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.volume-slider-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
}

.slider-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
}

.clean-slider {
  width: 82px;
  accent-color: var(--blue);
  cursor: pointer;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 310px 1fr;
  gap: 1.25rem;
  flex: 1;
  min-height: calc(100vh - 108px);
}

.dashboard-grid.widescreen {
  grid-template-columns: 1fr;
}
.dashboard-grid.widescreen .sidebar {
  display: none;
}

/* ==========================================================================
   LEFT SIDEBAR: COLOR/SPECTATOR ROSTER + BOTTOM LOBBY INFO & DISCONNECT
   ========================================================================== */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sidebar-panel {
  padding: 1.15rem;
}

.panel-title {
  font-family: var(--font-display);
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}

.roster-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.8rem;
}

.color-slots-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.color-slot-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-app);
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.color-slot-btn:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--bg-surface-alt);
}

.color-slot-btn.is-mine {
  border-width: 2px;
  background: var(--bg-surface-alt);
}

.color-slot-btn.slot-p1.is-mine { border-color: var(--blue); }
.color-slot-btn.slot-p2.is-mine { border-color: var(--red); }
.color-slot-btn.slot-p3.is-mine { border-color: var(--yellow); }
.color-slot-btn.slot-p4.is-mine { border-color: var(--green); }

.color-slot-btn:disabled {
  cursor: default;
}

.slot-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.color-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid rgba(255, 255, 255, 0.35);
}

.dot-p1 { background: var(--blue); }
.dot-p2 { background: var(--red); }
.dot-p3 { background: var(--yellow); }
.dot-p4 { background: var(--green); }
.dot-spec { background: var(--text-muted); }

.slot-color-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.88rem;
}

.slot-occupant {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}

.slot-occupant.active-player {
  color: var(--text-primary);
}

.spectator-box {
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border-subtle);
}

.spectator-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.spectator-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.spectator-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  min-height: 24px;
}

.spectator-chip {
  font-size: 0.78rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.spectator-chip.is-mine {
  border-color: var(--blue-light);
  color: var(--blue-light);
  font-weight: 600;
}

/* Bottom-Left Lobby Number & Disconnect Panel */
.lobby-footer-panel {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.lobby-code-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 0.85rem;
  border-radius: var(--radius-md);
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
}

.lobby-code-meta {
  display: flex;
  flex-direction: column;
}

.lobby-code-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.lobby-code-value {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--blue-light);
}

.lobby-role-summary {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.lobby-role-summary strong {
  color: var(--text-primary);
}

/* ==========================================================================
   CENTER STAGE: GAME SELECTION MENU
   ========================================================================== */

.main-stage {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
}

.screen-view {
  display: none;
  flex-direction: column;
  flex: 1;
}

.screen-view.active {
  display: flex;
}

.menu-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.15rem;
}

.screen-heading {
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--text-primary);
}

.active-count-pill {
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.guest-notice {
  margin-bottom: 1rem;
  padding: 0.7rem 1rem;
  border-radius: var(--radius-md);
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(265px, 1fr));
  gap: 1.15rem;
  align-content: start;
}

/* Non-host (Joined player) greyed-out & unclickable state */
.game-grid.guest-locked {
  filter: grayscale(100%);
  opacity: 0.52;
  pointer-events: none;
  user-select: none;
}

/* Host-only per-card grey-out when lobby player count is below min or above max (still clickable for warning) */
.game-card.card-unavailable {
  filter: grayscale(100%);
  opacity: 0.56;
}

.game-card.card-unavailable:hover {
  transform: none;
  box-shadow: none;
}

.game-card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.85rem;
  padding: 1.25rem;
  border-radius: var(--radius-lg);
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-top-width: 4px;
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.game-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(2, 6, 23, 0.4);
  border-color: var(--border-strong);
}

.game-card.accent-blue { border-top-color: var(--blue); }
.game-card.accent-red { border-top-color: var(--red); }
.game-card.accent-yellow { border-top-color: var(--yellow); }
.game-card.accent-green { border-top-color: var(--green); }

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.game-icon {
  font-size: 1.85rem;
  line-height: 1;
}

.players-badge {
  font-size: 0.74rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.game-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

.game-desc {
  font-size: 0.87rem;
  color: var(--text-muted);
  flex: 1;
}

.card-controls-hint {
  font-size: 0.78rem;
  color: var(--text-secondary);
  background: var(--bg-surface);
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
}

/* ==========================================================================
   ACTIVE GAME ARENA & OVERLAYS
   ========================================================================== */

.arena-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.active-game-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
}

.arena-top-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.arena-room-pill {
  padding: 0.35rem 0.7rem;
  border-radius: 8px;
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--blue-light);
}

.canvas-wrapper {
  position: relative;
  flex: 1;
  min-height: 440px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #020617;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
}

#game-canvas {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.spectator-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.4rem 1rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  z-index: 15;
}

.screen-controls {
  position: absolute;
  bottom: 10px;
  right: 10px;
  display: flex;
  gap: 0.4rem;
  z-index: 15;
}

.arena-footer {
  margin-top: 0.75rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.canvas-overlay {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.76);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 25;
}

.overlay-box {
  padding: 2rem 2.25rem;
  text-align: center;
  min-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.overlay-box h3 {
  font-family: var(--font-display);
  font-size: 1.65rem;
  font-weight: 800;
}

.overlay-buttons {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  margin-top: 0.5rem;
}

/* ==========================================================================
   MODALS
   ========================================================================== */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.74);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}

.modal-box {
  width: 100%;
  max-width: 500px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.75rem;
}

.modal-header h2 {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}

.close-btn:hover {
  color: var(--text-primary);
}

.match-preview-box {
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  font-size: 0.88rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.mods-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

.mod-option {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  font-size: 0.85rem;
  cursor: pointer;
}

.mod-option input {
  accent-color: var(--blue);
  width: 16px;
  height: 16px;
}

.help-modal-box {
  max-width: 780px;
  padding: 1.85rem 2.1rem;
  gap: 1.25rem;
}

.help-modal-box .modal-header h2 {
  font-size: 1.55rem;
}

.help-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-height: 70vh;
  overflow-y: auto;
  padding-right: 0.5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-elevated) transparent;
}

.help-list::-webkit-scrollbar {
  width: 7px;
}

.help-list::-webkit-scrollbar-track {
  background: transparent;
}

.help-list::-webkit-scrollbar-thumb {
  background: var(--bg-elevated);
  border-radius: 999px;
}

.help-item {
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.15rem 1.4rem;
}

.help-item h3 {
  font-family: var(--font-display);
  font-size: 1.24rem;
  margin-bottom: 0.45rem;
  color: var(--text-primary);
}

.help-item p {
  font-size: 1.08rem;
  line-height: 1.65;
  color: var(--text-secondary);
}

kbd {
  display: inline-block;
  padding: 0.14rem 0.5rem;
  font-family: monospace;
  font-size: 0.96rem;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  color: var(--text-primary);
}

/* ==========================================================================
   HIDDEN DEVELOPER DIAGNOSTICS OVERLAY (F3 ONLY — NOT VISIBLE BY DEFAULT)
   ========================================================================== */

.diagnostics-overlay {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 275px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.9rem;
  font-family: monospace;
  font-size: 0.78rem;
  color: var(--text-primary);
  z-index: 30;
}

.diag-header {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  color: var(--blue-light);
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.35rem;
  margin-bottom: 0.4rem;
}

.diag-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
}

.diag-val {
  color: var(--green-light);
  font-weight: 700;
}

.diag-actions {
  margin-top: 0.5rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.diag-interp-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  color: var(--text-muted);
}

/* Responsive */
@media (max-width: 960px) {
  .entry-cards {
    grid-template-columns: 1fr;
  }
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}
