:root {
  --bg: #ffffff;
  --fg: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --soft: #f1f5f9;
  --primary: #2563eb;
  --sea: #f3f7fc;
  --land: #dde3ec;
  --warn: #c2410c;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --fg: #e2e8f0;
    --muted: #94a3b8;
    --border: #1e293b;
    --soft: #111827;
    --primary: #3b82f6;
    --sea: #0e1626;
    --land: #1f2937;
    --warn: #fb923c;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.6 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
h2 { margin: 0; font-size: 16px; font-weight: 500; }

/* Container like Tailwind's */
.wrap { width: 100%; max-width: 1280px; margin: 0 auto; padding: 32px 16px 48px; display: grid; gap: 20px; }
.content { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
@media (min-width: 640px) { .wrap { padding-left: 24px; padding-right: 24px; gap: 40px; } }
@media (min-width: 1024px) { .wrap { padding-left: 32px; padding-right: 32px; gap: 60px; } }

.top { display: flex; align-items: center; gap: 12px; }
.top-text { flex: 1; min-width: 0; }
h1 { margin: 0; font-size: 26px; line-height: 1.25; font-weight: 500; }
.brand img { display: block; border-radius: 10px; }
.back { padding: 6px 10px; border-radius: 999px; font-size: 13px; text-decoration: none; white-space: nowrap; }
.back:hover { background: var(--soft); }
.card { display: grid; gap: 12px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 14px; min-width: 0; }
.sec-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
footer { text-align: center; }

/* Controls: 14px, 36px high */
input, select, textarea, button {
  font: inherit; font-size: 14px; color: var(--fg);
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
}
input, select { height: 36px; padding: 0 10px; width: 100%; min-width: 0; }
textarea { padding: 8px 10px; width: 100%; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); }
button { display: inline-flex; align-items: center; justify-content: center; height: 36px; padding: 0 14px; white-space: nowrap; cursor: pointer; }
button:hover { background: var(--soft); }
button:disabled { opacity: .5; cursor: default; }
.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.primary:hover { background: var(--primary); filter: brightness(.92); }
.icon { width: 36px; padding: 0; flex: none; }
.icon.on { color: var(--primary); border-color: var(--primary); }
.link { border: 0; height: auto; padding: 0; background: none; color: var(--primary); font-size: 13px; }
.link:hover { background: none; text-decoration: underline; }
.actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Admin bar: only visible when signed in to manage */
.admin-bar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border: 1px solid var(--primary); border-radius: 12px; background: color-mix(in srgb, var(--primary) 6%, var(--bg)); font-size: 14px; }
.admin-dot { width: 8px; height: 8px; border-radius: 50%; background: #16a34a; flex: none; }
.admin-bar.warn .admin-dot { background: var(--warn); }
.admin-text { flex: 1; min-width: 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; height: 36px; padding: 0 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--fg); font-size: 14px; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--soft); }

/* Map */
.map-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.progress { height: 6px; border-radius: 999px; background: var(--soft); overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--primary); border-radius: inherit; transition: width .4s; }
.map-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 12px; }
.map { height: 640px; border-radius: 10px; background: var(--sea); border: 1px solid var(--border); }
.leaflet-container { background: var(--sea); font: inherit; }
.province-label { background: none; border: 0; box-shadow: none; padding: 0; font-size: 6px; opacity: .8; color: var(--muted); white-space: nowrap; }
.province-label span, .island-label span { position: absolute; left: 0; top: 0; transform: translate(-50%, -50%); }
.province-label.visited { color: var(--fg); font-weight: 400; }
.island-label { font-size: 7px; color: var(--muted); white-space: nowrap; text-align: center; line-height: 1.3; }
.island-label b { display: block; width: 6px; height: 6px; margin: 0 auto 2px; border-radius: 50%; background: var(--muted); }
.leaflet-tooltip.tip { font-size: 13px; padding: 4px 8px; border-radius: 6px; }

.side { display: grid; grid-template-rows: auto 1fr; gap: 8px; min-width: 0; max-height: 640px; }
.side-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; }
.side-body { overflow: auto; min-height: 0; display: grid; align-content: start; gap: 6px; }
.prov { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; gap: 10px; align-items: center; height: auto; padding: 8px 10px; text-align: left; justify-content: stretch; }
.prov i { width: 12px; height: 12px; border-radius: 3px; }
.prov span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prov small { color: var(--muted); font-size: 13px; }
.empty { padding: 16px; text-align: center; color: var(--muted); font-size: 14px; border: 1px dashed var(--border); border-radius: 10px; }

/* Photo grids */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.side .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.thumb { position: relative; padding: 0; height: auto; aspect-ratio: 1; overflow: hidden; border-radius: 8px; border: 0; background: var(--soft); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.thumb:hover img { transform: scale(1.04); }

.timeline { display: grid; gap: 16px; }
.tl-month { display: grid; gap: 8px; }
.tl-month h3 { margin: 0; font-size: 14px; font-weight: 500; }
.tl-month h3 small { font-weight: 400; color: var(--muted); }
.timeline .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.tl-day { display: grid; gap: 6px; }
.tl-day-head { margin: 0; font-size: 14px; }
.tl-day-head small { color: var(--muted); font-size: 13px; }
.drop-overlay { position: fixed; inset: 0; z-index: 9000; display: grid; place-items: center; background: color-mix(in srgb, var(--primary) 12%, transparent); backdrop-filter: blur(2px); pointer-events: none; }
.drop-overlay div { padding: 18px 24px; border: 2px dashed var(--primary); border-radius: 14px; background: var(--bg); font-size: 15px; }

/* Dialogs */
.dlg { width: min(720px, calc(100% - 32px)); padding: 0; border: 1px solid var(--border); border-radius: 14px; background: var(--bg); color: var(--fg); }
.dlg::backdrop, .viewer::backdrop { background: rgba(15, 23, 42, .6); }
.dlg-box { display: grid; gap: 12px; padding: 14px 16px; }
.dlg-box p { margin: 0; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; }
.vis-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 4px; max-height: 55vh; overflow: auto; }
.vis-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; font-size: 14px; cursor: pointer; }
.vis-item:hover { background: var(--soft); }
.vis-item input { width: 16px; height: 16px; flex: none; }
.vis-item small { margin-left: auto; color: var(--muted); font-size: 12px; }
.side-body > button { width: 100%; }
.up-place { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; align-items: center; }
.up-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; max-height: 50vh; overflow: auto; }
.up-item { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--soft); }
.up-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.up-item span { position: absolute; inset: auto 0 0 0; padding: 2px 6px; font-size: 11px; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.65)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.up-item.ok::after, .up-item.err::after { position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; color: #fff; }
.up-item.ok::after { content: "✓"; background: #16a34a; }
.up-item.err::after { content: "!"; background: var(--warn); }
.up-progress { display: grid; gap: 6px; }
.up-progress .progress span { transition: width .2s; }

.viewer { width: 100%; max-width: 100%; height: 100%; max-height: 100%; margin: 0; padding: 0; border: 0; background: transparent; }
.viewer-box { position: relative; display: grid; grid-template-rows: minmax(0, 1fr) auto; height: 100%; padding: 16px; gap: 12px; }
.viewer-box > img { max-width: 100%; max-height: 100%; margin: auto; object-fit: contain; border-radius: 8px; }
.viewer-close { position: absolute; top: 16px; right: 16px; z-index: 2; }
.viewer-nav { position: absolute; top: 45%; z-index: 2; font-size: 22px; }
.viewer-nav.prev { left: 16px; }
.viewer-nav.next { right: 16px; }
.viewer-info { width: min(720px, 100%); margin: 0 auto; padding: 12px 14px; border-radius: 12px; background: var(--bg); font-size: 14px; display: grid; gap: 10px; }
.viewer-info p { margin: 0; }

/* How it works */
.howto { border: 1px solid var(--border); border-radius: 14px; padding: 0 16px; font-size: 14px; }
.howto summary { cursor: pointer; padding: 12px 0; }
.howto[open] summary { border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.howto ol { padding-left: 20px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 9999; transform: translate(-50%, 12px);
  padding: 10px 16px; border-radius: 10px; background: #0f172a; color: #fff; font-size: 14px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .18); opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .map-layout { grid-template-columns: 1fr; }
  .map { height: 520px; }
  .side { max-height: none; }
}
@media (max-width: 640px) {
  input, select, textarea { font-size: 16px !important; }
  .map { height: 460px; }
  .admin-bar { flex-wrap: wrap; }
  .admin-bar .actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .admin-bar .actions .btn { grid-column: 1 / -1; }
}

/* Province covers (list + map) */
.prov .prov-cover { width: 28px; height: 28px; border-radius: 6px; object-fit: cover; }
.prov:has(.prov-cover) { grid-template-columns: 28px minmax(0, 1fr) auto; }
.cover-pin { border: 2px solid #fff; border-radius: 8px; overflow: hidden; background: var(--soft); box-shadow: 0 2px 8px rgba(15, 23, 42, .35); cursor: pointer; }
.cover-pin img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.stat { display: grid; gap: 2px; padding: 10px 12px; border-radius: 10px; background: var(--soft); }
.stat strong { font-size: 18px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat span { font-size: 13px; color: var(--muted); }

/* Trips */
.trips { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.trip { position: relative; display: block; height: auto; padding: 0; aspect-ratio: 4 / 3; overflow: hidden; border: 0; border-radius: 10px; background: var(--soft); text-align: left; }
.trip img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.trip:hover img { transform: scale(1.04); }
.trip-info { position: absolute; inset: auto 0 0 0; display: grid; padding: 24px 10px 8px; color: #fff; background: linear-gradient(transparent, rgba(0, 0, 0, .7)); }
.trip-info strong, .trip-info small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trip-info small { font-size: 12px; opacity: .9; }
.trip-head { display: grid; gap: 6px; }
.trip-head p { margin: 0; }
.trip-head .actions { justify-content: flex-start; }

/* Multi-select */
.thumb .lock { position: absolute; top: 4px; left: 4px; font-size: 11px; padding: 1px 4px; border-radius: 6px; background: rgba(0, 0, 0, .55); }
.selecting .thumb::after { content: ""; position: absolute; top: 6px; right: 6px; width: 18px; height: 18px; border-radius: 50%; border: 2px solid #fff; background: rgba(0, 0, 0, .25); }
.selecting .thumb.sel { outline: 3px solid var(--primary); outline-offset: -3px; }
.selecting .thumb.sel::after { content: "✓"; display: grid; place-items: center; font-size: 11px; color: #fff; background: var(--primary); border-color: var(--primary); }
#selectBtn.on { color: var(--primary); border-color: var(--primary); }
.sel-bar { position: fixed; left: 50%; bottom: 16px; z-index: 1000; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; width: max-content; max-width: calc(100% - 32px); padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); box-shadow: 0 8px 24px rgba(15, 23, 42, .2); font-size: 14px; }
.sel-bar select { width: 180px; }
.selecting .wrap { padding-bottom: 120px; }
.viewer-tools { justify-content: flex-start; flex-wrap: wrap; }

@media (max-width: 640px) {
  .sel-bar { width: calc(100% - 32px); display: grid; grid-template-columns: 1fr 1fr; }
  .sel-bar strong, .sel-bar select { grid-column: 1 / -1; width: 100%; }
}
.leaflet-interactive:focus, .leaflet-container path:focus { outline: none; }
/* Select: own chevron with room on the right */
select {
  appearance: none; -webkit-appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 12px;
}

/* Specific places */
.place-add { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.place-results { display: grid; gap: 4px; }
.place-results:empty, .place-list:empty { display: none; }
.place-results button { justify-content: flex-start; height: auto; min-height: 36px; padding: 6px 10px; white-space: normal; text-align: left; font-size: 13px; }
.place-results small { color: var(--muted); margin-left: 6px; }
.place-list { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 4px 0 10px; border: 1px solid var(--border); border-radius: 999px; font-size: 13px; background: var(--soft); }
.chip small { color: var(--muted); }
.chip button { width: 22px; height: 22px; padding: 0; border: 0; border-radius: 50%; background: none; font-size: 12px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-row .chip { padding-right: 10px; }
.place-box { display: grid; gap: 8px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }

/* Map controls: same look as the site's buttons */
.map-ctrl { display: grid; gap: 6px; }
.map-ctrl button { width: 36px; height: 36px; padding: 0; font-size: 18px; line-height: 1; color: var(--fg); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 1px 2px rgba(15, 23, 42, .06); }
.map-ctrl button:hover { background: var(--soft); }
.leaflet-touch .leaflet-control-layers, .leaflet-touch .leaflet-bar { border: 0; }

/* Upload drop zone */
.dropzone { display: grid; gap: 4px; place-items: center; padding: 28px 16px; text-align: center; border: 1px dashed var(--border); border-radius: 10px; background: var(--soft); cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone { color: var(--muted); font-size: 14px; }
.dropzone:hover, .dropzone:focus-visible, .dropzone.over { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 6%, var(--bg)); outline: none; }
.up-grid:empty { display: none; }

/* Original photo info in the viewer */
.photo-info summary { cursor: pointer; font-size: 13px; color: var(--muted); }
.photo-info dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 12px; margin: 8px 0 0; font-size: 13px; }
.photo-info dt { color: var(--muted); }
.photo-info dd { margin: 0; overflow-wrap: anywhere; }
.leaflet-container:focus { outline: none; }

/* Photo list scrolls on its own: reaching the end no longer drags the page along */
.side-body { padding-right: 2px; }
.side-body.scrolls { overscroll-behavior: contain; }
.plans { display: grid; gap: 8px; }
.chip.plan { background: color-mix(in srgb, #f59e0b 10%, var(--bg)); border-color: color-mix(in srgb, #f59e0b 35%, var(--border)); }
/* Stats: label on top, value below, one full row */
.stats { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.stat span { order: 0; }
@media (max-width: 760px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.viewer-tools select { width: 200px; }

/* Settings (manage mode) */
.settings-btn { position: relative; }
.settings-btn.warn::after { content: ""; position: absolute; top: 6px; right: 6px; width: 7px; height: 7px; border-radius: 50%; background: var(--warn); }
.dlg-sm { width: min(400px, calc(100% - 32px)); }
.settings-status { display: flex; align-items: center; gap: 8px; font-size: 14px; overflow-wrap: anywhere; }
.settings-status .admin-dot { width: 8px; height: 8px; border-radius: 50%; background: #16a34a; flex: none; }
.settings-dlg.warn .admin-dot, .dlg.warn .admin-dot { background: var(--warn); }
.settings-list { display: grid; gap: 8px; }
.settings-list > * { width: 100%; justify-content: flex-start; }
#logoutBtn { color: var(--warn); }

/* Light type: nothing heavier than 500 */
strong, b, th, summary, .dlg-head strong { font-weight: 500; }

/* Download */
.viewer-download { position: absolute; top: 16px; right: 60px; z-index: 2; }
.selecting .toast { bottom: 96px; }

/* ---------- Mobile ---------- */
@media (max-width: 640px) {
  .wrap { padding-top: 16px; }
  .content { gap: 12px; }
  .top { gap: 8px; }
  .brand img { width: 32px; height: 32px; }
  h1 { font-size: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .back { padding: 6px 8px; font-size: 16px; }
  .back span { display: none; }
  .card { padding: 12px; border-radius: 12px; }

  /* Map header: title on top, actions as a 2×2 grid */
  .map-head { flex-direction: column; align-items: stretch; gap: 10px; }
  .map-head .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .map-head .actions button { width: 100%; }
  .map { height: 420px; }
  .side { max-height: 480px; }
  .map-ctrl button { width: 32px; height: 32px; }

  .stats { grid-template-columns: 1fr 1fr; }
  .stat:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .stat strong { font-size: 16px; }
  .trips { grid-template-columns: 1fr 1fr; gap: 8px; }
  .timeline .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }

  /* Select bar: bottom sheet */
  .sel-bar { left: 0; right: 0; bottom: 0; transform: none; width: 100%; max-width: none; border-radius: 14px 14px 0 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .sel-bar strong, .sel-bar select { grid-column: 1 / -1; width: 100%; }
  .sel-bar button { width: 100%; padding: 0 6px; font-size: 13px; }
  .sel-bar #selDone { grid-column: 1 / -1; }
  .selecting .toast { bottom: 190px; }
  .selecting .wrap { padding-bottom: 220px; }

  /* Dialogs as bottom sheets */
  .dlg { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 14px 14px 0 0; max-height: 90vh; }
  .dlg-box { padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); }
  .vis-list { grid-template-columns: 1fr 1fr; }
  .up-place { grid-template-columns: 1fr; gap: 6px; }

  /* Viewer */
  .viewer-box { padding: 8px; gap: 8px; }
  .viewer-close { top: 8px; right: 8px; }
  .viewer-download { top: 8px; right: 52px; }
  .viewer-nav { top: auto; bottom: 45%; }
  .viewer-nav.prev { left: 8px; }
  .viewer-nav.next { right: 8px; }
  .viewer-info { padding: 10px 12px; }
  .viewer-tools { display: grid; grid-template-columns: 1fr 1fr; }
  .viewer-tools select { grid-column: 1 / -1; width: 100%; }
  .viewer-tools button { width: 100%; font-size: 13px; }
}

/* Year filter */
.years { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.years button { height: 28px; padding: 0 10px; border-radius: 999px; font-size: 13px; }
.years button.on { background: var(--primary); border-color: var(--primary); color: #fff; }
/* Places to go: name, month, search */
.plan-add { grid-template-columns: minmax(0, 1fr) auto; }
.plan-when { grid-column: 1 / -1; display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.tl-more { padding: 12px; text-align: center; color: var(--muted); font-size: 13px; }

/* ---------- Viewer: light frosted overlay, photo first ---------- */
.viewer::backdrop { background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(18px) saturate(1.1); -webkit-backdrop-filter: blur(18px) saturate(1.1); }
.viewer-box > img { border-radius: 10px; box-shadow: 0 12px 40px rgba(15, 23, 42, .18); }
.viewer-close, .viewer-download, .viewer-nav { border: 1px solid var(--border); border-radius: 50%; background: color-mix(in srgb, var(--bg) 85%, transparent); color: var(--fg); backdrop-filter: blur(6px); box-shadow: 0 2px 8px rgba(15, 23, 42, .08); }
.viewer-close:hover, .viewer-download:hover, .viewer-nav:hover { background: var(--bg); }
.viewer-info { background: color-mix(in srgb, var(--bg) 92%, transparent); color: var(--fg); border: 1px solid var(--border); box-shadow: 0 8px 24px rgba(15, 23, 42, .08); gap: 8px; }
.viewer-tools { gap: 6px; }
.viewer-tools button, .viewer-tools select { height: 32px; font-size: 13px; }
.viewer-tools #deleteBtn { color: var(--warn); }
@media (max-width: 640px) {
  .viewer-nav { width: 36px; height: 36px; }
  /* Tools in one swipeable row instead of a big grid */
  .viewer-tools { display: flex; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .viewer-tools::-webkit-scrollbar { display: none; }
  .viewer-tools select { flex: none; width: 150px; }
  .viewer-tools button { flex: none; width: auto; padding: 0 12px; }
  .viewer-info { padding: 10px; font-size: 13px; }
}

/* Settings menu */
.m-only { display: none; }
.settings-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
@media (max-width: 640px) {
  .m-only { display: grid; }
  /* Map actions move into the menu; only "+ Thêm ảnh" stays on the page */
  #selectBtn, #visitedBtn, #plansBtn { display: none; }
  .map-head .actions { grid-template-columns: 1fr; }
  /* Menu opens full screen, evenly spaced rows */
  .dlg-menu { width: 100%; height: 100dvh; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; }
  .dlg-menu .dlg-box { min-height: 100%; align-content: start; gap: 16px; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
  .dlg-menu .settings-list > * { height: 48px; font-size: 15px; }
}

/* Phones: header stays on top; menu and sheets slide in / out */
@media (max-width: 640px) {
  .top { position: sticky; top: 0; z-index: 1100; margin: -16px -16px 0; padding: 10px 16px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }

  /* Every dialog is a drawer (~80% wide) sliding in from the left; tap outside to close */
  .dlg { width: 82%; max-width: 360px; height: 100dvh; max-height: 100dvh; margin: 0; border: 0; border-radius: 0 14px 14px 0; box-shadow: 8px 0 32px rgba(15, 23, 42, .25);
    transition: transform .28s cubic-bezier(.2, .8, .2, 1), overlay .28s allow-discrete, display .28s allow-discrete; transform: translateX(-100%); }
  .dlg[open] { transform: none; }
  @starting-style { .dlg[open] { transform: translateX(-100%); } }
  .dlg .dlg-box { min-height: 100%; align-content: start; gap: 14px; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }
  .dlg .vis-list, .dlg .up-grid { max-height: none; }
  .dlg::backdrop { transition: background .28s, overlay .28s allow-discrete, display .28s allow-discrete; background: rgba(15, 23, 42, 0); }
  .dlg[open]::backdrop { background: rgba(15, 23, 42, .6); }
  @starting-style { .dlg[open]::backdrop { background: rgba(15, 23, 42, 0); } }
}
@media (prefers-reduced-motion: reduce) { .dlg, .dlg::backdrop { transition: none; } }

/* Images fade in over a soft placeholder once loaded */
.thumb img, .trip img, .prov-cover { opacity: 0; transition: opacity .25s ease, transform .25s; }
.thumb img.ready, .trip img.ready, .prov-cover.ready { opacity: 1; }
.prov-cover { background: var(--soft); }

/* Phones: one scroll only (the page). Nested scroll areas made iOS jump back up */
@media (max-width: 640px) {
  .side { max-height: none; }
  .side-body, .side-body.scrolls { overflow: visible; max-height: none; overscroll-behavior: auto; }
}

/* Album in the side panel: places + search stick to the top, the photos scroll under them */
.side-body.album > .trip-head { position: sticky; top: 0; z-index: 2; background: var(--bg); padding-bottom: 8px; }
@media (max-width: 640px) {
  .side-body.album, .side-body.album.scrolls { overflow: visible; max-height: none; overscroll-behavior: auto; }
  .side-body.album > .place-box, .side-body.album > .chip-row, .side-body.album > .trip-head { position: static; }
}
.album-pages { display: grid; gap: 8px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 13px; color: var(--muted); }
.pager button { width: 34px; height: 34px; padding: 0; border-radius: 8px; font-size: 14px; }
.pager button.on { background: var(--primary); border-color: var(--primary); color: #fff; }
@media (max-width: 640px) { .album-pages .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; } }
/* Phones: clear break between the map and the place list below it */
@media (max-width: 640px) {
  .map-layout { gap: 20px; }
  .side { padding-top: 16px; border-top: 1px solid var(--border); }
  .side-head { font-size: 15px; }
}
/* Phones: tiny map labels (scaled, since browsers keep a minimum font size) */
@media (max-width: 640px) {
  .province-label span { transform: translate(-50%, -50%) scale(.7); }
  .island-label span { transform: translate(-50%, -50%) scale(.75); }
}
.prov-list { display: grid; gap: 6px; }

/* Places: grouped by area, with note and Google Maps link */
.place-tree { display: grid; gap: 10px; }
.place-area { display: grid; gap: 6px; }
.place-area-name { margin: 0; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
/* Same look as the place list rows (.prov) */
.place-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; width: 100%; height: auto; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); text-align: left; justify-content: stretch; white-space: normal; font-size: 14px; }
button.place-row:hover { background: var(--soft); }
.place-body { display: grid; gap: 2px; min-width: 0; }
.place-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.place-body small { color: var(--muted); font-size: 12px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.place-map { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; color: var(--muted); }
.place-map:hover { background: var(--soft); color: var(--primary); }
.place-box { display: grid; gap: 10px; }


/* "+ Thêm" choices */
.add-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.add-choices button { display: grid; gap: 2px; justify-items: start; height: auto; padding: 12px; text-align: left; white-space: normal; }
.add-choices strong { font-size: 14px; }
.add-choices small { color: var(--muted); font-size: 12px; }
.add-spot { display: grid; gap: 10px; }
.add-spot .link { justify-self: start; }
.add-choices button { min-height: 96px; align-content: start; gap: 4px; border-radius: 10px; }
.add-choices button svg { color: var(--primary); margin-bottom: 4px; }
.add-choices button:hover { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 5%, var(--bg)); }
.add-choices button { justify-content: start; justify-items: start; }
.form-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (max-width: 640px) { .form-2 { grid-template-columns: 1fr; } }
.form-2 .plan-when { grid-column: auto; }

/* Place rows with actions, quick add per area */
.place-acts { display: flex; gap: 2px; }
.place-act { display: grid; place-items: center; width: 30px; height: 30px; padding: 0; border: 0; border-radius: 50%; background: none; color: var(--muted); }
.place-act:hover { background: var(--soft); color: var(--primary); }
.quick-add input, .new-area input { height: 34px; font-size: 13px; }
.quick-add button, .new-area button { height: 34px; font-size: 13px; }
.quick-add input { border-style: dashed; }
.new-area { padding-top: 6px; border-top: 1px dashed var(--border); }
.quick-open { justify-self: start; padding: 2px 0; font-size: 13px; }
@media (max-width: 640px) { .timeline .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; } }
.area-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.area-head .place-act { width: 26px; height: 26px; }
/* Hierarchy: places sit indented under their area, with a guide line */
.place-area > .place-area-name ~ *, .place-area > .area-head ~ * { margin-left: 14px; }
.place-area:has(> .place-area-name, > .area-head) { position: relative; }
.place-area:has(> .place-area-name, > .area-head)::before { content: ""; position: absolute; left: 4px; top: 26px; bottom: 4px; border-left: 1px solid var(--border); }
/* "+ Thêm" has three choices now (places are added inside each province) */
.add-choices { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 640px) { .add-choices { grid-template-columns: 1fr; } .add-choices button { min-height: 0; } }
/* "+ Thêm" as a simple list: icon, name, short description in one row */
.add-choices { grid-template-columns: 1fr; gap: 6px; }
.add-choices button { min-height: 0; display: grid; grid-template-columns: 20px minmax(0, 1fr); grid-template-rows: auto auto; column-gap: 12px; row-gap: 0; align-items: center; padding: 10px 12px; }
.add-choices button svg { grid-row: 1 / 3; margin: 0; }
/* Phones: "+ Thêm" and "Chọn nhiều" live in the menu only */
@media (max-width: 640px) { #adminActions { display: none !important; } }

/* Phones: the settings button is a ☰ menu that turns into ✕ while open */
.burger { display: none; position: relative; width: 16px; height: 12px; }
.burger i { position: absolute; left: 0; width: 100%; height: 1.5px; border-radius: 2px; background: currentColor; transition: transform .25s ease, opacity .2s ease, top .25s ease; }
.burger i:nth-child(1) { top: 0; }
.burger i:nth-child(2) { top: 5px; }
.burger i:nth-child(3) { top: 10px; }
.open .burger i:nth-child(1) { top: 5px; transform: rotate(45deg); }
.open .burger i:nth-child(2) { opacity: 0; }
.open .burger i:nth-child(3) { top: 5px; transform: rotate(-45deg); }
@media (max-width: 640px) {
  #settingsBtn svg { display: none; }
  #settingsBtn .burger { display: block; }
  /* stays above the menu overlay so the ✕ is visible and taps close the menu */
  #settingsBtn.open { position: relative; z-index: 2; }
}
/* Desktop: map box sized to Vietnam's shape (no wide empty sea), the list gets the rest */
@media (min-width: 901px) {
  .map-layout { grid-template-columns: minmax(0, 560px) minmax(0, 1fr); }
  .map { height: 620px; }
  .side { max-height: 620px; }
}
/* Indented rows keep inside the panel: no sideways scroll */
.place-area > .place-area-name ~ *, .place-area > .area-head ~ * { width: auto; max-width: calc(100% - 14px); }
.place-area > .place-area-name ~ .place-row, .place-area > .area-head ~ .place-row, .place-area > .area-head ~ .place-add, .place-area > .place-area-name ~ .place-add { width: calc(100% - 14px); }
.side-body { overflow-x: hidden; }

/* Drag & drop places */
.place-row[draggable="true"] { cursor: grab; }
.place-row.dragging { opacity: .4; }
.place-row.drop-before { box-shadow: 0 -2px 0 var(--primary); }
.place-area.drop-in { outline: 2px dashed var(--primary); outline-offset: 4px; border-radius: 8px; }
.place-row.can-drag { grid-template-columns: 12px minmax(0, 1fr) auto; cursor: default; }
.grip { display: grid; place-items: center; color: var(--muted); opacity: .55; cursor: grab; }
.place-row.can-drag:hover .grip { opacity: 1; }
.place-row.dragging .grip { cursor: grabbing; }

/* Crisper text: no faded labels */
.province-label { opacity: 1; color: #475569; -webkit-font-smoothing: antialiased; }
.province-label.visited { color: var(--fg); font-weight: 500; }
.island-label { color: #475569; }
.place-area-name { color: #475569; }
@media (prefers-color-scheme: dark) { .province-label, .island-label, .place-area-name { color: #cbd5e1; } }

/* Phones: one compact header bar across the full width, stuck to the top (same in every tool) */
@media (max-width: 639px) {
  .wrap { padding-top: 0; }
  .top { position: sticky; top: 0; z-index: 1100; flex-wrap: nowrap; align-items: center; gap: 10px; margin: 0 -16px; padding: 10px 16px;
    background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
  .top-text { flex: 1; min-width: 0; }
  .brand img { width: 32px; height: 32px; }
  h1 { font-size: 18px; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .back { padding: 6px 8px; font-size: 16px; }
  .back span { display: none; }
}
