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

:root {
  --bg: #121213;
  --surface: #1e1e20;
  --surface-hover: #2a2a2d;
  --border: #3a3a3c;
  --text: #d7dadc;
  --text-muted: #818384;
  --correct: #538d4e;
  --correct-bg: rgba(83, 141, 78, 0.15);
  --incorrect: #c9444d;
  --incorrect-bg: rgba(201, 68, 77, 0.1);
  --accent: #e2a829;
  --accent-bg: rgba(226, 168, 41, 0.12);
  --primary: #4a90d9;
  --primary-hover: #5ba0e9;
  --radius: 10px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --tl-width: 3px;
  --tl-left: 28px;
  --tl-dot: 13px;
}

html {
  font-size: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 24px;
}

header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-bottom: 4px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.rabbit-icon {
  width: 32px;
  height: 32px;
  opacity: 0.35;
  transition: opacity 0.4s;
  vertical-align: middle;
}

.rabbit-icon:hover {
  opacity: 0.8;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.tagline {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 6px;
}

.tagline strong {
  color: var(--text);
}

/* Mode selector */
#mode-selector {
  display: flex;
  justify-content: center;
  padding: 4px 0 12px;
  margin-bottom: 4px;
}

#mode-dropdown {
  position: relative;
  width: 100%;
  max-width: 280px;
}

.mode-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.mode-toggle:hover {
  background: var(--surface-hover);
  border-color: #4a4a4e;
}

.mode-toggle.completed {
  border-color: rgba(83, 141, 78, 0.4);
}

.mode-toggle-arrow {
  font-size: 0.8rem;
  color: var(--text-muted);
  transition: transform 0.2s;
}

.mode-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.mode-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 10px 16px;
  border: none;
  background: none;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.1s;
  text-align: left;
}

.mode-menu-item:hover {
  background: var(--surface-hover);
}

.mode-menu-item.active {
  background: rgba(74, 144, 217, 0.1);
  color: var(--primary);
  font-weight: 600;
}

.mode-menu-item.completed .mode-item-label {
  color: var(--correct);
}

.mode-score {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(255,255,255,0.06);
  padding: 2px 8px;
  border-radius: 4px;
}

.mode-menu-item.completed .mode-score {
  color: var(--correct);
  background: var(--correct-bg);
}

/* Loading */
#loading {
  text-align: center;
  padding: 60px 0;
  color: var(--text-muted);
  font-size: 1rem;
}

/* Score panel */
#score-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  text-align: center;
}

#score-current {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

#score-current strong {
  color: var(--accent);
  font-size: 1.1rem;
}

#hint-penalty-display {
  color: var(--incorrect);
  font-size: 0.8rem;
  margin-left: 4px;
}

#score-scale {
  display: flex;
  justify-content: center;
  gap: 2px;
  flex-wrap: wrap;
}

.scale-tier {
  font-size: 0.7rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  padding: 3px 6px;
  border-radius: 4px;
  color: var(--text-muted);
  background: rgba(255,255,255,0.04);
  transition: all 0.2s;
}

.scale-tier.active {
  background: var(--accent-bg);
  color: var(--accent);
  border: 1px solid rgba(226, 168, 41, 0.3);
}

#score-scale-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 6px;
  letter-spacing: 0.05em;
  opacity: 0.6;
}

/* ===== Timeline wrapper ===== */
.timeline-wrapper {
  position: relative;
  padding-left: 0;
}

/* Top/bottom caps */
.timeline-cap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: calc(var(--tl-left) - var(--tl-dot) / 2);
}

.timeline-cap-start {
  margin-bottom: 4px;
}

.timeline-cap-end {
  margin-top: 4px;
}

.timeline-cap-dot {
  width: var(--tl-dot);
  height: var(--tl-dot);
  border-radius: 50%;
  background: var(--border);
  border: 2px solid var(--text-muted);
  flex-shrink: 0;
}

.timeline-cap-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.timeline-cap-start .timeline-cap-dot {
  background: var(--surface);
  border-color: var(--accent);
}

.timeline-cap-end .timeline-cap-dot {
  background: var(--surface);
  border-color: var(--primary);
}

/* The vertical line */
.timeline-track {
  position: relative;
  padding-left: calc(var(--tl-left) + var(--tl-width) / 2 + 16px);
}

.timeline-track::before {
  content: '';
  position: absolute;
  left: calc(var(--tl-left) + var(--tl-width) / 2 - var(--tl-width) / 2);
  top: 0;
  bottom: 0;
  width: var(--tl-width);
  background: linear-gradient(to bottom, var(--accent), var(--border) 20%, var(--border) 80%, var(--primary));
  border-radius: 2px;
}

/* ===== Event list (game) ===== */
#event-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 100px;
  padding: 8px 0;
}

/* Event card (game) */
.event-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px 14px 12px;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.2s ease;
  position: relative;
  touch-action: none;
}

/* Timeline dot on each card */
.event-card::before {
  content: '';
  position: absolute;
  left: calc(-16px - var(--tl-width) / 2 - var(--tl-dot) / 2 + var(--tl-width) / 2);
  top: 50%;
  transform: translateY(-50%);
  width: var(--tl-dot);
  height: var(--tl-dot);
  border-radius: 50%;
  background: var(--surface);
  border: var(--tl-width) solid var(--text-muted);
  z-index: 1;
  transition: border-color 0.2s, background 0.2s;
}

/* Connector from dot to card */
.event-card::after {
  content: '';
  position: absolute;
  left: calc(-16px + var(--tl-dot) / 2 - var(--tl-width) / 2);
  top: 50%;
  width: calc(16px - var(--tl-dot) / 2 + var(--tl-width) / 2);
  height: 2px;
  background: var(--border);
  transform: translateY(-50%);
}

.event-card:hover {
  background: var(--surface-hover);
  border-color: #4a4a4e;
}

.event-card:hover::before {
  border-color: var(--primary);
}

.event-card:active {
  cursor: grabbing;
}

/* Source card stays in place during drag — just dimmed & desaturated
   so you still see where it came from but focus shifts to the indicator. */
.event-card.dragging {
  opacity: 0.28;
  filter: grayscale(0.85);
}
.event-card.dragging::before { border-color: var(--text-muted); }

/* Drop slot indicator — appears in the gap between cards and extends
   past the container on each side with a soft fade so the line is
   visible even when the browser's drag-ghost occludes the center. */
.drop-indicator {
  height: 4px;
  margin: 0 -64px 0 -48px;
  background: var(--primary);
  border-radius: 3px;
  box-shadow: 0 0 14px rgba(74, 144, 217, 0.75);
  position: relative;
  z-index: 2;
  -webkit-mask-image: linear-gradient(to right, transparent 0%, black 8%, black 92%, transparent 100%);
          mask-image: linear-gradient(to right, transparent 0%, black 8%, black 92%, transparent 100%);
  animation: dropIndicatorIn 0.2s ease-out,
             dropIndicatorPulse 1.4s ease-in-out 0.2s infinite;
}

@keyframes dropIndicatorIn {
  from { opacity: 0; height: 0; }
  to   { opacity: 1; height: 4px; }
}

@keyframes dropIndicatorPulse {
  0%, 100% { box-shadow: 0 0 10px rgba(74, 144, 217, 0.6); }
  50%      { box-shadow: 0 0 18px rgba(74, 144, 217, 0.95); }
}

/* Settle animation after a successful drop — confirms where the card landed. */
.event-card.just-moved {
  animation: justMoved 0.45s cubic-bezier(0.34, 1.4, 0.64, 1);
}

@keyframes justMoved {
  0% {
    transform: scale(1.025);
    box-shadow: 0 0 0 2px var(--primary),
                0 8px 24px rgba(74, 144, 217, 0.35);
    background: rgba(74, 144, 217, 0.08);
  }
  100% {
    transform: scale(1);
    box-shadow: none;
    background: var(--surface);
  }
}


.event-card.just-added {
  animation: slideIn 0.3s ease-out;
  border-color: var(--accent);
}

.event-card.just-added::before {
  border-color: var(--accent);
  background: var(--accent-bg);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.card-grip {
  color: var(--text-muted);
  font-size: 1rem;
  flex-shrink: 0;
  line-height: 1;
}

.card-number {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-muted);
  min-width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.card-body {
  flex: 1;
  min-width: 0;
}

.card-event-name {
  font-size: 0.95rem;
  font-weight: 500;
  line-height: 1.3;
}

.card-hints-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.hint-btn {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  font-family: inherit;
  white-space: nowrap;
}

.hint-btn:hover {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: var(--accent);
}

.hint-cost {
  opacity: 0.7;
  font-weight: 400;
  margin-left: 2px;
}

.hint-revealed {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
}

.hint-cat-value {
  color: var(--accent);
  background: var(--accent-bg);
}

.hint-dec-value {
  color: var(--primary);
  background: rgba(74, 144, 217, 0.12);
}


/* Touch drag ghost */
.drag-ghost {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  opacity: 0.9;
  transform: scale(1.03);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  border-color: var(--primary) !important;
  background: var(--surface) !important;
}

/* ===== Controls ===== */
#controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
  font-family: inherit;
}

.btn:active {
  transform: scale(0.98);
}

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

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--accent-bg);
  color: var(--accent);
  border: 1px solid rgba(226, 168, 41, 0.25);
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(226, 168, 41, 0.2);
}

#draw-controls {
  display: flex;
  gap: 8px;
}

#draw-controls .btn {
  flex: 1;
}

#remaining-count {
  font-weight: 400;
  opacity: 0.8;
}

/* ===== Results ===== */
#results-header {
  text-align: center;
  margin-bottom: 24px;
}

#results-title {
  font-size: 1.4rem;
  margin-bottom: 8px;
}

#results-score {
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 4px;
}

#results-breakdown {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 12px;
}

#results-emoji {
  font-size: 1.6rem;
  letter-spacing: 4px;
  margin-bottom: 8px;
}

/* ===== Side-by-side results comparison ===== */
/* Widen the app shell while viewing results so the two columns have room. */
body.results-view #app {
  max-width: 880px;
}

#results-comparison {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-top: 8px;
  margin-bottom: 8px;
  position: relative; /* anchor for the SVG connector overlay */
}

/* SVG connector that draws a curve between matched rows on hover. */
#result-connector {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
  z-index: 0;
}

#result-connector path {
  fill: none;
  stroke: var(--primary);
  stroke-width: 2.5;
  stroke-linecap: round;
  opacity: 0;
  filter: drop-shadow(0 0 6px rgba(74, 144, 217, 0.55));
  transition: opacity 0.18s ease;
}

#result-connector.active path {
  opacity: 1;
}

.result-column {
  min-width: 0; /* allow children to shrink/wrap inside grid track */
}

.result-column-header {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: center;
  padding: 8px 6px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.result-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  counter-reset: result-row;
}

.result-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  position: relative;
  z-index: 1; /* sit above the SVG connector */
  /* Fixed height keeps left & right rows aligned regardless of text length. */
  min-height: 76px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
  cursor: pointer;
}

.result-row .row-position {
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--text-muted);
  min-width: 20px;
  text-align: center;
  align-self: center;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.result-row .row-body {
  flex: 1;
  min-width: 0;
}

.result-row .row-event {
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.3;
  overflow-wrap: anywhere;
  /* Clamp to 2 lines so all rows stay the same size; full text via title attr. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
          line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.result-row .row-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 3px;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.result-row .row-distance {
  font-weight: 700;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Accuracy color states */
.result-row.correct {
  background: var(--correct-bg);
  border-color: rgba(83, 141, 78, 0.3);
}
.result-row.correct .row-position,
.result-row.correct .row-distance { color: var(--correct); }

.result-row.close {
  background: var(--accent-bg);
  border-color: rgba(226, 168, 41, 0.3);
}
.result-row.close .row-position,
.result-row.close .row-distance { color: var(--accent); }

.result-row.incorrect {
  background: var(--incorrect-bg);
  border-color: rgba(201, 68, 77, 0.3);
}
.result-row.incorrect .row-position,
.result-row.incorrect .row-distance { color: var(--incorrect); }

/* Per-card score badge sits to the LEFT of the user-order card,
   outside its border, color-matched to the accuracy state. */
.result-row .row-score {
  position: absolute;
  right: calc(100% + 6px);
  top: 50%;
  transform: translateY(-50%);
  font-weight: 700;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}
.result-row.correct .row-score { color: var(--correct); }
.result-row.close .row-score { color: var(--accent); }
.result-row.incorrect .row-score { color: var(--incorrect); }

/* Cross-column match highlight (hover one side, peer lights up). */
.result-row.match-highlight {
  transform: scale(1.02);
  box-shadow: 0 0 0 2px var(--primary), 0 4px 14px rgba(74, 144, 217, 0.3);
  border-color: var(--primary);
  z-index: 1;
}

/* On narrow screens, stack the two columns vertically. */
@media (max-width: 540px) {
  #results-comparison {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  /* Connector between far-apart stacked rows is more confusing than helpful. */
  #result-connector { display: none; }
}

/* Below ~900px the body margin is too tight to fit the badge outside #app
   (results-view max-width is 880px), so fold the badge inline at the
   start of the row. */
@media (max-width: 900px) {
  .result-row .row-score {
    position: static;
    transform: none;
    margin-right: 4px;
    order: -1;
  }
}

#results-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  margin-top: 20px;
}

#copied-msg {
  color: var(--correct);
  font-size: 0.9rem;
  font-weight: 500;
}

/* ===== How to play ===== */
#how-to-play {
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

#how-to-play summary {
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  transition: color 0.15s, background 0.15s;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#how-to-play summary::-webkit-details-marker {
  display: none;
}

#how-to-play summary::after {
  content: 'Show ▾';
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--primary);
  background: rgba(74, 144, 217, 0.12);
  color: var(--primary-hover);
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}

#how-to-play[open] summary::after {
  content: 'Hide ▴';
  background: rgba(74, 144, 217, 0.22);
  color: #cfe3f7;
  border-color: var(--primary-hover);
}

#how-to-play summary:hover {
  background: var(--surface-hover);
}

#how-to-play summary:hover::after {
  background: rgba(74, 144, 217, 0.28);
  color: #ffffff;
  border-color: var(--primary-hover);
}

.help-content {
  padding: 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.7;
}

.help-content p {
  margin-bottom: 10px;
}

.help-content p:last-child {
  margin-bottom: 0;
}

.help-content strong {
  color: var(--text);
}

.scoring-table {
  width: 100%;
  margin: 8px 0 12px;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.scoring-table td {
  padding: 5px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.scoring-table tr:last-child td {
  border-bottom: none;
}

.scoring-table td:last-child {
  text-align: right;
  white-space: nowrap;
}

.example-table {
  margin-top: 6px;
}

.example-header td {
  font-weight: 700;
  color: var(--text);
  font-size: 0.75rem;
  padding-bottom: 3px;
}

.example-good td:last-child {
  color: var(--correct);
}

.example-bad td:last-child {
  color: var(--incorrect);
}

.help-content ul {
  margin: 4px 0 10px 20px;
}

.help-content li {
  margin-bottom: 4px;
}

.btn-disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* ===== Utility ===== */
.hidden {
  display: none !important;
}

/* ===== Responsive ===== */
@media (max-width: 400px) {
  :root {
    --tl-left: 20px;
    --tl-dot: 11px;
  }

  #app {
    padding: 16px 12px 32px;
  }

  header h1 {
    font-size: 1.5rem;
  }

  .event-card {
    padding: 12px 10px 12px 10px;
    gap: 8px;
  }

  .result-year {
    width: 40px;
    font-size: 0.7rem;
  }

  #score-preview {
    flex-direction: column;
    gap: 4px;
    text-align: center;
  }
}
