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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: #1a1a2e;
  color: #eee;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 16px;
}

.timeline-app {
  width: 100%;
  max-width: 820px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ---------- Header ---------- */

.timeline-header {
  position: relative;
  text-align: center;
  padding: 8px 0 4px;
}

.back-btn {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  color: #fff;
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 10px;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s ease, background 0.1s ease;
}

.back-btn:hover { background: #0f3460; }
.back-btn:active { transform: translateY(-50%) scale(0.96); }
.back-btn:focus-visible { outline: 2px solid #e94560; outline-offset: 2px; }

.timeline-title { font-size: 1.5rem; }
.timeline-subtitle { color: #999; font-size: 0.95rem; margin-top: 2px; }

/* ---------- Gallery button (header) ---------- */

.gallery-btn {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  color: #fff;
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s ease, background 0.1s ease;
}

.gallery-btn:hover { background: #0f3460; }
.gallery-btn:active { transform: translateY(-50%) scale(0.96); }
.gallery-btn:focus-visible { outline: 2px solid #e94560; outline-offset: 2px; }

/* ---------- Graph ---------- */

.graph-container {
  position: relative;
  width: 100%;
  height: 360px;
  padding: 0;
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 12px;
  overflow: hidden;
}

.graph-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.graph-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  color: #999;
  font-size: 1.05rem;
  text-align: center;
}

/* ---------- Controls ---------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px;
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 12px;
}

.control-btn {
  padding: 10px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  background: #e94560;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.1s ease, opacity 0.1s ease;
}

.control-btn:hover:not(:disabled) { background: #ff5570; }
.control-btn:active:not(:disabled) { transform: scale(0.96); }
.control-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.control-btn:focus-visible { outline: 2px solid #ffd166; outline-offset: 2px; }

.reset-btn { background: #0f3460; }
.reset-btn:hover:not(:disabled) { background: #1b4a86; }

.speed-group {
  display: flex;
  gap: 6px;
}

.speed-btn {
  padding: 8px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #ccc;
  background: #1a1a2e;
  border: 1px solid #0f3460;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.1s ease, color 0.1s ease, transform 0.1s ease;
}

.speed-btn:hover { background: #0f3460; color: #fff; }
.speed-btn.active { background: #e94560; border-color: #e94560; color: #fff; }
.speed-btn:active { transform: scale(0.96); }
.speed-btn:focus-visible { outline: 2px solid #ffd166; outline-offset: 2px; }

.timestamp-display {
  min-width: 96px;
  padding: 8px 12px;
  font-size: 0.95rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #ffd166;
  background: #1a1a2e;
  border: 1px solid #0f3460;
  border-radius: 8px;
  text-align: center;
}

/* ---------- Stats ---------- */

.stats-title {
  font-size: 1rem;
  font-weight: 600;
  color: #ccc;
  margin-bottom: 10px;
  text-align: center;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 10px;
}

.stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 4px;
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 10px;
}

.stat-name {
  font-size: 0.75rem;
  font-weight: 600;
  color: #ccc;
  text-align: center;
}

.stat-count {
  font-size: 1.4rem;
  font-weight: 700;
  color: #ffd166;
  font-variant-numeric: tabular-nums;
}

.stat-card.bump .stat-count {
  animation: stat-bump 0.3s ease;
}

@keyframes stat-bump {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.35); color: #e94560; }
  100% { transform: scale(1); }
}

/* ---------- Gallery modal ---------- */

.gallery-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.7);
}

.gallery-modal.open { display: flex; }

.gallery-modal-content {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  background: #1a1a2e;
  border: 1px solid #0f3460;
  border-radius: 12px;
  padding: 16px;
}

.gallery-modal-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 16px;
  padding-right: 36px;
}

.gallery-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  line-height: 1;
  color: #fff;
  background: #e94560;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.1s ease;
}

.gallery-modal-close:hover { background: #ff5570; }
.gallery-modal-close:active { transform: scale(0.92); }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.gallery-item {
  position: relative;
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 8px;
  overflow: hidden;
}

.gallery-item-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  background: #0f3460;
}

.gallery-item-timestamp {
  display: block;
  padding: 6px 4px;
  font-size: 0.7rem;
  color: #999;
  text-align: center;
}

.gallery-empty {
  padding: 24px 8px;
  color: #999;
  font-size: 0.95rem;
}

/* ---------- Photo modal (enlarged view + download/share/close) ---------- */

.photo-modal {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.9);
}

.photo-modal.open { display: flex; }

.photo-modal-content {
  position: relative;
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.photo-modal-img {
  max-width: 100%;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 8px;
  background: #111;
}

.photo-modal-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 8px;
}

.photo-modal-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  line-height: 1;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s ease, background 0.1s ease;
}

.photo-modal-btn:hover { background: rgba(0, 0, 0, 0.75); }
.photo-modal-btn:active { transform: scale(0.92); }
.photo-modal-btn:focus-visible { outline: 2px solid #e94560; outline-offset: 2px; }

.photo-modal-copied {
  position: absolute;
  top: 52px;
  right: 8px;
  padding: 4px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  color: #fff;
  background: #2e7d32;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.photo-modal-copied.show { opacity: 1; }

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .graph-container { height: 240px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .timeline-title { font-size: 1.2rem; }
  .controls { gap: 8px; padding: 12px; }
  .timestamp-display { min-width: 80px; }
}

@media (min-width: 480px) {
  .gallery-grid { grid-template-columns: repeat(3, 1fr); }
}
