@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;700&display=swap");

/* ── Design tokens ────────────────────────────────────────────────────────── */
:root {
  --accent:         #22c55e;
  --accent-text:    #16a34a;
  --accent-faded:   rgba(34, 197, 94, 0.55);
  --accent-dim:     rgba(34, 197, 94, 0.08);
  --accent-border:  rgba(34, 197, 94, 0.35);
  --accent-glow:    0 0 20px rgba(34, 197, 94, 0.12);

  --bg:             #2a2a32;
  --surface:        #2a2a32;
  --surface-raised: #32323c;
  --border:         rgba(255, 255, 255, 0.07);
  --border-strong:  rgba(255, 255, 255, 0.12);

  --text-primary:   #f0f0f4;
  --text-secondary: #a1a1aa;
  --text-muted:     #52525b;

  --sans:           "Inter", system-ui, -apple-system, sans-serif;
  --mono:           "JetBrains Mono", "SF Mono", monospace;

  --card-radius:    10px;
  --card-min-width: 240px;
  --gap:            8px;

  --card-shadow:       0 1px 3px rgba(0, 0, 0, 0.08);
  --card-shadow-hover: 0 6px 20px rgba(0, 0, 0, 0.12), var(--accent-glow);
}

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

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--sans);
  color: var(--text-primary);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Topbar ───────────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

.topbar-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

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

/* ── Subbar (sort row) ────────────────────────────────────────────────────── */
.subbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 6px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Sort toggle (TOP / BAD) ──────────────────────────────────────────────── */
.sort-toggle {
  display: flex;
  align-items: center;
  gap: 2px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 3px;
}

.sort-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 14px;
  border-radius: 999px;
  border: none;
  background: transparent;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  line-height: 1;
}

.sort-btn .sort-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
  opacity: 0.35;
  transition: opacity 0.15s, background 0.15s, box-shadow 0.15s;
}

/* TOP active — green */
.sort-btn--top.sort-btn--active {
  background: rgba(255, 255, 255, 0.1);
  color: var(--accent);
}
.sort-btn--top.sort-btn--active .sort-dot {
  background: var(--accent);
  opacity: 1;
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.8);
}

/* BAD active — red */
.sort-btn--bad.sort-btn--active {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
}
.sort-btn--bad.sort-btn--active .sort-dot {
  background: #ef4444;
  opacity: 1;
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.8);
}

/* OTHER active — amber */
.sort-btn--other.sort-btn--active {
  background: rgba(251, 191, 36, 0.1);
  color: #fbbf24;
}
.sort-btn--other.sort-btn--active .sort-dot {
  background: #f59e0b;
  opacity: 1;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.8);
}

.sort-btn:not(.sort-btn--active):hover {
  color: var(--text-secondary);
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: 7px;
  padding: 5px 12px;
  font-size: 12px;
  font-family: var(--sans);
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
  letter-spacing: 0.01em;
}
.btn:hover {
  color: var(--text-primary);
  background: var(--surface-raised);
}

.btn-primary {
  background: var(--accent-dim);
  border-color: var(--accent-border);
  color: var(--accent-text);
  font-weight: 600;
}
.btn-primary:hover {
  background: rgba(34, 197, 94, 0.14);
  border-color: var(--accent);
}

/* ── Mode pill ────────────────────────────────────────────────────────────── */
.pill {
  font-size: 10px;
  font-family: var(--mono);
  font-weight: 500;
  color: var(--text-muted);
  border: 1px solid var(--border);
  background: transparent;
  padding: 3px 9px;
  border-radius: 999px;
  letter-spacing: 0.04em;
}

/* ── Status ───────────────────────────────────────────────────────────────── */
.status {
  padding: 6px 16px;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ── Scroll container ─────────────────────────────────────────────────────── */
.matrix {
  flex: 1;
  overflow-y: auto;
  position: relative;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}
.matrix::-webkit-scrollbar { width: 6px; }
.matrix::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

/* ── Card — dark surface ──────────────────────────────────────────────────── */
.card {
  background: #131316;
  border-radius: var(--card-radius);
  border: 1px solid rgba(255, 255, 255, 0.11);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: border-color 0.18s, box-shadow 0.18s, transform 0.18s;
}
.card:hover {
  border-color: var(--accent-border);
  box-shadow: var(--card-shadow-hover);
  transform: translateY(-2px);
}

/* ── Card header — name above image ──────────────────────────────────────── */
.card-header {
  padding: 16px 14px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Image thumbnail — 4:5 portrait */
.card-thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: #1a1a1f;
  flex-shrink: 0;
}

.card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s ease;
}
.card:hover .card-img { transform: scale(1.03); }

.card-img-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 6px;
  color: #52525b;
  font-size: 12px;
  font-family: var(--mono);
}
.card-img-error span { font-size: 26px; opacity: 0.25; }

/* ── Card eyebrow + name ──────────────────────────────────────────────────── */
.card-eyebrow {
  margin: 0 0 2px;
  font-size: 9px;
  font-family: var(--mono);
  font-weight: 500;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.7;
}

.card-name {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  color: #f0f0f4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}

/* ── Card body — stars + metrics ─────────────────────────────────────────── */
.card-body {
  padding: 8px 10px 8px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── Stars — in header, after name, before image ─────────────────────────── */
.card-stars {
  display: inline-flex;
  flex-direction: row;
  gap: 2px;
  align-items: center;
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.3);
  border-radius: 5px;
  padding: 2px 6px;
  width: fit-content;
}

.card-star {
  font-size: 11px;
  line-height: 1;
  color: var(--accent);
}

/* ── Poop — shown when stars = 0 ─────────────────────────────────────────── */
.card-poop {
  display: inline-flex;
  align-items: center;
  background: rgba(139, 90, 43, 0.15);
  border: 1px solid rgba(139, 90, 43, 0.4);
  border-radius: 5px;
  padding: 2px 6px;
  width: fit-content;
  font-size: 11px;
  line-height: 1;
}

/* ── Metrics grid — full card width ───────────────────────────────────────── */
.card-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 0 -10px -8px;
  overflow: hidden;
  background: #0f0f12;
}

.card-metric-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 7px 4px;
  border-right: 1px solid rgba(34, 197, 94, 0.25);
  border-bottom: 1px solid rgba(34, 197, 94, 0.25);
}
.card-metric-cell:nth-child(3n)        { border-right: none; }
.card-metric-cell:nth-last-child(-n+3) { border-bottom: none; }

.card-metric-label {
  font-size: 8px;
  font-family: var(--mono);
  font-weight: 600;
  color: rgba(34, 197, 94, 0.6);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 2px;
}

.card-metric-value {
  font-size: 11px;
  font-family: var(--mono);
  font-weight: 700;
  color: #f0f0f4;
  font-variant-numeric: tabular-nums;
}

/* ── Settings modal ───────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.modal-box {
  background: #32323c;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 26px 28px 28px;
  width: min(500px, calc(100vw - 32px));
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.15);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}

.modal-title {
  margin: 0 0 3px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.modal-subtitle {
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--text-muted);
}

.modal-field  { margin-bottom: 12px; }

.modal-label {
  display: block;
  font-size: 11px;
  font-family: var(--mono);
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
  margin-bottom: 5px;
}

.modal-select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  font-size: 13px;
  font-family: var(--sans);
  background: #2a2a32;
  color: var(--text-primary);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23a1a1aa' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
  transition: border-color 0.12s;
}
.modal-select:focus {
  outline: none;
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.1);
}

.modal-loading {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text-muted);
  margin: 8px 0 14px;
}

.modal-error { color: #dc2626; font-size: 12px; margin-bottom: 10px; }

.modal-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0 14px;
}

.modal-section-label {
  margin: 0 0 10px;
  font-size: 10px;
  font-family: var(--mono);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.modal-metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0 10px;
}

.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 22px; }
