
:root {
  --bg: #0a0a0f;
  --surface: #13131f;
  --surface-raised: #1a1a2e;
  --border: #252538;
  --text-primary: #f0f0f5;
  --text-secondary: #a0a0b0;
  --text-tertiary: #6e6e80;
  --text-muted: #4a4a5c;
  --accent-green: #22c55e;
  --accent-blue: #3b82f6;
  --accent-red: #ef4444;
  --accent-amber: #f59e0b;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-xl: 16px;
}

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

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  padding: 24px 16px;
  line-height: 1.5;
  min-height: 100vh;
}

/* Header */
.site-header {
  max-width: 1200px;
  margin: 0 auto 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.site-title h1 {
  font-size: 35px;
  font-weight: 600;
  letter-spacing: -0.5px;
}

.site-title p {
  font-size: 16px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.controls label {
  font-size: 18px;
  color: var(--text-secondary);
}

#sortSelect {
  padding: 8px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  outline: none;
}

#sortSelect:focus {
  border-color: var(--accent-blue);
}

/* Grid */
#profiles {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  position: relative;
  overflow: hidden;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  border-color: #353550;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: transparent;
  transition: background 0.15s ease;
}

.card.done-today::before {
  background: var(--accent-green);
}

.card.not-done::before {
  background: var(--accent-red);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
  flex-shrink: 0;
}

.card-header-text {
  flex: 1;
  min-width: 0;
}

.card-header-text h3 {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-link {
  color: var(--text-primary);
  text-decoration: none;
}

.profile-link:hover {
  color: var(--accent-blue);
  text-decoration: underline;
}

.handle {
  font-size: 12px;
  color: var(--text-tertiary);
  display: block;
  margin-top: 1px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 8px currentColor;
}

.status-dot.done-today {
  background: var(--accent-green);
  color: var(--accent-green);
}

.status-dot.not-done {
  background: var(--accent-red);
  color: var(--accent-red);
}

/* Stats pills */
.stats-pills {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.pill {
  flex: 1;
  text-align: center;
  padding: 8px 4px;
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  transition: background 0.15s;
}

.pill-val {
  font-size: 16px;
  font-weight: 600;
  display: block;
  font-variant-numeric: tabular-nums;
}

.pill-label {
  font-size: 11px;
  color: var(--text-tertiary);
  display: block;
  margin-top: 2px;
}

.pill.easy .pill-val { color: var(--accent-green); }
.pill.medium .pill-val { color: var(--accent-blue); }
.pill.hard .pill-val { color: var(--accent-red); }

/* Streak */
.streak-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.streak-row svg {
  color: var(--accent-amber);
  flex-shrink: 0;
}

/* Mini heatmap */
.mini-heatmap {
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  gap: 2px;
  margin-bottom: 14px;
}

.mini-heat {
  aspect-ratio: 1;
  border-radius: 2px;
}

.mini-heat.level-0 { background: var(--surface-raised); }
.mini-heat.level-1 { background: rgba(34, 197, 94, 0.25); }
.mini-heat.level-2 { background: rgba(34, 197, 94, 0.45); }
.mini-heat.level-3 { background: rgba(34, 197, 94, 0.7); }
.mini-heat.level-4 { background: var(--accent-green); }

/* Recent list */
.recent-list {
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.recent-title {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-bottom: 8px;
  font-weight: 500;
}

.recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 12px;
}

.recent-item a {
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 70%;
}

.recent-item a:hover {
  text-decoration: underline;
  color: var(--accent-blue);
}

.tag {
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--surface-raised);
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.private-text {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.5;
}

/* Error card */
.error-card {
  opacity: 0.7;
}

.error-text {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-top: 8px;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 999;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.active {
  display: flex;
}

.modal-content {
  width: 540px;
  max-width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border);
  position: relative;
  box-shadow: 0 24px 48px rgba(0,0,0,0.4);
}

#closeModal {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  line-height: 1;
  z-index: 10;
  transition: all 0.15s;
}

#closeModal:hover {
  background: var(--border);
  color: var(--text-primary);
}

/* Modal hero */
.modal-hero {
  padding: 32px 28px 24px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.modal-avatar {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--border);
  margin-bottom: 14px;
}

.modal-hero h2 {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
}

.modal-handle {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

.modal-about {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 10px;
  line-height: 1.6;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

.rank-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 20px;
  background: var(--surface-raised);
  color: var(--text-secondary);
  margin-top: 12px;
  border: 1px solid var(--border);
}

.rank-badge svg {
  color: var(--accent-amber);
}

/* Modal body */
.modal-body {
  padding: 24px 28px;
}

.modal-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 24px;
}

.modal-stat {
  text-align: center;
  padding: 14px 8px;
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  border: 1px solid var(--border);
}

.modal-stat-val {
  font-size: 24px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.modal-stat-label {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 4px;
  font-weight: 500;
}

.modal-stat.total .modal-stat-val { color: var(--text-primary); }
.modal-stat.easy .modal-stat-val { color: var(--accent-green); }
.modal-stat.medium .modal-stat-val { color: var(--accent-blue); }
.modal-stat.hard .modal-stat-val { color: var(--accent-red); }

/* Modal sections */
.modal-section {
  margin-bottom: 24px;
}

.modal-section:last-child {
  margin-bottom: 0;
}

.modal-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-section-title svg {
  color: var(--text-tertiary);
  flex-shrink: 0;
}

/* Info grid */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.info-item {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  border: 1px solid var(--border);
}

.info-label {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-bottom: 2px;
}

.info-val {
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 600;
}

/* Socials */
.socials {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.social-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text-primary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}

.social-btn:hover {
  background: var(--border);
  border-color: #404060;
  transform: translateY(-1px);
}

.social-btn svg {
  color: var(--text-tertiary);
}

/* Modal recent */
.modal-recent-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.modal-recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  font-size: 13px;
}

.modal-recent-item a {
  color: var(--text-primary);
  text-decoration: none;
  font-weight: 600;
}

.modal-recent-item a:hover {
  text-decoration: underline;
  color: var(--accent-blue);
}

.private-msg {
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.6;
}

/* Modal heatmap override */
.modal .mini-heatmap {
  grid-template-columns: repeat(15, 1fr);
  gap: 3px;
}

.modal .mini-heat {
  border-radius: 3px;
}

/* Loading */
#profiles > p {
  text-align: center;
  color: var(--text-tertiary);
  font-size: 14px;
  padding: 40px;
  grid-column: 1 / -1;
}

/* Scrollbar */
.modal-content::-webkit-scrollbar {
  width: 6px;
}

.modal-content::-webkit-scrollbar-track {
  background: transparent;
}

.modal-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* Responsive */
@media (max-width: 640px) {
  body { padding: 16px 12px; }
  .site-header { flex-direction: column; align-items: flex-start; }
  #profiles { grid-template-columns: 1fr; }
  .modal-stats { grid-template-columns: repeat(2, 1fr); }
  .info-grid { grid-template-columns: 1fr; }
  .modal-content { max-height: 90vh; }
  .modal-hero { padding: 24px 20px 20px; }
  .modal-body { padding: 20px; }
}