/* ─── Reset ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
img, video { max-width: 100%; display: block; }
button, input, textarea, select { font: inherit; }

/* ─── Tokens ─────────────────────────────────────────────────────────────── */
:root {
  /* Palette – light */
  --bg:          #f8f6f1;
  --bg-raised:   #eeece7;
  --surface:     #ffffff;
  --border:      #d6d3cd;
  --border-focus:#9a3412;
  --text:        #1c1917;
  --text-muted:  #78716c;
  --text-inverse:#ffffff;
  --accent:      #9a3412;
  --accent-hover:#7c2d12;
  --accent-light:#fef3e2;
  --error:       #b91c1c;
  --error-bg:    #fef2f2;
  --success:     #15803d;
  --warn-bg:     #fffbeb;
  --warn-border: #d97706;

  /* Typography */
  --font-serif: Georgia, 'Times New Roman', serif;
  --font-sans:  system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono:  'Courier New', Courier, monospace;

  /* Scale */
  --text-xs:   0.75rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.25rem;
  --text-2xl:  1.5rem;
  --text-3xl:  1.875rem;

  /* Spacing */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.25rem;
  --sp-6: 1.5rem;
  --sp-8: 2rem;
  --sp-10: 2.5rem;
  --sp-12: 3rem;

  /* Radius */
  --r-sm: 3px;
  --r:    5px;
  --r-lg: 10px;
  --r-xl: 16px;

  /* Shadow */
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --shadow:    0 2px 8px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.12);

  /* Layout */
  --max-w:      680px;
  --max-w-wide: 1100px;
  --header-h:   56px;
}

/* ─── Dark mode tokens ───────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #1c1917;
    --bg-raised:   #292524;
    --surface:     #292524;
    --border:      #44403c;
    --border-focus:#fb923c;
    --text:        #f5f5f4;
    --text-muted:  #a8a29e;
    --text-inverse:#1c1917;
    --accent:      #fb923c;
    --accent-hover:#f97316;
    --accent-light:#431407;
    --error:       #f87171;
    --error-bg:    #450a0a;
    --success:     #4ade80;
    --warn-bg:     #1c1400;
    --warn-border: #f59e0b;
  }
}

[data-theme="dark"] {
  --bg:          #1c1917;
  --bg-raised:   #292524;
  --surface:     #292524;
  --border:      #44403c;
  --border-focus:#fb923c;
  --text:        #f5f5f4;
  --text-muted:  #a8a29e;
  --text-inverse:#1c1917;
  --accent:      #fb923c;
  --accent-hover:#f97316;
  --accent-light:#431407;
  --error:       #f87171;
  --error-bg:    #450a0a;
  --success:     #4ade80;
  --warn-bg:     #1c1400;
  --warn-border: #f59e0b;
}

/* ─── Base ───────────────────────────────────────────────────────────────── */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  color-scheme: light dark;
}

body {
  font-family: var(--font-serif);
  background: var(--bg);
  color: var(--text);
  margin: 0;
  line-height: 1.7;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.2s, color 0.2s;
}

/* ─── Layout ─────────────────────────────────────────────────────────────── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 var(--sp-6);
  gap: var(--sp-4);
  box-shadow: var(--shadow-sm);
}

.site-logo {
  font-family: var(--font-sans);
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
  margin-right: auto;
}
.site-logo:hover { color: var(--accent); }

.site-nav {
  display: flex;
  align-items: center;
  gap: var(--sp-5);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
}

.site-nav a {
  color: var(--text-muted);
  text-decoration: none;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: 0 var(--sp-2);
  border-radius: var(--r-sm);
  transition: color 0.15s;
}
.site-nav a:hover { color: var(--text); }
.site-nav a:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }

.site-footer {
  margin-top: auto;
  padding: var(--sp-8) var(--sp-6);
  border-top: 1px solid var(--border);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-4);
  align-items: center;
}
.site-footer a { color: var(--text-muted); text-decoration: underline; }
.site-footer a:hover { color: var(--text); }

.site-main {
  flex: 1;
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: var(--sp-8) var(--sp-6);
}

.site-main.wide {
  max-width: var(--max-w-wide);
}

/* ─── Typography ─────────────────────────────────────────────────────────── */
h1 { font-size: var(--text-2xl); font-weight: normal; margin: 0 0 var(--sp-3); line-height: 1.3; }
h2 { font-size: var(--text-xl);  font-weight: normal; margin: 0 0 var(--sp-2); line-height: 1.4; }
h3 { font-size: var(--text-lg);  font-weight: 600;    margin: 0 0 var(--sp-2); font-family: var(--font-sans); }
p  { margin: 0 0 var(--sp-4); }
a  { color: var(--accent); }
a:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; border-radius: var(--r-sm); }

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--bg-raised);
  padding: 0.1em 0.35em;
  border-radius: var(--r-sm);
}

/* Legal page */
.legal h2 { margin-top: var(--sp-8); font-size: var(--text-xl); }
.legal ul { padding-left: var(--sp-6); }
.legal li { margin-bottom: var(--sp-2); }

/* ─── Forms ──────────────────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  margin-bottom: var(--sp-5);
}

.form-label {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text);
}

.form-hint {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-size: var(--text-base);
  line-height: 1.5;
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
}

.form-textarea { resize: vertical; min-height: 80px; }

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.form-input::placeholder,
.form-textarea::placeholder { color: var(--text-muted); opacity: 0.7; }

.form-input:disabled,
.form-textarea:disabled { opacity: 0.5; cursor: not-allowed; background: var(--bg-raised); }

.form-input[type="file"] {
  padding: var(--sp-2);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
}

.form-char-count {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-align: right;
}
.form-char-count.warn { color: var(--warn-border); font-weight: 600; }

.field-error {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--error);
  margin: var(--sp-1) 0 0;
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 44px;
  padding: var(--sp-2) var(--sp-5);
  border: 1px solid transparent;
  border-radius: var(--r);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: var(--text-inverse);
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-raised); border-color: var(--text-muted); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
  padding-left: var(--sp-2);
  padding-right: var(--sp-2);
}
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--bg-raised); }

.btn-danger {
  background: var(--error);
  color: #fff;
  border-color: var(--error);
}
.btn-danger:hover:not(:disabled) { filter: brightness(0.9); }

.btn-sm { min-height: 36px; padding: var(--sp-1) var(--sp-3); font-size: var(--text-xs); }
.btn-lg { min-height: 52px; padding: var(--sp-3) var(--sp-6); font-size: var(--text-base); }

/* ─── Card ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-6);
  box-shadow: var(--shadow-sm);
}

/* ─── Theme toggle ───────────────────────────────────────────────────────── */
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--r);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
.theme-toggle:hover { background: var(--bg-raised); color: var(--text); }
.theme-toggle:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }

/* ─── Place entry ────────────────────────────────────────────────────────── */
.place-photo {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--r-lg);
  margin-bottom: var(--sp-5);
  box-shadow: var(--shadow);
}
.place-name        { margin: 0 0 var(--sp-2); font-size: var(--text-2xl); }
.place-sentence    { font-style: italic; margin: 0 0 var(--sp-2); font-size: var(--text-lg); }
.place-contributor { font-size: var(--text-sm); color: var(--text-muted); margin: 0 0 var(--sp-6); font-family: var(--font-sans); }

/* ─── Chain navigation ───────────────────────────────────────────────────── */
.chain-nav {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-4);
  margin: var(--sp-8) 0;
  padding: var(--sp-5) 0;
  border-top: 1px solid var(--border);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
}
.chain-nav a {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  color: var(--accent);
  text-decoration: none;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r);
  border: 1px solid var(--border);
  gap: var(--sp-2);
  transition: background 0.15s;
}
.chain-nav a:hover  { background: var(--bg-raised); }
.chain-nav a:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }

/* ─── Gallery ────────────────────────────────────────────────────────────── */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--sp-3);
  margin: var(--sp-6) 0;
}
@media (min-width: 480px) {
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}

.gallery-thumb {
  display: block;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: var(--r);
  min-height: 44px;
  min-width: 44px;
  cursor: pointer;
  background: var(--bg-raised);
  transition: transform 0.15s, box-shadow 0.15s;
}
.gallery-thumb:hover { transform: scale(1.02); box-shadow: var(--shadow); }
.gallery-thumb img  { width: 100%; height: 100%; object-fit: cover; }
.gallery-thumb:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 3px; }

/* ─── Map ────────────────────────────────────────────────────────────────── */
.map-island { margin: var(--sp-5) 0; }

.map-search {
  display: flex;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
  position: relative;
}
.map-search-input {
  flex: 1;
}
.map-search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 1000;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  max-height: 220px;
  overflow-y: auto;
}
.map-search-result {
  padding: var(--sp-3) var(--sp-4);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.map-search-result:last-child { border-bottom: none; }
.map-search-result:hover,
.map-search-result:focus { background: var(--bg-raised); outline: none; }
.map-search-result-name { font-weight: 500; }
.map-search-result-detail { color: var(--text-muted); font-size: var(--text-xs); margin-top: 2px; }

.map-container { border-radius: var(--r); overflow: hidden; border: 1px solid var(--border); }

.map-custom-marker {
  width: 20px;
  height: 20px;
  background: var(--accent);
  border: 3px solid var(--surface);
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.map-coords {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-3);
  margin-top: var(--sp-3);
}

.map-fuzz-note {
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--sp-2);
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

/* ─── Submission form ────────────────────────────────────────────────────── */
.submission-form { max-width: 100%; }

.submission-form section {
  animation: fadeSlide 0.2s ease;
}
@keyframes fadeSlide {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.submission-form h2 {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 var(--sp-5);
}

.step-nav {
  display: flex;
  gap: var(--sp-3);
  margin-top: var(--sp-6);
  padding-top: var(--sp-5);
  border-top: 1px solid var(--border);
}

.submission-success {
  padding: var(--sp-8) 0;
  text-align: center;
  font-size: var(--text-lg);
  color: var(--success);
  font-family: var(--font-sans);
}

.nudge {
  background: var(--accent-light);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--r) var(--r) 0;
  padding: var(--sp-4);
  margin-bottom: var(--sp-5);
  font-size: var(--text-sm);
}
.nudge p { margin: 0 0 var(--sp-2); font-family: var(--font-sans); }
.nudge p:last-child { margin: 0; }

.photo-preview {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  background: var(--bg-raised);
  border-radius: var(--r);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  margin-top: var(--sp-3);
}

.photo-thumb-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  border-radius: var(--r);
  overflow: hidden;
  flex-shrink: 0;
  display: block;
}
.photo-thumb-btn:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }

.photo-thumb {
  display: block;
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: var(--r);
}
.photo-thumb--sm { width: 44px; height: 44px; }

.details-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.details-header h2 { margin: 0; }

.photo-lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  cursor: pointer;
}
.photo-lightbox-img {
  max-width: min(90vw, 800px);
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--r);
  cursor: default;
}
.photo-lightbox-close {
  position: absolute;
  top: var(--sp-4);
  right: var(--sp-4);
  background: rgba(0,0,0,0.5);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 2.5rem;
  height: 2.5rem;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.photo-lightbox-close:hover { background: rgba(0,0,0,0.75); }

/* ─── Prompt / CTA ───────────────────────────────────────────────────────── */
.chain-context {
  background: var(--bg-raised);
  border-left: 3px solid var(--border);
  padding: var(--sp-4);
  border-radius: 0 var(--r) var(--r) 0;
  margin-bottom: var(--sp-6);
  font-size: var(--text-sm);
  font-family: var(--font-sans);
  color: var(--text-muted);
}
.chain-context em { font-style: italic; color: var(--text); }

.chain-prompt {
  margin: var(--sp-8) 0 var(--sp-4);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-family: var(--font-sans);
}

.cta-link {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 44px;
  color: var(--accent);
  font-size: var(--text-base);
  font-family: var(--font-sans);
  font-weight: 500;
  text-decoration: none;
  padding: var(--sp-2) var(--sp-4);
  border: 1px solid var(--accent);
  border-radius: var(--r);
  transition: background 0.15s;
}
.cta-link:hover { background: var(--accent-light); }
.cta-link:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }

.index-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  flex-wrap: wrap;
}

.secondary-link {
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--text-muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.secondary-link:hover { color: var(--text); }

/* ─── How to play ────────────────────────────────────────────────────────── */
.how-to-play { max-width: 640px; }
.how-to-play .lede {
  font-size: var(--text-lg);
  color: var(--text-muted);
  margin: 0 0 var(--sp-8);
  line-height: 1.6;
}
.how-to-play h2 { margin: var(--sp-8) 0 var(--sp-3); }
.how-to-play ol,
.how-to-play ul {
  padding-left: var(--sp-6);
  margin: 0 0 var(--sp-4);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.7;
}
.how-to-play li { margin-bottom: var(--sp-2); }
.how-to-play-cta { margin-top: var(--sp-10); }

/* ─── Report link ────────────────────────────────────────────────────────── */
.report-link { font-family: var(--font-sans); font-size: var(--text-sm); color: var(--text-muted); margin-top: var(--sp-8); }
.report-link button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: inherit;
  padding: 0;
  text-decoration: underline;
  min-height: 44px;
}
.report-form { margin-top: var(--sp-4); }

/* ─── Tombstone / status ─────────────────────────────────────────────────── */
.tombstone {
  padding: var(--sp-10);
  text-align: center;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: var(--r-lg);
  margin: var(--sp-5) 0;
  font-family: var(--font-sans);
}

/* ─── Accessibility ──────────────────────────────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  top: -100%;
  left: var(--sp-4);
  padding: var(--sp-2) var(--sp-4);
  background: var(--accent);
  color: var(--text-inverse);
  border-radius: 0 0 var(--r) var(--r);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  z-index: 9999;
  text-decoration: none;
}
.skip-link:focus { top: 0; }

:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* ─── Page utility ───────────────────────────────────────────────────────── */
/* Legacy .page class used by older pages */
.page { max-width: var(--max-w); margin: 0 auto; padding: var(--sp-8) var(--sp-6); }

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  :root { --sp-6: 1rem; --sp-8: 1.5rem; }
  .site-nav { gap: var(--sp-3); }
  .site-nav a { font-size: var(--text-xs); }
  h1 { font-size: var(--text-xl); }
  .map-coords { grid-template-columns: 1fr; }
}
