/* ============ Tokens ============ */
:root {
  --bg: #f7f2ea;
  --bg-2: #efe7da;
  --surface: #fffdf9;
  --ink: #2a2420;
  --ink-2: #6b6058;
  --ink-3: #9a8f86;
  --line: #e4d9ca;
  --accent: #c2553f;
  --accent-ink: #ffffff;
  --accent-soft: #f6e1da;
  --ok: #2f7d5b;
  --danger: #b3261e;
  --danger-soft: #fbe3e1;
  --shadow: 0 1px 2px rgba(42, 36, 32, .06), 0 8px 24px rgba(42, 36, 32, .08);
  --shadow-lg: 0 2px 6px rgba(42, 36, 32, .08), 0 24px 60px rgba(42, 36, 32, .18);
  --radius: 18px;
  --radius-sm: 12px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1816;
    --bg-2: #24201d;
    --surface: #2a2522;
    --ink: #f3ece4;
    --ink-2: #c3b8ad;
    --ink-3: #8f857c;
    --line: #3b3430;
    --accent: #e27a61;
    --accent-ink: #1b1816;
    --accent-soft: #43281f;
    --ok: #6cc59b;
    --danger: #ff8a80;
    --danger-soft: #45201d;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.3);
    --shadow-lg: 0 2px 6px rgba(0,0,0,.4), 0 24px 60px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}

/* ============ Base ============ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.15; margin: 0; letter-spacing: -.01em; }
p { margin: 0; }
a { color: var(--accent); }
img { max-width: 100%; display: block; }
button, input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ============ Buttons & inputs ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  min-height: 48px; padding: 0 22px;
  border: 1px solid transparent; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 600; font-size: 15px; cursor: pointer;
  transition: transform .12s ease, filter .15s ease, background .15s ease;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--bg-2); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.small { min-height: 38px; padding: 0 14px; font-size: 14px; }
.btn.block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer; box-shadow: var(--shadow);
  -webkit-tap-highlight-color: transparent;
}
.icon-btn svg { width: 20px; height: 20px; }

.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field small { color: var(--ink-3); font-size: 12.5px; }
.input, textarea.input, select.input {
  width: 100%; min-height: 48px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 16px; /* prevents iOS zoom */
  outline: none; transition: border-color .15s, box-shadow .15s;
}
textarea.input { min-height: 110px; resize: vertical; line-height: 1.45; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

.alert {
  padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--danger-soft); color: var(--danger);
  font-size: 14px; font-weight: 500; margin-bottom: 16px;
}

/* ============ Gate pages (wall / login) ============ */
.gate {
  min-height: 100vh; min-height: 100dvh;
  display: grid; place-items: center;
  padding: calc(24px + var(--safe-t)) 16px calc(24px + var(--safe-b));
  background:
    radial-gradient(1200px 600px at 10% -10%, var(--accent-soft), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, var(--bg-2), transparent 60%),
    var(--bg);
}
.card {
  width: 100%; max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
  padding: 32px 24px;
}
@media (min-width: 480px) { .card { padding: 40px 36px; } }
.brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--serif); font-size: 15px; color: var(--ink-2);
  margin-bottom: 28px;
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
}
.brand-mark svg { width: 18px; height: 18px; }
.card h1 { font-size: 28px; margin-bottom: 8px; }
.card .lede { color: var(--ink-2); margin-bottom: 28px; }

.progress { display: flex; gap: 6px; margin-bottom: 22px; }
.progress span { flex: 1; height: 4px; border-radius: 4px; background: var(--line); transition: background .3s; }
.progress span.on { background: var(--accent); }

.q-step { animation: slideIn .35s ease both; }
.q-count { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); margin-bottom: 8px; }
.q-prompt { font-family: var(--serif); font-size: 22px; line-height: 1.25; margin-bottom: 18px; }
.q-hint { font-size: 13px; color: var(--ink-3); margin-top: -8px; margin-bottom: 16px; }
.q-actions { display: flex; gap: 10px; margin-top: 8px; }
.q-actions .btn { flex: 1; }

@keyframes slideIn { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }
@keyframes shake { 10%, 90% { transform: translateX(-1px); } 20%, 80% { transform: translateX(3px); } 30%, 50%, 70% { transform: translateX(-6px); } 40%, 60% { transform: translateX(6px); } }
.shake { animation: shake .45s ease; }
.success-pop { display: grid; place-items: center; gap: 12px; text-align: center; padding: 16px 0; animation: slideIn .35s ease both; }
.success-pop .tick { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }

.footer-link { text-align: center; margin-top: 20px; font-size: 13px; color: var(--ink-3); }
.footer-link a { color: var(--ink-3); }

/* ============ Map page ============ */
.map-page { height: 100vh; height: 100dvh; overflow: hidden; }
#map { position: absolute; inset: 0; background: var(--bg-2); }
.topbar {
  position: absolute; z-index: 5; left: 12px; right: 12px; top: calc(12px + var(--safe-t));
  display: flex; align-items: center; gap: 8px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.title-pill {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 6px 16px 6px 6px; height: 48px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  box-shadow: var(--shadow);
}
.title-pill h1 { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title-pill .count { margin-left: auto; font-size: 12px; color: var(--ink-3); white-space: nowrap; }
.title-pill .brand-mark { flex: none; }

.map-empty, .map-error {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--ink-2);
}
.map-error .card { max-width: 420px; }

/* Photo markers */
.pin {
  position: relative; width: 52px; height: 52px; border-radius: 50%;
  border: 3px solid #fff; background: var(--accent) center/cover no-repeat;
  box-shadow: 0 4px 14px rgba(0,0,0,.3);
  cursor: pointer; transform-origin: 50% 100%;
  transition: transform .15s ease;
}
.pin::after {
  content: ""; position: absolute; left: 50%; bottom: -9px; transform: translateX(-50%);
  border: 7px solid transparent; border-top-color: #fff; border-bottom: 0;
}
.pin.no-photo { display: grid; place-items: center; color: #fff; }
.pin.no-photo svg { width: 22px; height: 22px; }
.pin.active { transform: scale(1.18); z-index: 2; }
.pin:hover { transform: scale(1.08); }

/* Bottom sheet / side panel */
.sheet {
  position: absolute; z-index: 10;
  left: 0; right: 0; bottom: 0;
  max-height: 82dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  box-shadow: var(--shadow-lg);
  padding-bottom: calc(20px + var(--safe-b));
  transform: translateY(105%);
  transition: transform .35s cubic-bezier(.2,.8,.2,1);
}
.sheet.open { transform: none; }
.sheet-grip { position: sticky; top: 0; z-index: 2; display: grid; place-items: center; height: 22px; }
.sheet-grip::before { content: ""; width: 40px; height: 5px; border-radius: 5px; background: var(--line); }
.sheet-close { position: absolute; top: 14px; right: 14px; z-index: 3; }
.sheet-photo { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--bg-2); margin-top: -22px; cursor: zoom-in; }
.sheet-body { padding: 20px 22px 4px; }
.sheet-date { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); margin-bottom: 6px; }
.sheet-title { font-size: 26px; margin-bottom: 12px; }
.sheet-desc { color: var(--ink-2); white-space: pre-wrap; overflow-wrap: anywhere; }
.sheet-nav { display: flex; gap: 10px; padding: 20px 22px 0; }
.sheet-nav .btn { flex: 1; }

@media (min-width: 820px) {
  .sheet {
    left: auto; top: calc(76px + var(--safe-t)); right: 12px; bottom: 12px;
    width: 400px; max-height: none;
    border-radius: 24px;
    transform: translateX(calc(100% + 24px));
  }
  .sheet-grip { display: none; }
  .sheet-photo { margin-top: 0; border-radius: 24px 24px 0 0; }
}

/* Timeline drawer */
.drawer {
  position: absolute; z-index: 12; inset: 0;
  background: rgba(20, 16, 14, .35);
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
.drawer.open { opacity: 1; pointer-events: auto; }
.drawer-panel {
  position: absolute; top: 0; bottom: 0; left: 0;
  width: min(380px, 88vw);
  background: var(--surface); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column;
  transform: translateX(-100%); transition: transform .3s cubic-bezier(.2,.8,.2,1);
  padding-top: var(--safe-t);
}
.drawer.open .drawer-panel { transform: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 18px 12px; }
.drawer-head h2 { font-size: 22px; }
.drawer-list { list-style: none; margin: 0; padding: 0 10px calc(16px + var(--safe-b)); overflow-y: auto; flex: 1; }
.drawer-list li button {
  width: 100%; display: flex; gap: 12px; align-items: center; text-align: left;
  padding: 10px; border: 0; border-radius: 14px; background: transparent; cursor: pointer;
}
.drawer-list li button:hover { background: var(--bg-2); }
.thumb { flex: none; width: 56px; height: 56px; border-radius: 12px; object-fit: cover; background: var(--accent-soft); display: grid; place-items: center; color: var(--accent); }
.thumb svg { width: 22px; height: 22px; }
.drawer-list .meta { min-width: 0; }
.drawer-list .meta strong { display: block; font-family: var(--serif); font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer-list .meta span { font-size: 13px; color: var(--ink-3); }
.drawer-year { font-size: 12px; font-weight: 700; letter-spacing: .08em; color: var(--ink-3); padding: 14px 10px 4px; }

/* Lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.92);
  display: grid; place-items: center; padding: 16px;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.lightbox.open { opacity: 1; pointer-events: auto; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 6px; }
.lightbox .icon-btn { position: absolute; top: calc(14px + var(--safe-t)); right: 14px; }

/* ============ Toasts ============ */
.toasts { position: fixed; z-index: 100; left: 50%; bottom: calc(20px + var(--safe-b)); transform: translateX(-50%); display: grid; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast {
  padding: 12px 16px; border-radius: 14px; background: var(--ink); color: var(--bg);
  box-shadow: var(--shadow-lg); font-size: 14px; font-weight: 500;
  animation: toastIn .25s ease both;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ============ Admin ============ */
.admin-shell { min-height: 100vh; min-height: 100dvh; }
.admin-header {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
  padding-top: var(--safe-t);
}
.admin-header-row { max-width: 1100px; margin: 0 auto; display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.admin-header-row .brand { margin: 0; color: var(--ink); font-size: 17px; }
.admin-header-row .spacer { flex: 1; }
.session-chip { font-size: 12px; color: var(--ink-3); white-space: nowrap; }
@media (max-width: 520px) { .session-chip { display: none; } }
.tabs { max-width: 1100px; margin: 0 auto; display: flex; gap: 4px; padding: 0 12px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; padding: 10px 14px 12px; border: 0; background: none; cursor: pointer;
  font-weight: 600; font-size: 14px; color: var(--ink-3);
  border-bottom: 2px solid transparent;
}
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }

.admin-main { max-width: 1100px; margin: 0 auto; padding: 24px 16px calc(48px + var(--safe-b)); }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.section-head h2 { font-size: 26px; }
.section-head p { color: var(--ink-2); font-size: 14px; margin-top: 4px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.panel + .panel { margin-top: 16px; }
.panel h3 { font-size: 18px; margin-bottom: 14px; }

.grid-places { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.place-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.place-card .ph { aspect-ratio: 16 / 10; background: var(--bg-2) center/cover; display: grid; place-items: center; color: var(--ink-3); }
.place-card .ph svg { width: 28px; height: 28px; }
.place-card .body { padding: 14px 16px; flex: 1; }
.place-card .body strong { display: block; font-family: var(--serif); font-size: 17px; font-weight: 600; margin-bottom: 2px; }
.place-card .body span { font-size: 13px; color: var(--ink-3); }
.place-card .actions { display: flex; gap: 8px; padding: 0 16px 14px; }
.place-card .actions .btn { flex: 1; }

.empty { text-align: center; color: var(--ink-3); padding: 40px 16px; border: 2px dashed var(--line); border-radius: var(--radius); }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.list-item { display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .grow strong { display: block; overflow-wrap: anywhere; }
.list-item .grow small { color: var(--ink-3); display: block; overflow-wrap: anywhere; }
.list-item .row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.order-btns { display: grid; gap: 2px; }
.order-btns button { width: 30px; height: 26px; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; cursor: pointer; color: var(--ink-2); display: grid; place-items: center; }
.order-btns button:disabled { opacity: .3; cursor: default; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 40; display: grid; align-items: end; justify-items: center; background: rgba(20,16,14,.45); padding: 0; }
@media (min-width: 720px) { .modal { align-items: center; padding: 24px; } }
.modal-card {
  width: 100%; max-width: 640px; max-height: 94dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: 24px 24px 0 0; box-shadow: var(--shadow-lg);
  padding: 22px 20px calc(20px + var(--safe-b));
  animation: modalIn .3s cubic-bezier(.2,.8,.2,1) both;
}
@media (min-width: 720px) { .modal-card { border-radius: 24px; padding: 28px; } }
@keyframes modalIn { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-head h2 { font-size: 22px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
@media (max-width: 480px) { .modal-actions .btn { flex: 1; } }

.picker-map { height: 260px; border-radius: var(--radius-sm); border: 1px solid var(--line); overflow: hidden; background: var(--bg-2); }
.picker-tools { display: flex; gap: 8px; margin-bottom: 8px; }
.picker-tools .input { flex: 1; min-height: 42px; padding: 8px 12px; }
.coords { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.coords .field { margin: 0; }
.coords .input { min-height: 40px; padding: 8px 10px; font-size: 14px; }

.photo-drop {
  display: grid; place-items: center; gap: 6px; text-align: center;
  min-height: 140px; padding: 16px;
  border: 2px dashed var(--line); border-radius: var(--radius-sm);
  background: var(--bg) center/cover no-repeat; cursor: pointer; color: var(--ink-3); font-size: 14px;
  position: relative;
}
.photo-drop.has-photo { min-height: 200px; border-style: solid; color: transparent; }
.photo-drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.photo-row { display: flex; gap: 8px; margin-top: 8px; }

.two-col { display: grid; gap: 16px; }
@media (min-width: 720px) { .two-col { grid-template-columns: 1fr 1fr; } }
.kbd-note { font-size: 13px; color: var(--ink-3); }
.status-ok { color: var(--ok); font-weight: 600; }
.status-bad { color: var(--danger); font-weight: 600; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn > span[data-icon] { display: inline-flex; }
