/* 宜居 Liveable — 編輯風（New Yorker / NYT 調性）。亮/暗雙主題以 CSS 變數切換。 */
:root {
  --bg: #efeee9;
  --card: #fffefb;
  --ink: #141414;
  --muted: #6f6c64;
  --hair: #e2dfd6;
  --accent: #2f6690;
  --media: #dededa;
  --media-ink: #88857d;
  --na: #9a958c;
  --shadow: rgba(0,0,0,.16);
  --serif: Georgia, "Times New Roman", "Songti TC", "Noto Serif TC", serif;
  --sans: "Helvetica Neue", Arial, system-ui, "PingFang TC", "Microsoft JhengHei", sans-serif;
}
[data-theme="dark"] {
  --bg: #161513;
  --card: #1d1c1a;
  --ink: #f3efe6;
  --muted: #9c978c;
  --hair: #322f2a;
  --accent: #8fb4d4;
  --media: #262420;
  --media-ink: #8a857b;
  --na: #6f6a60;
  --shadow: rgba(0,0,0,.5);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: var(--sans); }
#map { position: absolute; inset: 0; z-index: 1; background: var(--bg); }

/* 報頭（像刊物 masthead） */
#titlebar {
  position: absolute; top: 16px; left: 16px; z-index: 1000;
  background: var(--card); border: 1px solid var(--hair);
  border-radius: 6px; padding: 12px 14px; max-width: 340px;
  box-shadow: 0 4px 18px var(--shadow);
  display: flex; align-items: center; gap: 12px;
}
#titlebar h1 { font-family: var(--serif); font-weight: 600; font-size: 22px;
  letter-spacing: -.3px; margin: 0; color: var(--ink); }
.tb-sub { font-family: var(--sans); font-size: 9.5px; color: var(--muted);
  margin: 3px 0 0; letter-spacing: 2px; text-transform: uppercase; }
.tb-stats { font-size: 11px; color: var(--muted); border-left: 1px solid var(--hair); padding-left: 12px; }
#theme-btn, #help-btn { width: 26px; height: 26px; border-radius: 50%;
  border: 1px solid var(--hair); background: transparent; color: var(--muted);
  cursor: pointer; font-weight: 700; font-size: 13px; line-height: 1; padding: 0; }
#theme-btn { margin-left: auto; }
#theme-btn:hover, #help-btn:hover { color: var(--ink); border-color: var(--ink); }

/* 圖層切換 */
#layers {
  position: absolute; top: 16px; right: 16px; z-index: 1000;
  background: var(--card); border: 1px solid var(--hair); border-radius: 6px;
  padding: 4px; display: flex; gap: 2px; box-shadow: 0 4px 18px var(--shadow);
}
#layers button {
  border: 0; background: transparent; font-family: var(--serif); font-size: 13px;
  color: var(--muted); padding: 6px 11px; border-radius: 4px; cursor: pointer;
}
#layers button.active { background: var(--ink); color: var(--card); }

/* 城市切換器（segmented control，置頂置中）*/
#cityswitch {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  z-index: 1000; background: var(--card); border: 1px solid var(--hair);
  border-radius: 6px; padding: 4px; display: flex; gap: 2px;
  box-shadow: 0 4px 18px var(--shadow);
}
#cityswitch button {
  border: 0; background: transparent; font-family: var(--serif); font-size: 13px;
  color: var(--muted); padding: 6px 12px; border-radius: 4px; cursor: pointer;
}
#cityswitch button.active { background: var(--ink); color: var(--card); }

/* 圖例 */
#legend {
  position: absolute; bottom: 22px; right: 16px; z-index: 1000;
  background: var(--card); border: 1px solid var(--hair); border-radius: 6px;
  padding: 10px 12px; font-size: 11px; color: var(--muted);
  box-shadow: 0 4px 18px var(--shadow);
}
.legend-bar { width: 140px; height: 8px; border-radius: 2px;
  background: linear-gradient(90deg, #c0392b, #e67e22, #f4c724, #6aa84f, #2e7d32); }
.legend-labels { display: flex; justify-content: space-between; margin-top: 3px; }
.legend-na { margin-top: 6px; display: flex; align-items: center; gap: 5px; }
.na-swatch { width: 12px; height: 12px; background: var(--na); border-radius: 2px; display: inline-block; }

/* 開場浮層 */
#intro-overlay {
  position: absolute; inset: 0; z-index: 2000;
  background: rgba(20,18,12,.5); display: flex; align-items: center; justify-content: center;
}
#intro-overlay.hidden { display: none; }
.intro-card {
  background: var(--card); border-radius: 8px; padding: 28px 30px; max-width: 440px;
  position: relative; box-shadow: 0 18px 60px rgba(0,0,0,.4); font-family: var(--serif);
  border: 1px solid var(--hair);
}
.intro-close { position: absolute; top: 14px; right: 16px; border: 0; background: none;
  font-size: 18px; color: var(--muted); cursor: pointer; }
.intro-card h2 { font-size: 26px; margin: 0 0 10px; color: var(--ink); font-weight: 600; }
.intro-lead { font-size: 14px; color: var(--muted); line-height: 1.6; margin: 0 0 18px; }
.intro-steps { list-style: none; padding: 0; margin: 0 0 16px; counter-reset: s; }
.intro-steps li { counter-increment: s; display: flex; flex-direction: column;
  padding: 8px 0 8px 34px; position: relative; border-top: 1px solid var(--hair); }
.intro-steps li::before { content: counter(s); position: absolute; left: 0; top: 9px;
  width: 22px; height: 22px; border-radius: 50%; background: var(--ink); color: var(--card);
  font-family: var(--sans); font-size: 12px; display: flex; align-items: center; justify-content: center; }
.intro-steps b { font-size: 14px; color: var(--ink); }
.intro-steps span { font-family: var(--sans); font-size: 12px; color: var(--muted); margin-top: 2px; }
.intro-read { font-family: var(--sans); font-size: 13px; color: var(--muted); margin: 0 0 20px; }
.intro-start { font-family: var(--sans); font-size: 14px; background: var(--ink); color: var(--card);
  border: 0; border-radius: 6px; padding: 11px 22px; cursor: pointer; }

/* popup — 報刊資料卡 */
.leaflet-popup-content-wrapper { background: var(--card); border-radius: 6px;
  box-shadow: 0 10px 30px var(--shadow); }
.leaflet-popup-tip { background: var(--card); }
.leaflet-popup-content { margin: 0; width: 360px !important; font-family: var(--serif); color: var(--ink); }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }

.pop-photo { position: relative; height: 220px; border-radius: 6px 6px 0 0; background: var(--media); }
.pop-media { position: absolute; inset: 0; overflow: hidden; border-radius: 6px 6px 0 0; }
.pop-media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pop-score { position: absolute; right: 16px; bottom: -19px; width: 52px; height: 52px;
  border-radius: 50%; color: #fff; display: flex; align-items: center; justify-content: center;
  font-family: var(--serif); font-size: 20px; font-weight: 600; border: 3px solid var(--card);
  box-shadow: 0 2px 8px rgba(0,0,0,.3); z-index: 2; }
.pop-body { padding: 20px 20px 16px; }
.pop-kicker { font-family: var(--sans); font-size: 9.5px; letter-spacing: 2.5px; text-transform: uppercase;
  color: var(--muted); padding-bottom: 9px; border-bottom: 1px solid var(--hair);
  display: flex; justify-content: space-between; }
.pop-quote { font-family: var(--serif); font-size: 17px; line-height: 1.5; color: var(--ink); margin: 14px 0 18px; }
.pop-table { border-top: 1px solid var(--hair); }
.pop-row { display: flex; align-items: center; gap: 12px; padding: 9px 0;
  border-bottom: 1px solid var(--hair); font-size: 12px; }
.pop-row .lbl { font-family: var(--sans); width: 48px; color: var(--muted); letter-spacing: 1px; }
.pop-row .track { flex: 1; height: 3px; background: var(--hair); }
.pop-row .fill { display: block; height: 100%; }
.pop-row .val { font-family: var(--serif); font-weight: 600; width: 20px; text-align: right; color: var(--ink); }
.pop-obs { font-family: var(--sans); font-size: 11px; color: var(--muted); margin-top: 12px; }
.pop-obs summary { cursor: pointer; color: var(--accent); }
.pop-obs p { margin: 6px 0 0; line-height: 1.6; color: var(--ink); }
.pop-foot { margin-top: 14px; font-family: var(--sans); font-size: 11px; letter-spacing: .5px; }
.pop-foot a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--accent); padding-bottom: 1px; }
.pop-na { font-family: var(--sans); color: var(--muted); padding: 18px; text-align: center; }

/* Leaflet 控制項配合主題 */
.leaflet-bar a, .leaflet-control-attribution {
  background: var(--card); color: var(--muted); border-color: var(--hair); }
.leaflet-bar a { color: var(--ink); }
.leaflet-control-attribution a { color: var(--accent); }

/* RWD — 合併後統一在下方 768px block */

/* gated：鎖區深色塊上的標籤 */
.locked-label.leaflet-tooltip {
  background: transparent; border: 0; box-shadow: none; color: #e9e4d8;
  font-family: var(--sans); font-size: 12px; font-weight: 600;
}
.locked-label.leaflet-tooltip::before { display: none; }   /* 去掉小三角 */

/* gated：側邊區域清單 */
#sidepanel {
  position: absolute; top: 64px; right: 16px; z-index: 1000; width: 170px;
  max-height: calc(100vh - 150px);        /* 不超過視窗；為底部圖例留空間 */
  overflow: hidden auto;                  /* 區數多時面板內部垂直捲動 */
  background: var(--card); border: 1px solid var(--hair); border-radius: 6px;
  box-shadow: 0 4px 18px var(--shadow); font-family: var(--sans);
}
.sp-head { font-family: var(--serif); font-weight: 600; font-size: 13px; color: var(--ink);
  padding: 9px 12px; border-bottom: 1px solid var(--hair); }
.sp-row { display: flex; align-items: center; justify-content: space-between;
  padding: 7px 12px; border-bottom: 1px solid var(--hair); font-size: 12px; }
.sp-row:last-child { border-bottom: 0; }
.sp-name { color: var(--muted); }
.sp-row.open .sp-name { color: var(--ink); }
.sp-free { font-size: 10px; color: #2e7d32; font-weight: 700; }
.sp-unlock { font-size: 10px; background: var(--ink); color: var(--card); border: 0;
  border-radius: 5px; padding: 4px 8px; cursor: pointer; }

/* gated：解鎖視窗 */
#unlock-modal { position: absolute; inset: 0; z-index: 2001;
  background: rgba(20,18,12,.5); display: flex; align-items: center; justify-content: center; }
#unlock-modal.hidden { display: none; }
.unlock-card { background: var(--card); border: 1px solid var(--hair); border-radius: 10px;
  padding: 24px 26px; width: 280px; text-align: center; position: relative;
  box-shadow: 0 18px 60px rgba(0,0,0,.4); }
.unlock-close { position: absolute; top: 12px; right: 14px; border: 0; background: none;
  font-size: 16px; color: var(--muted); cursor: pointer; }
.unlock-card h3 { font-family: var(--serif); font-size: 18px; margin: 0 0 14px; color: var(--ink); }
.unlock-ad { background: var(--media); color: var(--media-ink); border-radius: 8px;
  padding: 22px 12px; font-size: 12px; margin-bottom: 14px; }
.unlock-go { font-family: var(--sans); font-size: 14px; background: var(--ink); color: var(--card);
  border: 0; border-radius: 7px; padding: 10px 20px; cursor: pointer; }
.unlock-go:disabled { opacity: .5; cursor: default; }


/* gated：已解鎖但無資料的區，中央標記 */
.nodata-label {
  color: var(--media-ink); font-family: var(--sans); font-size: 12px;
  white-space: nowrap; text-shadow: 0 1px 2px rgba(0,0,0,.4);
  transform: translate(-50%, -50%);
}

/* 輕量提示 toast */
#toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%) translateY(8px);
  background: rgba(20,18,12,.92); color: #fff; font-family: var(--sans); font-size: 13px;
  padding: 10px 16px; border-radius: 20px; z-index: 3000; max-width: 80vw; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* 尚未開放：地圖標籤（比鎖區更淡）+ 側邊清單按鈕 */
.locked-label.soon { color: #b8b2a4; font-weight: 500; }
.sp-soon { font-size: 10px; background: transparent; color: var(--muted);
  border: 1px solid var(--hair); border-radius: 5px; padding: 4px 8px; cursor: pointer; }

/* 手機版：底部抽屜 + 精簡控制項（桌機 >768px 不受影響）*/
.sp-handle { display: none; }        /* 桌機隱藏把手 */

@media (max-width: 768px) {
  #titlebar { left: 8px; right: 8px; top: 8px; max-width: none; }
  .intro-card { margin: 12px; padding: 22px; }
  .leaflet-popup-content { width: auto !important; }

  /* 城市切換：置頂整條 */
  #cityswitch { top: 50px; left: 8px; right: 8px; transform: none; justify-content: center; }
  #cityswitch button { flex: 1; }

  /* 圖層：頂部一排、可橫捲 */
  #layers { top: 92px; left: 8px; right: 8px; bottom: auto; overflow-x: auto; }

  /* 圖例：左下角精簡 */
  #legend { bottom: 60px; right: auto; left: 8px; transform: scale(.9); transform-origin: bottom left; }

  /* 側邊清單 → 底部抽屜 */
  #sidepanel {
    top: auto; bottom: 0; left: 0; right: 0; width: auto;
    /* 收合高度含瀏海手機底部安全區，讓把手不落在 home indicator 手勢區 */
    max-height: calc(48px + env(safe-area-inset-bottom, 0px)); overflow: hidden;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    border-radius: 12px 12px 0 0; border-bottom: 0;
    transition: max-height .25s ease; z-index: 1200;
  }
  #sidepanel.expanded { max-height: 65vh; overflow-y: auto; }
  .sp-handle {
    display: block; width: 100%; height: 48px; border: 0; background: var(--card);
    font-family: var(--serif); font-size: 14px; color: var(--ink); cursor: pointer;
    border-bottom: 1px solid var(--hair);
  }
  .sp-row { padding: 11px 14px; font-size: 13px; }      /* 觸控好按 */
  .sp-unlock, .sp-soon { padding: 7px 12px; font-size: 12px; }

  /* 解鎖視窗手機置中不爆版 */
  .unlock-card { width: min(90vw, 300px); }
}
