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

:root {
  --bg:       #080c14;
  --surface:  #0f1623;
  --border:   #1e2d45;
  --text:     #e2e8f0;
  --muted:    #4a6080;
  --red:      #ef4444;
  --red-glow: rgba(239,68,68,.15);
  --blue:     #3b82f6;
  --blue-glow:rgba(59,130,246,.15);
  --grey:     #64748b;
  --grey-glow:rgba(100,116,139,.12);
  --action:   #60a5fa;
  --action-glow:rgba(96,165,250,.15);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  padding: 0 0 80px;
}

/* ── Header ── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(8px);
}
header h1 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: .04em;
  color: #f8fafc;
}
header h1 span { color: var(--muted); font-weight: 400; }
.header-nav { display: flex; gap: 8px; flex-wrap: wrap; }
.header-nav a {
  font-size: 0.75rem;
  color: var(--muted);
  text-decoration: none;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: color .15s, border-color .15s;
}
.header-nav a:hover { color: var(--text); border-color: #334155; }

/* ── Timeline spine ── */
.timeline {
  max-width: 860px;
  margin: 0 auto;
  padding: 40px 16px 0;
  position: relative;
}
.timeline::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 0; bottom: 0;
  width: 1px;
  background: var(--border);
  transform: translateX(-50%);
}

/* ── Empty state ── */
.empty {
  text-align: center;
  color: var(--muted);
  padding: 80px 20px;
  font-size: 0.9rem;
}

/* ── Entry ── */
.entry {
  display: flex;
  margin-bottom: 28px;
  position: relative;
  align-items: flex-start;
}

/* spacer on opposite side */
.entry-spacer { flex: 1; }

/* bubble */
.bubble {
  flex: 1;
  max-width: calc(50% - 28px);
  cursor: pointer;
  border-radius: 12px;
  padding: 14px 16px;
  border: 1px solid transparent;
  transition: transform .15s, box-shadow .15s;
  user-select: none;
}
.bubble:hover { transform: translateY(-1px); }

.side-left  .bubble {
  margin-right: auto;
  border-color: var(--blue);
  background: var(--blue-glow);
}
.side-left  .bubble:hover { box-shadow: 0 4px 24px var(--blue-glow); }

.side-right .bubble {
  margin-left: auto;
  border-color: var(--red);
  background: var(--red-glow);
}
.side-right .bubble:hover { box-shadow: 0 4px 24px var(--red-glow); }

.side-center {
  justify-content: center;
}
.side-center .bubble {
  max-width: calc(50% - 28px);
  border-color: var(--grey);
  background: var(--grey-glow);
}
.side-center .bubble:hover { box-shadow: 0 4px 16px var(--grey-glow); }

/* bubble content */
.bubble-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.flag { font-size: 1.3rem; line-height: 1; flex-shrink: 0; }

.stage-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.35;
}

.bubble-date {
  font-size: 0.68rem;
  color: var(--muted);
  margin-top: 5px;
  font-variant-numeric: tabular-nums;
}

/* ── Expand panel ── */
.detail {
  display: none;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: #94a3b8;
  line-height: 1.6;
}
.detail.open { display: block; }

.detail-speaker {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
}
.detail-evidence {
  color: #cbd5e1;
  margin-bottom: 6px;
  word-break: break-word;
}
.detail-source {
  font-size: 0.72rem;
  color: var(--muted);
}

.detail a { color: #60a5fa; text-decoration: none; }
.detail a:hover { text-decoration: underline; }
.detail-source { display: flex; flex-direction: column; gap: 2px; }

/* Hide spine while skeletons are present */
.js-timeline:has(.skel-item)::before { display: none; }

/* ── Slide-up animation (JS-rendered timeline only) ── */
.js-timeline .entry {
  transition: opacity 0.45s ease, transform 0.45s ease;
}

/* ── Skeleton loading ── */
.skel-item {
  width: 100%;
  padding: 18px 0;
  border-bottom: 1px solid var(--border);
  animation: skel-pulse 1.6s ease-in-out infinite;
  animation-delay: var(--d, 0s);
}
.skel-bar {
  height: 13px;
  background: rgba(255,255,255,.08);
  border-radius: 5px;
  margin-bottom: 10px;
}
.skel-bar:last-child { margin-bottom: 0; }

.admin-badge {
  font-size: .6em;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #facc15;
  opacity: .85;
  vertical-align: middle;
}

@keyframes skel-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .3; }
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: #1e293b;
  border: 1px solid #334155;
  color: var(--text);
  padding: 10px 22px;
  border-radius: 8px;
  font-size: .82rem;
  opacity: 0;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 200;
  pointer-events: none;
  white-space: nowrap;
}
.toast.toast-show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.toast-err  { border-color: var(--red); color: #fca5a5; }

/* ── Admin: pencil ── */
.pencil-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: .72rem;
  opacity: 0;
  padding: 0 3px;
  transition: opacity .15s;
  color: var(--muted);
  line-height: 1;
  vertical-align: middle;
}
.bubble:hover .pencil-btn,
.pencil-btn:focus { opacity: 1; }

.stage-edit-input {
  font-size: .88rem;
  font-weight: 600;
  background: rgba(255,255,255,.05);
  border: 1px solid var(--blue);
  border-radius: 4px;
  color: var(--text);
  padding: 1px 6px;
  outline: none;
  width: 100%;
  min-width: 120px;
}

/* ── Admin: hide button (inside detail) ── */
.admin-actions {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.hide-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--muted);
  font-size: .72rem;
  padding: 3px 12px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.hide-btn:hover { color: var(--red); border-color: var(--red); }

/* ── Admin: chain/merge button ── */
.chain-btn {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  z-index: 5;
  background: var(--action);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: .78rem;
  opacity: 0;
  transition: opacity .15s, border-color .2s, background .2s;
  padding: 0;
}
.entry:hover .chain-btn { opacity: 1; }
.chain-btn.chain-active {
  opacity: 1;
  border-color: #facc15;
  background: rgba(250,204,21,.18);
}
.chain-btn.chain-target {
  opacity: 1;
  border-color: #4ade80;
  background: rgba(74,222,128,.12);
}

/* ── Mobile ── */
@media (max-width: 600px) {
  .timeline::before { display: none; }
  .chain-btn { display: none; }

  .bubble,
  .side-left .bubble,
  .side-right .bubble,
  .side-center .bubble {
    flex: 0 1 auto;
    max-width: 78%;
    margin: 0;
    border-radius: 8px;
  }
}
