/* =============================================================
   Chronologie — stylesheet
============================================================= */

/* ── Tokens ─────────────────────────────────────────────── */
:root {
  --ink:        #18181b;
  --ink-2:      #52525b;
  --ink-3:      #a1a1aa;
  --surface:    #fafaf9;
  --card-bg:    #ffffff;
  --border:     #e4e4e7;
  --border-2:   #d4d4d8;

  --green:      #16a34a;
  --green-lt:   #f0fdf4;
  --green-ring: #86efac;

  --red:        #dc2626;
  --red-lt:     #fef2f2;
  --red-ring:   #fca5a5;

  --amber:      #d97706;
  --amber-lt:   #fffbeb;

  --radius-sm:  6px;
  --radius:     10px;
  --radius-lg:  14px;

  --font-serif: 'Playfair Display', Georgia, serif;
  --font-sans:  'Inter', system-ui, -apple-system, sans-serif;

  --shadow-card: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lift: 0 8px 24px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.08);
}

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

body {
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ──────────────────────────────────────────────── */
header {
  width: 100%;
  height: 58px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 10;
}

.logo {
  font-family: var(--font-serif);
  font-size: 1.3rem;
  color: var(--ink);
  letter-spacing: 0.01em;
}

.stats-btn {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-2);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.stats-btn:hover { background: var(--surface); border-color: var(--border-2); color: var(--ink); }

/* ── Main ────────────────────────────────────────────────── */
main {
  width: 100%;
  max-width: 540px;
  padding: 2rem 1.25rem 4rem;
  flex: 1;
}

/* ── Meta row ────────────────────────────────────────────── */
.meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.meta__date {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

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

.meta__label {
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.pips {
  display: flex;
  gap: 5px;
}

.pip {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border-2);
  transition: background 0.3s;
}
.pip--used { background: var(--red); }

/* ── Instruction ─────────────────────────────────────────── */
.instruction {
  font-size: 13px;
  color: var(--ink-3);
  margin-bottom: 2rem;
  line-height: 1.6;
}

/* ── Timeline list ───────────────────────────────────────── */
.timeline {
  list-style: none;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 2rem;

  /* The vertical spine line */
  --spine-x: 19px;
}

/* Continuous vertical line behind all cards */
.timeline::before {
  content: '';
  position: absolute;
  left: var(--spine-x);
  top: 24px;
  bottom: 24px;
  width: 2px;
  background: var(--border);
  z-index: 0;
  border-radius: 2px;
}

/* ── Card ────────────────────────────────────────────────── */
.card {
  position: relative;
  padding: 10px 0 10px 0;
  cursor: grab;
  user-select: none;
  touch-action: none;
  /* Spacing between cards creates the "apart" feel */
  margin-bottom: 10px;
}

.card:last-child { margin-bottom: 0; }

.card__inner {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card-bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 14px 50px;
  box-shadow: var(--shadow-card);
  transition: border-color 0.18s, background 0.18s, box-shadow 0.18s;
  position: relative;
  min-height: 64px;
}

/* Timeline dot — sits on the spine */
.card__inner::before {
  content: '';
  position: absolute;
  left: calc(-1 * (50px - var(--spine-x)) - 5px);
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--border-2);
  border: 2px solid var(--card-bg);
  z-index: 1;
  /* No transition — prevents dot from animating on mousedown */
}

.card:not(.card--locked):hover .card__inner {
  border-color: var(--border-2);
  box-shadow: var(--shadow-lift);
  /* No transform — keeps ::before dot in place */
}

.card__text {
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  flex: 1;
}

/* Year badge — shown after game ends */
.card__year {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 2px 8px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Card states ─────────────────────────────────────────── */

/* Locked (permanently correct) */
.card--locked {
  cursor: default;
}
.card--locked .card__inner {
  border-color: var(--green-ring);
  background: var(--green-lt);
}
.card--locked .card__inner::before {
  background: var(--green);
  border-color: var(--green-lt);
  transform: translateY(-50%) scale(1.2);
}
.card--locked .card__text { color: var(--green); }
.card--locked .card__year { color: var(--green); border-color: var(--green-ring); background: var(--green-lt); }

/* Final correct (game over, correct position) */
.card--correct .card__inner {
  border-color: var(--green-ring);
  background: var(--green-lt);
}
.card--correct .card__inner::before { background: var(--green); border-color: var(--green-lt); }
.card--correct .card__text { color: var(--green); }
.card--correct .card__year { color: var(--green); border-color: var(--green-ring); background: var(--green-lt); }

/* Final wrong */
.card--wrong .card__inner {
  border-color: var(--red-ring);
  background: var(--red-lt);
}
.card--wrong .card__inner::before { background: var(--red); border-color: var(--red-lt); }
.card--wrong .card__text { color: var(--red); }
.card--wrong .card__year { color: var(--red); border-color: var(--red-ring); background: var(--red-lt); }

/* Dragging */
.card--dragging .card__inner {
  opacity: 0.25;
  box-shadow: none;
}

/* Drop target */
.card--drop-target .card__inner {
  border-color: var(--amber);
  background: var(--amber-lt);
  transform: translateX(4px);
}

/* Flash on submit */
.card--flash-correct .card__inner {
  border-color: var(--green-ring);
  background: var(--green-lt);
}
.card--flash-wrong .card__inner {
  border-color: var(--red-ring);
  background: var(--red-lt);
}

/* ── Ghost (drag preview) ────────────────────────────────── */
#drag-ghost {
  border-radius: var(--radius);
  overflow: hidden;
}

/* ── Actions ─────────────────────────────────────────────── */
.actions { margin-bottom: 0; }

.btn {
  padding: 11px 20px;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.1s;
  line-height: 1;
}
.btn:hover  { background: var(--surface); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.38; cursor: default; transform: none; }

.btn--primary {
  width: 100%;
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
}
.btn--primary:hover { background: #27272a; }

.btn--share {
  width: 100%;
  margin-top: 10px;
  background: transparent;
}

/* ── Result area ─────────────────────────────────────────── */
#result-area { margin-top: 1.5rem; }

.banner {
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 1.25rem;
  font-size: 14px;
  line-height: 1.5;
}
.banner strong { display: block; font-size: 15px; margin-bottom: 2px; }
.banner--success { background: var(--green-lt); border: 1px solid var(--green-ring); color: #15803d; }
.banner--fail    { background: var(--red-lt);   border: 1px solid var(--red-ring);   color: #b91c1c; }

/* ── Share ───────────────────────────────────────────────── */
.share {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.share__label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-3);
  margin-bottom: 10px;
}

.share__grid {
  font-size: 22px;
  letter-spacing: 3px;
  line-height: 1.65;
  margin-bottom: 4px;
}

.share__confirm {
  font-size: 12px;
  color: var(--green);
  text-align: center;
  margin-top: 6px;
  min-height: 18px;
}

/* ── Stats modal ─────────────────────────────────────────── */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(2px);
}
.modal-backdrop.open { display: flex; }

.modal {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 100%;
  max-width: 340px;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.18);
}

.modal h2 {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  margin-bottom: 1.25rem;
}

.modal-close {
  position: absolute;
  top: 14px; right: 14px;
  width: 28px; height: 28px;
  border: none; background: none;
  font-size: 17px; cursor: pointer;
  color: var(--ink-3);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  transition: background 0.12s;
}
.modal-close:hover { background: var(--surface); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 1.25rem;
}

.stat-cell {
  text-align: center;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 12px 6px;
}

.stat-num {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  line-height: 1;
  margin-bottom: 4px;
  color: var(--ink);
}

.stat-lbl {
  font-size: 10px;
  font-weight: 600;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.dist__label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--ink-3);
  margin-bottom: 8px;
}

.dist__row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  font-size: 12px;
}

.dist__key { min-width: 10px; color: var(--ink-3); }

.dist__track {
  flex: 1;
  background: var(--surface);
  border-radius: 4px;
  height: 20px;
  overflow: hidden;
}

.dist__bar {
  height: 100%;
  background: var(--ink);
  border-radius: 4px;
  min-width: 4px;
  display: flex;
  align-items: center;
  padding-left: 6px;
  transition: width 0.5s ease;
}

.dist__bar span {
  font-size: 11px;
  color: #fff;
  font-weight: 600;
}

.dist__bar--highlight { background: var(--green); }

/* ── Streak badge ────────────────────────────────────────── */
.streak-badge {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
  color: var(--amber);
  background: var(--amber-lt);
  border: 1px solid #f6d28a;
  border-radius: 100px;
  padding: 4px 12px;
  margin-bottom: 1rem;
}

/* ── Theme tag (shown during play, above timeline) ───────── */
.theme-tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 5px 14px 5px 10px;
  margin-bottom: 1rem;
}

.theme-tag__label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-3);
}

.theme-tag__name {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
}

/* ── Card body (wraps text + fact vertically) ────────────── */
.card__body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.card__fact {
  font-size: 11.5px;
  color: var(--ink-3);
  line-height: 1.5;
}

.card--correct .card__fact { color: var(--green); opacity: 0.8; }
.card--wrong   .card__fact { color: var(--red);   opacity: 0.7; }
.card--locked  .card__fact { color: var(--green); opacity: 0.8; }

/* ── Theme reveal ────────────────────────────────────────── */
.theme-reveal {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 1rem;
}

.theme-reveal__label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-3);
  white-space: nowrap;
}

.theme-reveal__name {
  font-family: var(--font-serif);
  font-size: 16px;
  color: var(--ink);
}

/* ── No puzzle state ─────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 1rem;
}
.empty-state h2 {
  font-family: var(--font-serif);
  font-size: 1.4rem;
  margin-bottom: 0.75rem;
}
.empty-state p  { font-size: 14px; color: var(--ink-2); line-height: 1.6; }
.empty-state code { font-size: 13px; background: var(--surface); padding: 1px 5px; border-radius: 4px; border: 1px solid var(--border); }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 420px) {
  main { padding: 1.5rem 1rem 3rem; }
  .card__text { font-size: 13px; }
  .logo { font-size: 1.15rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
