:root {
  --bg: #14161b;
  --panel: #1d2028;
  --border: #2c303b;
  --text: #e8eaf0;
  --muted: #9aa0ad;
  --accent: #ff4d6d;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: "Segoe UI", "Microsoft JhengHei", system-ui, sans-serif;
  display: flex; overflow: hidden;
}

/* ---------- sidebar ---------- */
#sidebar {
  width: 300px; flex: none; background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
#sidebar header { padding: 16px; border-bottom: 1px solid var(--border); }
#sidebar h1 { font-size: 18px; margin: 0 0 4px; }
#sidebar .sub { font-size: 12px; color: var(--muted); }
#search {
  margin-top: 12px; width: 100%; padding: 8px 10px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
#list { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 8px; }
#list li {
  padding: 10px; border-radius: 8px; cursor: pointer;
  display: flex; gap: 10px; align-items: flex-start;
}
#list li:hover, #list li.active { background: #272b35; }
#list .dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 4px; flex: none; }
#list .t { font-size: 14px; font-weight: 600; }
#list .p { font-size: 12px; color: var(--muted); }
#huntBar {
  display: none; padding: 8px 12px; border-top: 1px solid var(--border); text-align: right;
}
#huntBar button { font-size: 12px; }
body.hunt #huntBar { display: block; }
#list li.locked .t { color: var(--muted); }
button {
  background: #2a2e39; color: var(--text); border: 1px solid var(--border);
  padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
button:hover { background: #343947; }
button.on { background: var(--accent); border-color: var(--accent); }

/* ---------- map viewport ---------- */
#viewport { flex: 1; position: relative; overflow: hidden; cursor: grab; touch-action: none; }
#viewport.dragging { cursor: grabbing; }
#viewport.editing { cursor: crosshair; }
#stage { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#stage img { display: block; user-select: none; -webkit-user-drag: none; }

/* ---------- markers ---------- */
.marker { position: absolute; width: 0; height: 0; }
.marker.hidden { display: none; }
.marker.active { z-index: 2; }

/* 圖釘尖端 = 座標點；--inv 讓圖釘大小不隨縮放改變 */
.marker .pin {
  position: absolute; left: 0; top: 0;
  width: 28px; height: 38px;
  transform: translate(-50%, -100%) scale(var(--inv, 1));
  transform-origin: 50% 100%;
  cursor: pointer; transition: filter .15s;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.6));
}
.marker .pin span {
  position: absolute; left: 0; top: 0; width: 28px; height: 28px;
  border-radius: 50%; background: var(--c, var(--accent)); border: 2px solid #fff;
  text-align: center; line-height: 24px;
  font-size: 12px; font-weight: 700; color: #fff;
}
.marker .pin::after {
  content: ""; position: absolute; left: 50%; bottom: 0; transform: translateX(-50%);
  border: 7px solid transparent; border-bottom: 0;
  border-top: 12px solid #fff;
}
.marker.active .pin, .marker .pin:hover { filter: brightness(1.25) drop-shadow(0 2px 3px rgba(0,0,0,.6)); }
.marker.active .pin { animation: bounce .6s ease; }
@keyframes bounce {
  0%, 100% { margin-top: 0; } 40% { margin-top: -12px; }
}

/* 尋寶模式：未找到的點只顯示大概範圍（尺寸跟著地圖縮放） */
.marker .zone {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -50%);
  border-radius: 50%; cursor: pointer;
  border: 2px dashed var(--c, var(--accent));
  background: color-mix(in srgb, var(--c, var(--accent)) 15%, transparent);
  display: flex; align-items: center; justify-content: center;
}
.marker .zone span {
  transform: scale(var(--inv, 1));
  font-size: 13px; font-weight: 700; color: #fff; text-shadow: 0 1px 3px #000;
}
.marker.active .zone, .marker .zone:hover {
  border-style: solid;
  background: color-mix(in srgb, var(--c, var(--accent)) 30%, transparent);
}

/* ---------- popup ---------- */
#popup {
  position: absolute; min-width: 200px; max-width: 280px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.5);
  transform: translate(-50%, calc(-100% - 44px)); display: none; z-index: 10;
}
#popup h3 { margin: 0 0 4px; font-size: 15px; padding-right: 16px; }
#popup .who { font-size: 12px; color: var(--accent); margin-bottom: 6px; }
#popup p { margin: 0; font-size: 13px; line-height: 1.5; white-space: pre-wrap; }
#popup .xy { margin-top: 8px; font-size: 11px; color: var(--muted); font-family: Consolas, monospace; }
#popup .close { position: absolute; right: 6px; top: 2px; background: none; border: 0; font-size: 16px; padding: 4px; z-index: 1; }
#popup .photo {
  display: none; width: 100%; max-height: 160px; object-fit: cover;
  border-radius: 6px; margin-bottom: 8px; cursor: zoom-in;
}
#popup .photo.show { display: block; }
#popup.at-zone { transform: translate(-50%, calc(-100% - 8px)); }
#popupActions, #huntActions { display: none; gap: 6px; margin-top: 8px; }
#popupActions.show, #huntActions.show { display: flex; }

/* ---------- lightbox ---------- */
#lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.85); z-index: 50;
  display: none; align-items: center; justify-content: center; cursor: zoom-out;
}
#lightbox.show { display: flex; }
#lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 8px; }

/* ---------- HUD ---------- */
#hud { position: absolute; right: 12px; bottom: 12px; display: flex; gap: 6px; z-index: 5; }
#coords {
  position: absolute; left: 12px; bottom: 12px; z-index: 5;
  background: rgba(0,0,0,.65); padding: 4px 8px; border-radius: 6px;
  font-family: Consolas, monospace; font-size: 12px;
}
#toast {
  position: absolute; left: 50%; top: 16px; transform: translateX(-50%);
  background: #000c; padding: 8px 14px; border-radius: 8px; font-size: 13px;
  opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 20;
}
#toast.show { opacity: 1; }

/* ---------- edit dialog ---------- */
dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; width: 320px;
}
dialog::backdrop { background: rgba(0,0,0,.5); }
dialog label { display: block; font-size: 12px; color: var(--muted); margin: 8px 0 4px; }
dialog input, dialog textarea {
  width: 100%; padding: 6px 8px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text); font: inherit;
}
dialog input[type=color] { height: 34px; padding: 2px; }
dialog .row { display: flex; gap: 6px; justify-content: flex-end; margin-top: 12px; }

@media (max-width: 700px) {
  body { flex-direction: column-reverse; }
  #sidebar { width: 100%; height: 45%; border-right: 0; border-top: 1px solid var(--border); }
  #sidebar header { padding: 8px 12px; }
  #sidebar h1 { font-size: 15px; margin: 0 0 2px; }
  #search { margin-top: 6px; padding: 6px 8px; }
  #list { padding: 4px; }
  #list li { padding: 6px 8px; }
  #huntBar { padding: 6px 12px; }
  #huntBar button { padding: 4px 8px; font-size: 11px; }
}
