:root {
  --bg: #f7f6f3;
  --panel: #ffffff;
  --text: #37352f;
  --muted: #6b6b6b;
  --border: #e0dfdc;
  --blue: #2383e2;
}

body.dark-mode {
  --bg: #191919;
  --panel: #202020;
  --text: #d3d3d3;
  --muted: #9b9b9b;
  --border: #2f2f2f;
}

body.dark-mode .leaderboard-table thead th {
  background: rgba(32, 32, 32, 0.9);
}

body.dark-mode .leaderboard-table tr.lb-row:hover {
  background: rgba(255, 255, 255, 0.05);
}

body.dark-mode .dist-bar,
body.dark-mode .dim-bar,
body.dark-mode .pill {
  background: rgba(255, 255, 255, 0.1);
}

body.dark-mode .star-btn {
  background: rgba(255, 255, 255, 0.1);
  color: #666;
  border-color: var(--border);
}

body.dark-mode .star-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

body.dark-mode .star-btn.is-active,
body.dark-mode .star-btn.is-hover {
  background: rgba(223, 171, 1, 0.2);
  color: #dfab01;
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Space Grotesk", ui-sans-serif, system-ui, -apple-system,
    Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  line-height: 1.4;
}

a {
  color: var(--blue);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.semi-bold {
  font-weight: 600;
}

.medium {
  font-weight: 500;
}

.page-container {
  max-width: 980px;
  margin: 0 auto;
}

.app-header {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  position: relative;
}

.app-logo {
  color: var(--text);
  font-weight: 700;
  font-size: 1.125rem;
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.app-logo:hover {
  text-decoration: none;
  opacity: 0.8;
}

.app-logo__img {
  width: 3rem;
  border-radius: 0.25rem;
  overflow: hidden;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  justify-content: center;
}

.nav-link {
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
  padding: 8px 12px;
  border-radius: 6px;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

.nav-link:hover {
  color: var(--text);
  background: var(--bg);
  text-decoration: none;
}

.nav-link--active {
  color: var(--text);
  background: var(--bg);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.user-name {
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  margin-right: 8px;
}

.user-emoji {
  font-size: 20px;
}

.theme-toggle {
  padding: 6px 10px;
  font-size: 20px;
  min-width: auto;
}

.mobile-menu-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  cursor: pointer;
  flex-direction: column;
  gap: 4px;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.mobile-menu-toggle:hover {
  background: var(--bg);
}

.hamburger-icon {
  display: block;
  width: 24px;
  height: 2px;
  background: var(--text);
  position: relative;
  transition: background 0.2s ease;
}

.hamburger-icon::before,
.hamburger-icon::after {
  content: "";
  display: block;
  width: 24px;
  height: 2px;
  background: var(--text);
  position: absolute;
  left: 0;
  transition: transform 0.2s ease;
}

.hamburger-icon::before {
  top: -8px;
}

.hamburger-icon::after {
  bottom: -8px;
}

/* Mobile menu open state */
.nav-container.menu-open .hamburger-icon {
  background: transparent;
}

.nav-container.menu-open .hamburger-icon::before {
  transform: rotate(45deg);
  top: 0;
}

.nav-container.menu-open .hamburger-icon::after {
  transform: rotate(-45deg);
  bottom: 0;
}

/* Responsive styles */
@media (max-width: 768px) {
  .nav-container {
    padding: 12px 16px;
    flex-wrap: nowrap;
  }

  .app-logo {
    flex: 0 0 auto;
  }

  .mobile-menu-toggle {
    display: flex;
  }

  .nav-links {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    display: none !important; /* Force hide by default */
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 4px 12px rgba(55, 53, 47, 0.08);
    padding: 8px 0;
    z-index: 50;
    justify-content: flex-start;
    flex: none;
  }

  .nav-container.menu-open .nav-links {
    display: flex !important; /* Show when menu is open */
  }

  .nav-link {
    width: 100%;
    text-align: left;
    padding: 12px 16px;
    border-radius: 0;
  }

  .nav-actions {
    flex-shrink: 0;
    gap: 8px;
    margin-left: auto;
  }

  .user-name {
    display: none;
  }

  .theme-toggle {
    padding: 8px;
    font-size: 18px;
  }

  .btn--primary {
    padding: 8px 12px;
    font-size: 14px;
  }
}

/* Extra small screens */
@media (max-width: 480px) {
  .auth-guest.btn--primary {
    font-size: 13px;
    padding: 8px 10px;
  }

  .app-logo {
    font-size: 16px;
  }
}

.text-muted {
  color: var(--muted);
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.btn {
  display: inline-block;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}

.btn:hover {
  filter: brightness(0.98);
  text-decoration: none;
}

.btn--primary {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

.btn--ghost {
  background: transparent;
}

.input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--panel);
  color: var(--text);
  font-family: inherit;
}

.input:focus {
  outline: none;
  border-color: rgba(35, 131, 226, 0.7);
  box-shadow: 0 0 0 3px rgba(35, 131, 226, 0.15);
}

.user-avatar {
  width: 22px;
  height: 22px;
  background: var(--border);
  vertical-align: middle;
}

.user-menu {
  position: relative;
}

.user-menu__dropdown {
  position: absolute;
  right: 0;
  top: 36px;
  min-width: 180px;
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(55, 53, 47, 0.12);
  border-color: var(--border);
}

.stat-value {
  font-size: 28px;
  font-weight: 600;
}

.rating-scale-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

@media (max-width: 640px) {
  .rating-scale-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 360px) {
  .rating-scale-grid {
    grid-template-columns: 1fr;
  }
}

/* Model detail */
.back-link {
  color: var(--muted);
  font-weight: 700;
}

.back-link:hover {
  color: var(--text);
  text-decoration: none;
}

.dist-row {
  display: grid;
  grid-template-columns: 92px 1fr 120px;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

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

.dist-label {
  font-weight: 600;
  color: var(--text);
}

.dist-meta {
  text-align: right;
}

.dist-bar {
  height: 12px;
  border-radius: 999px;
  background: rgba(232, 231, 228, 0.9);
  overflow: hidden;
  border: 1px solid var(--border);
}

.dist-bar__fill {
  height: 100%;
  background: #dfab01;
  border-radius: 999px;
}

.task-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.dim-row {
  display: grid;
  grid-template-columns: 140px 1fr 92px;
  gap: 12px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

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

.dim-bar {
  height: 12px;
  border-radius: 999px;
  background: rgba(232, 231, 228, 0.9);
  overflow: hidden;
  border: 1px solid var(--border);
}

.dim-bar__fill {
  height: 100%;
  background: var(--blue);
  border-radius: 999px;
}

.dim-meta {
  text-align: right;
}

@media (max-width: 880px) {
  .task-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .task-grid {
    grid-template-columns: 1fr;
  }

  .dist-row {
    grid-template-columns: 72px 1fr 92px;
  }

  .dim-row {
    grid-template-columns: 120px 1fr 72px;
  }
}

/* Leaderboard */
.leaderboard-table {
  border-collapse: collapse;
  width: 100%;
}

.leaderboard-table th,
.leaderboard-table td {
  padding: 12px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.leaderboard-table thead th {
  background: rgba(239, 238, 233, 0.6);
  font-weight: 600;
  color: var(--text);
  position: sticky;
  top: 0;
}

.leaderboard-table tr.lb-row:hover {
  background: rgba(232, 231, 228, 0.6);
  cursor: pointer;
}

.lb-col-rank {
  width: 52px;
  color: var(--muted);
}

.lb-col-model {
  min-width: 260px;
}

.lb-model-link {
  color: var(--text);
  font-weight: 500;
}

.lb-model-link:hover {
  text-decoration: underline;
}

.lb-star {
  color: #dfab01;
}

th.lb-sort {
  user-select: none;
  cursor: pointer;
}

th.lb-sort--active {
  color: var(--blue);
}

.overflow-hidden {
  overflow: hidden;
}

.overflow-auto {
  overflow: auto;
}

.auth-guest {
  display: inline-block;
}

.auth-user {
  display: inline-block;
}

.authenticated .auth-guest {
  display: none !important;
}

.authenticated .auth-user {
  display: inline-block !important;
}

/* Rating form (Phase 5) */
.toast {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(55, 53, 47, 0.12);
  color: var(--text);
  font-weight: 600;
  max-width: 360px;
  line-height: 1.35;
  white-space: pre-wrap;
}

.toast--error {
  border-color: #e03e3e;
}

.toast--success {
  border-color: #0f7b6c;
}

.star-field {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.star-buttons {
  display: inline-flex;
  gap: 4px;
}

.star-btn {
  -webkit-appearance: none;
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(232, 231, 228, 0.55);
  color: #9b9a97;
  cursor: pointer;
  font-size: 28px;
  line-height: 1;
  padding: 6px 8px;
  border-radius: 10px;
  transition: transform 0.08s ease, background 0.12s ease, color 0.12s ease;
}

.star-btn:hover {
  background: rgba(232, 231, 228, 0.85);
  transform: translateY(-1px);
}

.star-btn:focus-visible {
  outline: none;
  border-color: rgba(35, 131, 226, 0.75);
  box-shadow: 0 0 0 3px rgba(35, 131, 226, 0.15);
}

.star-btn.is-active,
.star-btn.is-hover {
  color: #dfab01;
  border-color: rgba(223, 171, 1, 0.75);
  background: rgba(223, 171, 1, 0.14);
}

.rating-label {
  font-weight: 600;
  color: var(--muted);
}

.details-toggle {
  width: 100%;
  text-align: left;
}

.hint {
  color: var(--muted);
}

/* Small pill badge (Admin) */
.pill {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(232, 231, 228, 0.6);
  color: var(--muted);
  vertical-align: middle;
}

/* Modal overlay and content */
#modal-overlay {
  backdrop-filter: blur(2px);
}

#modal-overlay .card {
  box-shadow: 0 20px 60px rgba(55, 53, 47, 0.25);
  animation: modal-slide-in 0.2s ease;
}

@keyframes modal-slide-in {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(-10px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

#model-form label {
  display: block;
}

#model-form input[type="checkbox"] {
  margin-right: 8px;
  cursor: pointer;
}

/* 404 Page */
.card.block {
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.card.block:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(55, 53, 47, 0.12);
  text-decoration: none;
}
