/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f1117;
  color: #e2e8f0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Nav ─────────────────────────────────────────────────────────────────── */
#site-nav {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.nav-link {
  display: block;
  padding: 4px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #64748b;
  text-decoration: none;
  transition: color 0.15s, background 0.15s;
}
.nav-link:hover { color: #e2e8f0; background: #2d3148; }
.nav-link.active { color: #22d3ee; background: #2d3148; }

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  background: #1a1d27;
  border-bottom: 1px solid #2d3148;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #22d3ee;
  white-space: nowrap;
}

/* ── Search ──────────────────────────────────────────────────────────────── */
#search-input {
  background: #0f1117;
  border: 1px solid #2d3148;
  border-radius: 6px;
  color: #e2e8f0;
  padding: 5px 10px;
  font-size: 0.85rem;
  width: 180px;
  outline: none;
}
#search-input:focus { border-color: #0891b2; }

/* ── Unit filter pills ───────────────────────────────────────────────────── */
#unit-filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.unit-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.75rem;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s, opacity 0.15s;
}
.unit-pill input[type=checkbox] { display: none; }
.unit-pill .dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}
.unit-pill.active { border-color: currentColor; }
.unit-pill:not(.active) { opacity: 0.4; }

/* ── Main layout ─────────────────────────────────────────────────────────── */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Timeline container ──────────────────────────────────────────────────── */
#timeline-container {
  flex: 1;
  overflow: hidden;
  position: relative;
}

#timeline {
  width: 100%;
  height: 100%;
}

/* ── vis-timeline dark theme overrides ──────────────────────────────────── */
.vis-timeline {
  background: #0f1117 !important;
  border: none !important;
  color: #e2e8f0 !important;
}

.vis-panel.vis-center,
.vis-panel.vis-left,
.vis-panel.vis-right,
.vis-panel.vis-top,
.vis-panel.vis-bottom {
  border-color: #2d3148 !important;
}

.vis-time-axis .vis-text {
  color: #64748b !important;
}

.vis-time-axis .vis-grid.vis-minor { border-color: #1e2235 !important; }
.vis-time-axis .vis-grid.vis-major { border-color: #2d3148 !important; }

/* Item base */
.vis-item {
  border-radius: 4px !important;
  font-size: 0.75rem !important;
  font-weight: 600 !important;
  color: #fff !important;
  border-width: 2px !important;
  border-style: solid !important;
  border-color: transparent !important;
}

.vis-item.vis-selected {
  border-color: #fff !important;
  box-shadow: 0 0 0 2px #22d3ee !important;
}

/* Uncertain items — dashed border */
.vis-item.uncertain {
  border-style: dashed !important;
  border-color: rgba(255, 255, 255, 0.7) !important;
}

/* Group label (unit) */
.vis-label {
  color: #94a3b8 !important;
  font-size: 0.78rem !important;
  font-weight: 600 !important;
  padding: 0 8px !important;
  background: #131620 !important;
  border-color: #2d3148 !important;
}

/* Tooltip */
.vis-tooltip {
  background: #1e2235 !important;
  border: 1px solid #3d4268 !important;
  color: #e2e8f0 !important;
  border-radius: 6px !important;
  padding: 6px 10px !important;
  font-size: 0.8rem !important;
  max-width: 220px !important;
}

/* ── Detail panel ────────────────────────────────────────────────────────── */
#detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 300px;
  background: #1a1d27;
  border-left: 1px solid #2d3148;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 50;
  transition: transform 0.2s ease;
}

#detail-panel.hidden {
  transform: translateX(100%);
}

#detail-inner {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

#detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

#detail-panel h2 {
  font-size: 1rem;
  font-weight: 700;
  color: #67e8f9;
  line-height: 1.3;
  margin-bottom: 12px;
}

.detail-unit-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  margin-bottom: 10px;
  color: #fff;
}

.detail-field {
  margin-bottom: 10px;
}

.detail-field label {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  margin-bottom: 3px;
}

.detail-field p {
  font-size: 0.82rem;
  color: #cbd5e1;
  line-height: 1.5;
}

.detail-when {
  font-family: monospace;
  font-size: 0.8rem !important;
  color: #22d3ee !important;
}

#detail-close {
  background: none;
  border: none;
  color: #64748b;
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}
#detail-close:hover { color: #e2e8f0; background: #2d3148; }

/* ── Legend ──────────────────────────────────────────────────────────────── */
#legend {
  padding: 8px 10px;
  border-top: 1px solid #2d3148;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 0.7rem;
  color: #64748b;
  flex-shrink: 0;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
}
.legend-swatch {
  width: 18px; height: 10px;
  border-radius: 2px;
}
.legend-swatch.dashed {
  background: transparent;
  border: 2px dashed #64748b;
  height: 10px !important;
  border-radius: 2px;
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #0f1117; }
::-webkit-scrollbar-thumb { background: #2d3148; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #3d4268; }

/* ── BCE outlier bar ─────────────────────────────────────────────────────── */
#bce-bar {
  background: #131620;
  border-bottom: 1px solid #2d3148;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

#bce-bar::before {
  content: 'Pre-timeline';
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #475569;
  white-space: nowrap;
  margin-right: 4px;
}

.bce-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #1e2235;
  border: 1px solid var(--chip-color);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  color: #e2e8f0;
  font-size: 0.78rem;
  opacity: 0.85;
  transition: opacity 0.15s, background 0.15s;
}
.bce-chip:hover {
  opacity: 1;
  background: #252a3d;
}

.bce-chip-label {
  font-weight: 600;
}

.bce-chip-when {
  font-size: 0.7rem;
  color: #94a3b8;
  font-family: monospace;
}

/* ── Loading ─────────────────────────────────────────────────────────────── */
#loading {
  padding: 40px;
  color: #64748b;
  font-size: 0.9rem;
  text-align: center;
}

/* Timeline page: loading fills the container */
#timeline-container #loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0f1117;
  z-index: 100;
}

/* ── List page ───────────────────────────────────────────────────────────── */
.page-list #main {
  overflow-y: auto;
  align-items: flex-start;
}

#list-container {
  width: 100%;
  padding: 16px;
}

#facts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

#facts-table thead th {
  position: sticky;
  top: 0;
  background: #131620;
  color: #64748b;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid #2d3148;
  white-space: nowrap;
  user-select: none;
}

th.sortable { cursor: pointer; }
th.sortable:hover { color: #e2e8f0; }
th.sort-active { color: #22d3ee; }

.sort-icon { font-style: normal; }

#facts-table tbody tr.fact-row {
  border-bottom: 1px solid #1e2235;
  cursor: pointer;
  transition: background 0.1s;
}
#facts-table tbody tr.fact-row:hover { background: #1a1d27; }

#facts-table td {
  padding: 8px 10px;
  vertical-align: top;
  color: #cbd5e1;
  line-height: 1.4;
}

.col-num   { width: 20px; color: #475569; font-variant-numeric: tabular-nums; }
.col-unit  { width: 20px; padding-right: 0; }
.col-term  { width: 100px; color: #e2e8f0; }
.col-when  { width: 100px; color: #22d3ee; }
.col-who   { width: 100px; }
.col-what  { width: 260px; }
.col-where { width: 100px; }
.col-why   { width: 260px; }

#facts-table td.col-unit {
  padding-left: 20px;
}

.unit-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 3px;
}

#no-results {
  padding: 40px;
  text-align: center;
  color: #64748b;
  font-size: 0.85rem;
}

/* ── Study page ──────────────────────────────────────────────────────────── */

.page-study #main {
  overflow-y: auto;
  align-items: flex-start;
  justify-content: flex-start;
}

/* ── Selector screen ─────────────────────────────────────────────────────── */

#selector-screen {
  max-width: 680px;
  margin: 0 auto;
  padding: 24px 16px;
  width: 100%;
}

#selector-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

#selector-toolbar h2 {
  font-size: 1rem;
  font-weight: 700;
  color: #e2e8f0;
  white-space: nowrap;
}

#selector-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

#selected-count {
  font-size: 0.8rem;
  color: #64748b;
  white-space: nowrap;
}

#shuffle-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.8rem;
  color: #94a3b8;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
#shuffle-label input[type=checkbox] {
  accent-color: #22d3ee;
  width: 13px;
  height: 13px;
  cursor: pointer;
}

#selector-actions button {
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  border: 1px solid #2d3148;
  background: #1a1d27;
  color: #e2e8f0;
  transition: background 0.15s;
}
#selector-actions button:hover { background: #2d3148; }

#start-btn {
  background: #0891b2 !important;
  color: #fff !important;
  border-color: #0891b2 !important;
}
#start-btn:hover:not(:disabled) { background: #0e7490 !important; }
#start-btn:disabled { opacity: 0.4; cursor: not-allowed; }

#resume-btn {
  border: 1px solid #22d3ee !important;
  color: #22d3ee !important;
  background: transparent !important;
}
#resume-btn:hover { background: rgba(34, 211, 238, 0.08) !important; }

/* ── Accordion ───────────────────────────────────────────────────────────── */

.accordion-unit {
  border: 1px solid #2d3148;
  border-radius: 8px;
  margin-bottom: 8px;
  overflow: hidden;
}

.accordion-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  background: #1a1d27;
  user-select: none;
}
.accordion-header:hover { background: #1e2235; }

.accordion-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.accordion-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #e2e8f0;
}

.unit-count {
  font-size: 0.75rem;
  color: #64748b;
}

.accordion-chevron {
  margin-left: auto;
  font-size: 1.1rem;
  transition: transform 0.2s;
  color: #64748b;
}
.accordion-unit.open .accordion-chevron { transform: rotate(90deg); }

.accordion-body {
  display: none;
  border-top: 1px solid #2d3148;
}
.accordion-unit.open .accordion-body { display: block; }

.card-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  cursor: pointer;
  border-bottom: 1px solid #1e2235;
}
.card-row:hover { background: #1e2235; }
.card-row:last-child { border-bottom: none; }

.card-row input[type=checkbox] {
  flex-shrink: 0;
  accent-color: #22d3ee;
  width: 14px;
  height: 14px;
  cursor: pointer;
}

.accordion-header .unit-check {
  flex-shrink: 0;
  accent-color: #22d3ee;
  width: 14px;
  height: 14px;
  cursor: pointer;
}

.card-row-term {
  flex: 1;
  font-size: 0.82rem;
  color: #e2e8f0;
}

.card-row-when {
  font-size: 0.75rem;
  color: #64748b;
  font-family: monospace;
}

/* ── Study screen ────────────────────────────────────────────────────────── */

#study-screen {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  padding: 16px;
}

#study-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-shrink: 0;
}

#exit-btn {
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  border: 1px solid #2d3148;
  background: #1a1d27;
  color: #e2e8f0;
  white-space: nowrap;
  transition: background 0.15s;
}
#exit-btn:hover { background: #2d3148; }

#progress-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}

#progress-bar {
  flex: 1;
  height: 6px;
  background: #2d3148;
  border-radius: 3px;
  overflow: hidden;
}

#progress-fill {
  height: 100%;
  background: #22d3ee;
  border-radius: 3px;
  transition: width 0.3s ease;
  width: 0%;
}

#progress-text {
  font-size: 0.8rem;
  color: #64748b;
  white-space: nowrap;
}

#card-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  min-height: 0;
}

#card-scene {
  perspective: 1200px;
}

#card {
  width: min(560px, 90vw);
  height: min(340px, 50vw);
  min-height: 200px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.5s ease;
  cursor: pointer;
}
#card.flipped { transform: rotateY(180deg); }
#card.no-transition { transition: none !important; }

.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 12px;
  background: #1a1d27;
  border: 1px solid #2d3148;
  padding: 24px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.card-back {
  transform: rotateY(180deg);
  overflow-y: auto;
}

.card-front {
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.card-unit-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  color: #fff;
}

.card-term {
  font-size: 1.6rem;
  font-weight: 700;
  color: #e2e8f0;
  text-align: center;
}

.card-term-small {
  font-size: 1rem;
  font-weight: 700;
  color: #e2e8f0;
  margin-bottom: 8px;
  text-align: left;
}

.card-when {
  font-family: monospace;
  font-size: 0.85rem;
  color: #22d3ee;
}

.card-details {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card-detail-field {
  display: flex;
  gap: 8px;
  font-size: 0.82rem;
  line-height: 1.4;
}

.card-detail-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  white-space: nowrap;
  padding-top: 2px;
  min-width: 36px;
}

.card-detail-value {
  color: #cbd5e1;
}

.card-detail-when {
  font-family: monospace;
  color: #22d3ee;
}

#card-hint {
  font-size: 0.8rem;
  color: #475569;
}

#card-buttons {
  display: flex;
  gap: 16px;
}

#fail-btn {
  background: #7f1d1d;
  border: 1px solid #dc2626;
  color: #fca5a5;
  padding: 10px 28px;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s;
}
#fail-btn:hover { background: #991b1b; }

#pass-btn {
  background: #14532d;
  border: 1px solid #059669;
  color: #86efac;
  padding: 10px 28px;
  border-radius: 8px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s;
}
#pass-btn:hover { background: #166534; }

kbd {
  font-size: 0.7rem;
  background: #2d3148;
  border-radius: 3px;
  padding: 1px 4px;
}

#kb-hint {
  font-size: 0.72rem;
  color: #334155;
  margin-top: auto;
  padding-top: 12px;
  text-align: center;
  flex-shrink: 0;
}

/* ── Complete screen ─────────────────────────────────────────────────────── */

#complete-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  width: 100%;
}

#complete-inner {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

#complete-icon {
  font-size: 3rem;
  color: #22d3ee;
}

#complete-inner h2 {
  font-size: 1.4rem;
  font-weight: 700;
  color: #e2e8f0;
}

#complete-stats {
  font-size: 0.85rem;
  color: #64748b;
}

#again-btn, #new-selection-btn {
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s;
}

#again-btn {
  background: #0891b2;
  border: none;
  color: #fff;
}
#again-btn:hover { background: #0e7490; }

#new-selection-btn {
  background: transparent;
  border: 1px solid #2d3148;
  color: #94a3b8;
}
#new-selection-btn:hover { background: #1a1d27; }
