﻿/* =====================================================================
   THE COIN ATLAS: home page (globe) styles. Only used by index.html.
   Laid out like a printed map sheet: a framed title block, a map key,
   and controls grouped in the corner.
   ---------------------------------------------------------------------
   1. Globe colours (read by globe.js, so you can re-colour the globe here)
   2. Page layout
   3. Title block & header buttons
   4. Search box & suggestions
   5. Globe canvas, controls & hint
   6. Hover label
   7. Map key
   8. Index of countries (side panel)
   9. Phones & tablets
   ===================================================================== */


/* ---------------------------------------------------------------------
   1. GLOBE COLOURS
   globe.js reads these values when it draws, so changing a colour here
   changes the globe. No JavaScript editing needed.
   --------------------------------------------------------------------- */
.page-globe {
  --globe-ocean: #d7e6e8;                   /* the sea */
  --globe-land: #f6efe2;                    /* countries not collected yet */
  --globe-land-hover: #e9dcc6;
  --globe-coast: rgba(70, 55, 50, 0.55);    /* coastlines */
  --globe-border: rgba(70, 55, 50, 0.35);   /* lines between countries */
  --globe-collected: #b4236e;               /* countries in your collection */
  --globe-collected-hover: #7d1450;
  --globe-focus: #2b2125;                   /* outline of a country you searched for */
  --globe-graticule: rgba(60, 90, 100, 0.16);   /* latitude/longitude grid */
  --globe-rim: rgba(70, 55, 50, 0.6);       /* line around the globe */
  --globe-pin: #b4236e;                     /* dots for small countries */
  --globe-pin-ring: rgba(43, 33, 37, 0.55);

  /* Header/footer heights. globe.js measures the real values and updates these. */
  --header-h: 140px;
  --footer-h: 120px;
}


/* ---------------------------------------------------------------------
   2. PAGE LAYOUT
   The globe fills the whole screen. The title block, buttons and map key
   sit on top of it in the corners.
   --------------------------------------------------------------------- */
body.page-globe {
  height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-columns: 100%;
  grid-template-rows: auto 1fr auto;
}

.globe-stage {
  grid-area: 1 / 1 / -1 / -1;   /* spans every row, behind the header & footer */
  position: relative;
  min-height: 0;
  overflow: hidden;
}

.site-header {
  grid-area: 1 / 1;
  align-self: start;
  position: relative;
  z-index: 10;
}

.map-footer {
  grid-area: 3 / 1;
  align-self: end;
  position: relative;
  z-index: 10;
}


/* ---------------------------------------------------------------------
   3. TITLE BLOCK & HEADER BUTTONS
   --------------------------------------------------------------------- */
.site-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem 2rem;
  padding: calc(1.25rem + env(safe-area-inset-top)) var(--gutter) 0;
  pointer-events: none;           /* let drags pass through the empty space… */
}

.title-block,
.header-actions {
  pointer-events: auto;           /* …but keep the boxes and buttons usable */
}

/* A double-ruled frame, like the title on an old printed map */
.title-block {
  max-width: 24rem;
  padding: 1rem 1.35rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  box-shadow:
    inset 0 0 0 4px var(--surface),
    inset 0 0 0 5px var(--border);
}

.site-title {
  font-size: clamp(1.6rem, 2.6vw, 2.2rem);
  font-weight: 700;
  line-height: 1.1;
  color: var(--brand-600);
}

.site-subtitle {
  margin-top: 0.2rem;
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-style: italic;
  color: var(--text-muted);
}

.title-block-totals {
  margin-top: 0.65rem;
  padding-top: 0.6rem;
  font-size: 0.95rem;
  color: var(--text);
  border-top: 1px solid var(--border);
}

.title-block-totals:empty {
  display: none;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;               /* buttons move to a second line instead of squeezing the title */
  justify-content: flex-end;
  align-items: center;
  gap: 0.6rem;
}

.title-block {
  flex: none;
  min-width: 15rem;
}


/* ---------------------------------------------------------------------
   4. SEARCH BOX & SUGGESTIONS
   --------------------------------------------------------------------- */
.search {
  position: relative;
}

.search-icon {
  position: absolute;
  top: 50%;
  left: 0.85rem;
  width: 18px;
  height: 18px;
  translate: 0 -50%;
  fill: none;
  stroke: var(--text-dim);
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}

.search-input {
  width: 16rem;
  min-height: 44px;
  padding: 0.55em 0.9em 0.55em 2.5rem;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface-strong);
  border: 1px solid var(--border-input);
  border-radius: var(--radius);
  transition: border-color var(--dur) ease, width var(--dur) ease;
}

.search-input::placeholder {
  color: var(--text-dim);
}

.search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
  appearance: none;
}

.search-input:hover {
  border-color: var(--text-dim);
}

.search-input:focus {
  width: 19rem;
  outline: 3px solid var(--brand-100);
  outline-offset: 0;
  border-color: var(--brand);
}

.search:focus-within .search-icon {
  stroke: var(--brand);
}

/* Drop-down list of matching countries */
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 30;
  min-width: 260px;
  max-height: min(360px, 60dvh);
  overflow-y: auto;
  background: var(--surface-strong);
  border: 1px solid var(--border-input);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.search-option {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.65rem 0.85rem;
  font-size: 1rem;
  cursor: pointer;
}

.search-option + .search-option {
  border-top: 1px solid var(--border);
}

.search-option .flag {
  width: 24px;
}

.search-option-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The highlighted option (mouse hover or arrow keys) */
.search-option:hover,
.search-option[aria-selected="true"] {
  background: var(--brand-50);
}

.search-option mark {
  color: inherit;
  font-weight: 700;
  background: none;
  text-decoration: underline;
  text-decoration-color: var(--brand);
  text-underline-offset: 3px;
}

.search-option.is-uncollected {
  color: var(--text-muted);
}

.search-empty {
  padding: 0.85rem;
  font-size: 0.95rem;
  text-align: center;
  color: var(--text-dim);
}


/* ---------------------------------------------------------------------
   5. GLOBE CANVAS, CONTROLS & HINT
   --------------------------------------------------------------------- */
.globe-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;          /* globe.js handles drag & pinch itself */
  -webkit-tap-highlight-color: transparent;
}

.globe-canvas.is-dragging {
  cursor: grabbing;
}

.globe-canvas.is-over-collected {
  cursor: pointer;
}

.globe-canvas:focus-visible {
  outline-offset: -6px;
}

/* Zoom buttons joined into one block, with the pause button below */
.globe-controls {
  position: absolute;
  right: var(--gutter);
  bottom: calc(var(--footer-h) + 0.75rem);
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.zoom-group {
  display: flex;
  flex-direction: column;
  background: var(--surface-strong);
  border: 1px solid var(--border-input);
  border-radius: var(--radius);
  overflow: hidden;
}

.zoom-group .icon-btn {
  border: 0;
  border-radius: 0;
}

.zoom-group .icon-btn + .icon-btn {
  border-top: 1px solid var(--border);
}

/* Pause button: shows ❚❚ while spinning, ▶ while paused */
#spin-btn .icon-play {
  display: none;
}

#spin-btn[aria-pressed="true"] .icon-play {
  display: block;
}

#spin-btn[aria-pressed="true"] .icon-pause {
  display: none;
}

#spin-btn[aria-pressed="true"] {
  color: var(--brand);
  border-color: var(--brand);
}

/* Short "how to use" caption, fades away after the first interaction */
.globe-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--footer-h) + 1rem);
  z-index: 5;
  width: fit-content;
  max-width: calc(100% - 2 * var(--gutter));
  margin-inline: auto;
  padding: 0.35em 0.9em;
  font-family: var(--font-display);
  font-size: 1rem;
  font-style: italic;
  text-align: center;
  color: var(--text-muted);
  background: rgba(251, 247, 240, 0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  pointer-events: none;
  transition: opacity var(--dur-slow) ease;
}

.globe-hint.is-faded {
  opacity: 0;
}


/* ---------------------------------------------------------------------
   6. HOVER LABEL
   globe.js sets --x and --y (in px) to place it next to the mouse.
   --------------------------------------------------------------------- */
.globe-tooltip {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  max-width: 300px;
  padding: 0.6rem 0.9rem 0.6rem 0.7rem;
  translate: var(--x, 0px) var(--y, 0px);
  background: var(--surface-strong);
  border: 1px solid var(--border-input);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  pointer-events: none;
  will-change: translate;
}

.globe-tooltip .flag {
  width: 36px;
}

.tooltip-text {
  display: grid;
  min-width: 0;
}

.tooltip-name {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text);
}

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


/* ---------------------------------------------------------------------
   7. MAP KEY
   --------------------------------------------------------------------- */
.map-footer {
  padding: 0 var(--gutter) calc(1.25rem + env(safe-area-inset-bottom));
  pointer-events: none;
}

.map-key {
  display: inline-block;
  margin: 0;
  padding: 0.75rem 1rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  pointer-events: auto;
}

.map-key-title {
  margin-bottom: 0.4rem;
  font-family: var(--font-display);
  font-size: 1rem;
  font-style: italic;
  color: var(--text);
}

.map-key-list {
  display: grid;
  gap: 0.3rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.map-key-list li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.key-swatch {
  flex: none;
  width: 20px;
  height: 13px;
  border-radius: 1px;
}

.key-swatch--collected {
  background: var(--globe-collected);
}

.key-swatch--empty {
  background: var(--globe-land);
  box-shadow: inset 0 0 0 1px var(--globe-coast);
}

.key-swatch--pin {
  width: 12px;
  height: 12px;
  margin-inline: 4px;
  border-radius: 50%;
  background: var(--globe-pin);
  box-shadow: 0 0 0 2px #ffffff, 0 0 0 3px var(--globe-pin-ring);
}


/* ---------------------------------------------------------------------
   8. INDEX OF COUNTRIES (side panel)
   Laid out like the index at the back of a book: grouped by first letter,
   with a dotted line running to the number of photos.
   Uses the native <dialog> element, so Esc-to-close and keeping the
   keyboard focus inside the panel come for free.
   --------------------------------------------------------------------- */
.drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(420px, 100vw);
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  color: var(--text);
  background: var(--bg-0);
  border: none;
  border-left: 1px solid var(--border-input);
  box-shadow: -20px 0 40px -24px rgba(43, 33, 37, 0.3);
  translate: 100% 0;
  transition:
    translate 0.35s var(--ease-out),
    display 0.35s allow-discrete,
    overlay 0.35s allow-discrete;
}

.drawer[open] {
  display: grid;
  grid-template-rows: auto 1fr;
  translate: 0 0;
}

/* Where the slide-in starts from */
@starting-style {
  .drawer[open] {
    translate: 100% 0;
  }
}

/* Dim the page behind the panel a little, so the globe still shows */
.drawer::backdrop {
  background: rgba(43, 33, 37, 0);
  transition:
    background-color 0.35s ease,
    display 0.35s allow-discrete,
    overlay 0.35s allow-discrete;
}

.drawer[open]::backdrop {
  background: rgba(43, 33, 37, 0.18);
}

@starting-style {
  .drawer[open]::backdrop {
    background: rgba(43, 33, 37, 0);
  }
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: calc(1.4rem + env(safe-area-inset-top)) 1.5rem 1.1rem;
  border-bottom: 1px solid var(--border-input);
}

.drawer-title {
  font-size: 1.7rem;
  color: var(--brand-600);
}

.drawer-count {
  margin-top: 0.2rem;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.country-list {
  padding: 0 1.5rem calc(1.5rem + env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* The big letter at the start of each group (stays at the top while scrolling) */
.index-letter {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0;
  padding: 1rem 0 0.25rem;
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--brand-600);
  background: var(--bg-0);
  border-bottom: 1px solid var(--border);
}

.index-items {
  padding: 0.25rem 0 0.4rem;
}

.country-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.5rem 0.4rem;
  color: var(--text);
  text-decoration: none;
  border-radius: var(--radius-sm);
}

.country-link .flag {
  width: 30px;
}

.country-link-name {
  font-size: 1.05rem;
}

/* Dotted line between the name and the number, like a book index */
.country-link-leader {
  flex: 1;
  min-width: 1rem;
  align-self: end;
  margin-bottom: 0.45em;
  border-bottom: 2px dotted var(--border-input);
}

.country-link-meta {
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--text-muted);
}

.country-link:hover,
.country-link:focus-visible {
  background: var(--brand-50);
}

.country-link:hover .country-link-name,
.country-link:focus-visible .country-link-name {
  color: var(--brand-600);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.country-list-empty {
  padding: 2rem 0;
  text-align: center;
  color: var(--text-muted);
}


/* ---------------------------------------------------------------------
   9. PHONES & TABLETS
   --------------------------------------------------------------------- */
@media (max-width: 900px) {
  .site-header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .title-block {
    max-width: none;
  }

  .header-actions {
    width: 100%;
  }

  .search {
    flex: 1;
  }

  .search-input,
  .search-input:focus {
    width: 100%;
  }
}

@media (max-width: 600px) {
  /* Search box on its own line, the two buttons share the line below */
  .header-actions {
    flex-wrap: wrap;
  }

  .search {
    flex-basis: 100%;
  }

  .header-actions .btn {
    flex: 1;
  }

  .title-block {
    padding: 0.8rem 1rem 0.75rem;
  }

  .site-subtitle {
    font-size: 0.95rem;
  }

  /* Smaller map key: just the coloured squares and short labels */
  .map-key {
    padding: 0.55rem 0.75rem;
  }

  .map-key-title {
    display: none;
  }

  .map-key-list {
    font-size: 0.82rem;
  }

  .globe-controls .icon-btn {
    width: 42px;
    height: 42px;
  }

  /* Keep the caption clear of the zoom buttons on the right */
  .globe-hint {
    max-width: calc(100% - 2 * var(--gutter) - 110px);
    font-size: 0.9rem;
  }
}

/* Devices without a mouse: tapping replaces hovering, so the hover label is never shown */
@media (hover: none) {
  .globe-tooltip {
    display: none !important;
  }
}
