/* Theme values are injected as CSS custom properties on :root from config/ui.json. */
:root {
  --background: #0b1220;
  --accent: #c8a24a;
  --text: #e8e4d8;
  --muted: #9aa3b2;
  --panel: rgba(10, 14, 24, 0.92);
  --border: rgba(200, 162, 74, 0.4);
  --font-body: "Inter", -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-heading: "Cinzel", Georgia, "Iowan Old Style", "Times New Roman", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--background);
  color: var(--text);
  font-family: var(--font-body);
  overflow: hidden;
}

#map {
  position: fixed;
  inset: 0;
  background: var(--background);
}

.leaflet-container {
  background: var(--background);
  font: inherit;
  outline: none;
}

/* ---- Overlays ---- */
.overlay { position: fixed; z-index: 1000; }

.top-left {
  top: calc(10px + env(safe-area-inset-top));
  left: calc(10px + env(safe-area-inset-left));
}

.bottom-left {
  bottom: calc(10px + env(safe-area-inset-bottom));
  left: calc(10px + env(safe-area-inset-left));
}

/* Bottom-right sits above the Leaflet zoom bar (bottomright): two 32px
   buttons + border + 10px margin ≈ 78px, so 88px clears it. */
.bottom-right {
  bottom: calc(88px + env(safe-area-inset-bottom));
  right: calc(10px + env(safe-area-inset-right));
}

.fullscreen {
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--background);
  color: var(--muted);
  font-size: 16px;
  letter-spacing: 0.05em;
  padding: 0 24px;
  text-align: center;
}

#loading.error { color: #e06c60; }

/* ---- World switcher ---- */
#world-switcher {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

#world-switcher .ws-label {
  font-family: var(--font-heading);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 4px 2px;
}

#world-switcher button {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 12px;
  min-height: 36px;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
}

#world-switcher button:hover { border-color: var(--border); }

#world-switcher button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #16130a;
  font-weight: bold;
}

#world-switcher button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---- Footer credit ---- */
#footer {
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

#footer a { color: var(--accent); text-decoration: none; }
#footer a:hover { text-decoration: underline; }

/* ---- '+ Request' entry button ---- */
#request-btn {
  display: inline-block;
  background: var(--panel);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  font-family: var(--font-heading);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

#request-btn:hover {
  background: var(--accent);
  color: #16130a;
}

#request-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- Leaflet chrome, themed ---- */
.leaflet-bar {
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45) !important;
  overflow: hidden;
}

.leaflet-bar a {
  background: var(--panel) !important;
  color: var(--text) !important;
  border-bottom: 1px solid var(--border) !important;
  width: 32px !important;
  height: 32px !important;
  line-height: 32px !important;
}

.leaflet-bar a:last-child { border-bottom: none !important; }
.leaflet-bar a:hover { background: var(--accent) !important; color: #16130a !important; }

/* ---- Marker pins ---- */
.wow-pin-wrap { background: none; border: none; }

/* Fallback definition of the icon-font helper class (the Google Fonts CDN
   stylesheet in index.html defines it too; keep both in sync). */
.material-symbols-rounded {
  font-family: "Material Symbols Rounded";
  font-weight: normal;
  font-style: normal;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-smoothing: antialiased;
}

.wow-pin {
  width: 28px;
  height: 28px;
  background: var(--pin-color, #c8a24a);
  border: 2px solid #fff;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Glyph inside the teardrop, counter-rotated so it reads upright.
   The leading translate() compensates the icon font's optical offset.
   Because the pin itself is rotated -45deg, a translate on the glyph is
   conjugated by that rotation, so the values below are NOT plain screen
   offsets — they were solved from measured screen-space offsets
   (translate(t) on the glyph moves it by rotate(-45deg)·t on screen).
   Verified by pixel-measuring rendered pins in headless Chrome. */
.wow-pin-glyph {
  transform: translate(1.01px, -1.45px) rotate(45deg);
  font-size: 17px;
  color: var(--pin-glyph-color, #fff);
  user-select: none;
}

/* ---- Popups ---- */
.leaflet-popup-content-wrapper {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.leaflet-popup-content {
  margin: 10px 14px;
  font: inherit;
  font-size: 14px;
  line-height: 1.45;
  max-width: min(300px, 76vw) !important;
}

.leaflet-popup-content strong {
  color: var(--accent);
  font-family: var(--font-heading);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.leaflet-popup-content p { margin: 6px 0 0; }

/* ---- Popup card ---- */
.wow-popup {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.wow-popup-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.wow-popup-badge {
  flex: none;
  width: 34px;
  height: 34px;
  border: 1.5px solid var(--pin-color, var(--accent));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--pin-color, var(--accent));
}

.wow-popup-badge .material-symbols-rounded { font-size: 18px; }

.wow-popup-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.wow-popup-title strong {
  color: var(--accent);
  font-family: var(--font-heading);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.wow-popup-owner {
  color: var(--muted);
  font-size: 12px;
}

.wow-popup-desc { margin: 0; }

.wow-popup-ic {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

.wow-popup-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--pin-color, var(--accent));
}

.wow-popup-label .material-symbols-rounded { font-size: 13px; }

.wow-popup-ic-text { margin-top: 4px; font-weight: bold; }

.wow-popup-divider { border-top: 1px dashed var(--border); }

.wow-popup-ooc {
  display: flex;
  align-items: center;
  gap: 8px;
}

.wow-ooc-chip {
  flex: none;
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
}

.wow-popup-ooc-text { font-size: 13px; }

.leaflet-popup-tip {
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: none;
}

.leaflet-popup-close-button { color: var(--muted) !important; }

/* ---- Request page (request/index.html) ---- */
.top-center {
  top: calc(10px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
}

#live-preview {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  white-space: nowrap;
}

#request-panel {
  width: 340px;
  max-width: calc(100vw - 20px);
  max-height: calc(100% - 20px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#request-panel h1 {
  font-family: var(--font-heading);
  font-size: 20px;
  font-weight: 700;
  margin: 0;
}

#request-panel .panel-sub {
  margin: 2px 0 8px;
  font-size: 12px;
  color: var(--muted);
}

#marker-form label,
#marker-form legend,
#marker-form .picks-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 10px 0 4px;
  padding: 0;
}

#marker-form label .counter {
  float: right;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}

#marker-form input[type="text"],
#marker-form textarea,
#marker-form select,
#colour-hex {
  width: 100%;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
}

#marker-form textarea { resize: vertical; }

#marker-form input:focus,
#marker-form textarea:focus,
#marker-form select:focus,
#colour-hex:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: var(--accent);
}

#marker-form fieldset {
  border: none;
  margin: 0;
  padding: 0;
}

#icon-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
}

.icon-btn .material-symbols-rounded { font-size: 20px; }
.icon-btn:hover { border-color: var(--accent); }
.icon-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #16130a;
}
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

#colour-picker {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}

.swatch.active {
  border-color: #fff;
  box-shadow: 0 0 0 2px var(--accent);
}

.swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Native colour wheel (opens the OS colour picker). Deliberately styled as a
   rounded SQUARE, unlike the circular premade swatches, so custom vs preset
   is clear at a glance (matches the design mockup). */
#colour-wheel {
  width: 32px;
  height: 32px;
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

#colour-wheel::-webkit-color-swatch-wrapper { padding: 3px; }
#colour-wheel::-webkit-color-swatch { border: none; border-radius: 5px; }
#colour-wheel::-moz-color-swatch { border: none; border-radius: 5px; }
#colour-wheel:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#colour-hex {
  margin-top: 8px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  text-transform: lowercase;
}

#colour-hex.invalid { border-color: #e06c60; }

.colour-selected {
  margin-top: 4px;
  font-size: 11px;
  color: var(--muted);
  font-family: ui-monospace, Menlo, Consolas, monospace;
}

#json-details {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
}

#json-details summary {
  cursor: pointer;
  padding: 7px 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  user-select: none;
}

#json-preview {
  margin: 0;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 180px;
  overflow: auto;
}

#steps-heading {
  margin: 0 0 4px; /* first element in the form: instructions on top */
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

#request-steps {
  margin: 0;
  padding-left: 18px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--muted);
}

#request-steps li { margin: 2px 0; }

.hint {
  min-height: 16px;
  margin: 10px 0 0;
  font-size: 12px;
  color: var(--accent);
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  border: 1px solid var(--border);
}

.btn-primary {
  flex: 1;
  background: var(--accent);
  border-color: var(--accent);
  color: #16130a;
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary:not(:disabled):hover { filter: brightness(1.12); }
.btn-primary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-ghost {
  background: transparent;
  color: var(--text);
}

.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

.btn-block { width: 100%; }

/* Live-preview pin: same teardrop as real pins plus a pulsing ring. */
.wow-pin.preview-pin {
  animation: preview-pulse 1.6s ease-in-out infinite;
}

/* Ghost pin: the world position projected onto a zone layer when that zone
   has no own pick yet — dimmed, no pulse. */
.wow-pin.ghost-pin {
  opacity: 0.55;
}

/* Zone layers picked so far (each becomes a `layers` entry in the JSON). */
#zone-picks {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

#zone-picks li {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 4px 3px 10px;
}

.zone-pick-remove {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 50%;
}

.zone-pick-remove:hover { color: #e06c60; }
.zone-pick-remove:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

@keyframes preview-pulse {
  0%, 100% { box-shadow: 0 1px 6px rgba(0, 0, 0, 0.65), 0 0 0 0 rgba(200, 162, 74, 0.75); }
  50% { box-shadow: 0 1px 6px rgba(0, 0, 0, 0.65), 0 0 0 10px rgba(200, 162, 74, 0); }
}

/* ---- Result modal ---- */
#result-modal {
  z-index: 2000;
  background: rgba(4, 7, 13, 0.72);
  padding: 20px;
}

#result-modal[hidden] { display: none; }

.modal-card {
  width: min(560px, 100%);
  max-height: calc(100% - 40px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.modal-card h2 {
  font-family: var(--font-heading);
  font-size: 18px;
  margin: 0 0 10px;
}

#snippet-pre {
  margin: 0;
  padding: 10px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: auto;
  max-height: 46vh;
}

#snippet-pre code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre;
}

#snippet-copy {
  width: 100%;
  margin-top: 10px;
  padding: 11px;
  font-size: 15px;
}

#discord-hint {
  margin: 12px 0;
  font-size: 13px;
  line-height: 1.5;
}

#modal-close { margin-top: 4px; }

/* ---- Small screens ---- */
@media (max-width: 640px) {
  #world-switcher {
    flex-direction: row;
    align-items: center;
    gap: 2px;
    padding: 6px;
  }

  #world-switcher .ws-label { display: none; }

  #world-switcher button {
    font-size: 13px;
    padding: 6px 10px;
    min-height: 40px;
  }

  #footer {
    font-size: 11px;
    max-width: 62vw;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .leaflet-bar a {
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
  }

  /* zoom bar is taller (2 × 36px) on small screens */
  .bottom-right {
    bottom: calc(96px + env(safe-area-inset-bottom));
  }

  #request-btn {
    font-size: 14px;
    padding: 9px 13px;
  }

  #request-panel {
    left: calc(8px + env(safe-area-inset-left));
    right: calc(8px + env(safe-area-inset-right));
    width: auto;
    max-width: none;
    max-height: 52%;
    padding: 12px;
  }

  .modal-card { padding: 12px; }
}
