/* Mobile-first styles for the RAM Raid leaderboard */
:root {
  --bg: #0b0b0f;
  --card: #14141a;
  --text: #f1f5f9;
  --muted: #9aa3af;
  --accent: #8b5cf6;
  --accent-2: #22d3ee;
  --border: #242633;
}

/* Light theme overrides */
body.light-theme {
  --bg: #ffffff;
  --card: #f8f9fa;
  --text: #1a1a1a;
  --muted: #6c757d;
  --accent: #8b5cf6;
  --accent-2: #22d3ee;
  --border: #e0e0e0;
}

body.light-theme .site-header {
  background: linear-gradient(180deg, rgba(255,255,255,0.95), rgba(255,255,255,0.75));
}

body.light-theme .spinner {
  border-color: #e0e0e0;
  border-top-color: var(--accent);
}

* { 
  box-sizing: border-box; 
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
}

.site-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  position: sticky;
  top: 0;
  background: linear-gradient(180deg, rgba(11,11,15,0.95), rgba(11,11,15,0.75));
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
}

.brand { 
  display: flex; 
  align-items: center; 
  gap: .75rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;

  /* ✅ Add at least 100px space on the left */
  margin-left: 120px;
}

.brand .logo { 
  width: 32px; 
  height: 32px;
  flex-shrink: 0;
}

.brand h1 { 
  font-size: 1.1rem; 
  margin: 0; 
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.searchbar {
  display: grid;
  gap: .75rem;
  padding: .75rem 1rem;
  width: 100%;
  max-width: 100vw;
  overflow: hidden;
}

.controls-grid {
  display: grid;
  grid-template-columns: auto auto;
  gap: .75rem;
  align-items: center;
  width: 100%;
  overflow: hidden;
}

.activity-form, .event-form, .units-form {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: .75rem;
  display: grid;
  gap: .5rem;
  min-width: 0;
  overflow: hidden;
}

.event-form, .units-form {
  min-width: max-content;
  max-width: 100%;
}

.activity-form {
  min-width: 0;
}

.activity-form label, .event-form label, .units-form label, .user-form label {
  display: grid;
  gap: .25rem;
  color: var(--muted);
  font-size: .9rem;
  min-width: 0;
}

.event-id {
  font-family: monospace;
  font-size: 1rem;
  color: var(--text);
  background: transparent;
  padding: .5rem .6rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  display: block;
  white-space: nowrap;
}

.activity-form select, .units-form select, .user-form input {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .5rem .6rem;
  outline: none;
  font-size: 1rem;
  min-width: 0;
  max-width: 100%;
  width: 100%;
}

.activity-form select, .units-form select {
  cursor: pointer;
}

.activity-form select:hover,
.units-form select:hover,
.user-form input:hover,
.user-form input:focus,
.activity-form select:focus,
.units-form select:focus {
  border-color: var(--accent);
}

.activity-description {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
  margin-top: 0.25rem;
  padding: .75rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.user-form {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: .75rem;
  display: grid;
  gap: .5rem;
  width: 100%;
  min-width: 0;
}

.user-form button, .pager button {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: .55rem .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s ease;
  font-size: 0.9rem;
  white-space: nowrap;
  min-width: 0;
}

.user-form button:hover,
.pager button:not([disabled]):hover {
  opacity: 0.9;
}

.pager button[disabled] {
  opacity: .5;
  cursor: not-allowed;
}

/* Table container with horizontal scroll */
.table-container {
  width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
}

/* Simple, standard table formatting */
.board {
  width: 100%;
  min-width: 100%;
  border-collapse: collapse;
  background: var(--bg);
  margin: 0;
}

.board thead {
  background: var(--bg);
  z-index: 50;
}

.board th, .board td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  white-space: nowrap;
}

.board th {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  text-align: left;
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 50;
}

/* Column widths */
.board th:nth-child(1), .board td:nth-child(1) { /* Rank */
  width: 60px;
  text-align: left;
  padding-right: 0.5rem;
}

.board th:nth-child(2), .board td:nth-child(2) { /* User */
  text-align: left;
  padding-right: 0.5rem;
}

.board th:nth-child(3), .board td:nth-child(3) { /* Area */
  text-align: left;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
  font-variant-numeric: tabular-nums;
  white-space: nowrap; /* Prevent wrapping of area values */
}

/* User cell styling */
.user-cell {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-avatar {
  width: 32px;
  height: 20px;
  border-radius: 4px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: #0f0f14;
  flex-shrink: 0;
}

.username-display {
  transition: color 0.3s ease;
}

.username-display.loading-username {
  color: var(--muted);
  font-style: italic;
  position: relative;
}

.username-display.loading-username::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(139, 92, 246, 0.1), transparent);
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: 2px;
}

/* Loading states */
.username-display.loading-username {
  color: var(--muted);
  font-style: italic;
  position: relative;
}

.username-display.loading-username::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent, rgba(139, 92, 246, 0.1), transparent);
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: 2px;
}

@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

.loading {
  display: grid;
  place-items: center;
  gap: .5rem;
  color: var(--muted);
  padding: 1rem;
  width: 100%;
}

.loading[hidden] {
  display: none !important;
}

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.sentinel { 
  height: 1px; 
  width: 100%;
}

.site-footer {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: .6rem .75rem;
  display: grid;
  gap: .5rem;
  width: 100%;
  max-width: 100vw;
  margin-top: 4rem;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  width: 100%;
  min-width: 0;
}

#pageInfo {
  white-space: nowrap;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.update-note {
  margin: 0;
  padding: 0.25rem 0;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}

/* Mobile optimizations */
@media (max-width: 640px) {
  .site-header {
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
  }
  
  .brand h1 { 
    font-size: 1rem;
  }
  
  .searchbar {
    padding: .5rem .75rem;
  }
  
  .controls-grid {
    grid-template-columns: 1fr auto;
    gap: .5rem;
  }
  
  .board th, .board td {
    padding: 0.5rem 0.5rem;
    font-size: 0.85rem;
  }

  .board th:nth-child(1), .board td:nth-child(1) {
    width: 50px;
    padding-right: 0.35rem;
  }

  .board th:nth-child(2), .board td:nth-child(2) {
    padding-right: 0.35rem;
  }
  
  .user-cell {
    gap: 0.5rem;
  }
  
  .user-avatar {
    width: 28px;
    height: 18px;
  }

  .username-display {
    font-size: 0.85rem;
  }
  
  .pager {
    gap: .5rem;
  }
  
  .pager button {
    padding: .5rem .7rem;
    font-size: 0.85rem;
  }
  
  #pageInfo {
    font-size: 0.8rem;
  }
  
  .update-note {
    font-size: 0.75rem;
  }
}

/* Tablet and larger */
@media (min-width: 640px) {
  .brand h1 { font-size: 1.25rem; }
  
  .searchbar {
    padding: 0 1rem .75rem 1rem;
  }
  
  .user-form {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: end;
    gap: .75rem;
  }
}

@media (min-width: 768px) {
  .searchbar {
    padding: 0 1rem 1rem 1rem;
  }
}