:root {
  --font: ui-monospace, "JetBrains Mono", "Fira Code", "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --bg: #16181d;
  --bg-sidebar: #101216;
  --bg-card: #1c1f25;
  --bg-card-head: #22262d;
  --border: #2a2e36;
  --text: #d8dade;
  --muted: #8a8f98;
  --accent: #e8a44c;
  --accent-dim: #b97f34;
  --accent-text: #16181d;
  --shadow: rgba(0, 0, 0, 0.5);
}

:root[data-theme="light"] {
  --bg: #f7f6f3;
  --bg-sidebar: #ffffff;
  --bg-card: #ffffff;
  --bg-card-head: #f1efea;
  --border: #e2ded4;
  --text: #211f1c;
  --muted: #7a756c;
  --accent: #c9791e;
  --accent-dim: #a8631a;
  --accent-text: #ffffff;
  --shadow: rgba(0, 0, 0, 0.08);
}

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

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--font);
  overflow-x: hidden;
}

a { color: inherit; }

.brand {
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.01em;
}

/* ---------- theme toggle ---------- */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1rem;
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  cursor: pointer;
  line-height: 1;
}
.theme-toggle:hover { background: var(--bg-card); }

/* ---------- top bar (mobile) ---------- */
.topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 20;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
}
.menu-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.4rem;
  cursor: pointer;
}
.topbar-add { margin-left: auto; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 1.25rem 0.75rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.75rem 1.25rem;
}
.sidebar-brand { padding: 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.95rem;
}
.nav-item:hover { color: var(--text); background: var(--bg-card); }
.nav-item.active {
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--border);
}
.nav-num {
  font-size: 0.8rem;
  color: var(--muted);
  width: 1.4rem;
}
.nav-item.active .nav-num { color: var(--accent); }
.nav-item-btn {
  width: 100%;
  background: none;
  border: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.nav-sep { border-top: 1px solid var(--border); margin: 0.75rem 0.5rem; }

.auth-status {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.admin-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.content {
  flex: 1;
  min-width: 0;
  width: 100%;
  padding: 2rem 2.5rem 4rem;
}

.narrow { max-width: 760px; }

/* ---------- page head ---------- */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 2rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.page-head-left {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  flex: 1;
  min-width: 0;
}
h1 { font-size: 1.7rem; letter-spacing: -0.02em; white-space: nowrap; }
.head-num {
  font-size: 1rem;
  color: var(--accent);
  margin-right: 0.6rem;
  vertical-align: 0.1em;
}
.subtitle { color: var(--muted); margin-top: 0.25rem; }

.page-head-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* ---------- date nav ---------- */
.date-nav {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  border: 1px solid var(--border);
  background: var(--bg-card);
  border-radius: 8px;
  padding: 0.35rem 0.5rem;
}
.date-nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text);
}
.date-nav-btn:hover { background: var(--bg-card-head); }
.date-nav-btn.disabled { color: var(--border); pointer-events: none; }
.date-nav-label { font-size: 0.85rem; white-space: nowrap; min-width: 6rem; text-align: center; }

/* ---------- category bar ---------- */
.category-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  min-width: 0;
}
.pill {
  display: inline-block;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.8rem;
  white-space: nowrap;
}
.pill:hover { color: var(--text); }
.pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.pill-form { display: inline-block; }
.pill-input {
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: 999px;
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  padding: 0.3rem 0.75rem;
  width: 9rem;
}
.pill-input:focus { outline: none; border-color: var(--accent); color: var(--text); }

/* ---------- buttons ---------- */
.btn {
  display: inline-block;
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
}
.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.btn-accent:hover { background: var(--accent-dim); border-color: var(--accent-dim); }

/* ---------- news grid (grouped by category) ---------- */
.category-section { margin-bottom: 2.25rem; }
.category-heading {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.news-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1rem;
}
.news-grid .card { margin-bottom: 0; height: 100%; min-width: 0; display: flex; flex-direction: column; }
.news-grid .card-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.news-grid .card-title { font-size: 0.92rem; }
.news-grid .card-desc {
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.news-grid .card-category-form select { font-size: 0.7rem; padding: 0.2rem 0.3rem; max-width: 100%; }

/* Cards that pack in multiple items (e.g. Market Movers, GitHub
   Trending) — show full content instead of clamping, and take extra
   grid width so that content isn't squeezed into a single narrow
   column's worth of lines. */
.news-grid .card-wide { grid-column: span 2; }
.news-grid .card-wide .card-desc {
  display: block;
  -webkit-line-clamp: unset;
  max-height: 220px;
  overflow-y: auto;
}

.repo-list {
  list-style: decimal;
  margin: 0.4rem 0 0;
  padding-left: 1.2rem;
  color: var(--muted);
  font-size: 0.9rem;
}
.repo-list li { margin-bottom: 0.2rem; }
.repo-list a { color: var(--text); text-decoration: none; }
.repo-list a:hover { color: var(--accent); }

.mover-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.4rem;
  font-size: 0.85rem;
}
.mover-table th {
  text-align: left;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
}
.mover-table td {
  padding: 0.25rem 0.5rem 0.25rem 0;
  white-space: nowrap;
}
.mover-up { color: #2e9e4a; }
.mover-down { color: #d64545; }
.mover-pct { opacity: 0.75; font-size: 0.8em; }

@media (max-width: 1500px) { .news-grid { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 1150px) { .news-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 860px)  { .news-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px)  { .news-grid { grid-template-columns: 1fr; } }

/* ---------- cards ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 1rem;
  overflow: hidden;
}
.card-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 1.1rem;
  background: var(--bg-card-head);
  border-bottom: 1px solid var(--border);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.card-source { color: var(--accent); }
.card-date { color: var(--muted); }
.card-body { padding: 0.9rem 1.1rem 0.75rem; }
.card-title { font-size: 1.05rem; font-weight: 600; line-height: 1.4; }
.card-title a { text-decoration: none; }
.card-title a:hover { color: var(--accent); }
.card-author { color: var(--muted); font-size: 0.85rem; margin-top: 0.15rem; }
.card-desc { color: var(--muted); font-size: 0.9rem; margin-top: 0.4rem; overflow-wrap: anywhere; }
.card-title { overflow-wrap: anywhere; }
.card-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.6rem;
}
.card-category-form { margin-top: 0.5rem; }
.card-category-form select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  font: inherit;
  font-size: 0.78rem;
  padding: 0.25rem 0.4rem;
}
.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
}
.icon-btn:hover { color: var(--text); background: var(--bg-card-head); }
.icon-btn.fav { color: var(--accent); }

/* ---------- vote widget ---------- */
.vote-widget {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-right: auto;
}
.vote-widget form { display: contents; }
.vote-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.65rem;
  cursor: pointer;
  padding: 0.2rem 0.35rem;
  border-radius: 6px;
  line-height: 1;
}
.vote-btn:hover { color: var(--accent); background: var(--bg-card-head); }
.vote-score {
  font-size: 0.8rem;
  font-weight: 600;
  min-width: 1.2em;
  text-align: center;
}

.empty {
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 2.5rem;
  text-align: center;
}

/* ---------- add form ---------- */
.add-form { padding: 1.25rem; display: grid; gap: 1rem; }
.add-form label { display: grid; gap: 0.35rem; font-size: 0.9rem; color: var(--muted); }
.hint { font-size: 0.8rem; }
.add-form input,
.add-form select,
.add-form textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.55rem 0.7rem;
  font: inherit;
}
.add-form input:focus,
.add-form select:focus,
.add-form textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.add-form .btn { justify-self: start; }
.form-error {
  color: #d15a5a;
  font-size: 0.85rem;
  background: rgba(209, 90, 90, 0.1);
  border: 1px solid rgba(209, 90, 90, 0.3);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
}

/* ---------- mobile ---------- */
@media (max-width: 768px) {
  .topbar { display: flex; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 4px 0 24px var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar .theme-toggle { display: none; }
  .content { padding: 1.25rem 1rem 3rem; }
  .desktop-add, .page-head-right .btn { display: none; }
  .page-head-right { width: 100%; justify-content: flex-start; }
  .page-head-left { flex-direction: column; align-items: flex-start; }
  h1 { font-size: 1.5rem; white-space: normal; }
}
