:root {
  --bg: #0f0f12;
  --surface: #1a1a20;
  --surface-2: #25252d;
  --border: #33333d;
  --text: #f0f0f5;
  --muted: #a0a0b0;
  --primary: #2ed573;
  --primary-dark: #24aa5c;
  --accent: #1e90ff;
  --danger: #ff4757;
  --warning: #ffa502;
  --info: #747d8c;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0,0,0,0.4);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body, #app {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.screen {
  position: fixed;
  inset: 0;
  display: none;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  overflow-y: auto;
}

.screen.active {
  display: flex;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
  text-align: center;
}

.card.wide {
  max-width: 560px;
}

.card h1 {
  margin: 0 0 0.25rem 0;
  font-size: 1.75rem;
}

.card h2 {
  margin: 0 0 1rem 0;
  font-size: 1.4rem;
}

.subtitle {
  color: var(--muted);
  margin: 0 0 1.5rem 0;
  font-size: 0.95rem;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.5rem 0;
}

label {
  display: block;
  text-align: left;
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0.75rem 0 0.35rem 0;
}

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 0.85rem 1rem;
  font-size: 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  outline: none;
}

input[type="text"]:focus,
input[type="password"]:focus {
  border-color: var(--primary);
}

.btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  padding: 0.9rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.05s ease, background 0.15s ease;
  min-height: 48px;
}

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

.btn-primary {
  background: var(--primary);
  color: #052814;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-primary:disabled {
  background: #3a4a40;
  color: #777;
  cursor: not-allowed;
}

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

.btn-secondary:hover {
  background: #1873cc;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--surface-2);
}

.btn-stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.home-secondary {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
}

.language-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

.language-row label {
  margin: 0;
}

.language-row select {
  width: auto;
  min-width: 120px;
  margin: 0;
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin: 1rem 0;
}

.mode-btn {
  width: 100%;
  padding: 0.75rem 0.5rem;
  font-size: 0.95rem;
}

.mode-btn.selected {
  outline: 2px solid var(--primary);
}

.create-options {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: 1rem;
  text-align: left;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.form-row {
  margin: 0.75rem 0;
}

.form-row label {
  margin-top: 0;
}

.lobby-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
  text-align: left;
}

.lobby-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s ease;
}

.lobby-list li:last-child {
  border-bottom: none;
}

.lobby-list li:hover {
  background: var(--surface-2);
}

.lobby-list .lobby-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.form-error {
  color: var(--danger);
  font-size: 0.9rem;
  min-height: 1.2rem;
  margin-top: 0.5rem;
}

.hidden {
  display: none !important;
}

.code {
  font-family: 'SFMono-Regular', Consolas, monospace;
  letter-spacing: 0.05em;
  background: var(--surface-2);
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  font-size: 0.9rem;
}

.url {
  word-break: break-all;
  font-size: 0.8rem;
  color: var(--muted);
}

.player-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
  text-align: left;
}

.player-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
}

.player-list li:last-child {
  border-bottom: none;
}

.badge {
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  text-transform: uppercase;
  font-weight: 700;
}

.badge-host {
  background: var(--accent);
  color: #fff;
}

.badge-ready {
  background: var(--primary);
  color: #052814;
}

.badge-waiting {
  background: var(--surface-2);
  color: var(--muted);
}

.badge-spectator {
  background: var(--info);
  color: #fff;
}

.badge-danger {
  background: var(--danger);
  color: #fff;
}

.battle-notice {
  color: var(--danger);
  font-weight: 600;
}

.player-list .spectator-header {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

/* Game layout */
.game-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1rem;
  z-index: 20;
}

.game-title {
  font-weight: 700;
  font-size: 1rem;
}

.game-stats {
  display: flex;
  gap: 1rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.game-stats strong {
  color: var(--text);
}

.timer {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  transition: color 0.2s ease;
}

.timer.low {
  color: var(--danger);
  font-weight: 700;
}

.game-layout {
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
}

#panorama-section {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
}

#mly {
  width: 100%;
  height: 100%;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: rgba(0,0,0,0.92);
  z-index: 10;
  text-align: center;
  padding: 1rem;
}

.loading-overlay.hidden {
  display: none;
}

#loadingText {
  max-width: 90%;
  white-space: pre-line;
  line-height: 1.4;
  margin: 0 0 1rem 0;
}

#loadingActions {
  width: 100%;
  max-width: 280px;
}

#loadingActions .btn {
  min-height: 44px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--surface-2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 1rem;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#map-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
}

#minimap {
  flex: 1;
  min-height: 0;
}

.map-controls {
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  text-align: center;
}

.map-controls .hint {
  margin: 0.5rem 0;
}

.map-controls-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
}

.map-style-select {
  flex: 1;
  margin-top: 0;
  padding: 0.5rem 0.75rem;
  min-height: 40px;
  font-size: 0.9rem;
}

.btn-icon {
  width: 40px;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  font-size: 1.2rem;
}

/* Spectator / eliminated mode hides the guessing controls */
#map-section.spectator-mode .map-controls {
  display: none;
}

#map-section.spectator-mode::after {
  content: 'Spectator view';
  display: block;
  padding: 0.5rem;
  background: var(--surface-2);
  color: var(--muted);
  text-align: center;
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

/* Compass overlay */
.compass {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 64px;
  height: 64px;
  z-index: 5;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 50%;
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.compass.hidden {
  display: none;
}

.compass-rose {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.6);
  transition: transform 0.1s linear;
}

.compass-rose span {
  position: absolute;
  font-size: 0.65rem;
  font-weight: 700;
  color: #fff;
}

.compass-n { top: 2px; left: 50%; transform: translateX(-50%); color: #ff4757; }
.compass-e { right: 4px; top: 50%; transform: translateY(-50%); }
.compass-s { bottom: 2px; left: 50%; transform: translateX(-50%); }
.compass-w { left: 4px; top: 50%; transform: translateY(-50%); }

.compass-needle {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  height: 22px;
  background: var(--warning);
  transform: translate(-50%, -100%);
  transform-origin: bottom center;
  border-radius: 2px;
}

.achievement-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.4rem 0.75rem;
  margin: 0.25rem;
  font-size: 0.85rem;
}

.achievement-badge.unlocked {
  border-color: var(--primary);
  background: rgba(46, 213, 115, 0.15);
}

.achievement-badge.locked {
  opacity: 0.5;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  display: none;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  z-index: 100;
  overflow-y: auto;
}

.modal:not(.hidden) {
  display: flex;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.modal-card.wide {
  max-width: 900px;
}

.modal-card h2 {
  margin-top: 0;
  text-align: center;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.9rem;
}

.results-table th,
.results-table td {
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.results-table th {
  color: var(--muted);
  font-weight: 600;
}

.results-table td:last-child,
.results-table th:last-child {
  text-align: right;
}

.leaderboard-row {
  display: flex;
  justify-content: space-between;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

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

.place {
  color: var(--warning);
  font-weight: 700;
  margin-right: 0.5rem;
}

/* Game summary map modal */
.summary-map-card {
  width: 100%;
  max-width: 900px;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}

.summary-map-wrap {
  width: 100%;
  height: 50vh;
  min-height: 280px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  margin: 0.5rem 0 1rem 0;
}

#game-summary-map {
  width: 100%;
  height: 100%;
}

.summary-body {
  max-height: 25vh;
  overflow-y: auto;
  margin-bottom: 1rem;
}

.summary-legend {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.summary-legend .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 0.3rem;
}

.summary-legend .dot.green {
  background: var(--primary);
}

.summary-legend .dot.red {
  background: var(--danger);
}

.summary-round-row {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

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

/* Player guess markers on main map */
.mapboxgl-popup-content {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
}

.mapboxgl-popup-tip {
  border-top-color: var(--surface);
  border-bottom-color: var(--surface);
}

/* Touch-friendly map controls */
.mapboxgl-ctrl-group button {
  width: 36px;
  height: 36px;
}

.menu-links {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-top: 1rem;
}

.link-btn {
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 0.9rem;
  text-decoration: underline;
  cursor: pointer;
  padding: 0.25rem;
}

.bonus {
  color: var(--accent);
}

.bonus-tag {
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  margin-left: 0.25rem;
}

select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.8rem;
  font-size: 1rem;
  width: 100%;
  margin-top: 0.25rem;
  -webkit-appearance: none;
  appearance: none;
}

/* Mobile-first stacked layout */
.game-layout {
  display: flex;
  flex-direction: column;
  height: calc(100% - 56px);
}

#panorama-section {
  flex: 1.2;
  min-height: 0;
  position: relative;
}

#map-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border);
  transition: flex 0.25s ease;
}

#map-section.expanded {
  flex: 3;
}

#panorama-section.shrunk {
  flex: 0.6;
}

/* Tablet / desktop: side-by-side */
@media (min-width: 900px) {
  .game-layout {
    flex-direction: row;
  }

  #panorama-section {
    flex: 1.6;
    border-right: 1px solid var(--border);
  }

  #panorama-section.shrunk {
    flex: 1;
  }

  #map-section {
    flex: 1;
    border-top: none;
    max-width: 420px;
  }

  #map-section.expanded {
    flex: 1.8;
    max-width: 55vw;
  }
}

/* Large phones / small tablets in landscape */
@media (max-height: 500px) and (orientation: landscape) {
  .game-layout {
    flex-direction: row;
  }

  #panorama-section {
    flex: 1;
    border-right: 1px solid var(--border);
  }

  #map-section {
    flex: 1;
    border-top: none;
  }
}
