/* =====================================================================
   styles.css — the look of the Digital Garden: a pen-and-ink drawing
   in thin black lines on paper.
   Change the values in :root below to adjust paper, ink and line weights.
   ===================================================================== */

:root {
  --paper: #f7f5ef;
  --paper-white: #fdfcf8;
  --ink: #1d1b18;
  --ink-soft: #6b6760;
  --ink-faint: #b9b4aa;
  --danger: #8a2c1c;
  --focus: #2f5f9a;

  /* Line weights on the drawing, in screen pixels */
  --line: 1.1px;        /* outlines */
  --line-fine: .7px;    /* leaf marks, hatching */

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Baskerville, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Segoe UI", system-ui, sans-serif;
  --radius: 4px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--serif);
  color: var(--ink);
  background: var(--paper);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--ink); }
:focus-visible { outline: 1.5px solid var(--focus); outline-offset: 3px; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.defs { position: absolute; width: 0; height: 0; }

/* ---------- The drawing ---------- */
.stage { position: fixed; inset: 0; touch-action: none; user-select: none; -webkit-user-select: none; }
.world { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
body.dragging .world { cursor: grabbing; }
.world text { font-family: var(--serif); }

/* Mind map view */
.mindmap { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
body.map-view .world { visibility: hidden; }
body.map-view .context-bar, body.map-view .edit-toggle { display: none !important; }

/* Leaves */
.mass-fill { fill: var(--paper); }
.mass-line {
  fill: none; stroke: var(--ink); stroke-width: var(--line);
  stroke-linejoin: round; vector-effect: non-scaling-stroke;
}
.mass-marks, .mass-hatch, .mass-contour {
  fill: none; stroke: var(--ink); stroke-width: var(--line-fine);
  stroke-linecap: round; vector-effect: non-scaling-stroke;
}
.mass-hatch { opacity: .75; }
.mass-contour { opacity: .6; }
.mass-dots { fill: none; stroke: var(--ink); stroke-width: 1.6px; stroke-linecap: round; vector-effect: non-scaling-stroke; }

/* Branches and trunk */
.limb { fill: var(--ink); }
.trunk-line { fill: none; stroke: var(--ink); stroke-width: 1.4px; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.bark-mark, .bark-hatch { fill: none; stroke: var(--ink); stroke-width: var(--line-fine); stroke-linecap: round; vector-effect: non-scaling-stroke; }
.bark-hatch { opacity: .85; }
.bark-dark { fill: var(--ink); }
.ground-line { fill: none; stroke: var(--ink); stroke-width: 1.4px; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.ground-hatch { fill: none; stroke: var(--ink); stroke-width: var(--line-fine); vector-effect: non-scaling-stroke; opacity: .8; }
.stem { fill: none; stroke: var(--ink); stroke-width: var(--line); stroke-linecap: round; vector-effect: non-scaling-stroke; }

/* Words on the drawing. A paper-coloured edge keeps them readable over the lines. */
.mass-label, .trunk-name, .scene-title, .fruit-label, .empty-note, .bud-label {
  fill: var(--ink); stroke: var(--paper); stroke-width: .32em; stroke-linejoin: round; paint-order: stroke;
}
.mass-label { letter-spacing: .01em; }
.group-label { font-style: italic; }
.trunk-name { font-variant: small-caps; letter-spacing: .14em; }
.scene-title { letter-spacing: .01em; }
.fruit-label { font-style: italic; cursor: pointer; }
.fruit-label:hover { text-decoration: underline; }
.empty-note { fill: var(--ink-soft); font-style: italic; }

/* Masses you can tap rise a touch and their name underlines. */
.nav { cursor: pointer; outline: none; }
.lift { transition: transform .35s cubic-bezier(.3, 1.4, .6, 1); transform-box: fill-box; transform-origin: 50% 80%; }
.nav:hover .lift, .nav:focus-visible .lift { transform: translateY(-3px); }
.nav:hover .mass-label, .nav:focus-visible .mass-label { text-decoration: underline; }
.nav:hover .mass-line, .nav:focus-visible .mass-line { stroke-width: 1.8px; }

/* Buds (grow something new) and blossoms (add a fruit), in edit mode. */
.bud { cursor: pointer; outline: none; }
.hit-dot { fill: transparent; }
.ui-line { fill: var(--paper); stroke: var(--ink); stroke-width: var(--line); vector-effect: non-scaling-stroke; }
.bud-plus { fill: none; stroke: var(--ink); stroke-width: 1.4px; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.bud-label { font-style: italic; }
.bud:hover .ui-line, .bud:focus-visible .ui-line { fill: var(--paper-white); stroke-width: 1.8px; }
.bud:hover .bud-label, .bud:focus-visible .bud-label { text-decoration: underline; }

/* ---------- Fruit (line drawings) ---------- */
.fruit-ol { fill: var(--paper); stroke: var(--ink); stroke-width: var(--line); stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.fruit-line, .fruit-shade { fill: none; stroke: var(--ink); stroke-width: var(--line-fine); stroke-linecap: round; vector-effect: non-scaling-stroke; }
.fruit-line { stroke-width: var(--line); }
.fruit-dots { fill: none; stroke: var(--ink); stroke-width: 1.6px; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.fruit { animation: fruit-swing 4s ease-in-out infinite alternate; }
@keyframes fruit-swing { from { transform: rotate(-3deg); } to { transform: rotate(3deg); } }
.fruit-hover { transition: transform .25s ease; }
.fruit:not(.preview) { cursor: pointer; }
.fruit:not(.preview):hover .fruit-hover, .fruit.is-hover .fruit-hover { transform: scale(1.12); }
.fruit-icon .fruit-ol, .fruit-icon .fruit-line { stroke-width: 1px; }

/* ---------- Buttons and boxes ---------- */
.back-btn, .view-btn, .edit-toggle, .menu summary, .btn, .zoom-controls button, .breadcrumb, .search, .legend, .context-bar, .menu-panel, .icon-btn {
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper-white);
}
.back-btn, .view-btn, .edit-toggle, .menu summary, .btn, .zoom-controls button {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 42px; padding: 0 16px;
  color: var(--ink); font-size: 15px; text-decoration: none; cursor: pointer;
  transition: background .15s, color .15s;
}
.back-btn:hover, .view-btn:hover, .edit-toggle:hover, .menu summary:hover, .btn:hover, .zoom-controls button:hover { background: var(--ink); color: var(--paper-white); }
.btn.primary { background: var(--ink); color: var(--paper-white); }
.btn.primary:hover { background: #3a3732; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: var(--paper-white); }

/* ---------- Top bar ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 5;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) 14px 0;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.crumbs { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.breadcrumb {
  display: flex; align-items: center; flex-wrap: wrap; gap: 2px; margin: 0; padding: 4px 16px;
  list-style: none; min-height: 42px; min-width: 0; max-width: 100%; font-size: 16px;
}
.breadcrumb li { display: flex; align-items: center; min-width: 0; }
.breadcrumb li + li::before { content: "›"; margin: 0 8px; color: var(--ink-faint); font-size: 18px; }
.breadcrumb a, .breadcrumb span { text-decoration: none; color: var(--ink); display: inline-flex; align-items: center; gap: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.breadcrumb a { color: var(--ink-soft); padding: 4px 2px; }
.breadcrumb a:hover { color: var(--ink); text-decoration: underline; }
.breadcrumb [aria-current] span { font-style: italic; }

.tools { display: flex; gap: 8px; align-items: flex-start; flex: none; }
.switch { width: 34px; height: 18px; border-radius: 999px; border: 1px solid currentColor; position: relative; }
.knob { position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: currentColor; transition: transform .2s; }
.edit-toggle[aria-checked="true"] { background: var(--ink); color: var(--paper-white); }
.edit-toggle[aria-checked="true"] .knob { transform: translateX(16px); }

.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-panel { position: absolute; right: 0; top: calc(100% + 6px); z-index: 6; display: grid; min-width: 250px; padding: 4px; }
.menu-panel button { text-align: left; padding: 11px 14px; border: 0; background: none; border-radius: 2px; cursor: pointer; }
.menu-panel button:hover { background: var(--paper); text-decoration: underline; }

.sync-status {
  display: inline-flex; align-items: center; gap: 6px; min-height: 42px; padding: 0 12px;
  border: 1px solid var(--ink-faint); border-radius: var(--radius); background: var(--paper-white);
  color: var(--ink-soft); font-size: 14px; cursor: pointer;
}
.sync-status:hover { border-color: var(--ink); color: var(--ink); }
.sync-status[data-status="signed-out"], .sync-status[data-status="error"] { border-color: var(--ink); color: var(--ink); font-style: italic; }
.sync-status[data-status="saving"] svg { animation: sync-pulse 1.2s ease-in-out infinite; }
@keyframes sync-pulse { 50% { opacity: .35; } }

/* ---------- Bottom: search, edit bar, hint, legend, zoom ---------- */
.search {
  position: fixed; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 6;
  width: min(440px, calc(100vw - 260px));
  display: flex; align-items: center; gap: 8px; padding: 0 14px; min-height: 46px;
}
.search-icon { flex: none; color: var(--ink-soft); }
.search input { flex: 1; min-width: 0; border: 0; background: none; outline: none; font-size: 17px; padding: 10px 0; }
.search input::placeholder { color: var(--ink-soft); font-style: italic; }
.search:focus-within { outline: 1.5px solid var(--ink); outline-offset: 2px; }
.search-results {
  position: absolute; left: -1px; right: -1px; bottom: calc(100% + 6px);
  margin: 0; padding: 4px; list-style: none;
  max-height: min(52vh, 460px); overflow-y: auto;
  background: var(--paper-white); border: 1px solid var(--ink); border-radius: var(--radius);
}
.result { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; cursor: pointer; }
.result.active, .result:hover { background: var(--paper); }
.result-icon { flex: none; width: 28px; display: grid; place-items: center; padding-top: 2px; }
.result-text { display: grid; gap: 1px; min-width: 0; }
.result-text b { font-weight: 600; overflow-wrap: anywhere; }
.result-text small { color: var(--ink-soft); font-size: 13px; overflow-wrap: anywhere; }
.result-text .snippet { font-style: italic; }
.result mark { background: none; color: inherit; text-decoration: underline; text-decoration-thickness: 1.5px; text-underline-offset: 2px; }
.no-results { padding: 12px; color: var(--ink-soft); font-style: italic; }

.context-bar {
  position: fixed; left: 50%; bottom: calc(max(14px, env(safe-area-inset-bottom)) + 58px); transform: translateX(-50%); z-index: 4;
  display: flex; gap: 6px; align-items: center; padding: 5px; flex-wrap: nowrap;
  max-width: calc(100vw - 24px); overflow-x: auto;
}
.context-bar .btn { white-space: nowrap; min-height: 38px; }
.bar-hint { padding: 0 8px 0 10px; color: var(--ink-soft); font-size: 14px; font-style: italic; white-space: nowrap; }

.hint {
  position: fixed; left: 50%; bottom: 74px; transform: translateX(-50%); z-index: 3;
  margin: 0; padding: 4px 12px; color: var(--ink-soft); font-style: italic; font-size: 15px;
  pointer-events: none; white-space: nowrap; background: var(--paper);
  animation: hint-fade 6s ease forwards;
}
@keyframes hint-fade { 0%, 75% { opacity: 1; } 100% { opacity: 0; } }
body.editing .hint { bottom: 128px; }
body.map-view .hint { bottom: 74px; }

.legend { position: fixed; left: 14px; bottom: max(14px, env(safe-area-inset-bottom)); z-index: 3; padding: 4px 14px; font-size: 14px; }
.legend summary { cursor: pointer; padding: 6px 0; min-height: 30px; }
.legend ul { list-style: none; margin: 0 0 6px; padding: 0; display: grid; gap: 4px; }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend b { font-weight: 600; }

.zoom-controls { position: fixed; right: 14px; bottom: max(14px, env(safe-area-inset-bottom)); z-index: 3; display: grid; gap: 6px; }
.zoom-controls button { width: 44px; padding: 0; font-size: 20px; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; left: 50%; top: 72px; transform: translateX(-50%); z-index: 20; display: grid; gap: 8px; width: min(520px, calc(100vw - 24px)); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px;
  padding: 9px 9px 9px 16px; border-radius: var(--radius); background: var(--ink); color: var(--paper-white);
  font-size: 15px; animation: toast-in .3s ease; transition: opacity .35s, transform .35s;
}
.toast span { flex: 1; }
.toast.leaving { opacity: 0; transform: translateY(-8px); }
.toast-error { background: var(--danger); }
.toast-warn { background: #5a4a2a; }
.toast-btn { border: 1px solid rgba(255,255,255,.6); background: transparent; color: inherit; border-radius: var(--radius); padding: 5px 14px; cursor: pointer; min-height: 34px; }
.toast-btn:hover { background: rgba(255,255,255,.15); }
.toast-x { border: 0; background: none; color: inherit; opacity: .7; cursor: pointer; font-size: 15px; width: 32px; height: 32px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

/* ---------- Dialogs ---------- */
.modal {
  width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 32px);
  padding: 0; border: 1px solid var(--ink); border-radius: var(--radius);
  background: var(--paper-white); color: var(--ink); box-shadow: 0 18px 50px rgba(29, 27, 24, .18);
}
.modal.wide { width: min(760px, calc(100vw - 24px)); }
.modal::backdrop { background: rgba(247, 245, 239, .75); }
.modal[open] { animation: modal-in .25s ease; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px); } }
.modal-inner { padding: 24px 26px; }
.modal h2 { font-size: 25px; font-weight: 400; margin: 0 0 14px; line-height: 1.2; }

.form p { line-height: 1.5; }
.field { display: grid; gap: 6px; margin: 0 0 14px; }
.field > label, label.field > span { font-size: 15px; }
.field input[type=text], .field input[type=url], .field textarea, label.field input, .image-url {
  width: 100%; padding: 10px 12px; border: 1px solid var(--ink-soft); border-radius: var(--radius); background: #fff;
  font-size: 16px; /* 16px stops phones zooming in */
}
.field textarea { resize: vertical; min-height: 80px; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 14px; line-height: 1.5; }
.field input:focus, .field textarea:focus, .image-url:focus { border-color: var(--ink); outline: 1px solid var(--ink); }
.error { color: var(--danger); font-size: 14px; margin: 0; }
.muted { color: var(--ink-soft); }
.small { font-size: 13px; margin: 0; }
.actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 20px; }

.type-picker, .kind-picker { border: 0; padding: 0; margin: 0 0 16px; }
.type-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.type-picker legend, .kind-picker legend { margin-bottom: 8px; padding: 0; }
.type-option input, .kind-option input { position: absolute; opacity: 0; pointer-events: none; }
.type-option > span, .kind-option > span {
  display: grid; justify-items: center; gap: 2px; padding: 10px 6px; cursor: pointer;
  border: 1px solid var(--ink-faint); border-radius: var(--radius); background: #fff; text-align: center;
}
.type-option small, .kind-option small { color: var(--ink-soft); font-style: italic; }
.type-option input:checked + span, .kind-option input:checked + span { border-color: var(--ink); outline: 1px solid var(--ink); }
.type-option input:focus-visible + span, .kind-option input:focus-visible + span { outline: 1.5px solid var(--focus); outline-offset: 2px; }
.kind-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.kind-option > span { justify-items: start; text-align: left; padding: 10px 14px; }
.kind-option b { font-weight: 600; }

.move-list { display: grid; gap: 2px; max-height: 50vh; overflow-y: auto; margin: 8px 0; }
.move-option { display: flex; align-items: center; gap: 10px; padding: 8px 10px; padding-left: calc(10px + var(--depth, 0) * 22px); cursor: pointer; }
.move-option:hover { background: var(--paper); }
.move-option input { width: 16px; height: 16px; accent-color: var(--ink); }

.images-field { display: grid; gap: 12px; }
.image-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 300px; overflow-y: auto; }
.image-row { display: grid; grid-template-columns: 64px 1fr auto; gap: 10px; align-items: center; padding: 6px; border: 1px solid var(--ink-faint); border-radius: var(--radius); background: #fff; }
.image-row img { width: 64px; height: 48px; object-fit: cover; border: 1px solid var(--ink-faint); }
.image-row .image-caption { width: 100%; min-width: 0; padding: 8px 10px; border: 1px solid var(--ink-faint); border-radius: var(--radius); font-size: 16px; background: #fff; }
.image-row-tools { display: flex; gap: 4px; }
.image-row-tools .icon-btn { width: 34px; height: 34px; border: 1px solid var(--ink-faint); }
.image-row-tools .icon-btn:disabled { opacity: .3; cursor: default; }
.image-empty { padding: 14px; color: var(--ink-soft); font-style: italic; border: 1px dashed var(--ink-faint); border-radius: var(--radius); text-align: center; }
.image-inputs { display: grid; gap: 8px; }
.image-link-row { display: flex; gap: 8px; }
.image-link-row .image-url { flex: 1; min-width: 0; }
.file-btn { justify-self: start; }
.or { font-size: 13px; color: var(--ink-soft); font-style: italic; }

/* Fruit viewer */
.viewer-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.viewer-head > div { flex: 1; min-width: 0; }
.viewer-head h2 { margin: 0; overflow-wrap: anywhere; }
.eyebrow { margin: 0 0 2px; font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-soft); font-family: var(--sans); }
.icon-btn { flex: none; width: 40px; height: 40px; cursor: pointer; font-size: 15px; }
.viewer-body { line-height: 1.6; font-size: 17px; }
.link-url { font-family: ui-monospace, Menlo, monospace; font-size: 13px; color: var(--ink-soft); overflow-wrap: anywhere; }
.image-view { margin: 0; }
.image-view img { display: block; max-width: 100%; max-height: 65dvh; margin: 0 auto; border: 1px solid var(--ink); }
.image-view figcaption { text-align: center; color: var(--ink-soft); margin-top: 8px; font-style: italic; }
.gallery { margin-bottom: 8px; }
.gallery-stage { position: relative; touch-action: pan-y; }
.gallery-stage img { user-select: none; -webkit-user-drag: none; }
.gallery-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--ink);
  background: rgba(253, 252, 248, .92); color: var(--ink); font-size: 26px; line-height: 1; cursor: pointer;
}
.gallery-nav:hover { background: var(--ink); color: var(--paper-white); }
.gallery-nav.prev { left: 8px; } .gallery-nav.next { right: 8px; }
.gallery-count { text-align: center; margin: 6px 0; color: var(--ink-soft); font-size: 14px; }
.gallery-thumbs { display: flex; gap: 6px; overflow-x: auto; padding: 2px; justify-content: safe center; }
.gallery-thumb { flex: none; padding: 0; border: 1px solid var(--ink-faint); background: none; cursor: pointer; opacity: .65; }
.gallery-thumb img { display: block; width: 64px; height: 48px; object-fit: cover; }
.gallery-thumb[aria-current="true"] { opacity: 1; border-color: var(--ink); outline: 1px solid var(--ink); }
.gallery-thumb:hover { opacity: 1; }

/* Links to other fruit */
.fruit-ref { display: inline-flex; align-items: center; gap: 3px; color: var(--ink); text-decoration: underline; text-decoration-style: dotted; text-underline-offset: 3px; cursor: pointer; }
.fruit-ref:hover { text-decoration-style: solid; }
.fruit-ref .fruit-icon { flex: none; }
.fruit-ref.missing { color: var(--ink-soft); text-decoration: line-through; cursor: help; }
.backlinks { margin-top: 18px; padding-top: 12px; border-top: 1px solid var(--ink-faint); }
.backlinks h3 { margin: 0 0 6px; font-size: 13px; font-weight: 400; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-soft); font-family: var(--sans); }
.backlinks ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.backlinks small { color: var(--ink-soft); margin-left: 6px; }
.ref-tools { display: flex; }
.ref-btn { min-height: 34px; font-size: 14px; padding: 0 12px; }
.ref-picker { border: 1px solid var(--ink); border-radius: var(--radius); background: var(--paper-white); padding: 8px; display: grid; gap: 6px; }
.ref-search { width: 100%; padding: 9px 12px; border: 1px solid var(--ink-soft); border-radius: var(--radius); font-size: 16px; background: #fff; }
.ref-results { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow-y: auto; }

.video-frame { position: relative; aspect-ratio: 16 / 9; overflow: hidden; background: var(--ink); }
.video-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

.md h2, .md h3, .md h4, .md h5 { font-weight: 400; margin: 1em 0 .4em; line-height: 1.25; }
.md h2 { font-size: 22px; } .md h3 { font-size: 19px; font-style: italic; } .md h4, .md h5 { font-size: 17px; }
.md > :first-child { margin-top: 0; }
.md blockquote { margin: 1em 0; padding: 2px 16px; border-left: 1px solid var(--ink); font-style: italic; }
.md code { font-family: ui-monospace, Menlo, monospace; background: var(--paper); padding: 1px 5px; font-size: .88em; }
.md pre { background: var(--paper); padding: 12px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md hr { border: 0; border-top: 1px solid var(--ink-faint); margin: 1.4em 0; }

/* ---------- Medium screens: search goes full width above the corners ---------- */
@media (max-width: 860px) {
  .search { width: auto; left: 12px; right: 12px; transform: none; }
  .legend, .zoom-controls { bottom: calc(max(14px, env(safe-area-inset-bottom)) + 58px); }
  .context-bar { left: 12px; right: 12px; transform: none; justify-content: safe center; }
  body.editing .legend, body.editing .zoom-controls { bottom: calc(max(14px, env(safe-area-inset-bottom)) + 112px); }
  .hint { bottom: 126px; }
  body.editing .hint { bottom: 180px; }
  body.map-view .hint { bottom: 126px; }
}

/* ---------- Phones ---------- */
@media (max-width: 640px) {
  .topbar { padding: max(10px, env(safe-area-inset-top)) 10px 0; }
  .back-btn span, .menu summary span, .view-btn span { display: none; }
  .sync-status span { display: none; }
  .sync-status { padding: 0 10px; }
  .sync-status[data-status="signed-out"] span { display: inline; }
  .view-btn { padding: 0 12px; }
  .back-btn, .menu summary, .edit-toggle { padding: 0 12px; }
  .edit-toggle > span:last-child { display: none; }
  .crumbs { min-width: 0; flex: 1; flex-wrap: nowrap; }
  .breadcrumb { padding: 4px 12px; font-size: 15px; flex-wrap: nowrap; }
  .breadcrumb li:first-child a span { display: none; } /* just the tree icon */
  .breadcrumb li + li::before { margin: 0 5px; }
  .breadcrumb li { flex: 0 1 auto; min-width: 0; }
  .breadcrumb li:first-child { flex-shrink: 0; }
  .breadcrumb li:not(:first-child):not([aria-current]) { display: none; } /* the back button covers it */
  .breadcrumb li:not(:first-child) > a, .breadcrumb li[aria-current] > span { display: block; min-width: 0; }
  #zoomIn, #zoomOut { display: none; } /* pinch to zoom instead */
  .legend { font-size: 13px; }
  .legend:not([open]) { padding: 2px 12px; }
  .context-bar { gap: 3px; justify-content: flex-start; padding: 4px; }
  .context-bar .btn { padding: 0 8px; font-size: 14px; flex: none; }
  .bar-hint { display: none; }
  .kind-picker { grid-template-columns: 1fr; }
  .image-row { grid-template-columns: 52px 1fr; }
  .image-row img { width: 52px; height: 40px; }
  .image-row-tools { grid-column: 1 / -1; justify-content: flex-end; }
  .modal-inner { padding: 18px 16px; }
}

/* Respect "reduce motion" settings. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
