:root {
  --bg: #12120f;
  --bg-elevated: #1a1a16;
  --bg-card: #1e1e1a;
  --border: #2a2820;
  --border-light: #3a3830;
  --text: #e0e0e0;
  --text-dim: #888;
  --text-muted: #555;
  --accent: #d4c5a9;
  --accent-dim: #8a7d5a;
  --accent-glow: rgba(212, 197, 169, 0.12);
  --edit-color: #6a9fba;
  --edit-bg: rgba(106, 159, 186, 0.08);
  --danger: #c0392b;
  --radius: 4px;
  --font: system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Fira Mono', 'Consolas', monospace;
}

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

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Header ─────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(18, 18, 15, 0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
  height: 60px;
}
.back-link {
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
  transition: color 0.15s;
}
.back-link:hover { color: var(--accent); }

.header-title { flex: 1; }
.header-title h1 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.04em;
}
.header-title .tagline {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: -2px;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.35em 0.8em;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn:hover { color: var(--text); border-color: var(--border-light); }
.btn-edit { border-color: var(--edit-color); color: var(--edit-color); }
.btn-edit:hover { background: var(--edit-bg); }
.btn-edit.active { background: var(--edit-bg); }

/* ── Stats bar ─────────────────────────────────────────── */
.stats-bar {
  max-width: 1200px;
  margin: 1.5rem auto 0;
  padding: 0 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  font-size: 13px;
  color: var(--text-dim);
}
.stat { display: flex; flex-direction: column; }
.stat-value { font-size: 1.5rem; font-weight: 600; color: var(--accent); line-height: 1.2; }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }

/* ── Timeline ──────────────────────────────────────────── */
#timeline {
  max-width: 1200px;
  margin: 2rem auto;
  padding: 0 1.5rem 4rem;
}

.year-section { margin-bottom: 2.5rem; }
.year-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.4rem;
  margin-bottom: 1rem;
}

.month-section { margin-bottom: 1.5rem; }
.month-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
  padding-left: 0.5rem;
}

.day-row {
  display: grid;
  grid-template-columns: 100px 1fr auto;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  text-decoration: none;
  color: var(--text);
  transition: all 0.15s;
  cursor: pointer;
  background: transparent;
  width: 100%;
}
.day-row:hover {
  background: var(--bg-card);
  border-color: var(--border);
}

.day-date {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
}
.day-date .weekday { font-size: 11px; color: var(--text-muted); }

.day-content { min-width: 0; }
.day-title-view {
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.day-title-view.empty { color: var(--text-muted); font-style: italic; }
.day-thumbs {
  display: flex;
  gap: 3px;
  margin-top: 4px;
}
.day-thumb {
  width: 40px;
  height: 30px;
  object-fit: cover;
  border-radius: 2px;
  background: var(--bg-elevated);
  opacity: 0.7;
  transition: opacity 0.15s;
}
.day-row:hover .day-thumb { opacity: 1; }
.day-thumb-overflow {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.day-count {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  text-align: right;
  min-width: 60px;
}
.day-count strong { color: var(--accent-dim); }

/* Edit mode inline title input */
.day-title-input {
  width: 100%;
  background: var(--edit-bg);
  border: 1px solid var(--edit-color);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  padding: 0.2em 0.5em;
  outline: none;
  font-family: var(--font);
}
.day-title-input:focus { border-color: var(--edit-color); }

/* ── Day Page ──────────────────────────────────────────── */
.day-header {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.day-header-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}
.day-nav { display: flex; gap: 0.5rem; align-items: center; }
.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  padding: 0.3em 0.7em;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.nav-btn:hover { border-color: var(--border-light); color: var(--text); }
.nav-btn.disabled { opacity: 0.3; pointer-events: none; }

.day-title-h { margin-top: 0.5rem; }
.day-title-h h2 {
  font-size: 1.8rem;
  font-weight: 300;
  color: var(--accent);
  letter-spacing: 0.02em;
}
.day-title-h .day-subtitle { color: var(--text-dim); font-size: 14px; margin-top: 0.25rem; }

/* Custom title display / edit */
.day-custom-title-view {
  font-size: 1.1rem;
  color: var(--text);
  margin-top: 0.35rem;
  font-style: italic;
}
.day-custom-title-view.empty { display: none; }
.day-custom-title-input {
  width: 100%;
  max-width: 600px;
  background: var(--edit-bg);
  border: 1px solid var(--edit-color);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1.1rem;
  padding: 0.3em 0.6em;
  outline: none;
  font-family: var(--font);
  font-style: italic;
  margin-top: 0.35rem;
  display: none;
}

/* Narrative */
.day-narrative {
  max-width: 820px;
  margin-top: 1rem;
}
.narrative-view {
  font-size: 15px;
  color: var(--text);
  white-space: pre-wrap;
  line-height: 1.7;
}
.narrative-view.empty { color: var(--text-muted); font-style: italic; }
.narrative-input {
  width: 100%;
  min-height: 100px;
  background: var(--edit-bg);
  border: 1px solid var(--edit-color);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  padding: 0.6em 0.8em;
  outline: none;
  font-family: var(--font);
  line-height: 1.7;
  resize: vertical;
  display: none;
}

/* ── Photo Grid ─────────────────────────────────────────── */
.photo-grid-wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 4rem;
}
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 6px;
}
.photo-card {
  position: relative;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  border: 1px solid transparent;
  transition: border-color 0.15s;
}
.photo-card:hover { border-color: var(--accent-dim); }
.photo-card .thumb-wrap {
  position: relative;
  width: 100%;
  padding-top: 75%; /* 4:3 */
  overflow: hidden;
}
.photo-card img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s;
}
.photo-card:hover img { transform: scale(1.04); }

.photo-caption-view {
  padding: 0.4rem 0.5rem;
  font-size: 12px;
  color: var(--text-dim);
  min-height: 28px;
}
.photo-caption-view.empty { color: var(--text-muted); font-style: italic; }
.photo-caption-input {
  display: none;
  width: 100%;
  background: var(--edit-bg);
  border: none;
  border-top: 1px solid var(--edit-color);
  color: var(--text);
  font-size: 12px;
  padding: 0.4rem 0.5rem;
  outline: none;
  font-family: var(--font);
  resize: none;
  min-height: 36px;
}

/* Undated section */
.undated-section {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem 2rem;
}
.undated-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
  padding: 0.4em 0.8em;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}
.undated-toggle:hover { color: var(--text); border-color: var(--border-light); }

/* ── Lightbox ───────────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: stretch;
  background: rgba(0, 0, 0, 0.92);
}
.lightbox.hidden { display: none; }

.lb-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-width: 0;
  padding: 1rem;
}
.lb-main img {
  max-width: 100%;
  max-height: 100vh;
  object-fit: contain;
  display: block;
}

.lb-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,0.5);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fff;
  font-size: 1.5rem;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
  user-select: none;
}
.lb-arrow:hover { background: rgba(0,0,0,0.8); }
.lb-arrow.prev { left: 1rem; }
.lb-arrow.next { right: 1rem; }
.lb-arrow.hidden { display: none; }

.lb-panel {
  width: 320px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.lb-panel-inner {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.lb-close {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: transparent;
  border-top: none;
  border-left: none;
  border-right: none;
}
.lb-close button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.lb-close button:hover { color: var(--text); border-color: var(--border-light); }

.lb-caption-area { }
.lb-caption-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}
.lb-caption-text {
  font-size: 13px;
  color: var(--text);
  white-space: pre-wrap;
}
.lb-caption-text.empty { color: var(--text-muted); font-style: italic; }
.lb-caption-input {
  display: none;
  width: 100%;
  background: var(--edit-bg);
  border: 1px solid var(--edit-color);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  padding: 0.4em 0.6em;
  outline: none;
  font-family: var(--font);
  resize: vertical;
  min-height: 60px;
}

/* EXIF display */
.exif-section { margin-top: 0.25rem; }
.exif-heading {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}
.exif-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 12px;
  padding: 0.2rem 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.exif-row:last-child { border-bottom: none; }
.exif-key { color: var(--text-muted); white-space: nowrap; }
.exif-val { color: var(--text); text-align: right; font-family: var(--font-mono); font-size: 11px; word-break: break-all; }

/* source path */
.lb-source {
  font-size: 11px;
  color: var(--text-muted);
  word-break: break-all;
  font-family: var(--font-mono);
}

/* ── Edit mode indicator ─────────────────────────────────── */
.edit-mode-badge {
  display: none;
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--edit-color);
  color: #fff;
  font-size: 12px;
  padding: 0.4em 0.8em;
  border-radius: 20px;
  font-weight: 600;
  z-index: 200;
  pointer-events: none;
}
body.edit-mode .edit-mode-badge { display: block; }
body.edit-mode .narrative-input { display: block; }
body.edit-mode .narrative-view { display: none; }
body.edit-mode .day-custom-title-input { display: block; }
body.edit-mode .day-custom-title-view { display: none; }
body.edit-mode .photo-caption-input { display: block; }
body.edit-mode .lb-caption-input { display: block; }
body.edit-mode .lb-caption-text { display: none; }

/* ── Empty / loading states ─────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-muted);
}
.empty-state p { margin-top: 0.5rem; font-size: 13px; }

/* ── Date correction in lightbox ────────────────────────────────────────── */
.lb-date-orig {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  font-family: var(--font-mono);
}
.lb-date-orig .orig-val { color: var(--text-dim); }
.lb-corr-badge {
  display: inline-block;
  font-size: 11px;
  color: var(--edit-color);
  background: var(--edit-bg);
  border: 1px solid rgba(106,159,186,0.3);
  border-radius: 3px;
  padding: 0.15em 0.5em;
  margin-bottom: 0.4rem;
}
.lb-corr-badge.hidden { display: none; }
.lb-date-fields { display: none; }
body.edit-mode .lb-date-fields { display: block; }
.lb-date-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  padding: 0.3em 0.5em;
  outline: none;
  font-family: var(--font-mono);
  margin-bottom: 0.4rem;
}
.lb-date-input:focus { border-color: var(--edit-color); }
.lb-date-btns { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.3rem; }
.btn-sm {
  padding: 0.25em 0.6em;
  font-size: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-sm:hover { color: var(--text); border-color: var(--accent-dim); }
.btn-sm.primary { border-color: var(--edit-color); color: var(--edit-color); }
.btn-sm.primary:hover { background: var(--edit-bg); }
.btn-sm.warn { border-color: #c0392b; color: #c0392b; }
.btn-sm.warn:hover { background: rgba(192,57,43,0.1); }
.btn-sm.hidden { display: none; }
.lb-date-status { font-size: 11px; color: var(--edit-color); min-height: 14px; }

/* Corrected photo overlay badge */
.corr-overlay {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.72);
  color: var(--edit-color);
  font-size: 10px;
  padding: 0.2em 0.4em;
  text-align: center;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Bulk correction modal ───────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal.hidden { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.75);
}
.modal-box {
  position: relative;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  width: 100%;
  max-width: 680px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h3 { font-size: 1rem; font-weight: 600; color: var(--accent); }
.modal-close-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 26px; height: 26px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.modal-close-btn:hover { color: var(--text); }
.modal-hint {
  padding: 0.75rem 1.25rem;
  font-size: 13px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  line-height: 1.5;
}
.modal-hint strong { color: var(--accent); }
.modal-body { overflow-y: auto; flex: 1; padding: 0.75rem 1.25rem; }
.modal-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-muted);
  flex-wrap: wrap;
}
.modal-section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin: 0.75rem 0 0.4rem;
}

/* Camera cards */
.cam-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  overflow: hidden;
}
.cam-card.warn { border-color: rgba(212,150,50,0.4); }
.cam-header {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  background: rgba(255,255,255,0.02);
  cursor: pointer;
  user-select: none;
}
.cam-header:hover { background: rgba(255,255,255,0.04); }
.cam-name { font-size: 13px; font-weight: 600; color: var(--text); }
.cam-count { font-size: 12px; color: var(--text-muted); }
.cam-range { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); }
.badge-warn {
  font-size: 10px;
  background: rgba(212,150,50,0.12);
  border: 1px solid rgba(212,150,50,0.4);
  color: #d49632;
  padding: 0.1em 0.5em;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.badge-ok {
  font-size: 10px;
  background: rgba(80,160,80,0.08);
  border: 1px solid rgba(80,160,80,0.3);
  color: #5a9c5a;
  padding: 0.1em 0.5em;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.cam-body {
  padding: 0.6rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-top: 1px solid var(--border);
}
.cam-body.collapsed { display: none; }
.cam-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--text-dim);
}
.cam-input-date {
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
  padding: 0.25em 0.4em;
  font-family: var(--font-mono);
  outline: none;
  width: 132px;
}
.cam-input-date:focus { border-color: var(--edit-color); }
.cam-input-num {
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
  padding: 0.25em 0.4em;
  font-family: var(--font-mono);
  outline: none;
  width: 76px;
  text-align: right;
}
.cam-input-num:focus { border-color: var(--edit-color); }
.cam-preview { font-size: 11px; color: var(--edit-color); font-family: var(--font-mono); flex: 1; }
.cam-result { font-size: 12px; color: #5a9c5a; font-weight: 600; }
.cam-already { font-size: 11px; color: var(--edit-color); }

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .header-inner { height: 52px; }
  .header-title h1 { font-size: 0.95rem; }
  .header-title .tagline { display: none; }

  .day-row { grid-template-columns: 80px 1fr 40px; gap: 0.5rem; }
  .day-thumbs { display: none; }

  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 4px; }

  .lightbox { flex-direction: column; }
  .lb-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: 45vh;
  }
  .lb-main { max-height: 55vh; }
}

@media (max-width: 480px) {
  .photo-grid { grid-template-columns: repeat(2, 1fr); }
  .stats-bar { gap: 1rem; }
  .stat-value { font-size: 1.2rem; }
}
