/* ─── Base & Reset ─────────────────────────────────────────────────────────── */

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

html, body {
  height: 100%;
  overflow: hidden;
  background: #0a0e1a;
  color: #e2e8f0;
  font-family: "Press Start 2P", monospace;
  font-size: 10px;
  line-height: 1.6;
}

/* ─── App container ─────────────────────────────────────────────────────────── */

#app {
  height: 100vh;
  display: flex;
  position: relative;
}

/* ─── Utility ───────────────────────────────────────────────────────────────── */

.hidden {
  display: none !important;
}

/* ─── Pixel panel ───────────────────────────────────────────────────────────── */

.pixel-panel {
  background: #1a2035;
  border: 4px solid #2a4060;
  box-shadow: 4px 4px 0 #000;
}

/* ─── Pixel buttons ─────────────────────────────────────────────────────────── */

.pixel-btn {
  font-family: "Press Start 2P", monospace;
  font-size: 10px;
  padding: 10px 16px;
  cursor: pointer;
  border: none;
  border-radius: 0;
  color: #e2e8f0;
  background: #2d3748;
  box-shadow: 4px 4px 0 #000, inset 2px 2px 0 rgba(255,255,255,0.2), inset -2px -2px 0 rgba(0,0,0,0.3);
  transition: box-shadow 0.05s, transform 0.05s;
  display: inline-block;
  text-align: center;
  user-select: none;
  line-height: 1.5;
}

.pixel-btn:hover {
  background: #3d4a5e;
}

.pixel-btn:active {
  box-shadow: 2px 2px 0 #000, inset 2px 2px 0 rgba(255,255,255,0.1), inset -2px -2px 0 rgba(0,0,0,0.2);
  transform: translate(2px, 2px);
}

.pixel-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

.pixel-btn.primary {
  background: #2d6a4f;
  color: #ffffff;
}

.pixel-btn.primary:hover {
  background: #40916c;
}

.pixel-btn.secondary {
  background: #2d3748;
  color: #a0aec0;
}

.pixel-btn.secondary:hover {
  background: #4a5568;
}

.pixel-btn.danger {
  background: #7f1d1d;
  color: #fff;
}

.pixel-btn.danger:hover {
  background: #991b1b;
}

.pixel-btn.small {
  font-size: 8px;
  padding: 6px 10px;
}

.pixel-btn.large {
  font-size: 12px;
  padding: 14px 24px;
}

/* ─── Pixel input ───────────────────────────────────────────────────────────── */

.pixel-input {
  font-family: "Press Start 2P", monospace;
  font-size: 10px;
  background: #0d1526;
  border: 3px solid #2a4060;
  color: #e2e8f0;
  padding: 8px 10px;
  outline: none;
  border-radius: 0;
  width: 100%;
  box-shadow: inset 2px 2px 0 rgba(0,0,0,0.5);
}

.pixel-input.name-input {
  text-transform: uppercase;
}

.pixel-input:focus {
  border-color: #4fc3f7;
}

.pixel-input.small {
  font-size: 9px;
  padding: 6px 8px;
  width: 80px;
}

/* ─── Lobby layout ──────────────────────────────────────────────────────────── */

#lobby {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  overflow-y: auto;
  padding: 20px;
  gap: 20px;
}

/* ─── Title screen ──────────────────────────────────────────────────────────── */

.title-screen {
  text-align: center;
  margin-bottom: 10px;
}

.game-title {
  font-size: 36px;
  color: #4fc3f7;
  text-shadow: 4px 4px 0 #000, 0 0 20px rgba(79,195,247,0.5);
  letter-spacing: 4px;
  line-height: 1.3;
  margin-bottom: 10px;
}

.game-title.small {
  font-size: 18px;
  margin-bottom: 8px;
}

.subtitle {
  font-size: 10px;
  color: #f6e05e;
  text-shadow: 2px 2px 0 #000;
  margin-top: 6px;
}

/* ─── Mode selection ────────────────────────────────────────────────────────── */

#mode-selection {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

#mode-selection .pixel-btn {
  font-size: 12px;
  padding: 14px 22px;
  min-width: 200px;
}

/* ─── Section titles ────────────────────────────────────────────────────────── */

.section-title {
  font-size: 14px;
  color: #4fc3f7;
  text-shadow: 2px 2px 0 #000;
  margin-bottom: 16px;
  text-align: center;
}

/* ─── Form groups ───────────────────────────────────────────────────────────── */

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.form-group label {
  font-size: 9px;
  color: #a0aec0;
}

.form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.form-row .form-group {
  flex: 1;
  min-width: 70px;
}

/* ─── Number selector ───────────────────────────────────────────────────────── */

.number-selector {
  display: flex;
  align-items: center;
  gap: 16px;
}

.number-selector span {
  font-size: 18px;
  color: #f6e05e;
  min-width: 24px;
  text-align: center;
}

/* ─── Difficulty buttons ────────────────────────────────────────────────────── */

.difficulty-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.diff-btn,
.diff-btn-online {
  flex: 1;
  min-width: 80px;
  text-align: center;
  padding: 8px 6px;
  font-size: 7px;
}

.diff-btn.active,
.diff-btn-online.active {
  background: #2d6a4f;
  color: #fff;
  border: 2px solid #40916c;
}

.diff-btn small,
.diff-btn-online small {
  display: block;
  color: #a0aec0;
  margin-top: 4px;
  font-size: 7px;
}

/* ─── Local / Online sections ───────────────────────────────────────────────── */

#local-section,
#online-section,
#create-section,
#join-section {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#online-choice {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

#online-choice .pixel-btn {
  min-width: 180px;
  font-size: 10px;
}

#create-section h3,
#join-section h3 {
  font-size: 12px;
  color: #f6e05e;
  text-align: center;
  margin-bottom: 12px;
  text-shadow: 2px 2px 0 #000;
}

/* ─── Error message ─────────────────────────────────────────────────────────── */

.error-msg {
  font-size: 9px;
  color: #fc8181;
  text-align: center;
  padding: 6px;
  background: rgba(127, 29, 29, 0.3);
  border: 2px solid #7f1d1d;
}

/* ─── Loading ───────────────────────────────────────────────────────────────── */

.loading-text {
  font-size: 9px;
  color: #f6e05e;
  text-align: center;
  animation: blink 1s step-end infinite;
}

/* ─── Game screen layout ────────────────────────────────────────────────────── */

#game-screen {
  display: flex;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

/* ─── Sidebar ───────────────────────────────────────────────────────────────── */

#sidebar {
  width: 220px;
  min-width: 200px;
  height: 100%;
  overflow-y: auto;
  background: #0d1526;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: none;
  border-right: 4px solid #2a4060;
  box-shadow: none;
}

.sidebar-title {
  font-size: 9px;
  color: #4fc3f7;
  text-align: center;
  padding-bottom: 8px;
  border-bottom: 2px solid #2a4060;
  text-shadow: 1px 1px 0 #000;
}

.sidebar-section-title {
  font-size: 8px;
  color: #718096;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 2px solid #2a4060;
}

/* ─── Turn indicator ────────────────────────────────────────────────────────── */

.turn-indicator {
  font-size: 9px;
  color: #e2e8f0;
  text-align: center;
  padding: 8px;
  background: #0d1526;
  border: 2px solid #2a4060;
  line-height: 1.6;
  word-break: break-word;
}

.turn-indicator.your-turn {
  color: #f6e05e;
  border-color: #f6e05e;
  animation: glow 1s ease-in-out infinite alternate;
  text-shadow: 0 0 8px rgba(246, 224, 94, 0.8);
}

.turn-indicator.waiting-turn {
  color: #76e4f7;
  border-color: #76e4f7;
}

/* ─── Mine counter ──────────────────────────────────────────────────────────── */

.mine-counter {
  font-size: 12px;
  color: #fc8181;
  text-align: center;
  padding: 6px;
  background: #0d1526;
  border: 2px solid #2a4060;
}

/* ─── Player cards ──────────────────────────────────────────────────────────── */

.player-card {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px;
  border: 2px solid transparent;
  margin-bottom: 4px;
  background: rgba(13, 21, 38, 0.6);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.player-card.current-player {
  border-color: #f6e05e;
  box-shadow: 0 0 8px rgba(246, 224, 94, 0.4);
  background: rgba(246, 224, 94, 0.05);
}

.player-card.eliminated {
  opacity: 0.4;
}

.player-card.eliminated .player-name {
  text-decoration: line-through;
}

.player-dot {
  width: 12px;
  height: 12px;
  border-radius: 0;
  flex-shrink: 0;
  margin-top: 2px;
  box-shadow: 1px 1px 0 #000;
}

.player-info {
  flex: 1;
  min-width: 0;
}

.player-name {
  font-size: 8px;
  color: #e2e8f0;
  word-break: break-word;
  line-height: 1.4;
}

.player-stats {
  font-size: 7px;
  color: #718096;
  margin-top: 3px;
}

/* ─── Board container ───────────────────────────────────────────────────────── */

#board-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #0a0e1a;
  overflow: auto;
  position: relative;
  gap: 8px;
}

/* ─── Smiley bar ────────────────────────────────────────────────────────────── */

#smiley-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

#smiley-btn {
  cursor: pointer;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#game-canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ─── Waiting room ──────────────────────────────────────────────────────────── */

#waiting-room {
  width: 100%;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0e1a;
  overflow-y: auto;
}

.waiting-content {
  max-width: 480px;
  width: 90%;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  text-align: center;
}

#waiting-title {
  font-size: 12px;
  color: #f6e05e;
  text-shadow: 2px 2px 0 #000;
  animation: blink 2s step-end infinite;
}

#waiting-player-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 40px;
}

.waiting-player-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: #0d1526;
  border: 2px solid #2a4060;
  font-size: 9px;
  animation: slide-in 0.3s ease-out;
}

@keyframes slide-in {
  from { opacity: 0; transform: translateX(-20px); }
  to   { opacity: 1; transform: translateX(0); }
}

.player-dot-small {
  width: 10px;
  height: 10px;
  display: inline-block;
  flex-shrink: 0;
  box-shadow: 1px 1px 0 #000;
}

.host-badge {
  font-size: 7px;
  background: #2d6a4f;
  color: #fff;
  padding: 2px 5px;
  margin-left: auto;
}

.you-badge {
  font-size: 7px;
  color: #f6e05e;
}

.waiting-status {
  font-size: 9px;
  color: #a0aec0;
}

/* ─── Share box ─────────────────────────────────────────────────────────────── */

.share-box {
  width: 100%;
  background: #0d1526;
  border: 2px solid #2a4060;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  font-size: 8px;
  color: #a0aec0;
}

.share-code {
  font-size: 22px;
  color: #4fc3f7;
  letter-spacing: 6px;
  text-shadow: 0 0 10px rgba(79,195,247,0.5);
  padding: 8px;
  background: #0a0e1a;
  border: 2px solid #4fc3f7;
  width: 100%;
  text-align: center;
}

.share-link-row {
  display: flex;
  gap: 8px;
  width: 100%;
}

.share-input {
  flex: 1;
  font-size: 7px;
}

.small-text {
  font-size: 7px;
}

/* ─── Modal overlay ─────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.modal {
  max-width: 400px;
  width: 90%;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  text-align: center;
}

/* ─── Game over ─────────────────────────────────────────────────────────────── */

.game-over-content {
  max-width: 420px;
}

.game-over-title {
  font-size: 24px;
  color: #fc8181;
  text-shadow: 4px 4px 0 #000;
  animation: glow-red 1s ease-in-out infinite alternate;
}

@keyframes glow-red {
  from { text-shadow: 4px 4px 0 #000, 0 0 10px rgba(252, 129, 129, 0.3); }
  to   { text-shadow: 4px 4px 0 #000, 0 0 20px rgba(252, 129, 129, 0.8); }
}

.game-over-message {
  font-size: 9px;
  color: #a0aec0;
}

.winner-display {
  margin: 8px 0;
}

.winner-name {
  font-size: 13px;
  text-shadow: 2px 2px 0 #000;
  line-height: 1.6;
}

/* ─── Toast notifications ───────────────────────────────────────────────────── */

#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 900;
  pointer-events: none;
}

.toast {
  background: #1a2035;
  border: 3px solid #2a4060;
  box-shadow: 4px 4px 0 #000;
  color: #e2e8f0;
  font-family: "Press Start 2P", monospace;
  font-size: 8px;
  padding: 10px 14px;
  max-width: 280px;
  word-break: break-word;
  opacity: 0;
  transform: translateX(40px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast.toast-visible {
  opacity: 1;
  transform: translateX(0);
}

/* ─── Your turn toast ───────────────────────────────────────────────────────── */

.your-turn-toast {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 20px;
  z-index: 1000;
  pointer-events: none;
  animation: pulse-toast 1s ease-in-out infinite alternate;
  white-space: nowrap;
}

@keyframes pulse-toast {
  from { opacity: 0.7; transform: translateX(-50%) scale(0.97); }
  to   { opacity: 1;   transform: translateX(-50%) scale(1.03); }
}

/* ─── Animations ────────────────────────────────────────────────────────────── */

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

@keyframes glow {
  from { text-shadow: 0 0 4px rgba(246, 224, 94, 0.4); }
  to   { text-shadow: 0 0 12px rgba(246, 224, 94, 1), 0 0 24px rgba(246, 224, 94, 0.5); }
}

/* ─── Mobile sidebar ────────────────────────────────────────────────────────── */

@media (max-width: 640px) {
  html, body {
    overflow: hidden;
    height: 100%;
  }

  #app {
    height: 100%;
    flex-direction: column;
  }

  #game-screen {
    flex-direction: column;
    height: 100%;
  }

  #turn-indicator,
  .your-turn-toast {
    display: none !important;
  }

  #sidebar {
    width: 100%;
    min-width: unset;
    height: auto;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    flex-shrink: 0;
  }

  .sidebar-panel {
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 4px solid #2a4060;
    gap: 6px;
    padding: 8px;
  }

  .sidebar-title { display: none; }

  .sidebar-section-title {
    display: none;
  }

  #player-list {
    display: flex;
    flex-direction: row;
    gap: 6px;
    flex-wrap: wrap;
  }

  .player-card {
    margin-bottom: 0;
    min-width: 80px;
  }

  #board-container {
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  .game-title {
    font-size: 22px;
  }

  .your-turn-toast {
    font-size: 14px;
    top: 40px;
  }
}

/* ─── Scrollbar ─────────────────────────────────────────────────────────────── */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #0d1526;
}

::-webkit-scrollbar-thumb {
  background: #2a4060;
}

::-webkit-scrollbar-thumb:hover {
  background: #3d5a80;
}

/* ─── Scanline overlay (subtle) ─────────────────────────────────────────────── */

body::after {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.04) 2px,
    rgba(0, 0, 0, 0.04) 4px
  );
  pointer-events: none;
  z-index: 9999;
}

/* ─── Custom settings ───────────────────────────────────────────────────────── */

#custom-settings,
#custom-settings-online {
  margin-top: 8px;
  padding: 10px;
  background: #0d1526;
  border: 2px solid #2a4060;
}
