* { margin: 0; padding: 0; box-sizing: border-box; }

/* Theme palette. Dark values are applied via [data-theme="dark"] on <html>,
   set by an inline head script (pre-paint) and toggled from the header. */
:root {
  --bg: #f5f5f5;
  --text: #333;
  --panel: #fff;
  --border: #ddd;
  --border-faint: #f0f0f0;
  --heading: #555;
  --muted: #666;
  --muted-2: #888;
  --faint: #999;
  --control-bg: #f6f6f6;
  --control-hover: #eee;
  --accent: #2a2a2a;
  --accent-hover: #444;
  --accent-text: #fff;
  --inset-bg: #fafafa;
  --inset-bg-2: #eaeaea;
  --swatch-border: #ccc;
  --error: #c62828;
  --success: #2e7d32;
  --header-bg: #2a2a2a;
  --header-text: #fff;
  --header-muted: #999;
  --link: #1558a8;
}

[data-theme="dark"] {
  --bg: #1a1a1c;
  --text: #d6d6d6;
  --panel: #242427;
  --border: #3a3a3e;
  --border-faint: #2c2c2f;
  --heading: #b0b0b0;
  --muted: #9c9c9c;
  --muted-2: #8d8d8d;
  --faint: #7c7c7c;
  --control-bg: #2e2e31;
  --control-hover: #39393d;
  --accent: #e4e4e4;
  --accent-hover: #cfcfcf;
  --accent-text: #1a1a1c;
  --inset-bg: #202023;
  --inset-bg-2: #333336;
  --swatch-border: #4a4a4e;
  --error: #ef8080;
  --success: #7ac47e;
  --header-bg: #202022;
  --header-text: #eee;
  --header-muted: #8d8d8d;
  --link: #8ab4f8;
}

a { color: var(--link); }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  /* Header / main / footer as a column; main gets the leftover height so
     panels can scroll internally without magic-number viewport math. */
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

header h1 { font-size: 1.2rem; font-weight: 600; }
header span { font-size: 0.85rem; color: var(--header-muted); }

.badge-experimental {
  font-size: 0.68rem !important;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #d9a441 !important;
  border: 1px solid #d9a441;
  border-radius: 999px;
  padding: 0.1rem 0.55rem;
  line-height: 1.4;
}

/* Right-aligned header controls (About, theme toggle) */
.header-actions { margin-left: auto; display: flex; align-items: center; gap: 0.6rem; }

.header-pill {
  font-size: 0.78rem;
  color: #bbb;
  background: transparent;
  border: 1px solid #555;
  border-radius: 999px;
  padding: 0.2rem 0.75rem;
  line-height: 1.3;
  cursor: pointer;
}
.header-pill:hover { background: #3a3a3a; border-color: #777; color: #fff; }

/* About dialog */
.about-dialog {
  margin: auto;                 /* the global reset zeroes the UA's centring margin */
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  width: min(560px, calc(100vw - 2rem));
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}
.about-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.about-head { display: flex; align-items: center; padding: 0.9rem 1.25rem 0; }
.about-head h2 { font-size: 1rem; font-weight: 600; margin: 0; color: var(--heading); }
.about-close {
  margin-left: auto;
  width: 28px; height: 28px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: transparent;
  color: var(--muted-2);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}
.about-close:hover { color: var(--heading); background: var(--control-hover); }
.about-body { padding: 0.2rem 1.25rem 1.25rem; font-size: 0.86rem; line-height: 1.5; }
.about-body h3 {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted-2);
  margin: 0.9rem 0 0.25rem;
}
.about-body p { margin: 0; }
.about-list { margin: 0; padding-left: 1.1rem; }
.about-list li { margin: 0.15rem 0; }
.about-body code { font-size: 0.8em; }
.about-body a { color: var(--accent); }

#theme-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid #555;
  background: transparent;
  color: #bbb;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#theme-btn:hover { background: #3a3a3a; border-color: #777; color: #fff; }
#theme-btn svg { width: 15px; height: 15px; display: block; }

/* Moon in light mode (click → dark), sun in dark mode (click → light). */
#theme-btn .icon-sun { display: none; }
[data-theme="dark"] #theme-btn .icon-sun { display: block; }
[data-theme="dark"] #theme-btn .icon-moon { display: none; }

main {
  /* Two-column viewport-fit: reference material | output (preview, material
     sliders, readout, conversion settings). Each panel scrolls internally so
     the page itself never scrolls. */
  margin: 0;
  padding: 1rem 1.25rem;
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(360px, 1fr);   /* equal halves */
  gap: 1rem;
  flex: 1;
  min-height: 0;
  align-items: stretch;
}

/* Each direct grid child becomes a flex column taking its column's full
   height. Internal scroll only kicks in if content genuinely exceeds the
   panel — typical case is no scroll at all. */
main > .panel {
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Below this viewport width, drop the output panel to its own row.
   Below the next breakpoint, collapse to a single column. The page
   scrolls normally in stacked layouts. */
@media (max-width: 1100px) {
  body { height: auto; min-height: 100vh; overflow: auto; }
  main {
    grid-template-columns: 1fr;
    flex: none;
    height: auto;
  }
}

/* Panels */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem 1.1rem;
}

.opt-heading {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted-2);
  margin: 0.6rem 0 0.35rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-faint);
}
.opt-heading:first-child { margin-top: 0; padding-top: 0; border-top: none; }

/* Conversion settings, collapsed under the result in the Output panel */
.conv-settings {
  margin-top: 0.8rem;
  border-top: 1px solid var(--border-faint);
  padding-top: 0.5rem;
  font-size: 0.85rem;
}
.conv-settings > summary {
  cursor: pointer;
  list-style: none;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted-2);
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}
.conv-settings > summary::-webkit-details-marker { display: none; }
.conv-settings > summary::before { content: "▸"; font-size: 0.7rem; }
.conv-settings[open] > summary::before { content: "▾"; }
.conv-settings > summary .muted { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--muted); }
.conv-settings #advanced-options { margin-top: 0.5rem; }

/* When Advanced is on, slim down the spacing so the whole panel fits in
   the card without scrolling. */
#advanced-options .option-group { margin-bottom: 0.5rem; }
#advanced-options .option-group label { margin-bottom: 0.15rem; font-size: 0.75rem; }
#advanced-options .option-group select,
#advanced-options .option-group input { padding: 0.28rem 0.35rem; font-size: 0.8rem; }
#advanced-options .checkbox-row { margin-bottom: 0.3rem; font-size: 0.82rem; }
#advanced-options hr { margin: 0.5rem 0 !important; }
#advanced-options p { margin: 0.25rem 0 !important; font-size: 0.75rem !important; }

.panel h2 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--heading);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Tabs — styled as a pill-button group to match the Settings mode toggle. */
.tabs {
  display: flex;
  gap: 0;
  margin-bottom: 0.85rem;
  border-bottom: none;
}

.tab-btn {
  flex: 1;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  background: var(--control-bg);
  color: var(--heading);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
}
.tab-btn:first-child { border-radius: 4px 0 0 4px; }
.tab-btn:last-child  { border-radius: 0 4px 4px 0; }
/* Three segments now (Poly Haven | ambientCG | Upload Files): collapse the
   shared borders between neighbours, not just on the last one. */
.tab-btn:not(:first-child) { border-left: none; }
.tab-btn:hover { background: var(--control-hover); }

.tab-btn.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
  font-weight: 500;
}

.tab-content { display: none; }
/* Active tab fills the remaining card height so its grid can stretch. */
.tab-content.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  /* If the selection detail + a minimum-height grid don't fit (short
     windows), scroll the tab rather than squeezing either of them. */
  overflow-y: auto;
}

/* Drop zone */
.dropzone {
  border: 2px dashed var(--swatch-border);
  border-radius: 6px;
  padding: 2rem;
  text-align: center;
  color: var(--faint);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.dropzone.dragover {
  border-color: var(--muted);
  background: var(--border-faint);
}

.dropzone p { margin-bottom: 0.5rem; }
.dropzone small { font-size: 0.8rem; }

/* Channel table */
.channel-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.75rem;
  font-size: 0.85rem;
}

.channel-table th {
  text-align: left;
  padding: 0.4rem;
  border-bottom: 1px solid var(--border);
  color: var(--muted-2);
  font-weight: 500;
}

.channel-table td {
  padding: 0.4rem;
  border-bottom: 1px solid var(--border-faint);
}

.channel-table select {
  width: 100%;
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 3px;
}

/* Poly Haven grid */
.ph-search { width: 100%; padding: 0.5rem; border: 1px solid var(--border); border-radius: 4px; margin-bottom: 0.75rem; }
/* Asset grid fills remaining card height; scrolls internally if needed.
   When a Poly Haven asset is selected, the detail block below shrinks the
   grid via flex layout — no fixed max-height cutoff. */
.ph-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  /* Rows keep their content height and the grid scrolls. Without this the
     grid's auto rows (items are overflow:hidden → min-size 0) get the
     container's leftover height spread across ALL rows, collapsing every
     tile to a sliver when the selection detail opens below. */
  grid-auto-rows: max-content;
  gap: 0.4rem;
  flex: 1 1 auto;
  /* Never let the selection detail starve the grid: ≥ 2 full rows. */
  min-height: 236px;
  overflow-y: auto;
  align-content: start;
}
.ph-item { cursor: pointer; border: 2px solid transparent; border-radius: 4px; overflow: hidden; }
.ph-item.selected { border-color: var(--accent); }
.ph-item img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.ph-item-name { font-size: 0.7rem; padding: 0.2rem; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Options */
.option-group { margin-bottom: 0.75rem; }
.option-group label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.25rem; }
.option-group select, .option-group input { width: 100%; padding: 0.35rem; border: 1px solid var(--border); border-radius: 3px; font-size: 0.85rem; }
.option-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.checkbox-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; }
.checkbox-row input[type="checkbox"] { width: auto; }

/* Form controls pick up the theme (dark dropdowns/inputs need this). */
select, input, textarea {
  background: var(--panel);
  color: var(--text);
  color-scheme: light;
}
[data-theme="dark"] select,
[data-theme="dark"] input,
[data-theme="dark"] textarea { color-scheme: dark; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.6rem 1.25rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  width: 100%;
  margin-top: 0.5rem;
}

.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { background: #aaa; cursor: not-allowed; }
.btn-download { background: #2e7d32; color: #fff; }
.btn-download:hover { background: #388e3c; }

/* Output panel */
.status { font-size: 0.85rem; color: var(--muted-2); margin-bottom: 0.75rem; }
/* Heading row with the status on the right (Output panel) */
.panel-head { display: flex; align-items: baseline; gap: 1rem; margin-bottom: 0.75rem; }
.panel-head h2 { margin-bottom: 0; }
.panel-head .status { margin: 0 0 0 auto; text-align: right; }
.status.error { color: var(--error); }
.status.success { color: var(--success); }

/* Compact two-column summary so it fits in the output card without scrolling. */
.result-summary {
  font-size: 0.78rem;
  margin-bottom: 0.6rem;
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: 0.6rem;
  row-gap: 0.2rem;
  align-items: baseline;
}
.result-summary dt {
  font-weight: 600;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.7rem;
}
.result-summary dd { margin: 0; }

.color-swatch {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 1px solid var(--swatch-border);
  border-radius: 3px;
  vertical-align: middle;
  margin-right: 0.3rem;
}

/* Preview image grows to fill the remaining card height. The output panel
   is a flex column, so flex:1 here pushes the summary + Download button
   to the bottom of the card — mirroring the position of Fetch & Convert
   in the middle card. */
/* Render (and optional reference) side by side. Hidden until there is a
   result, so the Output tabs sit at the same height as the Reference panel's
   toggle on landing. With a result, the pair is sized by the panel's spare
   height: it is the only flex item that shrinks, so the sliders / summary
   never need to scroll on normal windows, and the images are never upscaled
   past their native 384 px. */
.preview-pair { display: none; }
.preview-pair.has-preview {
  display: flex;
  gap: 0.75rem;
  flex: 0 1 auto;       /* the only item that shrinks: previews give way first */
  min-height: 150px;
  margin-bottom: 0.6rem;
}
.preview-fig {
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0;
}
.preview-fig img {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  width: auto;
  max-width: 100%;
  max-height: 384px;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  border-radius: 4px;
  display: block;
}
.preview-fig figcaption {
  font-size: 0.7rem;
  color: var(--muted-2);
  margin-top: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.preview-fig figcaption .tip { vertical-align: -1px; }
/* Hidden until a result arrives (more specific than .preview-fig img). */
.preview-fig .preview-img { display: none; }
.preview-fig .preview-img.visible { display: block; }

/* Output panel: fixed height, tabs, pinned Download */
#output-panel { overflow-y: auto; }   /* last-resort scroll only (see .out-panes) */
.out-tabs {
  display: flex;
  gap: 0;
  margin: 0 0 0.6rem;
  flex: 0 0 auto;
}
.out-tab-btn {
  flex: 1;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  background: var(--control-bg);
  color: var(--heading);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
}
.out-tab-btn + .out-tab-btn { border-left: none; }
.out-tab-btn:first-child { border-radius: 4px 0 0 4px; }
.out-tab-btn:last-child  { border-radius: 0 4px 4px 0; }
.out-tab-btn:hover { background: var(--control-hover); }
.out-tab-btn.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
/* Panes stacked in one grid cell: the block is always as tall as the tallest
   tab, so switching tabs never resizes the previews. The panes never shrink;
   on a window too short even for the minimum previews, the panel itself
   scrolls as a last resort. */
.out-panes { flex: 1 0 auto; display: grid; align-content: start; }
.out-pane { grid-area: 1 / 1; visibility: hidden; pointer-events: none; }
.out-pane.active { visibility: visible; pointer-events: auto; }
.out-empty { font-size: 0.8rem; color: var(--muted-2); padding: 0.6rem 0.2rem; }
.out-note { font-size: 0.72rem; color: var(--muted-2); margin-top: 0.5rem; }
#download-btn { flex: 0 0 auto; }
.info-ico { vertical-align: -1px; margin-left: 0.15rem; color: var(--muted-2); }
.tip { display: inline-flex; align-items: center; cursor: help; outline: none; }
.tip:hover .info-ico, .tip:focus-visible .info-ico { color: var(--accent); }
/* The sliders that most often need a manual tweak (roughness, bump) get a
   subtly tinted ⓘ so the hint is visible before hovering. */
.tip-hot .info-ico { color: var(--accent); opacity: 0.75; }
.tip-hot:hover .info-ico, .tip-hot:focus-visible .info-ico { opacity: 1; }
#tooltip {
  position: fixed;
  z-index: 1000;
  max-width: 280px;
  background: var(--heading);
  color: var(--panel);
  padding: 0.4rem 0.6rem;
  border-radius: 5px;
  font-size: 0.74rem;
  line-height: 1.4;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s;
}
#tooltip.show { opacity: 1; }

/* Maps & Projection: compact rows so the tab fits without scrolling */
.opt-grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 0.5rem; }
.opt-grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.5rem; }
#advanced-options .option-group { margin-bottom: 0.35rem; }
.opt-inline { display: flex; gap: 1.2rem; align-items: center; flex-wrap: wrap; margin: 0.2rem 0 0.1rem; }
.opt-inline .checkbox-row { margin-bottom: 0; }
.opt-hint { font-size: 0.72rem; color: var(--muted-2); margin-left: auto; }
#advanced-options select:disabled, #advanced-options input:disabled { opacity: 0.5; }

/* Tune material (post-hoc sliders) */
.tune {
  border: 1px solid var(--border-faint);
  border-radius: 6px;
  padding: 0.5rem 0.65rem;
  margin-bottom: 0.6rem;
  font-size: 0.78rem;
}
.tune-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 600;
  color: var(--muted-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.7rem;
  margin-bottom: 0.35rem;
}
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.72rem;
  padding: 0;
  text-transform: none;
  letter-spacing: 0;
}
.tune-row {
  display: grid;
  grid-template-columns: 6rem 1fr 3rem 8.5rem;
  align-items: center;
  gap: 0.5rem;
  margin: 0.3rem 0;
}
.tune-derived { font-size: 0.72rem; color: var(--muted-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tune-row span { color: var(--muted); }
.tune-row input[type="range"] { width: 100%; margin: 0; accent-color: var(--accent); }
.tune-row output { text-align: right; font-variant-numeric: tabular-nums; color: var(--heading); }
.tune.busy { opacity: 0.55; pointer-events: none; }

/* Readout sub-sections */
.result-summary dt.section {
  grid-column: 1 / -1;
  margin-top: 0.35rem;
  padding-top: 0.3rem;
  border-top: 1px solid var(--border-faint);
  color: var(--heading);
  letter-spacing: 0.06em;
}
.result-summary dd .muted { color: var(--muted); }

.preview-img.visible { display: block; }

/* Selected-asset detail: one hero row (image · facts · res · CTA) + map tiles.
   Kept compact (~260px) so the catalog grid above keeps ≥ 2 usable rows. */
.asset-detail {
  flex: 0 0 auto;
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border-faint);
}
.asset-hero {
  display: flex;
  gap: 0.85rem;
  align-items: stretch;
}
.asset-hero-img {
  flex: 0 0 auto;
  width: 34%;
  max-width: 150px;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 6px;
  background: var(--inset-bg-2);
  display: block;
  align-self: flex-start;
}
.asset-hero-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.82rem;
}
.asset-hero-meta strong { font-size: 0.95rem; color: var(--heading); line-height: 1.25; }
.asset-hero-sub { color: var(--muted-2); }
.asset-hero-tags {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.45;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.asset-hero-link { font-size: 0.78rem; }
.asset-hero-actions {
  margin-top: auto;
  padding-top: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.asset-hero-actions .res-picker { margin-top: 0; }
/* Fetch & Convert closes the card, full width under the map tiles. */
.asset-detail-cta { margin-top: 0.5rem; width: 100%; }

/* Resolution picker */
.res-picker { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.res-btn {
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font-size: 0.8rem;
}
.res-btn.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* Per-map thumbnail grid with rotation controls (compact tiles) */
.map-thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
  gap: 0.4rem;
  margin-top: 0.5rem;
  padding: 0.4rem;
  background: var(--inset-bg);
  border-radius: 4px;
}
.map-thumb {
  text-align: center;
  font-size: 0.68em;
  position: relative;
}
.map-thumb-img-wrap {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--inset-bg-2);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.map-thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s ease;
  pointer-events: none;
}
.map-thumb-rot-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 0.7em;
  padding: 1px 4px;
  border-radius: 2px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}
.map-thumb[data-rot="90"] .map-thumb-rot-badge,
.map-thumb[data-rot="180"] .map-thumb-rot-badge,
.map-thumb[data-rot="270"] .map-thumb-rot-badge { opacity: 1; }

/* USED / IGNORED indicator (bottom-left of each map thumbnail) */
.map-thumb-usage-badge {
  position: absolute;
  bottom: 2px;
  left: 2px;
  font-size: 0.65em;
  font-weight: 600;
  padding: 1px 5px;
  border-radius: 2px;
  letter-spacing: 0.05em;
  pointer-events: none;
}
.map-thumb[data-used="true"] .map-thumb-usage-badge {
  background: rgba(46, 125, 50, 0.85);
  color: #fff;
}
.map-thumb[data-used="false"] .map-thumb-usage-badge {
  background: rgba(0, 0, 0, 0.55);
  color: #ccc;
}
/* Dim the whole tile when the map will not be consumed. */
.map-thumb[data-used="false"] .map-thumb-img { opacity: 0.45; filter: grayscale(0.5); }
.map-thumb[data-used="false"] .map-thumb-label { color: var(--faint); font-style: italic; }

.map-thumb-label {
  margin-top: 0.25rem;
  color: var(--heading);
  text-transform: capitalize;
}

.maps-loading { grid-column: 1 / -1; color: var(--muted-2); font-size: 0.8rem; margin: 0.2rem 0; }

/* Label-only tile for maps we have no picture for.
   Rotation and the USED/IGNORED badge still work on it. */
.map-thumb-placeholder {
  font-size: 0.85em;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--muted-2);
  pointer-events: none;
  transition: transform 0.2s ease;
}
.map-thumb[data-used="false"] .map-thumb-placeholder { opacity: 0.45; }

/* Footer — contact row, then attribution row; each a centred line with
   dot-separated groups and room to breathe. */
footer {
  text-align: center;
  padding: 1rem 1rem 1.2rem;
  font-size: 0.8em;
  line-height: 1.7;
  color: var(--muted);
  border-top: 1px solid var(--border-faint);
}
.footer-row {
  max-width: 60rem;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: baseline;
  column-gap: 0.6rem;
  row-gap: 0.15rem;
}
.footer-credits {
  margin-top: 0.45rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--border-faint);
  width: fit-content;
  min-width: min(100%, 28rem);
}
.footer-sep { color: var(--faint); }

/* ---------------------------------------------------------------------------
   Phone widths: serviceable, not optimised. The ≤1100px rule above already
   stacks the panels and lets the page scroll; this tidies the pieces that
   assumed desktop room (header tagline, slider rows, tab labels, stacked
   pane reservation, 4-up projection fields).
   ------------------------------------------------------------------------- */
@media (max-width: 640px) {
  header { padding: 0.7rem 1rem; gap: 0.6rem; flex-wrap: wrap; }
  header h1 { font-size: 1.1rem; }
  header > span:not(.badge-experimental) { display: none; }   /* tagline */
  main { padding: 0.75rem; gap: 0.75rem; }
  main > .panel, #output-panel { height: auto; overflow: visible; }
  .panel { padding: 0.85rem 0.8rem; }
  .panel-head { flex-wrap: wrap; }

  /* Segmented controls: let long labels wrap instead of clipping */
  .tab-btn, .out-tab-btn {
    font-size: 0.74rem;
    padding: 0.4rem 0.3rem;
    white-space: normal;
    line-height: 1.2;
  }

  /* Output tabs: the page scrolls, so don't reserve the tallest tab's height */
  .out-panes { display: block; }
  .out-pane { display: none; visibility: visible; pointer-events: auto; }
  .out-pane.active { display: block; }
  .preview-pair.has-preview { min-height: 0; }
  .preview-fig img { max-height: 200px; }

  /* Slider rows: label + derived value on one line, slider + number below */
  .tune-row {
    grid-template-columns: auto 1fr 3.2rem;
    grid-template-areas: "label derived derived" "slider slider value";
    row-gap: 0.15rem;
    margin: 0.5rem 0;
  }
  .tune-row > span:first-child { grid-area: label; }
  .tune-row > input { grid-area: slider; }
  .tune-row > output { grid-area: value; }
  .tune-row > .tune-derived { grid-area: derived; text-align: right; min-width: 0; }

  /* Maps & Projection: two fields per row */
  .opt-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .opt-grid-2-1 { grid-template-columns: 1fr 1fr; }
  .opt-inline { gap: 0.4rem 1rem; }
  .opt-hint { margin-left: 0; }

  #tooltip { max-width: calc(100vw - 16px); }
  .about-dialog { width: calc(100vw - 1.5rem); }
  footer { padding: 0.8rem 0.75rem 1rem; }
}
