/* Mapfinder – shared styles for Sheetfinder (charlesclosesociety.org)
   and the Soviet Map Identifier (redatlasbook.com).

   Each site loads this file and then its own small theme file, which overrides the
   brand tokens below (--brand*, --header-*, --cta-*) for light and dark mode. */

:root {
  --cta-bg: #ffd166;
  --cta-hover: #ffdd8a;
  --cta-text: #1d2124;
  --ok: #1e6b3a;
  --ok-tint: #e3f2e8;
  --highlight: #d9480f;
  --brand: #34775a;
  --brand-strong: #285d46;
  --brand-tint: #e7f0eb;
  --accent: #a7bd43;
  --bg: #f4f2ed;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --text: #2a2e31;
  --heading: #1d2124;
  --muted: #5a6066;
  --border: #dbdbd3;
  --border-strong: #b9b9ae;
  --danger: #a3302a;
  --danger-tint: #fbeceb;
  --focus: #1a5fb4;
  --header-bg: #2f6b51;
  --header-text: #ffffff;
  --grid-line: rgba(255, 255, 255, 0.07);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.06);
  --radius: 10px;
  --radius-sm: 6px;
  --font-text: "Open Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-heading: "Roboto", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand: #7cc4a0;
    --brand-strong: #a3d9bd;
    --brand-tint: #1d3229;
    --bg: #14181b;
    --surface: #1c2125;
    --surface-2: #20262a;
    --text: #e3e5e6;
    --heading: #f3f4f4;
    --muted: #a9b0b5;
    --border: #2f373c;
    --border-strong: #46525a;
    --danger: #f19a92;
    --danger-tint: #3a1f1d;
    --focus: #8ab4ff;
    --header-bg: #1d3a2d;
    --ok: #8fd6a8;
    --ok-tint: #1c3325;
    --grid-line: rgba(255, 255, 255, 0.05);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

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

[hidden] { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--font-text);
}

h1, h2, h3, h4 { font-family: var(--font-heading); color: var(--heading); line-height: 1.25; margin: 0; }

a { color: var(--brand-strong); text-underline-offset: 0.15em; }
a:hover { color: var(--brand); }

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

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.mono { font-family: var(--font-mono); font-size: 0.94em; }
kbd {
  font-family: var(--font-mono); font-size: 0.85em; padding: 0.05em 0.4em;
  border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; background: var(--surface);
}

.icon { width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em; }
.icon-lg { width: 2.25rem; height: 2.25rem; }

/* ---------- Skip links ---------- */
.skip-link {
  position: absolute; left: 1rem; top: -4rem; z-index: 100;
  background: var(--surface); color: var(--heading); padding: 0.6rem 1rem;
  border-radius: var(--radius-sm); box-shadow: var(--shadow); font-weight: 600;
}
.skip-link:focus { top: 1rem; }

/* ---------- Header ---------- */
.site-header {
  display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 2rem;
  padding: 1rem clamp(1rem, 3vw, 2rem);
  background-color: var(--header-bg);
  /* a faint kilometre grid, in the spirit of the National Grid */
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: 32px 32px;
  color: var(--header-text);
}

.brand { display: flex; align-items: center; gap: 1rem; flex: 1 1 22rem; min-width: 0; }
.brand-logo {
  flex: none; display: block; background: #fff; border-radius: var(--radius-sm); padding: 4px 6px; line-height: 0;
}
.brand-logo img { width: 148px; height: auto; display: block; }
.brand-logo:focus-visible { outline-color: #fff; }
.brand-wordmark {
  flex: none; display: grid; place-items: center; width: 3.25rem; height: 3.25rem; border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.12); border: 1px solid rgba(255, 255, 255, 0.35); color: #fff; text-decoration: none;
}
.brand-wordmark .icon { width: 1.9rem; height: 1.9rem; }
.brand-wordmark:hover { background: rgba(255, 255, 255, 0.2); color: #fff; }
.brand-kicker { margin: 0 0 0.1rem !important; font-size: 0.72rem !important; letter-spacing: 0.14em; text-transform: uppercase; font-weight: 600; }
.brand-kicker a { color: inherit; text-decoration: none; }
.brand-kicker a:hover { text-decoration: underline; color: #fff; }
.brand-text h1 { color: #fff; font-size: clamp(1.4rem, 2.4vw, 1.75rem); font-weight: 700; letter-spacing: 0.01em; }
.brand-text p { margin: 0.15rem 0 0; font-size: 0.92rem; color: rgba(255, 255, 255, 0.86); }

/* ---------- Search ---------- */
.search { flex: 1 1 34rem; min-width: 0; }
.search label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.3rem; color: rgba(255, 255, 255, 0.92); }
.search-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.search-field { position: relative; flex: 1 1 16rem; min-width: 0; }
.search-field .icon { position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-field input {
  width: 100%; height: 2.75rem; padding: 0 0.85rem 0 2.4rem;
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid transparent; border-radius: var(--radius-sm);
}
.search-field input::placeholder { color: var(--muted); opacity: 1; }
.search-field input:focus-visible { outline: 3px solid var(--cta-bg); outline-offset: 1px; }
.search-message { margin: 0.35rem 0 0; min-height: 1.4em; font-size: 0.9rem; color: #fff; }
.search-message.is-error::before { content: "⚠ "; }
.site-header .btn:focus-visible { outline-color: var(--cta-bg); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  min-height: 2.75rem; padding: 0 1.1rem;
  font: 600 0.95rem/1 var(--font-text); white-space: nowrap;
  border-radius: var(--radius-sm); border: 1px solid transparent; cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--cta-bg); color: var(--cta-text); }
.btn-primary:hover { background: var(--cta-hover); }
.btn-ghost { background: transparent; color: #fff; border-color: rgba(255, 255, 255, 0.55); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.12); }
.btn-secondary { background: var(--surface); color: var(--brand-strong); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { border-color: var(--brand); background: var(--brand-tint); }
.btn-small { min-height: 2rem; padding: 0 0.65rem; font-size: 0.85rem; }
.btn-icon {
  display: inline-grid; place-items: center; width: 2rem; height: 2rem; padding: 0;
  background: transparent; color: var(--muted); border: 1px solid transparent; border-radius: var(--radius-sm); cursor: pointer;
}
.btn-icon:hover { color: var(--brand-strong); background: var(--brand-tint); }
.btn-icon.is-done, .btn.is-done { color: var(--brand); }

/* ---------- Workspace ---------- */
.workspace { display: grid; grid-template-columns: 1fr; }

.map-pane { display: flex; flex-direction: column; background: var(--surface); border-bottom: 1px solid var(--border); }
.map-frame { position: relative; height: 58vh; height: 58svh; min-height: 300px; max-height: 720px; background: #dfe3dc; }
.map { position: absolute; inset: 0; }
.crosshair {
  position: absolute; left: 50%; top: 50%; width: 28px; height: 28px; margin: -14px 0 0 -14px;
  pointer-events: none; opacity: 0; transition: opacity 0.2s;
  background:
    linear-gradient(#1d2124, #1d2124) center / 2px 100% no-repeat,
    linear-gradient(#1d2124, #1d2124) center / 100% 2px no-repeat;
  filter: drop-shadow(0 0 1.5px #fff) drop-shadow(0 0 1.5px #fff);
}
.map-frame:focus-within .crosshair, .map-pane.show-crosshair .crosshair { opacity: 0.85; }
.map-fallback {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 2rem; gap: 0.25rem; background: var(--surface-2); color: var(--muted);
}
.map-fallback p { margin: 0; max-width: 28rem; }
.map-fallback strong { color: var(--heading); }

.map-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; padding: 0.75rem clamp(1rem, 3vw, 1.25rem); }
.map-tools .hint { margin: 0; font-size: 0.88rem; color: var(--muted); flex: 1 1 14rem; }
.jump-link { font-weight: 600; font-size: 0.92rem; }

.results-pane { padding: 1.25rem clamp(1rem, 3vw, 1.5rem) 2rem; outline: none; }

/* ---------- Location card ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.location-card { padding: 1rem 1.1rem; margin-bottom: 1.25rem; }
.eyebrow { margin: 0 0 0.15rem; font-size: 0.75rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--brand-strong); }
.location-card h3 { font-size: 1.2rem; outline: none; overflow-wrap: anywhere; }
.coords { display: grid; gap: 0.5rem; margin: 0.8rem 0 0.9rem; }
.coords > div { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 0.5rem; }
.coords dt { grid-column: 1 / -1; font-size: 0.8rem; color: var(--muted); }
.coords dd { margin: 0; font-family: var(--font-mono); font-size: 1rem; color: var(--heading); overflow-wrap: anywhere; }
.coords .copy-cell { grid-column: 2; grid-row: 2; }
.location-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* ---------- Summary ---------- */
.summary { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin: 0 0 0.75rem; }
.summary p { margin: 0; color: var(--muted); font-size: 0.95rem; }
.summary strong { color: var(--heading); font-size: 1.05rem; }
.summary .toggle-all { background: none; border: 0; padding: 0.25rem; font: 600 0.88rem var(--font-text); color: var(--brand-strong); cursor: pointer; text-decoration: underline; text-underline-offset: 0.15em; white-space: nowrap; }

/* ---------- Result groups ---------- */
.group { margin-bottom: 1rem; overflow: hidden; }
.group-head {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.15rem 0.6rem;
  padding: 0.8rem 1.1rem 0.7rem; border-bottom: 1px solid var(--border);
  background: linear-gradient(90deg, var(--brand-tint), transparent 85%);
}
.group-head h3 { font-size: 1.05rem; }
.group-head .scale { font-size: 0.8rem; color: var(--muted); }
.group-head .count { margin-left: auto; }

.count {
  display: inline-block; min-width: 1.6rem; padding: 0.05rem 0.5rem; border-radius: 999px;
  font: 600 0.78rem/1.5 var(--font-text); text-align: center;
  background: var(--brand-tint); color: var(--brand-strong);
}

.series { border-top: 1px solid var(--border); }
.series:first-of-type { border-top: 0; }
.series > summary {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.6rem 1.1rem;
  cursor: pointer; list-style: none; font-weight: 600; font-size: 0.95rem; color: var(--heading);
}
.series > summary::-webkit-details-marker { display: none; }
.series > summary::before {
  content: ""; flex: none; width: 0.5rem; height: 0.5rem; margin-right: 0.1rem;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg); transition: transform 0.15s;
}
.series[open] > summary::before { transform: rotate(45deg); }
.series > summary:hover { background: var(--surface-2); }
.series > summary .series-name { flex: 1; min-width: 0; }

.sheet-list { list-style: none; margin: 0; padding: 0 1.1rem 0.6rem 2.2rem; }
.sheet-list li { padding: 0.25rem 0; }
.sheet-link, .sheet-plain { display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 0.1rem 0.5rem; }
.sheet-no { font-weight: 600; white-space: nowrap; }
.sheet-name { font-style: italic; }
.sheet-link .icon { width: 0.85em; height: 0.85em; vertical-align: -0.05em; opacity: 0.75; }
.sheet-plain .sheet-no { color: var(--heading); }
.unavailable { font-size: 0.8rem; color: var(--muted); }

/* NLS cards (with thumbnails) */
.nls-list { list-style: none; margin: 0; padding: 0.35rem 0.6rem 0.6rem; display: grid; gap: 0.15rem; }
.nls-item { display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 0.75rem; align-items: center; padding: 0.4rem 0.5rem; border-radius: var(--radius-sm); }
.nls-item:hover { background: var(--surface-2); }
.thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 4px; background: var(--surface-2); border: 1px solid var(--border); display: block; }
.thumb--empty { display: grid; place-items: center; color: var(--border-strong); }
.nls-body { min-width: 0; }
.nls-body .title { font-weight: 600; overflow-wrap: anywhere; }
.nls-body .title .icon { width: 0.85em; height: 0.85em; vertical-align: -0.05em; opacity: 0.75; margin-left: 0.25rem; }
.nls-body .meta { margin: 0.05rem 0 0; font-size: 0.85rem; color: var(--muted); }
.badge {
  display: inline-block; margin-left: 0.35rem; padding: 0 0.45rem; border-radius: 999px;
  font-size: 0.72rem; font-weight: 600; line-height: 1.6; vertical-align: 0.1em;
  border: 1px solid var(--border-strong); color: var(--muted); background: var(--surface-2);
}

/* "rows" style: one row per scale (label | sheet | status) */
.row-list { list-style: none; margin: 0; padding: 0; }
.row-item {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0.1rem 0.75rem; align-items: center;
  padding: 0.7rem 1.1rem; border-top: 1px solid var(--border);
}
.row-item:first-child { border-top: 0; }
.row-item.has-bounds:hover, .row-item.has-bounds:focus-within { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--highlight); }
.row-label { grid-column: 1 / -1; font-size: 0.78rem; font-weight: 600; letter-spacing: 0.02em; color: var(--muted); font-variant-numeric: tabular-nums; }
.row-body { min-width: 0; }
.row-body .title { font-family: var(--font-mono); font-size: 1.02rem; font-weight: 600; color: var(--heading); overflow-wrap: anywhere; }
.row-body a.title { color: var(--brand-strong); }
.row-body .title .icon { width: 0.8em; height: 0.8em; margin-left: 0.3rem; vertical-align: -0.02em; opacity: 0.75; }
.row-body .meta { margin: 0.1rem 0 0; font-size: 0.82rem; color: var(--muted); }
.row-actions { justify-self: end; display: inline-flex; align-items: center; gap: 0.35rem; }
.no-map .row-actions .btn-icon { display: none; }
.status { white-space: nowrap; padding: 0.1rem 0.55rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600; line-height: 1.6;
  color: var(--muted); background: var(--surface-2); border: 1px solid var(--border);
}
.status--ok { color: var(--ok); background: var(--ok-tint); border-color: transparent; }

.group-note { margin: 0; padding: 0.8rem 1.1rem; color: var(--muted); font-size: 0.92rem; }
.group-error { margin: 0; padding: 0.8rem 1.1rem; display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; background: var(--danger-tint); color: var(--danger); font-size: 0.92rem; }

/* loading skeleton */
.skeleton { padding: 0.6rem 1.1rem 0.9rem; display: grid; gap: 0.6rem; }
.skeleton span { display: block; height: 0.9rem; border-radius: 4px; background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.3s linear infinite; }
.skeleton span:nth-child(2) { width: 80%; }
.skeleton span:nth-child(3) { width: 60%; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- Empty / welcome state ---------- */
.welcome { padding: 1.25rem 1.25rem 1.1rem; margin-bottom: 1.25rem; }
.welcome h3 { font-size: 1.15rem; margin-bottom: 0.35rem; }
.welcome p { margin: 0 0 0.75rem; color: var(--muted); }
.welcome ol { margin: 0; padding: 0; list-style: none; display: grid; gap: 0.6rem; }
.welcome li { display: grid; grid-template-columns: 2rem 1fr; gap: 0.6rem; align-items: start; }
.welcome li .icon { width: 1.4rem; height: 1.4rem; color: var(--brand); margin-top: 0.1rem; }
.welcome .examples { margin-top: 0.9rem; font-size: 0.9rem; color: var(--muted); }
.welcome .examples button {
  font: inherit; font-family: var(--font-mono); font-size: 0.85rem; color: var(--brand-strong);
  background: var(--brand-tint); border: 0; border-radius: 4px; padding: 0.1rem 0.45rem; margin: 0.15rem 0.1rem; cursor: pointer;
}
.welcome .examples button:hover { text-decoration: underline; }

.notice { padding: 1rem 1.1rem; margin-bottom: 1rem; }
.notice p { margin: 0; }

/* ---------- About ---------- */
.about { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--border); font-size: 0.9rem; color: var(--muted); }
.about details { margin-bottom: 0.5rem; }
.about summary { cursor: pointer; font-weight: 600; color: var(--heading); padding: 0.25rem 0; }
.about ul { padding-left: 1.2rem; margin: 0.4rem 0 0.8rem; }
.about li { margin-bottom: 0.3rem; }
.about p { margin: 0.4rem 0; }
.about-foot { margin-top: 0.8rem !important; }

.noscript { margin: 1rem; padding: 1rem; background: var(--danger-tint); color: var(--danger); border-radius: var(--radius); }

@media (max-width: 520px) {
  .brand { align-items: flex-start; }
  .brand-logo img { width: 92px; }
  .brand-text p { font-size: 0.85rem; }
  .search-row .btn { flex: 1 1 auto; }
}

/* ---------- Desktop: app layout, map and results side by side ---------- */
@media (min-width: 960px) {
  .workspace { grid-template-columns: minmax(0, 1fr) clamp(380px, 34vw, 480px); }
  .map-pane { border-bottom: 0; border-right: 1px solid var(--border); }
  .jump-link { display: none; }
}
@media (min-width: 960px) and (min-height: 620px) {
  body { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
  .workspace { flex: 1; min-height: 0; }
  .map-pane { min-height: 0; }
  .map-frame { flex: 1; height: auto; max-height: none; }
  .results-pane { overflow-y: auto; overscroll-behavior: contain; }
}

/* ---------- Preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (forced-colors: active) {
  .count, .badge { border: 1px solid CanvasText; }
  .crosshair { background: none; border: 2px solid CanvasText; border-radius: 50%; }
}

/* ---------- Print: just the location and results ---------- */
@media print {
  body { background: #fff; color: #000; height: auto; overflow: visible; display: block; }
  .site-header .search, .map-pane, .skip-link, .about, .location-actions, .btn-icon, .toggle-all, .thumb { display: none !important; }
  .site-header { background: none; color: #000; padding: 0 0 1rem; }
  .brand-text h1, .brand-text p { color: #000; }
  .workspace { display: block; }
  .results-pane { overflow: visible; padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
  .series:not([open]) > *:not(summary) { display: block; }
  a { color: #000; }
}
