:root {
  --ink: #1a1a1a;
  --paper: #faf7f0;
  --accent: #004e38;      /* W&M green - buttons */
  --accent-2: #fdb714;    /* W&M gold - timeline/year slider */
  --panel-border: rgba(0, 0, 0, 0.1);
  --muted: #555;
}

/* ---- Dark mode: toggled via data-theme on <html> (js/app.js's
   wireDarkMode()), falling back to the OS prefers-color-scheme when the
   user hasn't picked one explicitly yet. Only the palette changes here -
   layout rules above/below stay the same in both themes. ---- */
:root[data-theme="dark"] {
  --ink: #f0ebe0;
  --paper: #1c1a17;
  --accent: #fdb714;
  --accent-2: #b8ddb1;
  --panel-border: rgba(255, 255, 255, 0.12);
  --muted: #b7b0a2;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #f0ebe0;
    --paper: #1c1a17;
    --accent: #fdb714;
    --accent-2: #b8ddb1;
    --panel-border: rgba(255, 255, 255, 0.12);
    --muted: #b7b0a2;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
  transition: background-color 0.15s ease, color 0.15s ease;
}

/* ---- Immersive viewer (comic-view.html): no header, no page scroll - the
   whole viewport is the "screen" the visual novel plays on. dvh (not vh)
   so mobile browser chrome showing/hiding doesn't leave a sliver of scroll
   room at the bottom. See css/comic.css for the panel-frame sizing that
   fills this space. ---- */
body[data-page="viewer"] {
  height: 100dvh;
  overflow: hidden;
  background: #0b0a09; /* neutral stage color behind/around the panel, independent of light/dark theme */
}

body[data-page="viewer"] #comic-main {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

body[data-page="viewer"] #generate-status {
  color: #fdfaf3;
  padding: 12px 20px;
  text-align: center;
}

body[data-page="viewer"] #no-path-message {
  color: #fdfaf3;
  border-color: rgba(255, 255, 255, 0.2);
  margin: 20px;
}

/* ---- Floating badge: replaces the old static <header>. Sits over the
   map/page instead of pushing content down, and doubles as its own
   dismiss control - the whole badge is clickable (see wireAppBadge() in
   js/shared.js), not just a small close icon in the corner. Positioned
   fixed (not absolute) so it stays put over the map on scroll, same as
   the dark mode toggle. ---- */
.floating-badge {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 900;
  max-width: min(320px, calc(100vw - 84px));
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 8px 14px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}

.floating-badge strong {
  display: block;
  font-size: 1rem;
}

.floating-badge .tagline {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

/* Hidden (not removed) once dismissed, so wireAppBadge() only needs to
   toggle one attribute rather than tear down/rebuild the element. */
.floating-badge[hidden] {
  display: none;
}

#dark-mode-toggle.floating-toggle {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 900;
  flex: 0 0 auto;
  background: var(--paper);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: 999px;
  width: 36px;
  height: 36px;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

main {
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* Clears the floating badge + dark-mode toggle (both position: fixed
     over the top of the page - see .floating-badge / #dark-mode-toggle.
     floating-toggle above), so Leaflet's own top-left zoom control and
     comic.html's setup panel don't render underneath them (100px clears
     comic.html's taller badge, which also carries the "back to the map"
     link). Not wanted on
     comic-view.html's immersive viewer, which has neither floating
     element - overridden back to 0 below for that page. */
  padding-top: 100px;
}

body[data-page="viewer"] main {
  padding-top: 0;
}

#map {
  height: 70vh;
  width: 100%;
}

#timeline-controls {
  padding: 8px 20px;
}

/* ---- Year RANGE slider (two handles, not a single "current year" scrubber) ----
   Two <input type=range> stacked on the same track. Each one's own runnable
   track is transparent and click-through (pointer-events: none on the
   input), so only the thumb itself is draggable - that's what lets both
   handles live on one track without one permanently covering the other.
   The native thumbs are made invisible (opacity: 0) but stay the actual
   drag/keyboard target; the ".year-range-pill" divs on top are what's
   visually shown, positioned in JS to match. See renderYearRangeSlider()
   in js/app.js. */
.year-range {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.year-range-label {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--ink);
}

/* ---- Histogram: one bar per calendar year, sitting above the axis/track
   so you can see where the photos are before you drag. Deliberately one
   bar per YEAR, not per day - a day-level version of this was tried and
   just produced visual noise at this dataset size. ---- */
.year-histogram {
  display: flex;
  align-items: flex-end;
  height: 56px;
  background: rgba(0, 0, 0, 0.03);
  border-radius: 6px 6px 0 0;
  overflow: hidden;
}

.year-histogram-col {
  flex: 1;
  height: 100%;
  min-width: 1px;
  display: flex;
  align-items: flex-end;
}

.year-histogram-bar {
  width: 100%;
  background: #cfc7ba;
  border-radius: 1px 1px 0 0;
  transition: background 0.15s ease;
}

.year-histogram-col.in-range .year-histogram-bar {
  background: var(--accent-2);
}

.year-axis {
  position: relative;
  height: 16px;
  margin: 2px 0 6px;
  font-size: 0.68rem;
  color: #888;
}

.year-axis span {
  position: absolute;
  top: 0;
  transform: translateX(-50%);
  white-space: nowrap;
}

.year-axis span.latest {
  top: -2px;
  background: var(--ink);
  color: var(--paper);
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
}

.year-range-track {
  position: relative;
  height: 28px;
}

/* Thin rail (not a thick bar) - the "fill" below is just this same rail
   recolored between the two handles. */
.year-range-rail {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  height: 2px;
  border-radius: 2px;
  background: #d8d3c8;
}

.year-range-rail-fill {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  height: 2px;
  border-radius: 2px;
  background: var(--accent-2);
}

/* The visible handle: a pill showing the selected year. Purely decorative
   (pointer-events: none) - dragging happens on the invisible native thumb
   underneath, which is kept the same width so the two line up. */
.year-range-pill {
  position: absolute;
  top: 50%;
  width: 46px;
  height: 22px;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-2);
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 999px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.year-range-input {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 100%;
  height: 22px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  pointer-events: none; /* the track/input itself ignores clicks... */
}

.year-range-input::-webkit-slider-runnable-track {
  background: transparent;
}

.year-range-input::-moz-range-track {
  background: transparent;
}

.year-range-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  pointer-events: auto; /* ...but the thumb itself is still grabbable */
  width: 46px;
  height: 22px;
  border-radius: 999px;
  background: transparent;
  border: none;
  opacity: 0; /* invisible - the .year-range-pill on top is what's shown */
  cursor: grab;
}

.year-range-input:active::-webkit-slider-thumb {
  cursor: grabbing;
}

.year-range-input::-moz-range-thumb {
  pointer-events: auto;
  width: 46px;
  height: 22px;
  border-radius: 999px;
  background: transparent;
  border: none;
  opacity: 0;
  cursor: grab;
}

.year-range-input:active::-moz-range-thumb {
  cursor: grabbing;
}

#story-panel {
  padding: 16px 20px;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}

footer {
  padding: 16px 20px;
  text-align: center;
}

footer a {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.85rem;
}

footer a:hover {
  text-decoration: underline;
}

/* ---- Halftone CSS fallback (leanrada.com pure-CSS technique) ----
   WebGL-unavailable fallback ONLY now. The real halftone effect is
   glfx-es6's colorHalftone(), baked into the stylized canvas's pixels
   directly by stylizePhoto() (js/stylize.js). This class is applied by
   callers only when stylizePhoto() returns ditherStyle: "css-fallback",
   so there's still some visible stylization when WebGL genuinely isn't
   available, instead of a plain, unindicated photo. */
.style-halftone {
  position: relative;
  isolation: isolate;
}

.style-halftone::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(circle, #000 55%, transparent 56%);
  background-size: 6px 6px;
  mix-blend-mode: screen;
  filter: contrast(999);
  opacity: 0.85;
}

/* ---- Photo thumbnail map markers (screenshot-style, L.divIcon) ---- */
.photo-marker {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  overflow: hidden;
  background: #ccc;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.photo-marker img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ---- Route profile picker (walking/cycling/roads) ---- */
#route-profile-controls {
  padding: 4px 20px 0;
  font-size: 0.8rem;
  color: var(--muted);
}

#route-profile-controls select {
  margin-left: 6px;
  font-size: 0.85rem;
}

#route-status {
  margin-left: 12px;
  font-size: 0.8rem;
  font-style: italic;
}

#route-status[data-state="ok"] {
  color: #4a6b3a;
}

#route-status[data-state="no-footpaths"],
#route-status[data-state="fallback"] {
  color: #8a3324;
}

/* ---- Filmstrip ("photostream"): prev/next through the current Tier-A
   batch. Tier A is capped (see tierASize() in app.js) so this never grows
   past what fits on one row on a phone. ---- */
#filmstrip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 20px;
}

.filmstrip-nav {
  flex: 0 0 auto;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  border-radius: 999px;
  width: 28px;
  height: 28px;
  font-size: 1rem;
  cursor: pointer;
}

.filmstrip-nav:disabled {
  opacity: 0.3;
  cursor: default;
}

.filmstrip-track {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.filmstrip-item {
  flex: 0 0 auto;
  width: 64px;
  margin: 0;
  cursor: pointer;
  text-align: center;
}

.filmstrip-item img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}

.filmstrip-item figcaption {
  font-size: 0.6rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Path plotting (map A -> B -> C waypoint picker) ---- */
#path-controls {
  padding: 8px 20px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

#path-controls .waypoint-chip {
  background: var(--accent);
  color: var(--paper);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.8rem;
}

/* ---- Story panel: passage text, character sprite, choices ---- */
#story-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#story-bg-wrap {
  display: block;
  position: relative;
}

#story-bg {
  display: block;
  width: 100%;
  max-height: 50vh;
  object-fit: contain;
  background: #000;
}

/* Character art (thatch.png, kathy0-9.png, ...) composites over the
   background rectangle above: same box via position:absolute + inset:0,
   scaled down to fit inside it without cropping (object-fit: contain) and
   anchored to the bottom edge rather than centered (object-position:
   bottom), so every sprite - regardless of its own art's aspect ratio or
   how much headroom/transparent padding it has above the character -
   visually stands on the floor of the frame instead of floating mid-panel. */
#story-sprite {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: bottom;
  pointer-events: none;
}

#story-feel {
  font-style: italic;
  color: var(--muted);
  font-size: 0.85rem;
}

#story-choices {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#story-choices button {
  text-align: left;
  padding: 8px 12px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--ink);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.95rem;
}

#story-choices button:hover {
  background: var(--accent);
  color: var(--paper);
}

#generate-comic-btn {
  background: var(--accent);
  color: var(--paper);
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  cursor: pointer;
}

/* ---- Credits / license panel ---- */
#credits-panel {
  padding: 12px 20px;
  font-size: 0.8rem;
  color: var(--muted);
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}

#credits-panel ul {
  margin: 6px 0 0;
  padding-left: 18px;
}

#credits-panel a {
  color: var(--accent);
}

#credits-panel summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--accent);
  list-style: none;
}

#credits-panel summary::-webkit-details-marker { display: none; }

#credits-panel summary::before {
  content: "▸ ";
  display: inline-block;
  transition: transform 0.15s ease;
}

#credits-panel[open] summary::before {
  transform: rotate(90deg);
}

/* ---- Copy-pastable plain-text attribution block, under the linked list.
   The <pre> holds the exact CC-style attribution text (see
   attributionLine() in js/app.js) - selectable/copyable as-is, no markup. ---- */
.attribution-copy-block {
  margin-top: 10px;
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  overflow: hidden;
}

.attribution-copy-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.03);
  font-size: 0.75rem;
  font-weight: 600;
}

.attribution-copy-header button {
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  border-radius: 4px;
  padding: 2px 10px;
  font-size: 0.75rem;
  cursor: pointer;
}

#attribution-plaintext {
  margin: 0;
  padding: 10px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.72rem;
  line-height: 1.5;
  max-height: 220px;
  overflow-y: auto;
}
