:root {
  --bg: #faf8f4;
  --surface: #ffffff;
  --surface-2: #f4f1ea;
  --ink: #23201b;
  --ink-soft: #6b6459;
  --line: #e7e2d8;
  --accent: #b4623a;
  --accent-soft: #f0e3da;
  --origin: #3a7a5c;
  --shadow: 0 1px 2px rgba(35, 32, 27, .06), 0 8px 24px rgba(35, 32, 27, .06);
  --radius: 16px;
  --font: "Iowan Old Style", "Palatino Linotype", Palatino, "Georgia", serif;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17150f;
    --surface: #211e17;
    --surface-2: #2a261d;
    --ink: #ece7dc;
    --ink-soft: #a49d8e;
    --line: #35301f;
    --accent: #d98a5f;
    --accent-soft: #33291f;
    --origin: #6bbd8f;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
  }
}
:root[data-theme="light"] {
  --bg: #faf8f4; --surface: #fff; --surface-2: #f4f1ea; --ink: #23201b;
  --ink-soft: #6b6459; --line: #e7e2d8; --accent: #b4623a; --accent-soft: #f0e3da;
  --origin: #3a7a5c; --shadow: 0 1px 2px rgba(35,32,27,.06), 0 8px 24px rgba(35,32,27,.06);
}
:root[data-theme="dark"] {
  --bg: #17150f; --surface: #211e17; --surface-2: #2a261d; --ink: #ece7dc;
  --ink-soft: #a49d8e; --line: #35301f; --accent: #d98a5f; --accent-soft: #33291f;
  --origin: #6bbd8f; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 720px; margin: 0 auto; padding: 0 20px 80px; }

/* Header */
.topbar {
  position: sticky; top: 0; z-index: 500;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  font-weight: 600; font-size: 1.35rem; letter-spacing: -.01em;
  color: var(--ink); text-decoration: none;
}
.brand span { color: var(--accent); }
.topbar nav { display: flex; gap: 8px; align-items: center; }

/* Typography */
h1 { font-size: 1.9rem; letter-spacing: -.02em; margin: .6em 0 .2em; }
h2 { font-size: 1.3rem; letter-spacing: -.01em; margin: 0; }
.muted { color: var(--ink-soft); }
.sans { font-family: var(--sans); }
small { color: var(--ink-soft); }
a { color: var(--accent); }

/* Buttons */
.btn, button, input[type=submit] {
  font-family: var(--sans); font-size: .95rem; font-weight: 500;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 9px 16px; border-radius: 999px; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; gap: 6px;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover, button:hover { background: var(--surface-2); }
.btn:active, button:active { transform: translateY(1px); }
.btn-primary, input[type=submit] {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.btn-primary:hover, input[type=submit]:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 5px 11px; font-size: .85rem; }
.btn-danger:hover { color: #c0392b; border-color: #c0392b; }

/* Forms */
label { font-family: var(--sans); font-size: .82rem; font-weight: 600; color: var(--ink-soft); display: block; margin-bottom: 5px; }
input, textarea, select {
  width: 100%; font-family: var(--sans); font-size: 1rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 13px;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; line-height: 1.5; }
.field { margin-bottom: 16px; }
.field .helptext, .errorlist { font-family: var(--sans); font-size: .8rem; }
.errorlist { color: #c0392b; list-style: none; padding: 0; margin: 6px 0 0; }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
}

/* Auth pages */
.auth { max-width: 380px; margin: 8vh auto 0; padding: 0 20px; }
.auth .card { padding: 28px; }
.auth h1 { margin-top: 0; text-align: center; }

/* Trip list */
.trip-grid { display: grid; gap: 16px; margin-top: 24px; }
.trip-card {
  display: block; text-decoration: none; color: inherit;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px;
  transition: transform .1s, box-shadow .15s;
}
.trip-card:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,.08), 0 16px 40px rgba(0,0,0,.1); }
.trip-card h2 { margin-bottom: 4px; }
.pill {
  font-family: var(--sans); font-size: .72rem; font-weight: 600; letter-spacing: .03em;
  text-transform: uppercase; padding: 3px 10px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}
.pill.done { background: var(--surface-2); color: var(--ink-soft); }

/* Map */
#map { height: 300px; border-radius: var(--radius); border: 1px solid var(--line);
  box-shadow: var(--shadow); margin: 20px 0; z-index: 1; }
.leaflet-container { font-family: var(--sans); background: var(--surface-2); }

/* Timeline */
.timeline { position: relative; margin: 24px 0; padding-left: 26px; }
.timeline::before {
  content: ""; position: absolute; left: 7px; top: 6px; bottom: 6px;
  width: 2px; background: var(--line);
}
.stop { position: relative; margin-bottom: 22px; }
.stop::before {
  content: ""; position: absolute; left: -26px; top: 22px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--bg);
}
.stop .card { padding: 18px 20px; }
.stop-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.stop-date { font-family: var(--sans); font-size: .8rem; color: var(--ink-soft); }
.stop-notes { margin: 10px 0 0; white-space: pre-wrap; }
.stop-actions { display: flex; gap: 4px; margin-top: 12px; }
.no-coords { font-family: var(--sans); font-size: .78rem; color: var(--accent); }

/* Photos */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; margin-top: 12px; }
.photo { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo form { position: absolute; top: 4px; right: 4px; margin: 0; }
.photo button {
  padding: 0; width: 22px; height: 22px; border-radius: 50%; font-size: .7rem;
  background: rgba(0,0,0,.55); color: #fff; border: none; line-height: 1;
  opacity: 0; transition: opacity .15s;
}
.photo:hover button { opacity: 1; }
.photo-add { font-family: var(--sans); font-size: .82rem; margin-top: 10px; }
.photo-add input[type=file] { font-size: .82rem; padding: 6px; }

/* Add-destination composer */
.composer { margin-top: 8px; }
.composer summary { list-style: none; cursor: pointer; }
.composer summary::-webkit-details-marker { display: none; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }
.flash { font-family: var(--sans); font-size: .9rem; padding: 10px 14px; border-radius: 12px; background: var(--accent-soft); margin: 12px 0; }
.center { text-align: center; }
.spacer { height: 8px; }
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
