:root {
  --bg: #0d0f11;
  --bar: #1c2126;
  --bar-line: #2b3238;
  --ink: #e6e9ec;
  --ink-dim: #97a1aa;
  --accent: #b8452f;
  --accent-soft: #d9634b;
  --field: #12151800;
  color-scheme: dark;
}

/* Same UI font the game itself uses (Noto Sans SemiBold, per the .fnt
   descriptors in media/fonts/EN — the game has no standalone .ttf, it bakes
   this into a bitmap font). Self-hosted, same reasoning as vendoring
   OpenSeadragon: no CDN request for something this small and static. */
@font-face {
  font-family: "Noto Sans";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../vendor/fonts/NotoSans-SemiBold-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122;
}
@font-face {
  font-family: "Noto Sans";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("../vendor/fonts/NotoSans-SemiBold-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-024F, U+0300-036F, U+1E00-1EFF, U+2020, U+2113;
}

* { box-sizing: border-box; }

/* Any rule below that sets `display` on an element ties the [hidden]
   attribute in specificity and, being later in the stylesheet, would win and
   make the element visible anyway (happened to .panel and .editor, both
   `display: flex`/`grid`). Force the attribute to always win instead. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.4 "Noto Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
}

/* ---------- top bar ---------- */

.bar {
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 20;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  background: linear-gradient(var(--bar), color-mix(in srgb, var(--bar) 88%, transparent));
  border-bottom: 1px solid var(--bar-line);
  backdrop-filter: blur(6px);
}

.brand {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: .3px;
  white-space: nowrap;
  display: flex;
  align-items: baseline;
  gap: 9px;
}

.brand-sub {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--accent-soft);
}

/* ---------- search ---------- */

.search { position: relative; flex: 1; max-width: 420px; }

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  width: 15px;
  height: 15px;
  transform: translateY(-50%);
  color: var(--ink-dim);
  pointer-events: none;
}

.search input {
  width: 100%;
  height: 34px;
  padding: 0 12px 0 32px;
  border: 1px solid var(--bar-line);
  border-radius: 6px;
  background: #11151a;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}

.search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.results {
  position: absolute;
  top: 40px;
  left: 0;
  right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  max-height: 320px;
  overflow-y: auto;
  background: #171c21;
  border: 1px solid var(--bar-line);
  border-radius: 6px;
  box-shadow: 0 12px 28px #0009;
}

.results li {
  padding: 7px 10px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.results li:hover,
.results li[aria-selected="true"] { background: #232a31; }

.results .kind {
  font-size: 10px;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--ink-dim);
  flex: none;
}

.results .empty { color: var(--ink-dim); cursor: default; }
.results .empty:hover { background: none; }

/* ---------- buttons ---------- */

.tools { margin-left: auto; display: flex; align-items: center; gap: 6px; }

.btn {
  height: 34px;
  padding: 0 13px;
  border: 1px solid var(--bar-line);
  border-radius: 8px;
  background: #1a1f25;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease, transform .06s ease;
}

.btn:hover { background: #232a31; border-color: #3a444d; }
.btn:active { transform: scale(.96); }
.btn[aria-pressed="false"] { color: var(--ink-dim); }
.btn-sm { height: 27px; padding: 0 10px; font-size: 12px; border-radius: 6px; }

.layers { display: flex; gap: 4px; }
.layers .btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Each toolbar control is its own distinct pill button — icon plus a short
   label where there's room, icon alone where space is tight (zoom cluster). */
.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.icon-btn svg { width: 16px; height: 16px; flex: none; }
.icon-btn[aria-pressed="false"] svg,
.icon-btn[aria-expanded="false"] svg { opacity: .75; }

.icon-btn.on,
.icon-btn[aria-pressed="true"],
.icon-btn[aria-expanded="true"] {
  background: color-mix(in srgb, var(--accent) 16%, #1a1f25);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--bar-line));
  color: #fff;
}

.icon-only {
  width: 34px;
  padding: 0;
  display: grid;
  place-items: center;
}
.icon-only.btn-sm { width: 27px; }

.tools-sep {
  width: 1px;
  height: 20px;
  margin: 0 2px;
  background: var(--bar-line);
}

/* ---------- map ---------- */

/* --bar-h is measured in JS: the bar wraps to two rows on narrow screens */
/* Pure black, not --bg. The renderer fills everything outside the isometric
   diamond with #000, so any other shade here draws a visible rectangle around
   the pyramid showing exactly where the image stops. Matching it makes the
   edge of the map disappear into the void. */
.map {
  position: absolute;
  inset: var(--bar-h, 56px) 0 0 0;
  background: #000;
}

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

/* ---------- labels ---------- */

.lbl {
  position: absolute;
  transform: translate(-50%, -50%);
  white-space: pre;
  text-align: center;
  pointer-events: none;
  user-select: none;
  font-weight: 700;
  letter-spacing: .6px;
  text-shadow:
     0 0 4px #000, 0 0 4px #000,
     1px 1px 2px #000, -1px 1px 2px #000,
     1px -1px 2px #000, -1px -1px 2px #000;
  transition: opacity .18s ease;
}

.lbl-town   { color: #fff;    font-size: 19px; letter-spacing: 2.2px; }
.lbl-poi    { color: #f2e6d8; font-size: 12px; font-weight: 600; }
.lbl-nature { color: #a8c69a; font-size: 13px; letter-spacing: 1.2px; }
.lbl-water  { color: #8fb6d1; font-size: 13px; letter-spacing: 1.6px; font-style: italic; }

.lbl-hidden { opacity: 0; }

.pin {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px #0008, 0 2px 6px #000a;
  pointer-events: none;
  animation: ping 1.4s ease-out 3;
}

@keyframes ping {
  0%   { transform: scale(1);   box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 70%, transparent); }
  70%  { transform: scale(1.1); box-shadow: 0 0 0 14px transparent; }
  100% { transform: scale(1);   box-shadow: 0 0 0 0 transparent; }
}

/* ---------- status bar ---------- */

.status {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px 5px 11px;
  background: #171c21e0;
  border: 1px solid var(--bar-line);
  border-radius: 6px;
  backdrop-filter: blur(4px);
}

.coords {
  font: 12px/1 ui-monospace, "Cascadia Mono", Consolas, monospace;
  color: var(--ink-dim);
  min-width: 118px;
}

.loading {
  position: absolute;
  left: 50%;
  top: calc(var(--bar-h, 56px) + 50%);
  transform: translate(-50%, -50%);
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: #171c21e6;
  border: 1px solid var(--bar-line);
  border-radius: 8px;
  color: var(--ink-dim);
  font-size: 13px;
  pointer-events: none;
  transition: opacity .3s ease;
}

.loading.done { opacity: 0; }

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid #ffffff26;
  border-top-color: var(--accent-soft);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 3s; }
  .pin { animation: none; }
}

.err {
  position: absolute;
  inset: var(--bar-h, 56px) 0 0 0;
  z-index: 30;
  display: grid;
  place-content: center;
  gap: 10px;
  text-align: center;
  padding: 24px;
  color: var(--ink-dim);
  pointer-events: none;
}

.err code {
  display: block;
  margin-top: 6px;
  padding: 8px 10px;
  background: #11151a;
  border: 1px solid var(--bar-line);
  border-radius: 5px;
  font-size: 12px;
  color: var(--ink);
  word-break: break-all;
}

/* ---------- markers panel ---------- */

.panel {
  position: absolute;
  top: var(--bar-h, 56px);
  right: 0;
  bottom: 0;
  z-index: 18;
  width: 310px;
  display: flex;
  flex-direction: column;
  background: #171c21f2;
  border-left: 1px solid var(--bar-line);
  backdrop-filter: blur(6px);
}

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

.panel-head h2 { margin: 0; font-size: 14px; letter-spacing: .4px; }

.panel-body { padding: 14px; overflow-y: auto; flex: 1; }
.panel-body h3 {
  margin: 20px 0 8px;
  font-size: 11px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.panel-body section:first-of-type h3 { margin-top: 20px; }

.btn-wide { width: 100%; justify-content: center; }

/* A full-width action that should read as secondary to Add Marker: same shape,
   less weight. Leaving a group is not destructive -- the code still works --
   so it stays a normal button rather than a warning-coloured one, and only
   picks up a warmer tone on hover. */
.btn-thin {
  height: 28px;
  font-size: 12px;
  margin-top: 10px;
}

#group-leave:hover {
  background: #3a2320;
  border-color: #6b3a33;
  color: #e8a294;
}
.btn-quiet { background: none; color: var(--ink-dim); }
.btn-quiet:hover { background: #232a31; color: var(--ink); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-soft); border-color: var(--accent-soft); }
.btn-primary svg { color: #fff; }
.btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.hint { margin: 8px 0; font-size: 12px; line-height: 1.45; color: var(--ink-dim); }
.hint.bad { color: #e08b7c; }

/* Marks the joined state as a state, not another form to fill in. */
.joined {
  margin: 10px 0 12px;
  padding: 8px 10px;
  border-left: 2px solid var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border-radius: 0 5px 5px 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--ink);
}

.mini {
  display: block;
  margin: 10px 0 3px;
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.group-row { display: flex; gap: 6px; align-items: center; margin: 8px 0; }
.group-row input {
  flex: 1;
  min-width: 0;
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--bar-line);
  border-radius: 5px;
  background: #11151a;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}
.group-row input:focus { outline: none; border-color: var(--accent); }
.group-row code {
  flex: 1;
  padding: 6px 9px;
  background: #11151a;
  border: 1px solid var(--bar-line);
  border-radius: 5px;
  font: 13px/1.2 ui-monospace, Consolas, monospace;
  color: var(--accent-soft);
  word-break: break-all;
}

.marker-list { list-style: none; margin: 0; padding: 0; }
.marker-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-bottom: 1px solid #ffffff0d;
}
.marker-list li.empty { color: var(--ink-dim); font-size: 12px; border: 0; }

.swatch {
  position: relative;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex: none;
}

.swatch .mk-glyph {
  left: 50%;
  top: 50%;
  width: 11px;
  height: 11px;
  margin: -5.5px 0 0 -5.5px;
}

/* ---------- icon picker ---------- */

.icons {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}

.icon-chip {
  position: relative;
  height: 30px;
  border: 1px solid var(--bar-line);
  border-radius: 6px;
  background: #11151a;
  cursor: pointer;
  padding: 0;
}

.icon-chip:hover { background: #232a31; }

.icon-chip.on {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 22%, #11151a);
}

.icon-chip .mk-glyph {
  left: 50%;
  top: 50%;
  width: 17px;
  height: 17px;
  margin: -8.5px 0 0 -8.5px;
  background: var(--ink-dim);
}

.icon-chip:hover .mk-glyph,
.icon-chip.on .mk-glyph { background: #fff; }

/* "no icon" chip: a plain dot, so the absence reads as a choice */
.icon-chip.icon-none::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  background: var(--ink-dim);
}

.icon-chip.icon-none:hover::after,
.icon-chip.icon-none.on::after { background: #fff; }

.mk-name {
  flex: 1;
  min-width: 0;
  text-align: left;
  background: none;
  border: 0;
  padding: 0;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mk-name:hover { color: var(--accent-soft); }

.mk-del {
  flex: none;
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--ink-dim);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.mk-del:hover { background: #3a2320; color: #e08b7c; }

/* ---------- markers on the map ---------- */

.mk {
  position: absolute;
  display: flex;
  /* tag above, pin below, so the pin's tip (not its center) lands on the
     exact coordinate */
  flex-direction: column-reverse;
  align-items: center;
  gap: 2px;
  transform: translate(-50%, -100%);
  cursor: pointer;
  pointer-events: auto;
}

/* Same pin silhouette the game uses for its own foraging map markers
   (media/textures/Foraging/pinIconBlank.png), recolored per marker.
   The shape lives on ::before rather than on .mk-dot itself: a CSS mask
   applies to an element's children too, so masking .mk-dot directly would
   clip the glyph inside it to the pin outline. */
.mk-dot {
  position: relative;
  display: block;
  width: 22px;
  height: 33px;
}

.mk-dot::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--pin, var(--accent));
  -webkit-mask: url("../img/pin.png") center / contain no-repeat;
          mask: url("../img/pin.png") center / contain no-repeat;
  filter: drop-shadow(0 2px 3px #000b) drop-shadow(0 0 3px #0009);
}

/* Centred on the pin's head, which is the top ~2/3 of the teardrop */
.mk-glyph {
  position: absolute;
  left: 50%;
  top: 3px;
  width: 15px;
  height: 15px;
  margin-left: -7.5px;
  background: var(--ink, #fff);
  -webkit-mask: center / contain no-repeat;
          mask: center / contain no-repeat;
}

.mk-group .mk-dot { opacity: .85; }

/* ---------- clusters ---------- */

.mk-cluster { transform: translate(-50%, -50%); }

.mk-cluster-dot {
  display: grid;
  place-items: center;
  min-width: 26px;
  height: 26px;
  padding: 0 7px;
  border: 2px solid #fff;
  border-radius: 13px;
  background: var(--accent);
  box-shadow: 0 0 0 1.5px #0009, 0 2px 6px #000a;
  font-size: calc(12px * var(--mk-scale, 1));
  font-weight: 700;
  color: #fff;
  line-height: 1;
}

.mk-cluster:hover .mk-cluster-dot { background: var(--accent-soft); }

/* Always shown. Names used to disappear when zoomed out, which hid exactly
   the information the marker exists to carry; they shrink with the place
   names instead (--mk-scale, set from PZMap.labelScale). */
.mk-tag {
  font-size: calc(11px * var(--mk-scale, 1));
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  text-shadow: 0 0 3px #000, 0 0 3px #000, 1px 1px 2px #000;
}

/* ---------- editor dialog ---------- */

.editor {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: #0009;
  backdrop-filter: blur(2px);
}

.editor-box {
  width: min(340px, calc(100vw - 32px));
  padding: 18px;
  background: #1b2127;
  border: 1px solid var(--bar-line);
  border-radius: 10px;
  box-shadow: 0 20px 50px #000b;
}

.editor-box h3 { margin: 0 0 14px; font-size: 15px; }

.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block;
  margin-bottom: 6px;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.field input {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--bar-line);
  border-radius: 6px;
  background: #11151a;
  color: var(--ink);
  font: inherit;
}
.field input:focus { outline: none; border-color: var(--accent); }

.colors { display: flex; gap: 8px; }
.chip {
  width: 26px;
  height: 26px;
  border: 2px solid transparent;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
}
.chip.on { border-color: #fff; box-shadow: 0 0 0 2px #0008; }

.editor-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ---------- toast ---------- */

.toast {
  position: absolute;
  left: 50%;
  bottom: 58px;
  transform: translateX(-50%);
  z-index: 45;
  max-width: min(420px, calc(100vw - 32px));
  padding: 10px 16px;
  background: #1b2127f2;
  border: 1px solid var(--bar-line);
  border-radius: 8px;
  box-shadow: 0 10px 30px #000a;
  font-size: 13px;
  line-height: 1.45;
  text-align: center;
  pointer-events: none;
  transition: opacity .25s ease;
}

.toast.out { opacity: 0; }

@media (max-width: 720px) {
  .panel { width: 100%; }
}

.fallback { position: absolute; inset: 56px 0 0 0; display: grid; place-content: center; }

/* OpenSeadragon's own zoom buttons sit under our bar by default */
.openseadragon-container + .bar { pointer-events: auto; }

@media (max-width: 720px) {
  .bar {
    height: auto;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
  }
  .brand { font-size: 15px; }
  .brand-sub { display: none; }

  /* full-width on its own row rather than crushed between the title and
     the buttons */
  .search { order: 3; flex: 1 0 100%; max-width: none; }
  .results { top: 38px; }

  .tools { margin-left: auto; gap: 5px; }
  /* Icon + text doesn't fit next to the zoom cluster on narrow screens;
     drop to icon-only, same as the zoom buttons already are.
     Scoped to .tools: unscoped, this also caught #add-mode in the markers
     panel, collapsing the full-width "Add Marker" button into an unlabelled
     34px square on every phone. */
  .tools .icon-btn span { display: none; }
  .tools .icon-btn { width: 34px; padding: 0; justify-content: center; }
  .status { left: 8px; bottom: 8px; }
}
