:root {
  --ink: #1f2933;
  --muted: #66727f;
  --line: #dde2e8;
  --paper: #ffffff;
  --canvas: #e9edf1;
  --accent: #0b6e8a;
  --marker: #d92d20;

  /* 热点尺寸：*-map 是“地图原生坐标系”下的大小，随 #stage 的缩放一起变化（#stage 用 transform: scale()，
     子元素的像素尺寸会被这个 scale 自动放大/缩小，不需要额外逻辑）。
     线网图上单个站点图示实际约 30px，可见圆环按 30px 定义，
     这样放大到 1:1 及以上时会跟图示等比例放大，严丝合缝；
     hit（点击区）比 dot（可见圆环）略大一圈，方便点击。
     *-min-screen 是缩得很小、站点密集时的屏幕像素下限，避免完全点不到。 */
  --dot-map: 30px;
  --dot-min-screen: 8px;
  --hit-map: 34px;
  --hit-min-screen: 12px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  font: 15px/1.5 system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

button { font: inherit; color: inherit; }

/* ---------- 工具栏 ---------- */
.toolbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.toolbar h1 { margin: 0; font-size: 16px; font-weight: 600; white-space: nowrap; }
#status a { color: var(--accent); }
#status { min-width: 0; font-size: 13px; color: var(--marker); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.zoom-ctrl { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.zoom-ctrl button {
  min-width: 32px; height: 32px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--paper); cursor: pointer;
}
.zoom-ctrl button:hover { background: #f1f4f7; }
#zoomLabel { min-width: 48px; text-align: center; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- 地图视口 ---------- */
#viewport {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  touch-action: none;            /* 触摸手势全部交给 app.js（拖动 / 双指缩放） */
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  background: var(--canvas);
}
#viewport.dragging { cursor: grabbing; }

#stage {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  background: #fff;
  --s: 1;                        /* 当前缩放倍数，由 app.js 的 apply() 写入 */
}
#stage img {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  -webkit-user-drag: none;
}
#hotspots { position: absolute; inset: 0; }

.hotspot {
  /* --s 变大（放大地图）时，--hit-min-screen/--s 变小，max() 选中固定的 *-map 值，
     这个固定值会随 #stage 的 transform: scale() 一起放大 —— 这就是热点跟着图示放大的机制。
     --s 变小（缩小地图）时相反，max() 选中 *-min-screen/--s，保证缩得再小也有最低可点击尺寸。 */
  --hit: max(var(--hit-map), calc(var(--hit-min-screen) / var(--s)));
  --dot: max(var(--dot-map), calc(var(--dot-min-screen) / var(--s)));
  --badge: calc(var(--dot) * 0.4);
  position: absolute;
  width: var(--hit);
  height: var(--hit);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  transform: translate(-50%, -50%);
  cursor: pointer;
}
.hotspot::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--dot);
  height: var(--dot);
  transform: translate(-50%, -50%);
  border: calc(var(--dot) * 0.12) solid var(--accent);
  border-radius: 50%;
  background: rgba(11, 110, 138, 0.14);
}
.hotspot:hover::before,
.hotspot:focus-visible::before { background: rgba(11, 110, 138, 0.38); }
.hotspot:focus-visible { outline: none; }

/* 右上角小红点：这个站点有文字笔记 */
.hotspot.has-notes::after {
  content: "";
  position: absolute;
  width: var(--badge);
  height: var(--badge);
  left: calc(50% + var(--dot) * 0.32 - var(--badge) / 2);
  top: calc(50% - var(--dot) * 0.32 - var(--badge) / 2);
  border-radius: 50%;
  background: var(--marker);
  box-shadow: 0 0 0 calc(var(--badge) * 0.22) #fff;
}

/* 左上角小蓝点：这个站点有照片。独立于 has-notes 的 ::after，
   用一个真实的子元素而不是伪元素，因为一个元素只有 ::before/::after 两个坑位，
   ::before 已经用来画可见圆环了 */
.hotspot .ph-badge {
  position: absolute;
  width: var(--badge);
  height: var(--badge);
  left: calc(50% - var(--dot) * 0.32 - var(--badge) / 2);
  top: calc(50% - var(--dot) * 0.32 - var(--badge) / 2);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 calc(var(--badge) * 0.22) #fff;
  display: none;
}
.hotspot.has-photos .ph-badge { display: block; }

/* ---------- 笔记弹窗：只用 px / 视口单位，页面不缩放，所以大小恒定 ---------- */
dialog {
  width: min(440px, calc(100vw - 32px));
  max-height: min(86vh, 680px);
  max-height: min(86dvh, 680px);
  padding: 0;
  border: 0;
  border-radius: 10px;
  overflow: hidden;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.28);
}
dialog[open] { display: flex; }
dialog::backdrop { background: rgba(15, 23, 42, 0.45); }

.dlg { flex: 1; min-height: 0; width: 100%; display: flex; flex-direction: column; }

.dlg-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 8px 12px 16px;
  border-bottom: 1px solid var(--line);
}
.dlg-head h2 { margin: 0; font-size: 17px; font-weight: 600; overflow-wrap: anywhere; }
.icon-btn {
  flex: none; width: 36px; height: 36px;
  border: 0; border-radius: 6px; background: none;
  font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: #f1f4f7; color: var(--ink); }

/* 笔记 + 照片都放在这个可滚动区域里，只有头部固定 */
.dlg-body { flex: 1; min-height: 0; overflow-y: auto; }

.note-section { padding: 12px 16px 14px; border-bottom: 1px solid var(--line); }
.note-meta-line { margin: 0 0 8px; font-size: 12px; color: var(--muted); min-height: 15px; }
.note-form { display: flex; flex-direction: column; }
.note-form textarea {
  min-height: 92px; max-height: 240px; padding: 8px 10px;
  resize: vertical;
  border: 1px solid #c5ccd4; border-radius: 6px; background: #fff;
  font-family: inherit;
  font-size: 16px;               /* ≥16px，iOS 聚焦输入框时才不会自动放大页面 */
  line-height: 1.5;
  color: var(--ink);
}
.note-form textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.form-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; }
.form-actions { display: flex; align-items: center; gap: 8px; }
.hint { min-width: 0; font-size: 12px; color: var(--muted); }
.hint.error { color: var(--marker); }
.primary {
  flex: none; padding: 8px 16px;
  border: 0; border-radius: 6px;
  background: var(--accent); color: #fff; cursor: pointer;
}
.primary:hover:not(:disabled) { background: #095c74; }
.primary:disabled { opacity: 0.5; cursor: default; }
.danger {
  flex: none; padding: 8px 14px;
  border: 1px solid #e9b4ae; border-radius: 6px;
  background: #fff; color: var(--marker); cursor: pointer;
}
.danger:hover:not(:disabled) { background: #fef3f2; }
.danger:disabled { opacity: 0.5; cursor: default; }

/* ---------- 照片：列表只显示备注文字，不内嵌缩略图（省带宽），
   预览靠单独的按钮按需加载大图 ---------- */
.photo-section { padding: 12px 16px 16px; }
.photo-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.photo-head h3 { margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.upload-btn {
  flex: none; padding: 6px 12px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--paper); color: var(--accent); font-size: 13px; cursor: pointer;
}
.upload-btn:hover { background: #f1f4f7; }

.photo-list { margin: 10px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.photo-item { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }
.photo-row { display: flex; align-items: center; gap: 6px; }
.photo-preview {
  flex: none; padding: 6px 10px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--paper); color: var(--accent); font-size: 12px; cursor: pointer;
}
.photo-preview:hover { background: #f1f4f7; }
.photo-caption {
  flex: 1; min-width: 0; padding: 6px 8px;
  border: 1px solid #c5ccd4; border-radius: 6px; background: #fff;
  font-family: inherit; font-size: 14px; color: var(--ink);
}
.photo-caption:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.photo-del {
  flex: none; width: 28px; height: 28px;
  border: 0; border-radius: 6px; background: none;
  color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer;
}
.photo-del:hover:not(:disabled) { color: var(--marker); background: #fef3f2; }
.photo-del:disabled { opacity: 0.5; cursor: default; }
.photo-meta { margin: 4px 2px 0; font-size: 11px; color: var(--muted); }

/* ---------- 位置微调 ---------- */
.pos-section { padding: 0 16px; border-top: 1px solid var(--line); }
.pos-section summary { padding: 12px 0; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; }
.pos-section[open] summary { padding-bottom: 8px; }
.pos-body { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; padding-bottom: 16px; }
.pos-loupe { flex: none; border: 1px solid var(--line); border-radius: 8px; background: var(--canvas); }
.pos-ctrl { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.dpad { display: grid; grid-template-columns: repeat(3, 36px); grid-template-rows: repeat(3, 36px); gap: 4px; }
.nudge {
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--paper); font-size: 16px; line-height: 1; cursor: pointer;
}
.nudge:hover { background: #f1f4f7; }
.nudge:active { background: #e3e8ee; }
.nudge-up { grid-area: 1 / 2; }
.nudge-left { grid-area: 2 / 1; }
.nudge-right { grid-area: 2 / 3; }
.nudge-down { grid-area: 3 / 2; }
.pos-readout { margin: 0; font-size: 13px; white-space: pre; font-variant-numeric: tabular-nums; }

/* ---------- 大图预览悬浮窗：和 noteDialog 是两个独立的 <dialog>，
   可以叠在 noteDialog 上面，关闭只收起自己。
   窗口大小固定，照片放在 .viewer-stage 里用 transform 缩放 / 平移（逻辑在 app.js） ---------- */
#photoViewer {
  width: min(94vw, 1000px);
  height: min(90vh, 760px);
  height: min(90dvh, 760px);
  max-height: none;
  padding: 0;
  border: 0;
  border-radius: 10px;
  overflow: hidden;
  background: #0b0d10;
}
#photoViewer[open] { display: block; }
#photoViewer::backdrop { background: rgba(8, 10, 12, 0.72); }
.viewer { position: relative; width: 100%; height: 100%; }
.viewer-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;            /* 拖动 / 双指缩放由 app.js 处理 */
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}
.viewer-stage img {
  position: absolute;
  left: 0;
  top: 0;
  max-width: none;
  max-height: none;
  transform-origin: 0 0;
  visibility: hidden;            /* 加载完成并适配好大小之前不显示，避免闪一下原始尺寸 */
  pointer-events: none;
  -webkit-user-drag: none;
}
.viewer-stage img.ready { visibility: visible; }
.viewer-bar {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.65);
  color: #fff;
}
.viewer-bar button {
  min-width: 32px; height: 30px; padding: 0 8px;
  border: 0; border-radius: 6px; background: transparent; color: #fff; cursor: pointer;
}
.viewer-bar button:hover { background: rgba(255, 255, 255, 0.18); }
.viewer-bar span { min-width: 46px; text-align: center; font-size: 13px; font-variant-numeric: tabular-nums; }
.viewer-close {
  position: absolute; top: 8px; right: 8px;
  background: rgba(15, 23, 42, 0.55); color: #fff;
}
.viewer-close:hover { background: rgba(15, 23, 42, 0.8); color: #fff; }

.zoom-ctrl button:focus-visible,
.icon-btn:focus-visible,
.primary:focus-visible,
.danger:focus-visible,
.upload-btn:focus-visible,
.photo-preview:focus-visible,
.nudge:focus-visible,
.viewer-bar button:focus-visible,
.photo-del:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- 只读账号：隐藏所有修改入口（真正的拦截在后端 requireWriter，这里只是不让人白点） ---------- */
body.readonly .form-actions,
body.readonly .upload-btn,
body.readonly .photo-del,
body.readonly .pos-section { display: none; }
.note-form textarea[readonly],
.photo-caption[readonly] { background: #f6f8fa; }
