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

:root {
  --bg: #050608;
  --surface: #0e1116;
  --surface2: #161b22;
  --border: var(--border);
  --text: #e9edf1;
  --text2: #94a3b8;
  --primary: #fee942;
  --primary-hover: #fff34d;
  --primary-ink: #001c3e;
  --primary-dim: rgba(254, 233, 66, 0.12);
  --accent: #6fb0e8;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --twitter: #1da1f2;
}

body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

nav {
  background: var(--surface);
  padding: 1rem 2rem;
  display: flex;
  gap: 1.5rem;
  align-items: center;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

nav .brand {
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--primary);
  text-decoration: none;
  margin-right: auto;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

nav a {
  color: var(--text2);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  transition: background 0.2s, color 0.2s;
}

nav a:hover { background: var(--surface2); color: var(--text); }
nav a[target=_blank]::after {
  content: " ↗";
  font-size: 0.75em;
  opacity: 0.6;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem;
}

h1 { font-size: 1.8rem; margin-bottom: 1.5rem; }
h2 { font-size: 1.3rem; margin-bottom: 1rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.card h3 { margin-bottom: 0.5rem; }
.card .meta {
  color: var(--text2);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.card .score {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.score .up { color: var(--green); }
.score .down { color: var(--red); }

.btn {
  display: inline-block;
  padding: 0.5rem 1.2rem;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s;
}

.btn-primary { background: var(--primary); color: var(--primary-ink); font-weight: 600; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-up { background: var(--green); color: white; }
.btn-down { background: var(--red); color: white; }
.btn-sm { padding: 0.3rem 0.8rem; font-size: 0.8rem; }
.btn-active { background: var(--primary); color: var(--primary-ink); font-weight: 600; }

.btn-twitter {
  background: var(--twitter);
  color: white;
  font-size: 0.8rem;
  padding: 0.25rem 0.7rem;
  border-radius: 4px;
}
.btn-twitter:hover { filter: brightness(1.1); }

form label {
  display: block;
  margin-bottom: 0.3rem;
  color: var(--text2);
  font-size: 0.9rem;
}

form input, form textarea {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 1rem;
}

form textarea { min-height: 120px; resize: vertical; }
form input:focus, form textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.status-badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}
.status-voting { background: var(--amber); color: #000; }
.status-answered { background: var(--green); color: #000; }
.status-failed { background: var(--red); color: #fff; }

.loading {
  text-align: center;
  color: var(--text2);
  padding: 2rem;
}

/* Question grid: ensures no blank line when empty */
.question-grid {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.question-grid:empty { display: none; }
.question-grid > .card { margin-bottom: 1rem; }
.question-grid > .card:last-child { margin-bottom: 0; }

.error {
  background: var(--red);
  color: white;
  padding: 0.8rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
}

.success {
  background: var(--green);
  color: #000;
  padding: 0.8rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
}

.answer-box {
  background: var(--surface2);
  border-left: 3px solid var(--primary);
  padding: 1rem;
  border-radius: 0 6px 6px 0;
  margin-top: 1rem;
  white-space: pre-wrap;
  font-size: 0.95rem;
}

/* Search bar */
.search-bar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}
.search-bar input {
  flex: 1;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
}
.search-bar input:focus {
  outline: none;
  border-color: var(--primary);
}
.search-bar input::placeholder { color: var(--text2); }
.search-bar .btn { border-radius: 8px; }

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1.5rem;
  background: var(--surface);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.tab {
  flex: 1;
  padding: 0.7rem 1rem;
  text-align: center;
  cursor: pointer;
  color: var(--text2);
  font-size: 0.9rem;
  transition: background 0.2s, color 0.2s;
  border: none;
  background: transparent;
}
.tab:hover { background: var(--surface2); color: var(--text); }
.tab.active { background: var(--primary); color: white; font-weight: 600; }

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  margin: 1.5rem 0;
  flex-wrap: wrap;
}
.pagination .btn { min-width: 2.2rem; text-align: center; border-radius: 6px; }
.pagination .btn-active { background: var(--primary); color: var(--primary-ink); font-weight: 600; }
.pagination-dots { color: var(--text2); padding: 0 0.2rem; }

/* Page size selector */
.page-size-selector {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-bottom: 1rem;
  color: var(--text2);
  font-size: 0.85rem;
}
.page-size-selector select {
  padding: 0.3rem 0.5rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}

/* Duplicate check panel */
.dup-panel {
  background: var(--surface);
  border: 1px solid var(--amber);
  border-radius: 8px;
  padding: 0.8rem 1rem;
  margin: -0.5rem 0 1rem;
  font-size: 0.85rem;
}
.dup-panel .dup-header {
  color: var(--amber);
  font-weight: 600;
  margin-bottom: 0.4rem;
}
.dup-panel .dup-item {
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: color 0.2s;
}
.dup-panel .dup-item:last-child { border-bottom: none; }
.dup-panel .dup-item:hover { color: var(--primary); }
.dup-panel .dup-close {
  float: right;
  cursor: pointer;
  color: var(--text2);
  font-size: 1.1rem;
  line-height: 1;
}
.dup-panel .dup-close:hover { color: var(--text); }

/* Result count */
.result-count {
  color: var(--text2);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

/* Category badges */
.category-badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.category-code {
  background: #1e40af;
  color: var(--accent);
}
.category-concept {
  background: var(--primary);
  color: var(--accent);
}
.category-general {
  background: var(--text2);
  color: var(--text);
}

/* Category tabs on index */
.category-tabs {
  margin-bottom: 1rem;
}
.category-tabs .tab {
  flex: 0 1 auto;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
}

/* Confidence bar (refined) */
.confidence-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
  font-size: 0.85rem;
}
.confidence-track {
  flex: 1;
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
  max-width: 120px;
}
.confidence-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}
.confidence-high .confidence-fill { background: var(--green); }
.confidence-mid .confidence-fill { background: var(--amber); }
.confidence-low .confidence-fill { background: var(--red); }
.confidence-label {
  font-weight: 600;
  white-space: nowrap;
}

/* Share button inline */
.share-btn {
  cursor: pointer;
  color: var(--text2);
  font-size: 0.85rem;
  text-decoration: none;
  transition: color 0.2s;
  margin-left: auto;
  white-space: nowrap;
}
.share-btn:hover { color: var(--twitter); }

/* ========================================
   Bug report banner
   ======================================== */
.bug-banner {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid var(--red);
  border-radius: 8px;
  padding: 1rem;
  margin-top: 1rem;
}
.bug-banner .bug-title {
  color: var(--red);
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 0.3rem;
}
.bug-banner .bug-context {
  color: var(--text2);
  font-size: 0.85rem;
  white-space: pre-wrap;
}

/* ========================================
   Guide card (homepage)
   ======================================== */
.guide-card {
  background: linear-gradient(135deg, var(--surface), var(--surface2));
  border: 1px solid var(--primary);
  border-radius: 10px;
  padding: 1.2rem 1.5rem;
  margin-top: 2rem;
  font-size: 0.9rem;
  line-height: 1.7;
}
.guide-card h3 {
  color: var(--primary);
  margin-bottom: 0.5rem;
}
.guide-card a { color: var(--primary); text-decoration: underline; }

/* ========================================
   Help page
   ======================================== */
.help-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  margin-bottom: 1.2rem;
}
.help-section h2 {
  color: var(--primary);
  font-size: 1.15rem;
  margin-bottom: 0.8rem;
}
.help-section p, .help-section li {
  color: var(--text2);
  font-size: 0.9rem;
  line-height: 1.8;
}
.help-section ul { padding-left: 1.5rem; }
.help-section li { margin-bottom: 0.3rem; }
.help-section a { color: #ffffff !important; text-decoration: underline; text-underline-offset: 2px; font-weight: 500; }
.help-section a:hover { color: var(--accent) !important; }
.help-section .badge-demo {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
}

/* ========================================
   Admin pages
   ======================================== */
.admin-container { max-width: 1100px; }
.bug-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.bug-table th {
  text-align: left;
  padding: 0.6rem 0.8rem;
  background: var(--surface2);
  color: var(--text2);
  font-weight: 600;
  border-bottom: 2px solid var(--border);
}
.bug-table td {
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.bug-table tr:hover { background: rgba(59, 130, 246, 0.05); }
.bug-table .bug-cell-title { max-width: 250px; overflow: hidden; text-overflow: ellipsis; }
.bug-table .bug-cell-context { max-width: 300px; white-space: pre-wrap; }
.bug-table .bug-cell-conf {
  text-align: center;
  font-weight: 600;
}
.conf-high { color: var(--green); }
.conf-mid { color: var(--amber); }
.conf-low { color: var(--red); }

/* ========================================
   Source citation card
   ======================================== */
.source-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.8rem 1rem;
  margin-top: 1rem;
  font-size: 0.85rem;
}
.source-title {
  font-weight: 600;
  margin-bottom: 0.4rem;
  color: var(--text);
}
.source-list {
  margin: 0.3rem 0;
  padding-left: 1.2rem;
}
.source-list li { margin-bottom: 0.2rem; }
.source-list a, .source-link {
  color: var(--primary);
  text-decoration: none;
}
.source-list a:hover, .source-link:hover { text-decoration: underline; }
.source-text {
  color: var(--text2);
  margin-bottom: 0.3rem;
  white-space: pre-wrap;
}

/* ========================================
   Hamburger menu toggle
   ======================================== */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.3rem;
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 900px) {
  .container { padding: 1.5rem; }
  h1 { font-size: 1.6rem; }
  .bug-table { font-size: 0.8rem; }
  .bug-table .bug-cell-context { max-width: 200px; }
}

/* ========================================
   Toast notifications
   ======================================== */
#toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  display: none;
}
.toast {
  padding: 0.75rem 1.2rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  animation: toast-in 0.25s ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}
.toast-success { background: var(--green); color: #000; }
.toast-error { background: var(--red); color: #fff; }
.toast-info { background: var(--primary); color: #fff; }

/* ========================================
   Spinner for loading buttons
   ======================================== */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 0.3rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

/* ========================================
   Back to top
   ======================================== */
.back-to-top {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  display: none;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}
.back-to-top:hover { background: var(--primary-hover); transform: translateY(-2px); }
.back-to-top.visible { display: flex; }

/* ========================================
   History page: inline question list
   ======================================== */
.history-cycle-card { cursor: pointer; }
.history-cycle-card .cycle-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.history-cycle-card .cycle-arrow {
  transition: transform 0.2s;
  font-size: 0.8rem;
  color: var(--text2);
}
.history-cycle-card.expanded .cycle-arrow { transform: rotate(90deg); }
.cycle-questions {
  margin-top: 1rem;
  border-top: 1px solid var(--border);
  padding-top: 0.8rem;
  display: none;
}
.cycle-questions.open { display: block; }
.cycle-question-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.cycle-question-item:last-child { border-bottom: none; }
.cycle-question-item a { color: #ffffff !important; text-decoration: underline; flex: 1; text-underline-offset: 2px; font-weight: 500; }
.cycle-question-item a:hover { color: var(--accent) !important; }
.cycle-question-item .score-mini {
  font-size: 0.78rem;
  color: var(--text2);
  white-space: nowrap;
}

@media (max-width: 640px) {
  .nav-links {
    display: none;
    flex-direction: column;
    width: 100%;
    gap: 0.3rem;
    padding: 0.5rem 0;
  }
  .nav-links.open { display: flex; }
  .nav-toggle { display: block; }
  nav { padding: 0.8rem 1rem; flex-wrap: wrap; }
  nav .brand { flex: 1; font-size: 1rem; }
  nav a { font-size: 0.85rem; padding: 0.4rem 0.6rem; border-radius: 6px; }
  .container { padding: 0.8rem; }
  h1 { font-size: 1.3rem; }
  h2 { font-size: 1.1rem; }
  .card { padding: 1rem; }
  .btn { width: 100%; text-align: center; }
  .btn-sm { width: auto; }
  .score { flex-wrap: wrap; }
  .tabs { flex-wrap: wrap; }
  .tab { flex: 1 1 auto; padding: 0.5rem 0.6rem; font-size: 0.8rem; }
  .search-bar { flex-direction: column; }
  .search-bar input { font-size: 16px; }
  .page-size-selector { justify-content: flex-start; }
  .pagination .btn { min-width: 1.8rem; font-size: 0.75rem; }
  table, .bug-table { font-size: 0.75rem; }
  .bug-table th, .bug-table td { padding: 0.3rem 0.4rem; }
  .bug-table .bug-cell-title { max-width: 120px; }
  .bug-table .bug-cell-context { max-width: 80px; }
  .confidence-track { max-width: 80px; }
}
