/* ── App styles ───────────────────────────────────────────────────────────────
 * Consumes the design system in `tokens.css` (loaded first): palette, scales
 * and the `ui-*` primitives. This file holds only what is specific to the map
 * viewer. Prefer semantic tokens (--bg-surface, --text-muted, --accent) over
 * raw ramp steps so a brand change stays a four-line edit in tokens.css.
 * ────────────────────────────────────────────────────────────────────────── */

/* Brand: the `copper` profile from tokens.css §1b, selected by
   `<html data-brand="copper">` in index.html. Vintage Story is an earthy
   survival game, so the chrome runs copper-on-slate: warm enough to feel
   hand-made, desaturated enough that it never competes with the map's own
   colours. To try another look, change that one attribute; to invent one,
   override the dials here — this file loads last and wins. */

:root {
  --sidebar-w: 368px;

  /* Aliases for the names this file already used. */
  --bg-sidebar: var(--bg-panel);
  --text-dim:   var(--text-muted);
  --font:       var(--font-sans);
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: row;
  /* A faint warm glow behind the sidebar edge keeps the two panes from
     reading as one flat sheet. */
  background:
    radial-gradient(1200px 600px at 0% 0%, var(--accent-softer), transparent 60%),
    var(--bg);
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  box-shadow: 1px 0 0 var(--wash-1);
}

.sidebar-header {
  padding: var(--space-5) var(--space-6) var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  border-bottom: 1px solid var(--border);
}

.sidebar-header-actions {
  display: flex;
  gap: var(--space-3);
  flex-shrink: 0;
}

/* ── Tab bar ──────────────────────────────────────────────────────────────── */

/* Nine tabs do not fit on one row at sidebar width. Rather than let them wrap
   into ragged thirds, they are pills on a padded rail: wrapping then looks
   deliberate and each target stays comfortably clickable. */
.tab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  color: var(--text-muted);
  font-family: var(--font);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  letter-spacing: 0.01em;
  padding: var(--space-3) var(--space-5);
  line-height: 1;
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
}

.tab-btn:hover { color: var(--text); background: var(--wash-2); }

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

.tab-content {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

/* ── Upload drop zone ─────────────────────────────────────────────────── */

.upload-drop-zone {
  margin: var(--space-5) var(--space-6);
  padding: var(--space-7) var(--space-6);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--wash-1);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--dur-base) var(--ease-out),
              background var(--dur-base) var(--ease-out);
}

.upload-drop-zone:hover,
.upload-drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-softer);
}

.upload-drop-icon {
  font-size: 24px;
  margin-bottom: 6px;
}

.upload-drop-label {
  font-size: 12px;
  color: var(--text);
  margin-bottom: 4px;
}

.upload-drop-label code {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 11px;
}

.upload-drop-sublabel {
  font-size: 11px;
  color: var(--text-dim);
}

/* Save-load busy state (app.js setSaveLoadBusy): shared by all three upload
   boxes. The box keeps receiving dragover/drop while busy (no pointer-events:
   none), so a second drop is refused by app.js instead of falling through to
   the browser, which would open the file. */
.upload-drop-zone.loading {
  cursor: progress;
  border-style: solid;
  border-color: var(--accent);
  background: var(--accent-softer);
}

/* The sublabel (with its browse button) stays, dimmed and below the status,
   so a keyboard user's focus on "browse" is not lost when the box goes busy. */
.upload-drop-zone.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.upload-drop-zone.loading .upload-drop-icon,
.upload-drop-zone.loading .upload-drop-label {
  display: none;
}

.upload-drop-zone.loading .upload-drop-sublabel {
  order: 1;
  margin-top: var(--space-3);
  opacity: 0.5;
}

.upload-drop-busy {
  display: none;
}

.upload-drop-zone.loading .upload-drop-busy {
  display: flex;
  justify-content: center;
  margin-bottom: var(--space-3);
}

.upload-drop-spinner {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  border: 3px solid var(--wash-2);
  border-top-color: var(--accent);
  animation: wasm-spin 0.8s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  .upload-drop-spinner { animation: none; }
}

.upload-drop-status {
  font-size: var(--text-sm);
  color: var(--text);
  overflow-wrap: anywhere;
}

.upload-drop-status:empty {
  display: none;
}

.upload-drop-zone:not(.loading) .upload-drop-status {
  margin-top: var(--space-3);
  color: var(--text-muted);
}

.upload-browse-btn[aria-disabled="true"] {
  cursor: progress;
}

.btn-unload[aria-disabled="true"] {
  cursor: progress;
  opacity: 0.5;
}

.upload-browse-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-family: var(--font);
  font-size: 11px;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.upload-browse-btn:hover {
  filter: brightness(1.2);
}

/* ── Save loaded banner ───────────────────────────────────────────────── */

.save-loaded-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: var(--space-5) var(--space-6);
  padding: var(--space-4) var(--space-5);
  background: var(--accent-soft);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-md);
}

.save-banner-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.save-banner-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.save-banner-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-unload {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  padding: 2px 7px;
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
  transition: color .15s, border-color .15s, background .15s;
  line-height: 1;
}

.btn-unload:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* ── Placeholder text in save tabs ────────────────────────────────────── */

.placeholder-text {
  font-size: 12px;
  color: var(--text-dim);
  font-style: italic;
}

/* ── Disabled / frozen settings ───────────────────────────────────────── */

.settings-frozen .setting-group input:disabled,
.settings-frozen .setting-group select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.settings-frozen .btn-icon:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.settings-frozen .btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  filter: none;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.debug-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 11px;
}
.debug-table th,
.debug-table td {
  padding: 3px 6px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}
.debug-table th:first-child,
.debug-table td:first-child { text-align: left; }
.debug-table th {
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10px;
}
.debug-table .debug-total td {
  font-weight: 700;
  border-top: 2px solid var(--border);
  border-bottom: none;
}

.sidebar-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semi);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
  /* The title is the one place the brand colour gets to show off. */
  background: linear-gradient(105deg, var(--text) 30%, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ── Centered error overlay ──────────────────────────────────────────────── */

.error-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in oklab, var(--n-950) 95%, transparent);
  color: var(--n-50);
  font-family: var(--font-mono);
  font-size: 14px;
  padding: 24px;
  text-align: center;
  white-space: pre-line; /* save-load errors put the details on their own line */
  pointer-events: none;
}

/* ── Centered WASM-loading overlay ───────────────────────────────────────── */

.wasm-loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 9;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in oklab, var(--n-950) 60%, transparent);
  pointer-events: none;
}

.wasm-loading-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-5);
  background: var(--bg-overlay);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), var(--rim);
  padding: var(--space-7) var(--space-9);
  color: var(--text);
}

.wasm-loading-spinner {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  border: 3px solid var(--wash-2);
  border-top-color: var(--accent);
  animation: wasm-spin 0.8s linear infinite;
}

@keyframes wasm-spin {
  to { transform: rotate(360deg); }
}

.wasm-loading-text {
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}

.sidebar-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.section-heading {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.setting-group {
  margin-bottom: 10px;
}

.setting-group label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.setting-group input,
.setting-group select {
  width: 100%;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  color: var(--text);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  font-size: var(--text-md);
  font-family: var(--font);
  transition: border-color var(--dur-fast) var(--ease-out);
}

.setting-group input:hover,
.setting-group select:hover { border-color: var(--border-strong); }

.setting-group input:focus-visible,
.setting-group select:focus-visible { border-color: var(--accent); }

/* Replace the platform select arrow with one drawn from the palette, so the
   selects match the rest of the chrome on every OS. */
.setting-group select {
  appearance: none;
  padding-right: var(--space-8);
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
                    linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: calc(100% - 15px) calc(50% + 1px), calc(100% - 10px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.seed-row {
  display: flex;
  gap: 6px;
}

.seed-row input {
  flex: 1;
  min-width: 0;
}

.range-input {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--n-800);
  border-radius: var(--radius-full);
  outline: none;
  border: none;
  padding: 0;
}

.range-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: var(--radius-full);
  background: var(--accent);
  border: 2px solid var(--bg-sidebar);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out);
}

.range-input::-webkit-slider-thumb:hover { transform: scale(1.18); }

.range-input::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: var(--radius-full);
  background: var(--accent);
  border: 2px solid var(--bg-sidebar);
  cursor: pointer;
}

.range-value {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  min-width: 32px;
  text-align: right;
}

.btn-icon {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  color: var(--text);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  transition: border-color var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out);
}

.btn-icon:hover { border-color: var(--accent); background: var(--accent-softer); }

.btn-primary {
  background: var(--accent);
  border: none;
  color: var(--accent-contrast);
  padding: var(--space-4) var(--space-6);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--text-md);
  font-weight: var(--weight-semi);
  font-family: var(--font);
  box-shadow: var(--rim);
  transition: background var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}

.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:active:not(:disabled) { transform: translateY(1px); }

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  padding: var(--space-4) var(--space-6);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  font-family: var(--font);
  margin-top: var(--space-3);
  transition: color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out);
}

.btn-secondary:hover {
  color: var(--text);
  border-color: var(--n-600);
  background: var(--wash-1);
}

.btn-secondary.copied {
  color: var(--success);
  border-color: var(--success);
  background: var(--success-soft);
}

.btn-full { width: 100%; }

.config-btn-row {
  display: flex;
  gap: 6px;
  width: 100%;
}

.btn-half { flex: 1; min-width: 0; }

/* Match .btn-secondary's top margin so primary/secondary buttons sharing a row
   align at the top (flex stretch then equalizes their heights). */
.config-btn-row .btn-primary { margin-top: 6px; }

/* Thin divider between controls inside a sidebar section. */
.sidebar-separator {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}

.btn-secondary.paste-error {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--danger-soft);
}

.sidebar-footer {
  margin-top: auto;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
}

.coords {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
}

/* ── Sidebar toggle button ────────────────────────────────────────────── */

.sidebar-toggle {
  display: none;             /* hidden on desktop by default */
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 100;
  width: 40px;
  height: 40px;
  background: var(--bg-overlay);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: background var(--dur-base) var(--ease-out), left var(--dur-slow) var(--ease-out);
  box-shadow: var(--shadow-md), var(--rim);
}

.sidebar-toggle:hover {
  background: var(--bg-surface);
}

/* ── Mobile / narrow-screen layout ────────────────────────────────────── */

@media (max-width: 768px) {
  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 90;
    width: min(var(--sidebar-w), 85vw);
    transform: translateX(0);
    transition: transform .3s ease;
  }

  .sidebar.collapsed {
    transform: translateX(-100%);
  }

  /* Shift toggle button to hug the sidebar edge when open */
  .sidebar:not(.collapsed) ~ .sidebar-toggle {
    left: min(var(--sidebar-w), 85vw);
  }

  /* Show backdrop when sidebar is open */
  .sidebar:not(.collapsed) ~ .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  main {
    /* full width on mobile, sidebar overlays */
    width: 100%;
  }
}

/* Backdrop (only shown on mobile when sidebar is open) */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: color-mix(in oklab, var(--n-950) 60%, transparent);
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s ease;
}

/* ── Main / Canvas ───────────────────────────────────────────────────────── */

main {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.canvas-container {
  flex: 1;
  overflow: hidden;
  position: relative;
}

#map-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  touch-action: none;
  height: 100%;
  cursor: grab;
}

#map-canvas:active { cursor: grabbing; }

/* ── Ore checkbox list ─────────────────────────────────────────────────── */

.ore-group {
  margin-bottom: 16px;
}

.ore-group-heading {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-dim);
  margin-bottom: 4px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.hint-text {
  font-size: 11px;
  line-height: 1.4;
  color: var(--text-dim);
  margin: 0 0 8px;
}

.structure-row {
  display: flex;
  align-items: center;
  gap: 2px;
}

.structure-row .ore-checkbox {
  flex: 1;
  min-width: 0;
}

.btn-goto {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  font-size: 12px;
  padding: 3px 6px;
  cursor: pointer;
  flex-shrink: 0;
  transition: color .15s, border-color .15s, background .15s;
  line-height: 1;
}

.btn-goto:hover {
  color: var(--text);
  border-color: var(--text-dim);
  background: var(--wash-1);
}

.ore-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text);
  padding: 5px 8px;
  margin: 0 -8px;
  border-radius: 4px;
  cursor: pointer;
  transition: background .12s;
  user-select: none;
}

.ore-checkbox:hover {
  background: var(--wash-1);
}

.ore-checkbox input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-xs);
  background: var(--bg-sunken);
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  transition: background .12s, border-color .12s;
}

.ore-checkbox input[type="checkbox"]:hover {
  border-color: var(--text-dim);
}

.ore-checkbox input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.ore-checkbox input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 4.5px;
  top: 1px;
  width: 4px;
  height: 9px;
  border: solid var(--accent-contrast);
  border-width: 0 2px 2px 0;
  transform: rotate(42deg);
}

/* ── Save ore scanning ────────────────────────────────────────────────────── */

.save-ore-status {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.save-ore-count {
  margin-left: auto;
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
}

/* ── Scan progress bar (Features tab) ─────────────────────────────────── */

.scan-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.scan-progress-track {
  flex: 1;
  height: 6px;
  background: var(--wash-2);
  border-radius: 3px;
  overflow: hidden;
}

.scan-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.15s ease;
}

.scan-progress-label {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  min-width: 28px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ── Ore density tooltip ──────────────────────────────────────────────────── */

.ore-tooltip {
  position: absolute;
  z-index: var(--z-tooltip);
  background: var(--bg-overlay);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5);
  pointer-events: none;
  min-width: 180px;
  max-width: 260px;
  box-shadow: var(--shadow-lg), var(--rim);
}

.ore-tip-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  line-height: 1.8;
}

.ore-tip-name {
  flex: 1;
  color: var(--text);
  font-weight: 500;
  white-space: nowrap;
}

.ore-tip-pct {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text);
  min-width: 30px;
  text-align: right;
}

.ore-tip-lkl {
  font-size: 10px;
  color: var(--text-dim);
  min-width: 55px;
  text-align: right;
}

/* ── Floating map overlays ───────────────────────────────────────────────── */

.map-overlay {
  position: absolute;
  z-index: 5;
  pointer-events: none;
}

.map-overlay--tr {
  top: 12px;
  right: 12px;
}

.map-overlay--br {
  bottom: 12px;
  right: 12px;
}

.map-overlay--bl {
  bottom: 12px;
  left: 12px;
}

/* ── Loading bar (bottom-left) ─────────────────────────────────────────── */

.loading-panel {
  min-width: 190px;
}

.loading-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

.loading-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.loading-count {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.loading-track {
  height: 6px;
  background: var(--wash-2);
  border-radius: 3px;
  overflow: hidden;
}

.loading-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.15s ease;
}

.loading-breakdown {
  margin-top: 6px;
  font-size: 10px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  min-height: 12px;
}

.overlay-panel {
  pointer-events: auto;
  background: var(--bg-overlay);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md), var(--rim);
  padding: var(--space-4) var(--space-5);
  color: var(--text);
  font-size: var(--text-sm);
}

/* ── Controls (top-right) ─────────────────────────────────────────────── */

.overlay-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.overlay-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 12px;
  padding: 2px 0;
  user-select: none;
}

.overlay-toggle input[type="checkbox"] {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  cursor: pointer;
}

.overlay-separator {
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}

.overlay-mode {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  font-family: var(--font);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  padding: var(--space-3) var(--space-4);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
}

.overlay-row > .overlay-mode:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.overlay-row > .overlay-mode:last-child  { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.overlay-row > .overlay-mode:not(:first-child) { border-left: none; }

.overlay-mode:hover {
  color: var(--text);
  border-color: var(--text-dim);
}

.overlay-mode.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
  font-weight: var(--weight-semi);
}

/* ── Legend (bottom-right) ────────────────────────────────────────────── */

.overlay-legend {
  padding: 8px 12px;
}

.legend-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  line-height: 1.8;
  color: var(--text);
}

.legend-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
  border: 1px solid var(--wash-2);
}

.legend-gradient {
  height: 10px;
  border-radius: 3px;
  margin: 4px 0 3px;
  border: 1px solid var(--wash-2);
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--text-dim);
}

/* ── Report buttons + dialog ─────────────────────────────────────────────── */

.feedback-btn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  text-decoration: none;
  transition: background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
}

.feedback-btn--default:hover {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

.feedback-btn--bug {
  color: var(--danger);
  border-color: color-mix(in oklab, var(--danger) 40%, transparent);
}

.feedback-btn--bug:hover {
  background: var(--danger);
  color: var(--n-950);
  border-color: var(--danger);
}

/* Dialog ------------------------------------------------------------------- */

.report-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  background: color-mix(in oklab, var(--n-950) 62%, transparent);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: report-fade var(--dur-base) var(--ease-out);
}

.report-modal {
  width: 480px;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl), var(--rim);
  animation: report-rise var(--dur-base) var(--ease-out);
  overflow: hidden;
}

@keyframes report-fade { from { opacity: 0; } }
@keyframes report-rise { from { opacity: 0; transform: translateY(10px) scale(0.985); } }

.report-modal form {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
}

.report-header {
  display: flex;
  align-items: flex-start;
  gap: var(--space-5);
  padding: var(--space-6);
  border-bottom: 1px solid var(--border);
}

/* Tinted glyph badge — recoloured per report type by `.report-modal--bug`. */
.report-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  color: var(--accent);
}

.report-heading { flex: 1; min-width: 0; }

.report-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semi);
  color: var(--text);
}

.report-subtitle {
  margin-top: 2px;
  font-size: var(--text-sm);
  color: var(--text-dim);
  line-height: var(--leading-normal);
}

.report-close {
  background: none;
  border: none;
  color: var(--text-subtle);
  font-size: 22px;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease-out);
}

.report-close:hover { color: var(--text); }

/* Type switch — lets someone who opened the wrong dialog change their mind
   without losing what they already typed. */
.report-switch {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-5) var(--space-6) 0;
}

.report-switch-btn {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-family: var(--font);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  padding: var(--space-4);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
}

.report-switch-btn:hover { color: var(--text); background: var(--wash-1); }

.report-switch-btn.active {
  background: var(--accent-soft);
  border-color: var(--border-accent);
  color: var(--accent);
  font-weight: var(--weight-semi);
}

.report-textarea {
  display: block;
  width: calc(100% - var(--space-6) * 2);
  margin: var(--space-5) var(--space-6) 0;
  padding: var(--space-5);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--text-md);
  line-height: var(--leading-normal);
  resize: vertical;
  min-height: 120px;
  transition: border-color var(--dur-fast) var(--ease-out);
}

.report-textarea:hover { border-color: var(--border-strong); }
.report-textarea:focus-visible { border-color: var(--accent); }
.report-textarea::placeholder { color: var(--text-subtle); }

.report-field {
  display: block;
  padding: var(--space-5) var(--space-6) 0;
}

.report-field-label {
  display: block;
  font-size: var(--text-sm);
  color: var(--text-dim);
  margin-bottom: var(--space-2);
}

.report-optional {
  color: var(--text-subtle);
  font-size: var(--text-xs);
}

.report-input {
  width: 100%;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: var(--space-3) var(--space-4);
  font-family: var(--font);
  font-size: var(--text-md);
  transition: border-color var(--dur-fast) var(--ease-out);
}

.report-input:hover { border-color: var(--border-strong); }
.report-input:focus-visible { border-color: var(--accent); }
.report-input::placeholder { color: var(--text-subtle); }

/* Diagnostics disclosure --------------------------------------------------- */

.report-diag { margin: var(--space-5) var(--space-6) 0; }

.report-diag-summary {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  color: var(--text-dim);
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: background var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
}

.report-diag-summary::-webkit-details-marker { display: none; }
.report-diag-summary:hover { background: var(--wash-1); border-color: var(--border-strong); }

.report-diag-caret {
  display: inline-block;
  font-size: 14px;
  line-height: 1;
  transition: transform var(--dur-base) var(--ease-out);
}

.report-diag[open] .report-diag-caret { transform: rotate(90deg); }

.report-diag[open] .report-diag-summary {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.report-diag-count {
  margin-left: auto;
  font-size: var(--text-xs);
  color: var(--text-subtle);
  font-variant-numeric: tabular-nums;
}

.report-diag-body {
  max-height: 180px;
  overflow: auto;
  margin: 0;
  padding: var(--space-4);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  line-height: 1.55;
  color: var(--text-dim);
  white-space: pre;
}

/* Footer ------------------------------------------------------------------- */

.report-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
  margin-top: var(--space-6);
  padding: var(--space-5) var(--space-6);
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
}

.report-status {
  font-size: var(--text-sm);
  color: var(--text-dim);
  min-width: 0;
}

.report-status.error { color: var(--danger); }
.report-status.success { color: var(--success); }

.report-actions {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  flex: none;
}

.report-counter {
  font-size: var(--text-sm);
  color: var(--text-subtle);
  font-variant-numeric: tabular-nums;
}

.report-counter.over { color: var(--danger); }

.report-submit {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: var(--radius-sm);
  padding: var(--space-4) var(--space-7);
  font-family: var(--font);
  font-size: var(--text-sm);
  font-weight: var(--weight-semi);
  cursor: pointer;
  box-shadow: var(--rim);
  transition: background var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}

.report-submit:hover:not(:disabled) { background: var(--accent-hover); }
.report-submit:active:not(:disabled) { transform: translateY(1px); }
.report-submit:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

/* Bug mode swaps the accent for the danger hue across the whole dialog, so the
   two report types are distinguishable at a glance. */
.report-modal--bug {
  --accent: var(--danger);
  --accent-hover: color-mix(in oklab, var(--danger) 85%, white);
  --accent-contrast: var(--n-950);
  --accent-soft: var(--danger-soft);
  --border-accent: color-mix(in oklab, var(--danger) 45%, transparent);
}

@media (max-width: 560px) {
  .report-backdrop { padding: 0; align-items: stretch; }
  .report-modal { width: 100%; max-height: 100%; border-radius: 0; border: none; }
}

/* ── World Search Settings ──────────────────────────────────────────────── */

.search-config-input {
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  tab-size: 2;
}
.search-config-input:focus {
  outline: none;
  border-color: var(--accent);
}

.search-config-error {
  display: none;
  margin: 6px 0 0;
  color: var(--accent);
  font-size: 11px;
  font-family: var(--font-mono);
  white-space: pre-wrap;
}

.block-codes-filter {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  margin-bottom: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
}
.block-codes-filter:focus {
  outline: none;
  border-color: var(--accent);
}

.block-codes-list {
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

.bc-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 2px 8px;
  border-bottom: 1px solid var(--border);
}
.bc-row:last-child { border-bottom: none; }

.bc-cat {
  flex: 0 0 auto;
  min-width: 70px;
  color: var(--text-dim);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.bc-code {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text);
  word-break: break-all;
}

/* Captured (merged-name) portion of a matched block code. */
.bc-cap {
  color: var(--success);
  font-weight: var(--weight-semi);
}

/* Codes no category matches are dimmed so matches stand out. */
.bc-unmatched .bc-code { color: var(--text-dim); opacity: 0.7; }
