:root {
  --ink:        #0a151e;
  --ink-2:      #0e1c27;
  --panel:      #13242f;
  --parchment:  #ece0c6;
  --muted:      #8fa1a4;
  --brass:      #c8a25a;
  --brass-lit:  #e6c98a;
  --verdigris:  #5e8b7e;
  --line:       rgba(200,162,90,0.22);
  --line-soft:  rgba(236,224,198,0.10);

  --display: "Cormorant Garamond", Georgia, serif;
  --body:    "Inter", system-ui, sans-serif;
  --mono:    "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--parchment);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#map {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(120% 120% at 50% 45%, var(--ink-2) 0%, var(--ink) 62%, #060d13 100%);
}

/* Leaflet panels: tiles sit seamlessly at rest; the gilt frame (like an
   archival plate) appears only on hover so it never reads as a per-cell edge. */
.leaflet-image-layer {
  border: 0;
  box-shadow: none;
  transition: filter .18s ease, box-shadow .18s ease;
  image-rendering: auto;
  /* While a panel's image is still downloading, don't render its alt text
     (the post title) as a wall of words — show a quiet placeholder plate with
     a little brass dot orbiting the centre (a spinner). The thumbnail paints
     opaque over it once it arrives. We animate background-position rather than
     transform, because Leaflet owns each panel's transform for positioning. */
  color: transparent;
  font-size: 0;
  background-color: var(--ink-2);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='9' viewBox='0 0 9 9'%3E%3Ccircle cx='4.5' cy='4.5' r='3' fill='%23e6c98a'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: 9px 9px;
  animation: panel-spin .8s linear infinite;
}
@keyframes panel-spin {
  0%    { background-position: calc(50% + 9px) 50%; }
  12.5% { background-position: calc(50% + 6.4px) calc(50% + 6.4px); }
  25%   { background-position: 50% calc(50% + 9px); }
  37.5% { background-position: calc(50% - 6.4px) calc(50% + 6.4px); }
  50%   { background-position: calc(50% - 9px) 50%; }
  62.5% { background-position: calc(50% - 6.4px) calc(50% - 6.4px); }
  75%   { background-position: 50% calc(50% - 9px); }
  87.5% { background-position: calc(50% + 6.4px) calc(50% - 6.4px); }
  100%  { background-position: calc(50% + 9px) 50%; }
}
@media (prefers-reduced-motion: reduce) {
  .leaflet-image-layer { animation: none; background-position: center; }
}
/* once the real image has loaded, drop the placeholder + spinner so tier swaps
   on zoom don't flash it back. */
.leaflet-image-layer.is-loaded {
  background-image: none;
  background-color: transparent;
  animation: none;
}
.leaflet-image-layer:hover {
  filter: saturate(1.08) brightness(1.05);
  box-shadow: 0 0 0 1px var(--brass), 0 10px 26px rgba(0,0,0,0.55);
  cursor: zoom-in;
}

/* coordinate tag shown above the hovered cell */
.leaflet-tooltip.cell-tip {
  background: rgba(10,21,30,0.92);
  border: 1px solid var(--line);
  border-radius: 2px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.5);
  color: var(--brass-lit);
  font-family: var(--mono); font-size: 12px; letter-spacing: .1em;
  padding: 3px 8px;
}
.leaflet-tooltip.cell-tip.leaflet-tooltip-top::before { border-top-color: var(--line); }
.leaflet-container { background: transparent; outline: none; }
.leaflet-control-zoom a {
  background: var(--panel); color: var(--parchment);
  border-color: var(--line); font-weight: 500;
}
.leaflet-control-zoom a:hover { background: var(--ink-2); color: var(--brass-lit); }

/* a faint circular suggestion over everything, never intercepts clicks */
.vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 400;
  background: radial-gradient(circle at 50% 47%,
      transparent 0 46%, rgba(6,12,18,0.34) 70%, rgba(4,8,12,0.7) 100%);
  mix-blend-mode: multiply;
}

/* --- header plate --------------------------------------------------------- */
.plate {
  position: fixed; top: 18px; left: 18px; z-index: 500;
  display: flex; gap: 16px; align-items: flex-start;
  max-width: 360px; padding: 16px 20px 14px;
  background: linear-gradient(180deg, rgba(19,36,47,0.92), rgba(10,21,30,0.92));
  border: 1px solid var(--line);
  border-radius: 2px;
  backdrop-filter: blur(6px);
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.compass { width: 58px; height: 58px; flex: none; margin-top: 4px; }
.c-ring { fill: none; stroke: var(--line); stroke-width: 1; }
.c-ring--inner { stroke: var(--line-soft); }
.c-n { fill: var(--brass); }
.c-s { fill: var(--verdigris); }
.c-e { fill: rgba(236,224,198,0.5); }
.c-hub { fill: var(--brass-lit); }

.plate h1 {
  margin: 0; font-family: var(--display); font-weight: 600;
  font-size: 30px; letter-spacing: .5px; line-height: 1; color: var(--parchment);
}
.tagline {
  margin: 6px 0 12px; font-family: var(--display); font-style: italic;
  font-size: 15px; color: var(--muted);
}
.stats { display: flex; gap: 18px; margin: 0; }
.stats dt {
  font-size: 9.5px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 2px;
}
.stats dd {
  margin: 0; font-family: var(--mono); font-size: 18px; color: var(--brass-lit);
}

/* --- loose-leaves drawer -------------------------------------------------- */
.drawer-tab {
  position: fixed; top: 50%; right: 0; z-index: 500;
  transform: translateY(-50%) rotate(180deg); writing-mode: vertical-rl;
  padding: 16px 10px; border: 1px solid var(--line); border-right: none;
  border-radius: 2px 0 0 2px;
  background: rgba(19,36,47,0.92); color: var(--parchment);
  font-family: var(--body); font-size: 12px; letter-spacing: .14em;
  text-transform: uppercase; cursor: pointer;
}
.drawer-tab:hover { color: var(--brass-lit); }
.tab-count {
  font-family: var(--mono); color: var(--brass); margin-top: 6px;
}

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 600;
  width: min(420px, 92vw); padding: 22px 22px 32px;
  background: linear-gradient(180deg, var(--ink-2), var(--ink));
  border-left: 1px solid var(--line);
  box-shadow: -20px 0 60px rgba(0,0,0,0.55);
  transform: translateX(102%); transition: transform .32s cubic-bezier(.2,.7,.2,1);
  overflow-y: auto;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: baseline; justify-content: space-between; }
.drawer-head h2 {
  margin: 0; font-family: var(--display); font-weight: 600; font-size: 24px;
}
.drawer-note { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 8px 0 18px; }
.loose-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.loose-item { cursor: zoom-in; border: 1px solid var(--line); border-radius: 2px; overflow: hidden; background: #000; }
.loose-item img { display: block; width: 100%; height: 130px; object-fit: cover; transition: transform .25s ease, opacity .25s ease; opacity: 0; }
.loose-item img.loaded { opacity: 1; }
.loose-item:hover img { transform: scale(1.05); }
.loose-cap { padding: 6px 8px; font-size: 11px; color: var(--muted); }

code { font-family: var(--mono); color: var(--brass-lit); font-size: .92em; }

/* --- lightbox ------------------------------------------------------------- */
.lightbox {
  position: fixed; inset: 0; z-index: 800;
  display: flex; align-items: center; justify-content: center;
  padding: clamp(16px, 4vw, 56px);
  background: rgba(4,8,12,0.88); backdrop-filter: blur(3px);
  animation: fade .2s ease;
}
.lightbox[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }

.lb-figure {
  margin: 0; display: grid; gap: 24px; align-items: center;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 320px);
  max-width: 1100px; width: 100%; max-height: 100%;
}
.lb-stage {
  display: flex; align-items: center; justify-content: center;
  max-height: 86vh; overflow: hidden; position: relative;
}
.lb-stage img {
  max-width: 100%; max-height: 86vh; object-fit: contain;
  border: 1px solid var(--line);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.5), 0 24px 70px rgba(0,0,0,0.6);
  transform-origin: center center; will-change: transform;
  cursor: zoom-in; user-select: none; -webkit-user-drag: none;
}
.lb-stage.zoomable img { cursor: grab; }
.lb-stage.zoomable:active img { cursor: grabbing; }
.lb-caption { align-self: center; }
.lb-coord {
  font-family: var(--mono); font-size: 13px; letter-spacing: .12em;
  color: var(--brass); margin: 0 0 6px;
}
.coord-edit {
  background: none; border: none; padding: 0; margin: 0 0 10px;
  color: var(--muted); font-family: var(--body); font-size: 11px;
  letter-spacing: .06em; cursor: pointer; border-bottom: 1px dotted var(--line);
}
.coord-edit:hover { color: var(--brass-lit); }
.coord-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 12px; }
.coord-form[hidden] { display: none; }
.coord-form input {
  background: var(--ink); border: 1px solid var(--line); border-radius: 2px;
  color: var(--parchment); font-family: var(--mono); font-size: 13px;
  padding: 6px 9px; width: 130px;
}
.coord-save {
  background: var(--brass); color: var(--ink); border: none; border-radius: 2px;
  font-family: var(--body); font-size: 12px; font-weight: 600; padding: 6px 12px; cursor: pointer;
}
.coord-save:hover { background: var(--brass-lit); }
.coord-msg { font-family: var(--mono); font-size: 11px; color: var(--muted); flex-basis: 100%; }

.lb-caption h2 {
  margin: 0; font-family: var(--display); font-weight: 600; font-size: 26px; line-height: 1.15;
}
.lb-date { color: var(--muted); font-size: 13px; margin: 8px 0 14px; }
.lb-link { color: var(--brass-lit); font-size: 13px; text-decoration: none; border-bottom: 1px solid var(--line); }
.lb-link:hover { color: var(--parchment); border-color: var(--brass); }
.lb-close { position: fixed; top: 18px; right: 22px; }

/* the signature: a stratigraphy of revisions, newest on top */
.strata { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 14px; }
.strata-label { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin: 0 0 10px; }
.strata-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.stratum {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 7px 10px; cursor: pointer; text-align: left;
  background: var(--panel); color: var(--muted);
  border: 1px solid transparent; border-left: 2px solid var(--line);
  font-family: var(--mono); font-size: 12px; transition: all .15s ease;
}
.stratum:hover { color: var(--parchment); border-left-color: var(--verdigris); }
.stratum[aria-current="true"] {
  color: var(--ink); background: var(--brass); border-left-color: var(--brass-lit);
  font-weight: 500;
}
.stratum .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }

.strata-hint { color: var(--muted); opacity: .7; font-weight: 400; letter-spacing: 0; text-transform: none; }
.stratum-row { display: flex; align-items: stretch; gap: 6px; }
.stratum-row .stratum { flex: 1; }
.stratum-row .grip {
  display: flex; align-items: center; padding: 0 4px; cursor: grab;
  color: var(--muted); font-size: 13px; user-select: none;
}
.stratum-row.dragging { opacity: .5; }
.stratum-row.is-current .stratum {
  color: var(--ink); background: var(--brass); border-left-color: var(--brass-lit); font-weight: 500;
}
.strata-actions { display: flex; align-items: center; gap: 10px; margin-top: 10px; }

.icon-btn {
  background: var(--panel); color: var(--parchment); border: 1px solid var(--line);
  width: 38px; height: 38px; border-radius: 2px; font-size: 22px; line-height: 1;
  cursor: pointer; display: grid; place-items: center;
}
.icon-btn:hover { color: var(--brass-lit); }

/* --- empty state ---------------------------------------------------------- */
.empty { position: fixed; inset: 0; z-index: 550; display: grid; place-items: center; padding: 24px; }
.empty[hidden] { display: none; }
.empty-card {
  max-width: 460px; text-align: center; padding: 36px 32px;
  background: rgba(19,36,47,0.94); border: 1px solid var(--line); border-radius: 2px;
}
.empty-card h2 { font-family: var(--display); font-weight: 600; font-size: 30px; margin: 0 0 12px; }
.empty-card p { color: var(--muted); line-height: 1.6; }
.empty-card pre {
  background: var(--ink); border: 1px solid var(--line); border-radius: 2px;
  padding: 12px 16px; margin: 16px 0; text-align: left; overflow-x: auto;
}
.empty-sub { font-size: 13px; }

/* --- focus + motion + small screens -------------------------------------- */
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }

@media (max-width: 760px) {
  .plate { max-width: none; left: 12px; right: 12px; top: 12px; }
  .lb-figure { grid-template-columns: 1fr; gap: 14px; }
  .lb-stage img { max-height: 56vh; }
  .lb-stage { max-height: 56vh; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
