/* Urban Companion PWA — cùng ngôn ngữ thị giác với WORKFLOW.html:
   giấy ấm, nâu accent, sáng/tối. Mobile-first, chạm lớn, tôn trọng reduced-motion. */

:root {
  --bg: #fbfaf8; --surface: #ffffff; --surface-2: #f4f2ee;
  --ink: #1c1b19; --ink-2: #56534d; --ink-3: #8a867e; --line: #e2ded6;
  --accent: #9a5b2c; --accent-soft: #f5ece3;
  --ok: #3f6b47; --ok-soft: #eaf2eb; --warn: #96602a; --warn-soft: #fbf0e2;
  --map-water: #c4d5d3; --map-shore: #9fb9b5; --map-park: #dde3d2;
  --map-casing: #cabda9; --map-fill: #fffdf8; --map-fill-min: #f6f1e8;
  --map-label: #6b655c; --map-label-major: #3f3a34; --map-halo: #f4f2ee;
  --radius: 12px; --tap: 46px;
  --fs: 17px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
:root[data-theme="dark"] {
  --bg: #161513; --surface: #1e1d1a; --surface-2: #262420;
  --ink: #ece9e3; --ink-2: #b0aca3; --ink-3: #7d7970; --line: #33302b;
  --accent: #d99a63; --accent-soft: #2b2119;
  --ok: #86bb92; --ok-soft: #1b2620; --warn: #d6a468; --warn-soft: #2a2118;
  --map-water: #1f2c2b; --map-shore: #3a4a48; --map-park: #23281f;
  --map-casing: #4a4237; --map-fill: #322d25; --map-fill-min: #2a261f;
  --map-label: #b0aca3; --map-label-major: #d8d3ca; --map-halo: #1a1917;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--sans); font-size: var(--fs); line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
a { color: inherit; }
button { font-family: inherit; }

.skip {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--accent); color: var(--bg); padding: 10px 14px; border-radius: 0 0 8px 0;
}
.skip:focus { left: 0; }

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; text-decoration: none; letter-spacing: -.01em; font-size: 18px; }
.brand-mark { color: var(--accent); }
.topbar-actions { display: flex; gap: 6px; }
.iconbtn {
  min-width: var(--tap); height: var(--tap); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-2); border-radius: 10px;
  font-size: 16px; cursor: pointer;
}
.iconbtn:active { background: var(--surface-2); }
.iconbtn sup { font-size: 10px; }

/* ---- layout ---- */
main { max-width: 720px; margin: 0 auto; padding: 16px; }
h1.page { font-size: 15px; font-family: var(--mono); letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-3); margin: 4px 0 14px; font-weight: 600; }
.muted { color: var(--ink-2); }
.dim { color: var(--ink-3); }

/* ---- Khám phá: feed thẻ ảnh tư liệu ---- */
.feed-intro { margin: 2px 0 18px; }
.feed-intro h1 { font-size: clamp(24px, 6.5vw, 30px); line-height: 1.12; letter-spacing: -.02em;
  margin: 0 0 6px; text-wrap: balance; }
.feed-intro p { margin: 0; color: var(--ink-2); font-size: 15px; max-width: 32ch; }
.feed { display: flex; flex-direction: column; gap: 18px; }
.fcard { position: relative; display: block; border-radius: 16px; overflow: hidden; text-decoration: none;
  background: var(--surface-2); aspect-ratio: 16 / 11; box-shadow: 0 2px 18px rgba(40,28,14,.10);
  transform: translateZ(0); }
.fcard:active { transform: scale(.985); }
.fcard img { width: 100%; height: 100%; object-fit: cover; display: block; filter: saturate(.9) contrast(1.03); }
.fcard .scrim { position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(24,16,8,.86) 0%, rgba(24,16,8,.42) 38%, rgba(24,16,8,.02) 66%); }
.fcard .fbody { position: absolute; left: 0; right: 0; bottom: 0; padding: 16px 18px 15px; color: #fbf6ef; }
.fcard .fname { font-size: 21px; font-weight: 700; line-height: 1.18; letter-spacing: -.01em;
  text-shadow: 0 1px 12px rgba(0,0,0,.35); text-wrap: balance; }
.fcard .fteaser { font-size: 14.5px; line-height: 1.4; margin-top: 4px; color: rgba(251,246,239,.94);
  text-shadow: 0 1px 8px rgba(0,0,0,.3); }
.fcard .fmeta { display: flex; gap: 8px; margin-top: 12px; }
.fpill { font-family: var(--mono); font-size: 11.5px; letter-spacing: .02em; color: #fbf6ef;
  background: rgba(255,255,255,.17); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  padding: 4px 10px; border-radius: 100px; }
.fpill.audio { background: var(--accent); color: #fff; }
.fcard.plain { aspect-ratio: auto; background: var(--surface); border: 1px solid var(--line); }
.fcard.plain .fbody { position: static; color: var(--ink); padding: 15px 17px; }
.fcard.plain .fname { text-shadow: none; font-size: 17px; }
.fcard.plain .fteaser { color: var(--ink-2); text-shadow: none; }
/* hàng gọn: ảnh nhỏ trái, chữ phải — cắt bớt cuộn cho danh sách */
.fcard.row { aspect-ratio: auto; display: flex; gap: 13px; align-items: stretch;
  background: var(--surface); border: 1px solid var(--line); padding: 10px; box-shadow: none; }
.fcard.row img { width: 96px; min-width: 96px; height: 96px; object-fit: cover; border-radius: 10px; filter: saturate(.9) contrast(1.03); }
.fcard.row .fbody { position: static; color: var(--ink); padding: 2px 6px 2px 0;
  display: flex; flex-direction: column; justify-content: center; }
.fcard.row .fname { font-size: 16px; line-height: 1.22; text-shadow: none; color: var(--ink); }
.fcard.row .fteaser { color: var(--ink-2); text-shadow: none; font-size: 13.5px; margin-top: 3px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.fcard.row .fmeta { margin-top: 8px; }
.fcard.row .fpill { color: var(--ink-3); background: var(--surface-2); backdrop-filter: none; -webkit-backdrop-filter: none; }
.fcard.row .fpill.audio { background: var(--accent-soft); color: var(--accent); }
.fcard.row.plain { padding: 14px 16px; }
.feed-rest { margin: 22px 0 6px; padding: 15px 17px; border: 1px dashed var(--line); border-radius: 14px;
  color: var(--ink-2); font-size: 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.feed-rest a { color: var(--accent); text-decoration: none; white-space: nowrap; font-weight: 600; }

/* ---- point list ---- */
.plist { display: flex; flex-direction: column; gap: 10px; }
.pcard {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; text-decoration: none; min-height: var(--tap);
}
.pcard:active { background: var(--surface-2); }
.pcard .pname { font-weight: 600; font-size: 16.5px; }
.pcard .pmeta { grid-column: 1; font-size: 13px; color: var(--ink-3); font-family: var(--mono); }
.pcard .pdist { grid-row: 1 / span 2; grid-column: 2; font-family: var(--mono); font-size: 13px;
  color: var(--ink-2); text-align: right; white-space: nowrap; }
.pcard .badges { display: inline-flex; gap: 6px; margin-left: 8px; vertical-align: 1px; }
.chip { font-family: var(--mono); font-size: 11px; padding: 2px 7px; border-radius: 100px;
  border: 1px solid var(--line); color: var(--ink-3); }
.chip.audio { color: var(--accent); border-color: transparent; background: var(--accent-soft); }
.chip.visited { color: var(--ok); border-color: transparent; background: var(--ok-soft); }
.chip.soon { color: var(--ink-3); background: var(--surface-2); border-color: transparent; }

/* ---- detail ---- */
.detail h2 { font-size: clamp(24px, 6vw, 32px); line-height: 1.15; margin: 4px 0 6px; letter-spacing: -.02em; }
.detail .sub { color: var(--ink-3); font-family: var(--mono); font-size: 13px; margin-bottom: 16px; }
.photo { margin: 0 -16px 4px; background: var(--surface-2); }
.photo img { width: 100%; display: block; }
.photo figcaption { padding: 8px 16px 0; font-size: 13px; color: var(--ink-3); }

/* so sánh thời gian (then → then → now) */
.compare .cmp-stage { position: relative; aspect-ratio: 3 / 2; background: var(--surface-2); overflow: hidden; }
.compare .cmp-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  opacity: 0; transition: opacity .5s ease; }
.compare .cmp-img.on { opacity: 1; }
.compare .cmp-hint { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
  font-family: var(--mono); font-size: 11.5px; color: #fbf6ef; background: rgba(24,16,8,.55);
  backdrop-filter: blur(4px); padding: 4px 11px; border-radius: 100px; pointer-events: none; }
.compare .cmp-bar { display: flex; justify-content: center; padding: 12px 0 2px; }
.compare .cmp-tabs { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 100px; padding: 3px; gap: 2px; }
.compare .cmp-tab { border: none; background: none; font-family: var(--mono); font-size: 13px;
  color: var(--ink-2); padding: 7px 18px; border-radius: 100px; cursor: pointer; min-height: 38px; }
.compare .cmp-tab.on { background: var(--accent); color: var(--bg); }
.compare figcaption { padding: 10px 16px 0; }
.compare .cmp-note { font-size: 14.5px; line-height: 1.5; color: var(--ink-2); margin-bottom: 6px; }
.compare .cmp-caps { position: relative; min-height: 1.4em; }
.compare .cmp-cap { position: absolute; left: 0; top: 0; font-size: 12.5px; color: var(--ink-3);
  font-family: var(--mono); opacity: 0; transition: opacity .3s; }
.compare .cmp-cap.on { opacity: 1; }
.backlink { display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap);
  color: var(--ink-2); text-decoration: none; font-size: 15px; margin-bottom: 4px; }

/* audio player */
.player { position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 10;
  margin: 16px -16px; padding: 14px 16px; background: var(--surface);
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.player-row { display: flex; align-items: center; gap: 14px; }
.playbtn { min-width: 56px; height: 56px; border-radius: 50%; border: none;
  background: var(--accent); color: var(--bg); font-size: 22px; cursor: pointer; flex: none; }
.playbtn:active { transform: scale(.96); }
.player-meta { flex: 1; min-width: 0; }
.player-meta .ptitle { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scrub { width: 100%; margin-top: 6px; accent-color: var(--accent); height: 24px; }
.times { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 12px; color: var(--ink-3); }
.no-audio { margin: 16px 0; padding: 14px 16px; border: 1px dashed var(--line);
  border-radius: var(--radius); color: var(--ink-2); font-size: 14.5px; background: var(--surface); }

/* transcript / text */
.script { font-size: var(--fs); line-height: 1.75; margin: 18px 0; }
.script p { margin: 0 0 1em; }

/* sources + confidence */
.sources { margin: 20px 0; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.sources h3 { margin: 0 0 10px; font-size: 13px; font-family: var(--mono); text-transform: uppercase;
  letter-spacing: .07em; color: var(--ink-3); }
.conf { display: inline-flex; align-items: center; gap: 7px; font-size: 14px; padding: 6px 12px;
  border-radius: 100px; margin-bottom: 12px; }
.conf.verified { background: var(--ok-soft); color: var(--ok); }
.conf.review { background: var(--warn-soft); color: var(--warn); }
.srclist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.srclist a { display: block; min-height: var(--tap); display: flex; align-items: center;
  font-size: 14.5px; text-decoration: none; color: var(--accent); }
.srclist .stype { font-family: var(--mono); font-size: 12px; color: var(--ink-3); margin-right: 8px; }

/* chân trang + trang quyền riêng tư */
.appfoot { margin: 28px 0 8px; padding-top: 16px; border-top: 1px solid var(--line);
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--ink-3); }
.appfoot a { color: var(--ink-2); text-decoration: none; border-bottom: 1px solid var(--line);
  min-height: 32px; display: inline-flex; align-items: center; }
.prose h3.ph { font-size: 15px; margin: 26px 0 8px; letter-spacing: -.01em; }
.prose p { font-size: var(--fs); line-height: 1.65; margin: 0 0 12px; color: var(--ink-2); }
.prose code { font-family: var(--mono); font-size: .88em; background: var(--surface-2);
  padding: 1px 5px; border-radius: 5px; color: var(--ink); }
.plainlist { list-style: none; margin: 0 0 12px; padding: 0;
  display: flex; flex-direction: column; gap: 8px; }
.plainlist li { font-size: 14.5px; line-height: 1.5; color: var(--ink-2);
  padding-left: 16px; position: relative; }
.plainlist li::before { content: '·'; position: absolute; left: 4px; color: var(--ink-3); }
.privacy-toggle { margin-top: 4px; }
.privacy-toggle label { display: flex; align-items: center; gap: 10px;
  min-height: var(--tap); font-size: 15px; cursor: pointer; }
.privacy-toggle input { width: 22px; height: 22px; accent-color: var(--accent); }
.privacy-toggle input:disabled + span { color: var(--ink-3); }

/* directions */
.directions { display: flex; align-items: center; justify-content: center; gap: 10px;
  min-height: var(--tap); width: 100%; margin: 8px 0 24px; border-radius: var(--radius);
  background: var(--accent); color: var(--bg); text-decoration: none; font-weight: 600; font-size: 16px; }
.directions:active { filter: brightness(.95); }

/* tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(8px); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 0 8px; text-decoration: none; color: var(--ink-3); font-size: 11.5px; min-height: 56px; }
.tab-ico { font-size: 20px; }
.tab[aria-current="page"] { color: var(--accent); }

/* toast */
.toast { position: fixed; left: 50%; transform: translateX(-50%) translateY(20px);
  bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 40;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 100px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 88vw; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- map view ---- */
.mapwrap { position: fixed; inset: 0; top: 0; bottom: calc(56px + env(safe-area-inset-bottom)); }
.mapwrap canvas { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
.mapwrap canvas:active { cursor: grabbing; }
.map-hint { position: absolute; top: calc(12px + env(safe-area-inset-top) + 52px); left: 50%; transform: translateX(-50%);
  font-family: var(--mono); font-size: 12px; color: var(--ink-2); background: color-mix(in srgb, var(--surface) 82%, transparent);
  padding: 5px 12px; border-radius: 100px; border: 1px solid var(--line); pointer-events: none; white-space: nowrap; }
.map-attr { position: absolute; bottom: 8px; right: 10px; font-size: 10px; color: var(--ink-3);
  font-family: var(--mono); background: color-mix(in srgb, var(--surface) 70%, transparent); padding: 2px 6px; border-radius: 4px; }
.mapsheet { position: absolute; left: 12px; right: 12px; bottom: 12px; display: flex; gap: 14px; align-items: stretch;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: inherit;
  box-shadow: 0 8px 34px rgba(30,20,10,.18); padding: 12px; overflow: hidden;
  transform: translateY(150%); transition: transform .24s cubic-bezier(.2,.7,.3,1); }
.mapsheet.show { transform: translateY(0); }
.mapsheet:active { background: var(--surface-2); }
.mapsheet .msphoto { width: 88px; min-width: 88px; height: 88px; object-fit: cover; border-radius: 9px;
  background: var(--surface-2); filter: saturate(.9); }
.mapsheet .msinfo { display: flex; flex-direction: column; justify-content: center; min-width: 0; padding-right: 8px; }
.mapsheet .mtitle { font-weight: 650; font-size: 16.5px; line-height: 1.2; }
.mapsheet .mmeta { font-size: 13px; color: var(--ink-2); margin-top: 3px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mapsheet .msopen { color: var(--accent); font-weight: 600; font-size: 14px; margin-top: 8px; }
.mapsheet .mclose { position: absolute; top: 6px; right: 8px; background: color-mix(in srgb, var(--surface) 70%, transparent); border: none;
  color: var(--ink-3); font-size: 18px; cursor: pointer; width: 28px; height: 28px; border-radius: 50%; }
.map-legend { position: absolute; top: calc(12px + env(safe-area-inset-top) + 52px); right: 12px;
  background: color-mix(in srgb, var(--surface) 88%, transparent); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; font-size: 11.5px; color: var(--ink-2); display: flex; flex-direction: column; gap: 5px; }
.map-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.map-legend .d-audio { background: var(--accent); }
.map-legend .d-content { background: var(--surface); border: 2px solid var(--accent); }
.map-legend .d-soon { background: var(--ink-3); width: 6px; height: 6px; }

.empty { text-align: center; color: var(--ink-3); padding: 48px 16px; }
.spinner { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
  .spinner { animation: none; border-top-color: var(--accent); }
}
