:root {
  --parchment: #f3e9d2;
  --parchment-deep: #e8d9b8;
  --ink: #2b2116;
  --ink-soft: #55452f;
  --gold: #b8860b;
  --gold-soft: #d4af6a;
  --panel: #241b10;
  --panel-line: #3c2f1d;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: 'Alegreya', Georgia, serif;
  color: var(--ink);
  background: var(--panel);
}

.terrain-main {
  position: absolute;
  inset: 0 0 0 300px;
}

#map {
  width: 100%;
  height: 100%;
  background: var(--parchment-deep);
}

/* Sidebar */
.terrain-sidebar {
  position: absolute;
  inset: 0 auto 0 0;
  width: 300px;
  background: linear-gradient(180deg, #2a2013, var(--panel));
  border-right: 2px solid var(--gold);
  display: flex;
  flex-direction: column;
  z-index: 1100;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--panel-line);
}

.sidebar-title {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  color: var(--gold-soft);
}

.lang-toggle {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--parchment);
  background: transparent;
  border: 1px solid var(--gold);
  border-radius: 4px;
  padding: 4px 10px;
  cursor: pointer;
}
.lang-toggle:hover { background: var(--gold); color: var(--panel); }

.sidebar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 14px;
  padding: 7px 10px;
  background: rgba(243, 233, 210, 0.08);
  border: 1px solid var(--panel-line);
  border-radius: 6px;
  color: var(--gold-soft);
}
.sidebar-search input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--parchment);
  font-family: inherit;
  font-size: 0.95rem;
}
.sidebar-search input::placeholder { color: rgba(243, 233, 210, 0.45); }

.category-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--gold) transparent;
}

.cat-section { margin-bottom: 6px; }

.cat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--parchment);
  font-family: 'Cinzel', serif;
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  padding: 9px 8px;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
}
.cat-head:hover { background: rgba(243, 233, 210, 0.07); }
.cat-head > span:first-of-type { flex: 1; }
.cat-head .bx { font-size: 1.15rem; }

.cat-count {
  font-family: 'Alegreya', serif;
  font-size: 0.75rem;
  color: var(--gold-soft);
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  padding: 1px 8px;
}

.cat-eye { color: rgba(243, 233, 210, 0.5); }
.cat-off > .cat-head { opacity: 0.45; }

.cat-items {
  list-style: none;
  margin: 0;
  padding: 0 0 4px 34px;
}
.cat-items a {
  display: block;
  color: rgba(243, 233, 210, 0.85);
  text-decoration: none;
  font-size: 0.95rem;
  padding: 4px 8px;
  border-radius: 4px;
}
.cat-items a:hover { color: var(--gold-soft); background: rgba(243, 233, 210, 0.06); }
.cat-off > .cat-items { display: none; }

.cat-empty {
  color: rgba(243, 233, 210, 0.6);
  font-style: italic;
  padding: 16px;
}

.sidebar-foot {
  padding: 10px 16px;
  border-top: 1px solid var(--panel-line);
  color: rgba(243, 233, 210, 0.45);
  font-size: 0.78rem;
  font-style: italic;
}

/* Markers */
.terrain-pin-wrap { background: transparent; border: none; }

.terrain-pin {
  --pin: var(--gold);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: var(--parchment);
  border: 2px solid var(--pin);
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.terrain-pin .bx {
  transform: rotate(45deg);
  font-size: 1.05rem;
  color: var(--pin);
}

/* Popup */
.leaflet-popup-content-wrapper {
  background: var(--parchment);
  color: var(--ink);
  border: 2px solid var(--gold);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.leaflet-popup-tip { background: var(--gold); }
.leaflet-popup-content { margin: 12px 14px; }

.terrain-popup .tp-img-link { display: block; margin: -4px -4px 8px; }
.terrain-popup .tp-img {
  display: block;
  width: 100%;
  max-height: 150px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--gold-soft);
}
.terrain-popup .tp-name {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink);
  margin-bottom: 4px;
}
.terrain-popup .tp-desc {
  font-size: 0.9rem;
  color: var(--ink-soft);
  line-height: 1.35;
}
.terrain-popup .tp-link {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-top: 8px;
  color: var(--gold);
  font-weight: 600;
  text-decoration: none;
  font-size: 0.88rem;
}
.terrain-popup .tp-link:hover { text-decoration: underline; }

/* Coord picker badge */
.coord-badge {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  color: var(--gold-soft);
  border: 1px solid var(--gold);
  border-radius: 6px;
  padding: 8px 14px;
  font-family: 'Cinzel', serif;
  font-size: 0.85rem;
  z-index: 1200;
  white-space: pre;
}

/* Mobile drawer */
.drawer-toggle {
  display: none;
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 1300;
  width: 44px;
  height: 44px;
  background: var(--panel);
  border: 2px solid var(--gold);
  border-radius: 8px;
  color: var(--gold-soft);
  font-size: 1.4rem;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}

@media (max-width: 820px) {
  .terrain-main { inset: 0; }
  .drawer-toggle { display: flex; }
  .terrain-sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    width: min(300px, 85vw);
    box-shadow: 4px 0 18px rgba(0, 0, 0, 0.5);
  }
  .terrain-sidebar.open { transform: translateX(0); }
}

@media (prefers-reduced-motion: reduce) {
  .terrain-sidebar { transition: none; }
}

/* Subcategories */
.cat-sub { margin-left: 14px; border-left: 1px solid var(--panel-line); }
.cat-sub-head { font-size: 0.78rem; padding: 7px 8px; }
.cat-sub-off .cat-items { display: none; }
.cat-sub-off .cat-sub-head { opacity: 0.45; }

/* Free-standing custom icon pins: no bubble, silhouette highlight in the category color */
.terrain-pin-free {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
}
.terrain-pin-free .pin-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter:
    drop-shadow(1px 0 0 var(--pin))
    drop-shadow(-1px 0 0 var(--pin))
    drop-shadow(0 1px 0 var(--pin))
    drop-shadow(0 -1px 0 var(--pin))
    drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35));
}

/* Guild block in popups */
.tp-guild {
  margin-top: 10px;
  padding: 10px 12px;
  background: rgba(184, 134, 11, 0.08);
  border: 1px solid var(--gold-soft);
  border-radius: 6px;
}
.tp-guild-name {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--gold);
  margin-bottom: 6px;
}
.tp-guild-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.92rem;
  padding: 2px 0;
}
.tp-guild-label {
  font-family: 'Cinzel', serif;
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  padding-top: 2px;
}
.tp-guild-value {
  color: var(--ink);
  font-weight: 600;
  text-align: right;
}

/* Larger popups */
.terrain-popup .tp-img {
  max-height: 42vh;
  height: auto;
}
.terrain-popup .tp-img-link { margin: -6px -6px 12px; }
.terrain-popup .tp-name { font-size: 1.3rem; margin-bottom: 6px; }
.terrain-popup .tp-desc { font-size: 1.05rem; line-height: 1.45; }
.terrain-popup .tp-link { font-size: 1rem; margin-top: 12px; }
.tp-guild-row { font-size: 1rem; padding: 3px 0; }
.tp-guild-label { font-size: 0.8rem; }
.tp-guild-name { font-size: 1.05rem; }
.leaflet-popup-content { margin: 16px 18px; }

/* Tall popups scroll instead of clipping offscreen */
.leaflet-popup-content {
  max-height: 68vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--gold) transparent;
}

.terrain-popup .tp-web { margin-left: 14px; }
.terrain-popup .tp-web .bx { vertical-align: middle; }

/* Artist credit */
.artist-credit {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  color: var(--gold-soft);
  font-family: 'Cinzel', serif;
  font-size: 0.8rem;
  font-style: normal;
  line-height: 1.4;
  margin-bottom: 6px;
}
.artist-credit .bx {
  font-size: 1rem;
  margin-top: 1px;
  flex-shrink: 0;
}

.map-credit {
  position: absolute;
  bottom: 10px;
  right: 10px;
  z-index: 1000;
  background: rgba(36, 27, 16, 0.85);
  color: var(--gold-soft);
  border: 1px solid var(--gold);
  border-radius: 6px;
  padding: 5px 10px;
  font-family: 'Cinzel', serif;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  pointer-events: none;
}

@media (max-width: 820px) {
  .map-credit { font-size: 0.65rem; bottom: 8px; right: 8px; }
}

/* Event schedule in popups */
.tp-events {
  margin-top: 10px;
  padding: 10px 12px;
  background: rgba(43, 33, 22, 0.05);
  border: 1px solid var(--gold-soft);
  border-radius: 6px;
}
.tp-events-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink);
  margin-bottom: 6px;
}
.tp-event {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 3px 0;
  font-size: 0.98rem;
  border-bottom: 1px dashed rgba(85, 69, 47, 0.25);
}
.tp-event:last-child { border-bottom: none; }
.tp-event-title { color: var(--ink); font-weight: 600; }
.tp-event-when {
  color: var(--ink-soft);
  white-space: nowrap;
  text-align: right;
}

/* Marker suggestions */
.suggest-box { padding: 10px 14px 0; }
.btn-suggest {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  padding: 9px;
  background: var(--gold);
  border: none;
  border-radius: 6px;
  color: #fff;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
}
.btn-suggest:hover { filter: brightness(1.08); }
.suggest-login {
  display: block;
  text-align: center;
  color: var(--gold-soft);
  font-size: 0.85rem;
  text-decoration: none;
  padding: 6px;
  border: 1px dashed var(--panel-line);
  border-radius: 6px;
}
.suggest-login:hover { border-color: var(--gold); }

.suggest-cursor { cursor: crosshair; }
.pin-suggest { border-style: dashed; }

.suggest-panel {
  position: absolute;
  top: 14px;
  right: 14px;
  width: min(340px, calc(100vw - 28px));
  max-height: calc(100% - 28px);
  display: flex;
  flex-direction: column;
  background: var(--parchment);
  border: 2px solid var(--gold);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  z-index: 1150;
  overflow: hidden;
}
.suggest-panel[hidden] { display: none; }

.suggest-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--gold);
  color: #fff;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 0.88rem;
}
.suggest-head button {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1.3rem;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}

.suggest-body { padding: 12px 14px 14px; overflow-y: auto; }
.s-field { display: block; margin-bottom: 10px; }
.s-field > span {
  display: block;
  font-family: 'Cinzel', serif;
  font-size: 0.72rem;
  color: var(--ink-soft);
  margin-bottom: 3px;
  letter-spacing: 0.03em;
}
.s-field input,
.s-field select,
.s-field textarea {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid var(--gold-soft);
  border-radius: 5px;
  background: #fffdf7;
  font-family: 'Alegreya', serif;
  font-size: 0.95rem;
  color: var(--ink);
  box-sizing: border-box;
}
.s-field textarea { resize: vertical; }

.suggest-msg {
  border-radius: 5px;
  padding: 7px 9px;
  font-size: 0.88rem;
  margin-bottom: 10px;
}
.suggest-msg.ok { background: #e3ecd9; border: 1px solid #6b7d5a; color: #3d4a31; }
.suggest-msg.err { background: #f6dcd7; border: 1px solid #b2503d; color: #7c2f20; }

.btn-suggest-send {
  width: 100%;
  padding: 9px;
  background: var(--gold);
  border: none;
  border-radius: 6px;
  color: #fff;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 0.84rem;
  cursor: pointer;
}
.btn-suggest-send:hover { filter: brightness(1.08); }

@media (max-width: 820px) {
  .suggest-panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 62vh;
    border-radius: 12px 12px 0 0;
    border-bottom: none;
  }
}

/* Site navigation bar */
.site-nav {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  background: linear-gradient(180deg, #2f2415, #241b10);
  border-bottom: 2px solid var(--gold);
  z-index: 1400;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}

.nav-brand {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--parchment);
  text-decoration: none;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}
.nav-brand span { color: var(--gold-soft); }

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  height: 100%;
}
.nav-links::-webkit-scrollbar { display: none; }

.nav-link {
  font-family: 'Cinzel', serif;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: rgba(243, 233, 210, 0.75);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 5px;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.nav-link:hover {
  color: var(--gold-soft);
  background: rgba(243, 233, 210, 0.07);
}
.nav-active {
  color: var(--gold-soft);
  border-bottom-color: var(--gold);
}

/* Layout offsets when the nav bar is present */
.has-nav .terrain-sidebar { top: 52px; }
.has-nav .terrain-main { top: 52px; }

@media (max-width: 820px) {
  .has-nav .drawer-toggle { top: 64px; }
  .nav-brand { font-size: 1rem; }
}
