﻿/* =====================================================================
   THE COIN ATLAS: country page styles. Only used by country.html.
   Laid out like an entry in a printed encyclopedia: a reading column on
   the left, a facts box on the right, then the collection shown as
   numbered plates. The accent colour (--accent) is set by js/country.js
   from the country's "accentColor" in info.json.
   ---------------------------------------------------------------------
   1.  Page basics
   2.  Top bar
   3.  Entry header
   4.  Reading column
   5.  Facts box
   6.  Collection: section and scrolling strip
   7.  Collection: plates
   8.  Full-screen viewer
   9.  Previous / next country
   10. Not found, footer
   11. Phones & tablets
   ===================================================================== */


/* ---------------------------------------------------------------------
   1. PAGE BASICS
   --------------------------------------------------------------------- */
body.page-country {
  overflow-x: clip;   /* never scroll sideways (but keeps the sticky top bar working) */
}

main {
  padding-bottom: 2rem;
}

.section-title {
  font-size: clamp(1.6rem, 3vw, 2rem);
}

/* Small text button with a border, used on the plates */
.btn-small {
  min-height: 40px;
  padding: 0.4em 0.85em;
  font-size: 0.88rem;
}


/* ---------------------------------------------------------------------
   2. TOP BAR
   --------------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  padding: calc(0.7rem + env(safe-area-inset-top)) var(--gutter) 0.7rem;
  background: var(--bg-0);
  border-bottom: 1px solid var(--border);
}

.back-link {
  justify-self: start;
}

.topbar-brand {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--brand-600);
}

.topbar-nav {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.topbar-position {
  min-width: 3.5em;
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--text-muted);
}


/* ---------------------------------------------------------------------
   3. ENTRY HEADER
   Name on the left, finished with a double rule like a printed page.
   --------------------------------------------------------------------- */
.entry-head {
  padding: clamp(2rem, 5vw, 3.5rem) 0 1.5rem;
  border-bottom: 3px double var(--border-input);
}

.entry-title {
  margin-top: 0.15rem;
  font-size: clamp(2.6rem, 6.5vw, 4.4rem);
  font-weight: 600;
  line-height: 1.02;
  color: var(--accent-text);
}

.entry-official {
  margin-top: 0.4rem;
  font-family: var(--font-display);
  font-size: clamp(1.1rem, 2vw, 1.3rem);
  font-style: italic;
  color: var(--text-muted);
}

.entry-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
  margin-top: 1.25rem;
  font-size: 1.05rem;
}


/* ---------------------------------------------------------------------
   4. READING COLUMN
   --------------------------------------------------------------------- */
.entry-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  align-items: start;
  gap: clamp(2rem, 5vw, 4rem);
  margin-top: 2.25rem;
}

.entry-text {
  max-width: 38rem;   /* about 70 letters per line: comfortable to read */
}

.entry-section + .entry-section {
  margin-top: 2.5rem;
}

.entry-section .section-title {
  margin-bottom: 0.9rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}

.entry-section p {
  font-size: 1.05rem;
  line-height: 1.75;
}

.entry-section p + p {
  margin-top: 0.8rem;
}

.entry-event {
  font-family: var(--font-display);
  font-size: 1.2rem !important;
  font-style: italic;
  line-height: 1.45 !important;
  color: var(--accent-text);
}

/* Fun facts: a plain numbered list */
.facts-list {
  display: grid;
  gap: 0.9rem;
  padding-left: 1.75rem;
  list-style: decimal;
  font-size: 1.05rem;
  line-height: 1.7;
}

.facts-list li {
  padding-left: 0.35rem;
}

.facts-list li::marker {
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--accent-text);
}


/* ---------------------------------------------------------------------
   5. FACTS BOX
   --------------------------------------------------------------------- */
.infobox {
  padding: 1rem 1.1rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
}

.infobox-title {
  margin-bottom: 0.85rem;
  padding-bottom: 0.6rem;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  text-align: center;
  border-bottom: 1px solid var(--border);
}

.infobox-figure {
  margin: 0 0 0.9rem;
  text-align: center;
}

.infobox-flag {
  width: 180px;
  height: auto;
  aspect-ratio: 3 / 2;
  margin-inline: auto;
  object-fit: cover;
  border: 1px solid var(--border-input);
}

/* Small outline map of the country (drawn by js/country.js) */
.infobox-map-figure {
  padding: 0.5rem;
  background: var(--bg-1);
  border-radius: var(--radius-sm);
}

.infobox-map {
  width: 100%;
  height: auto;
  aspect-ratio: 400 / 260;
}

.infobox-map:empty {
  display: none;
}

.infobox-map-figure:has(.infobox-map:empty) {
  display: none;
}

.infobox-map path {
  fill: var(--accent-soft);
  stroke: var(--accent-text);
  stroke-width: 1;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

/* Label | value rows with thin rules between them */
.infobox-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
  line-height: 1.45;
}

.infobox-table th,
.infobox-table td {
  padding: 0.55rem 0;
  text-align: left;
  vertical-align: top;
  border-top: 1px solid var(--border);
}

.infobox-table th {
  width: 40%;
  padding-right: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
}

/* Group heading inside the table, e.g. "Currency" */
.infobox-table .infobox-group th {
  width: auto;
  padding: 1.1rem 0 0.35rem;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--accent-text);
  border-top: 0;
  border-bottom: 1px solid var(--border-input);
}

.infobox-table .infobox-group + tr th,
.infobox-table .infobox-group + tr td {
  border-top: 0;
}

.infobox-table tr:first-child th,
.infobox-table tr:first-child td {
  border-top: 0;
}

.infobox-note {
  color: var(--text-muted);
}


/* ---------------------------------------------------------------------
   6. COLLECTION: SECTION AND SCROLLING STRIP
   --------------------------------------------------------------------- */
.plates-section {
  margin-top: clamp(3.5rem, 8vw, 5.5rem);
  padding-top: 0.5rem;
  scroll-margin-top: 70px;   /* so the sticky top bar doesn't cover the heading */
}

.plates-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem 2rem;
  padding-top: 1.5rem;
  border-top: 3px double var(--border-input);
}

.plates-count {
  margin-top: 0.3rem;
  color: var(--text-muted);
}

.gallery-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.gallery-counter {
  margin-right: 0.4rem;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.gallery-controls .btn:disabled {
  opacity: 0.4;
  pointer-events: none;
}

/* The sideways-scrolling strip */
.gallery-track {
  --edge: max(var(--gutter), (100% - var(--content-width)) / 2);
  position: relative;   /* lets gallery.js measure where each plate sits */
  display: flex;
  gap: clamp(20px, 3vw, 36px);
  margin: 0;
  padding: 1.75rem var(--edge) 1.5rem;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scroll-padding-inline: var(--edge);
  scrollbar-width: thin;
  list-style: none;
  cursor: grab;
}

.gallery-track:focus-visible {
  outline-offset: -4px;
}

/* While dragging with the mouse: no snapping, no text selection */
.gallery-track.is-dragging {
  cursor: grabbing;
  scroll-snap-type: none;
  user-select: none;
}

.gallery-track.is-dragging .plate {
  pointer-events: none;
}

.gallery-item {
  flex: 0 0 clamp(240px, 25vw, 300px);
  scroll-snap-align: start;
}

/* No photos yet */
.gallery-empty {
  margin-top: 1.5rem;
  padding: 2.5rem 1.5rem;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border-input);
  border-radius: var(--radius-sm);
}

.gallery-empty-title {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 600;
}

.gallery-empty-text {
  max-width: 32rem;
  margin: 0.4rem auto 0;
  color: var(--text-muted);
}


/* ---------------------------------------------------------------------
   7. COLLECTION: PLATES
   Each photo sits on white paper with a caption underneath, like a
   numbered plate in a museum catalogue.
   --------------------------------------------------------------------- */
.plate {
  margin: 0;
}

.plate-photo {
  position: relative;
  aspect-ratio: 1;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  perspective: 1200px;
}

/* The part that turns over to show the reverse side */
.plate-flipper {
  position: absolute;
  inset: 1.1rem;
  transform-style: preserve-3d;
  transition: transform 0.6s var(--ease-in-out);
}

.plate.is-flipped .plate-flipper {
  transform: rotateY(180deg);
}

.plate-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.plate-back {
  transform: rotateY(180deg);
}

/* Soft pulse while the photo loads */
.plate-face:not(.is-loaded):not(.is-missing)::before {
  content: "";
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  background: linear-gradient(110deg, var(--bg-1) 30%, var(--bg-2) 50%, var(--bg-1) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.6s linear infinite;
}

.plate-img {
  position: absolute;   /* fill the square exactly, so tall scans can't spill over the caption */
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0;
  filter: drop-shadow(0 6px 8px rgba(43, 33, 37, 0.18));
  transition: opacity 0.4s ease;
}

.plate-face.is-loaded .plate-img {
  opacity: 1;
}

/* Shown when a photo file can't be found */
.plate-missing {
  display: grid;
  justify-items: center;
  gap: 0.45rem;
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.plate-missing-icon {
  width: 56px;
  aspect-ratio: 1;
  margin-bottom: 0.25rem;
  border: 2px dashed var(--border-input);
  border-radius: 50%;
}

.plate-missing small {
  max-width: 100%;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.75rem;
  color: var(--text-dim);
  word-break: break-all;
}

/* Invisible button covering the photo: opens the full-screen viewer */
.plate-open {
  position: absolute;
  inset: 0;
  z-index: 2;
  padding: 0;
  background: none;
  border: 0;
  cursor: zoom-in;
}

.plate-open:focus-visible {
  outline-offset: -4px;
}

.plate-caption {
  margin-top: 0.8rem;
}

.plate-number {
  display: block;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-style: italic;
  color: var(--text-dim);
}

.plate-title {
  display: block;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 600;
  line-height: 1.3;
}

.plate-meta {
  display: block;
  margin-top: 0.1rem;
  font-size: 0.92rem;
  color: var(--text-muted);
}

.plate-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.7rem;
}


/* ---------------------------------------------------------------------
   8. FULL-SCREEN VIEWER
   --------------------------------------------------------------------- */
.lightbox {
  width: 100vw;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  color: var(--text);
  background: var(--bg-0);
  border: 0;
  opacity: 0;
  transition:
    opacity 0.25s ease,
    display 0.25s allow-discrete,
    overlay 0.25s allow-discrete;
}

.lightbox[open] {
  display: grid;
  grid-template-rows: auto 1fr auto;
  opacity: 1;
}

@starting-style {
  .lightbox[open] {
    opacity: 0;
  }
}

.lightbox::backdrop {
  background: rgba(43, 33, 37, 0.3);
}

.lightbox-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: calc(0.8rem + env(safe-area-inset-top)) var(--gutter) 0.8rem;
  border-bottom: 1px solid var(--border);
}

.lightbox-counter {
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

.lightbox-stage {
  --ox: 50%;
  --oy: 50%;
  position: relative;
  min-height: 0;
  padding: 1.5rem var(--gutter);
  overflow: hidden;
  cursor: zoom-in;
  touch-action: none;   /* swipes are handled by js/gallery.js */
  perspective: 1600px;
}

.lightbox-stage.is-zoomed {
  cursor: zoom-out;
}

.lightbox-flip {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.6s var(--ease-in-out);
}

.lightbox-flip.is-flipped {
  transform: rotateY(180deg);
}

.lightbox-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  filter: drop-shadow(0 10px 16px rgba(43, 33, 37, 0.2));
  transform-origin: var(--ox) var(--oy);
  transition: scale 0.35s ease;
  user-select: none;
  -webkit-user-drag: none;
}

.lightbox-back {
  transform: rotateY(180deg);
  transform-origin: calc(100% - var(--ox)) var(--oy);   /* mirrored, because it's facing backwards */
}

.lightbox-stage.is-zoomed .lightbox-img {
  scale: 2.6;
}

/* Spinner while a big photo loads */
.lightbox-stage.is-loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { rotate: 360deg; }
}

/* Photo file not found */
.lightbox-stage.is-missing .lightbox-img {
  visibility: hidden;
}

.lightbox-stage.is-missing::before {
  content: "Photo not found";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-style: italic;
  color: var(--text-dim);
}

.lightbox-bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem 2rem;
  padding: 1rem var(--gutter) calc(1.2rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
}

.lightbox-caption {
  display: grid;
  gap: 0.2rem;
  max-width: 60ch;
}

.lightbox-title {
  font-family: var(--font-display);
  font-size: clamp(1.25rem, 2.5vw, 1.6rem);
  font-weight: 600;
}

.lightbox-meta {
  color: var(--text-muted);
}

.lightbox-notes {
  line-height: 1.6;
}

.lightbox-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}


/* ---------------------------------------------------------------------
   9. PREVIOUS / NEXT COUNTRY
   --------------------------------------------------------------------- */
.country-pager {
  display: flex;
  justify-content: space-between;
  gap: 1.5rem;
  margin-top: clamp(3rem, 7vw, 4.5rem);
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-input);
}

.pager-link {
  display: grid;
  gap: 0.1rem;
  color: var(--text);
  text-decoration: none;
}

.pager-next {
  margin-left: auto;
  text-align: right;
}

.pager-label {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.pager-name {
  font-family: var(--font-display);
  font-size: clamp(1.2rem, 2.2vw, 1.45rem);
  font-weight: 600;
  color: var(--brand-600);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
}

.pager-link:hover .pager-name {
  color: var(--brand);
  text-decoration-thickness: 2px;
}


/* ---------------------------------------------------------------------
   10. NOT FOUND & FOOTER
   --------------------------------------------------------------------- */
.not-found {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 1rem;
  min-height: 70vh;
  padding: 4rem 0;
  text-align: center;
}

.not-found-title {
  font-size: clamp(2rem, 5vw, 3rem);
}

.not-found-text {
  max-width: 36rem;
  margin-bottom: 0.5rem;
  color: var(--text-muted);
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem 1rem;
  padding: 3rem var(--gutter) calc(2.5rem + env(safe-area-inset-bottom));
  font-size: 0.92rem;
  color: var(--text-dim);
}

.site-footer a {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--brand-600);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--brand);
  text-decoration: underline;
}


/* ---------------------------------------------------------------------
   11. PHONES & TABLETS
   --------------------------------------------------------------------- */
@media (max-width: 960px) {
  /* Facts box moves above the text */
  .entry-body {
    grid-template-columns: 1fr;
  }

  .infobox {
    order: -1;
    width: 100%;
    max-width: 520px;
  }
}

@media (max-width: 760px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

  .topbar-brand {
    display: none;
  }

  .gallery-item {
    flex-basis: min(74vw, 290px);
  }

  .gallery-controls {
    width: 100%;
  }

  .gallery-counter {
    margin-right: auto;
  }

  .country-pager {
    flex-direction: column;
  }

  .lightbox-bar {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 480px) {
  .back-link {
    padding-inline: 0.8em;
    font-size: 0.9rem;
  }

  .infobox-table th {
    width: 45%;
  }
}
