* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Fonts bundled with the app (SIL Open Font License, see fonts/), so nothing is loaded from the internet */
@font-face { font-family: "Inter"; font-weight: 400; font-display: swap; src: url(fonts/inter-400.woff2) format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 500; font-display: swap; src: url(fonts/inter-500.woff2) format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 600 900; font-display: swap; src: url(fonts/inter-600.woff2) format("woff2"); }
@font-face { font-family: "Plus Jakarta Sans"; font-weight: 600; font-display: swap; src: url(fonts/jakarta-600.woff2) format("woff2"); }
@font-face { font-family: "Plus Jakarta Sans"; font-weight: 700; font-display: swap; src: url(fonts/jakarta-700.woff2) format("woff2"); }
@font-face { font-family: "Plus Jakarta Sans"; font-weight: 800; font-display: swap; src: url(fonts/jakarta-800.woff2) format("woff2"); }

:root {
  --danger: #e8505b;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Plus Jakarta Sans", "Inter", system-ui, sans-serif;
}
/* Five themes. --root = centre topic, --cta = main call-to-action button, --glow-1/2 = landing page light */
body.theme-light {
  --bg: #f4f6fa; --surface: #ffffff; --text: #1f2633; --muted: #6b7486; --border: #dde2ec; --dot: #d9dee8;
  --accent: #6B64F2; --root: #1f2a5c; --cta: #6B64F2; --cta-text: #ffffff;
  --glow-1: rgba(107,100,242,.16); --glow-2: rgba(18,201,184,.12); --glass: rgba(255,255,255,.72);
}
body.theme-dark {
  --bg: #161a22; --surface: #222835; --text: #e8ecf3; --muted: #9aa3b5; --border: #343c4d; --dot: #2a3140;
  --accent: #8b85ff; --root: #4b47c9; --cta: #8b85ff; --cta-text: #10131a;
  --glow-1: rgba(139,133,255,.18); --glow-2: rgba(18,201,184,.10); --glass: rgba(34,40,53,.72);
}
body.theme-paper {
  --bg: #f7f1e3; --surface: #fffaf0; --text: #3b3226; --muted: #85786a; --border: #e3d8c3; --dot: #e8dcc4;
  --accent: #6B64F2; --root: #3b3226; --cta: #c2752e; --cta-text: #ffffff;
  --glow-1: rgba(247,177,76,.18); --glow-2: rgba(107,100,242,.08); --glass: rgba(255,250,240,.75);
}
/* inspired by lumioraacademy.com: deep navy, indigo, cyan, gold */
body.theme-lumiora {
  --bg: #0A0F1C; --surface: #141C30; --text: #EAEFFB; --muted: #9AA5C0; --border: #232E48; --dot: #1a2338;
  --accent: #6366F1; --root: #6366F1; --cta: #FBBF24; --cta-text: #0A0F1C;
  --glow-1: rgba(99,102,241,.30); --glow-2: rgba(6,182,212,.18); --glass: rgba(255,255,255,.055);
}
/* soft and playful, for younger learners */
body.theme-pastel {
  --bg: #f6f3ff; --surface: #ffffff; --text: #2d2650; --muted: #7a74a0; --border: #e4defa; --dot: #e7e1fb;
  --accent: #8b7cf6; --root: #6d5dd3; --cta: #ff7eb3; --cta-text: #ffffff;
  --glow-1: rgba(255,126,179,.18); --glow-2: rgba(139,124,246,.16); --glass: rgba(255,255,255,.75);
}

html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.35 var(--font-body);
  overflow: hidden; overscroll-behavior: none;
}
h1, h2, h3 { font-family: var(--font-display); letter-spacing: -0.02em; }
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 6px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  z-index: 5;
}
.topbar h1 { font-size: 20px; margin: 0 4px; }
.spacer { flex: 1; }
.icon-btn {
  min-width: 44px; height: 44px; border: 0; border-radius: 10px;
  background: transparent; font-size: 22px;
}
.icon-btn:active, .icon-btn:hover { background: var(--bg); }
.icon-btn:disabled { opacity: .3; }
.map-title {
  border: 0; background: transparent; font-size: 18px; font-weight: 600;
  padding: 6px 10px; border-radius: 8px; max-width: 45vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.map-title:hover { background: var(--bg); }
.btn {
  border: 1px solid var(--border); background: var(--surface);
  padding: 10px 16px; border-radius: 10px; font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.cta { background: var(--cta); border-color: var(--cta); color: var(--cta-text); box-shadow: 0 6px 18px -6px var(--cta); }
.btn.danger { color: var(--danger); }

/* ---------- landing page (map list) ---------- */
#home {
  display: block; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background:
    radial-gradient(900px 500px at 10% -10%, var(--glow-1), transparent 60%),
    radial-gradient(800px 500px at 100% 10%, var(--glow-2), transparent 60%),
    var(--bg);
}
.home-wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px calc(env(safe-area-inset-bottom) + 24px); }
.home-top {
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 14px) 0 10px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { width: 40px; height: 40px; flex: none; }
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: 20px; letter-spacing: -0.02em; line-height: 1.1; }
.brand-name span { display: block; font-weight: 600; font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); }
.glass {
  background: var(--glass); border: 1px solid var(--border);
  -webkit-backdrop-filter: blur(18px) saturate(150%); backdrop-filter: blur(18px) saturate(150%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.18), 0 10px 32px -14px rgba(0,0,0,.35);
}
.hero { border-radius: 24px; padding: 32px 28px; margin: 8px 0 26px; position: relative; overflow: hidden; }
.hero::after { /* soft orbit ring, echoing the logo */
  content: ""; position: absolute; right: -80px; top: -60px; width: 320px; height: 320px; border-radius: 50%;
  border: 2px dashed var(--glow-1); pointer-events: none;
}
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px;
  font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  border: 1px solid var(--border); color: var(--muted); background: var(--surface);
}
.hero h2 { font-size: clamp(28px, 5vw, 44px); line-height: 1.08; margin: 14px 0 10px; font-weight: 800; }
.hero h2 em {
  font-style: normal; background: linear-gradient(90deg, var(--accent), #12C9B8);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero p { color: var(--muted); max-width: 560px; margin: 0 0 20px; line-height: 1.55; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.hero-actions .btn { padding: 12px 20px; border-radius: 12px; white-space: nowrap; }
.stats { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }
.stat { padding: 10px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); min-width: 110px; }
.stat b { display: block; font-family: var(--font-display); font-size: 22px; line-height: 1.1; }
.stat small { color: var(--muted); font-size: 12px; }
.backup-status { margin-top: 14px; font-size: 13px; color: var(--muted); }
.backup-status.overdue { color: var(--danger); }

.section-head { display: flex; align-items: baseline; gap: 10px; margin: 6px 2px 12px; }
.section-head h3 { margin: 0; font-size: 20px; }
.section-head small { color: var(--muted); }

.map-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); margin-bottom: 30px; }
.map-card {
  border-radius: 18px; padding: 12px; display: flex; flex-direction: column; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  transition: transform .15s, box-shadow .15s;
}
.map-card:hover { transform: translateY(-2px); box-shadow: 0 14px 30px -18px rgba(0,0,0,.45); }
.map-card .open { flex: 1; text-align: left; border: 0; background: none; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.map-card .thumb { width: 100%; height: 130px; border-radius: 12px; background: var(--bg); display: block; }
.map-card .info { padding: 0 4px; }
.map-card .open strong { display: block; font-family: var(--font-display); font-size: 17px; margin-bottom: 2px; word-break: break-word; }
.map-card small { color: var(--muted); }
.map-card .row { display: flex; gap: 2px; justify-content: flex-end; flex-wrap: wrap; }
.map-card .row button { border: 0; background: none; color: var(--muted); padding: 6px 8px; border-radius: 8px; font-size: 13px; }
.map-card .row button:hover { background: var(--bg); color: var(--text); }
.new-card {
  border: 2px dashed var(--border); border-radius: 18px; background: transparent; min-height: 150px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; color: var(--muted); font-weight: 600;
}
.new-card span { font-size: 34px; color: var(--accent); }
.new-card:hover { border-color: var(--accent); color: var(--text); }

/* Lumiora Academy section */
.academy-frame { margin-top: 18px; border-radius: 16px; overflow: hidden; border: 1px solid var(--border); background: #0A0F1C; }
.academy-frame iframe { display: block; width: 100%; height: min(70vh, 720px); border: 0; }
.academy-note { margin: 10px 2px 0; font-size: 12px; color: var(--muted); }

.home-foot { padding: 6px 0 4px; text-align: center; font-size: 13px; color: var(--muted); }
.home-foot a { color: var(--muted); }

/* ---------- profile chip, small links ---------- */
.profile-chip {
  width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--accent); padding: 0;
  background: var(--surface); color: var(--text); font-weight: 700; font-family: var(--font-display);
}
.profile-chip:hover { background: var(--accent); color: #fff; }
.link-btn { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 6px 4px; white-space: nowrap; }
.section-head { flex-wrap: wrap; row-gap: 2px; }
.section-head h3 { white-space: nowrap; }
.section-head .spacer { flex: 1; }
@media (max-width: 600px) { #quickSection .section-head small { display: none; } }

/* ---------- first-time guidance ---------- */
.empty-guide { border-radius: 24px; padding: 24px; margin-bottom: 26px; }
.empty-guide h3 { margin: 0 0 4px; font-size: 22px; }
.empty-guide > p { margin: 0 0 16px; color: var(--muted); }
.guide-steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.guide-steps.one-col { grid-template-columns: 1fr; margin-top: 6px; }
.guide-step {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 12px; align-items: center;
  text-align: left; padding: 16px; border-radius: 16px; border: 1.5px solid var(--border); background: var(--surface);
  transition: border-color .15s, transform .15s;
}
.guide-step span { grid-row: span 2; font-size: 28px; }
.guide-step small { color: var(--muted); }
.guide-step:hover, .guide-step:active { border-color: var(--accent); transform: translateY(-2px); }

/* ---------- recent maps & quick start ---------- */
.recent-row, .quick-row { display: flex; gap: 12px; overflow-x: auto; padding: 2px 2px 14px; margin-bottom: 14px; scrollbar-width: thin; }
.recent-card {
  flex: 0 0 auto; min-width: 200px; max-width: 260px; display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 16px; border: 1px solid var(--border); background: var(--surface); text-align: left;
}
.recent-card .dot { width: 12px; height: 34px; border-radius: 6px; flex: none; }
.recent-card b { display: block; font-family: var(--font-display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; }
.recent-card small { color: var(--muted); }
.recent-card:hover { border-color: var(--accent); }
.quick-card {
  flex: 0 0 auto; width: 170px; padding: 10px; border-radius: 16px; border: 1px solid var(--border); background: var(--surface);
  text-align: left; display: flex; flex-direction: column; gap: 6px; transition: transform .15s, border-color .15s;
}
.quick-card .thumb { height: 80px; }
.quick-card b { font-size: 14px; }
.quick-card small { color: var(--muted); font-size: 12px; }
.quick-card:hover { transform: translateY(-3px); border-color: var(--accent); }

/* ---------- template gallery ---------- */
#gallery { background: var(--bg); }
.gallery-title { margin: 0 6px; font-size: 20px; }
.gallery-tools { padding: 12px 16px 4px; background: var(--surface); border-bottom: 1px solid var(--border); }
#tplSearch {
  width: 100%; font: inherit; padding: 11px 14px; border: 1.5px solid var(--border); border-radius: 12px;
  background: var(--bg); color: var(--text); outline: none;
}
#tplSearch:focus { border-color: var(--accent); }
.tpl-cats { flex-wrap: nowrap; overflow-x: auto; padding: 12px 0 10px; }
.tpl-cats .chip { white-space: nowrap; }
.gallery-body { flex: 1; overflow-y: auto; padding: 16px; }
.tpl-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); max-width: 1180px; margin: 0 auto; }
.tpl-card {
  position: relative; border-radius: 18px; padding: 10px; background: var(--surface); border: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 8px; text-align: left; transition: transform .15s, box-shadow .15s;
}
.tpl-card:hover { transform: translateY(-2px); box-shadow: 0 14px 30px -18px rgba(0,0,0,.45); }
.tpl-card .thumb { height: 110px; }
.tpl-card .open { flex: 1; border: 0; background: none; padding: 0; text-align: left; display: flex; flex-direction: column; gap: 6px; }
.tpl-card b { font-family: var(--font-display); font-size: 16px; }
.tpl-card small { color: var(--muted); }
.tpl-card .tpl-cat { font-size: 12px; color: var(--accent); font-weight: 600; }
.tpl-card .tpl-actions { display: flex; gap: 6px; }
.tpl-card .tpl-actions .btn { flex: 1; padding: 8px 10px; font-size: 14px; }
.fav-btn {
  border: 0; background: none; font-size: 24px; line-height: 1; padding: 4px 6px; color: var(--muted); border-radius: 8px;
}
.fav-btn.on { color: #FBBF24; }
.tpl-card .fav-btn { position: absolute; top: 14px; right: 14px; background: var(--surface); }
.tpl-empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 40px 0; }

.tpl-preview-card { width: min(560px, 100%); max-height: 90vh; overflow-y: auto; }
.tpl-preview-head { display: flex; align-items: flex-start; gap: 10px; }
.tpl-preview-head > div { flex: 1; }
.tpl-preview-head small { color: var(--accent); font-weight: 600; }
.tpl-preview-head h3 { margin: 2px 0 0; }
.tpl-prev-thumb .thumb { height: 190px; margin: 12px 0 4px; }
.tpl-outline { margin: 0 0 4px; padding-left: 18px; color: var(--text); font-size: 14px; columns: 2; column-gap: 24px; }
.tpl-outline li { break-inside: avoid; margin-bottom: 6px; }
.tpl-outline li span { color: var(--muted); }

/* ---------- business family cards ---------- */
.family { margin-bottom: 18px; }
.family-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.biz-card {
  --glow: #6366F1;
  position: relative; isolation: isolate; overflow: hidden; border-radius: 20px; padding: 18px;
  background: var(--surface); border: 1px solid var(--border); min-height: 190px;
  display: flex; flex-direction: column; gap: 8px;
  transition: transform .35s cubic-bezier(.2,.8,.2,1), box-shadow .35s;
}
/* rotating gradient border, revealed on hover */
.biz-card::before {
  content: ""; position: absolute; inset: -60%; z-index: -2; opacity: 0; transition: opacity .35s;
  background: conic-gradient(from 0deg, var(--glow), transparent 30%, var(--glow) 55%, transparent 80%, var(--glow));
  animation: biz-spin 4s linear infinite;
}
.biz-card::after { content: ""; position: absolute; inset: 2px; z-index: -1; border-radius: 18px; background: var(--surface); }
.biz-card .shine {
  position: absolute; inset: 0; pointer-events: none; z-index: 1; border-radius: inherit;
  background: linear-gradient(115deg, transparent 30%, rgba(255,255,255,.18) 48%, transparent 62%);
  transform: translateX(-120%);
}
.biz-logo {
  width: 54px; height: 54px; border-radius: 16px; display: grid; place-items: center; flex: none;
  background: color-mix(in srgb, var(--glow) 18%, transparent); font-family: var(--font-display); font-weight: 800; font-size: 24px; color: var(--glow);
  transition: transform .35s;
}
.biz-logo img { width: 40px; height: 40px; }
.biz-card b { font-family: var(--font-display); font-size: 17px; }
.biz-card small { color: var(--muted); }
.biz-card .biz-actions { margin-top: auto; display: flex; gap: 6px; flex-wrap: wrap; }
.biz-card .biz-actions .btn { padding: 7px 12px; font-size: 13px; }
.biz-card .soon { margin-top: auto; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--glow); }
.biz-card:hover, .biz-card:focus-within, .biz-card.touched {
  transform: translateY(-6px) scale(1.02);
  box-shadow: 0 18px 40px -16px var(--glow);
}
.biz-card:hover::before, .biz-card:focus-within::before, .biz-card.touched::before { opacity: 1; }
.biz-card:hover .biz-logo, .biz-card.touched .biz-logo { animation: biz-float 1.6s ease-in-out infinite; }
.biz-card:hover .shine, .biz-card.touched .shine { transform: translateX(120%); transition: transform .9s ease; }
@keyframes biz-spin { to { transform: rotate(360deg); } }
@keyframes biz-float { 0%, 100% { transform: translateY(0) rotate(0); } 50% { transform: translateY(-5px) rotate(-6deg); } }
@media (prefers-reduced-motion: reduce) {
  .biz-card, .biz-card::before, .biz-logo, .biz-card .shine { animation: none !important; transition: none !important; }
}

/* ---------- profile / onboarding ---------- */
#onboarding { overflow-y: auto; display: block; background:
  radial-gradient(900px 500px at 10% -10%, var(--glow-1), transparent 60%),
  radial-gradient(800px 500px at 100% 10%, var(--glow-2), transparent 60%), var(--bg); }
.onb-wrap { max-width: 520px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 24px) 16px 30px; }
.onb-brand { margin-bottom: 16px; }
.onb-card { border-radius: 22px; padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.onb-card h2 { margin: 0; font-size: 24px; }
.onb-intro { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.fld { display: flex; flex-direction: column; gap: 5px; font-size: 14px; }
.fld span { color: var(--muted); font-weight: 600; }
.fld input, .fld select {
  font: inherit; padding: 11px 12px; border: 1.5px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); outline: none;
}
.fld input:focus, .fld select:focus { border-color: var(--accent); }
.fld.bad input, .fld.bad select { border-color: var(--danger); }
.phone-row { display: flex; gap: 8px; }
.phone-row .cc { width: 68px; flex: none; text-align: center; }
.phone-row input[name=phone] { flex: 1; min-width: 0; }
.phone-row .btn { flex: none; padding: 0 14px; white-space: nowrap; }
.fld .phone-row input { font: inherit; padding: 11px 12px; border: 1.5px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); outline: none; }
.fld .phone-row input:focus { border-color: var(--accent); }
.fld.bad .phone-row input { border-color: var(--danger); }
.fld-note { color: var(--muted); font-size: 13px; font-weight: 400; }
.check-row { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; line-height: 1.45; }
.check-row input { width: 20px; height: 20px; margin: 0; flex: none; accent-color: var(--accent); }
.check-row a { color: var(--accent); }
.guardian { border: 1.5px dashed var(--accent); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.guardian p { margin: 0; font-size: 13px; color: var(--muted); }
.onb-warn, .onb-error { margin: 0; padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.onb-warn { background: color-mix(in srgb, #FBBF24 18%, transparent); }
.onb-error { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.onb-actions { display: flex; gap: 10px; justify-content: flex-end; }
.onb-actions .btn { padding: 12px 22px; }

/* theme picker */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin-top: 6px; }
.theme-tile { border: 2px solid var(--border); border-radius: 14px; padding: 8px; background: var(--surface); text-align: left; }
.theme-tile.active { border-color: var(--accent); }
.theme-tile .prev { height: 64px; border-radius: 10px; position: relative; overflow: hidden; margin-bottom: 6px; }
.theme-tile .prev i { position: absolute; border-radius: 6px; }
.theme-tile b { font-size: 14px; }
.empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 60px 0; }

/* ---------- canvas ---------- */
#viewport {
  position: relative; flex: 1; overflow: hidden; touch-action: none;
  user-select: none; -webkit-user-select: none;
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 1.2px, transparent 1.2px);
  background-size: 24px 24px;
}
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#links { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
#links path { fill: none; stroke-linecap: round; }

.node {
  --c: var(--accent);
  position: absolute; left: 0; top: 0;
  width: max-content; max-width: 260px; padding: 7px 12px;
  border-radius: 8px; white-space: pre-wrap; word-break: break-word;
  font-size: 15px; cursor: pointer;
  transition: box-shadow .15s;
}
.node .emoji { margin-right: 6px; }
.node .text { outline: none; }
.node .text:empty::before { content: "Type here"; opacity: .45; font-weight: 400; }
.node.bold { font-weight: 700; }
.node.big { font-size: 19px; }

.node.root { font-size: 20px; font-weight: 700; padding: 14px 22px; border-radius: 14px; max-width: 320px; }

.node.shape-filled { background: var(--c); color: var(--fg, #fff); box-shadow: 0 2px 6px rgba(0,0,0,.15); }
.node.shape-box    { background: var(--surface); border: 2px solid var(--c); }
.node.shape-pill   { background: var(--surface); border: 2px solid var(--c); border-radius: 999px; padding-left: 16px; padding-right: 16px; }
.node.shape-line   { background: transparent; border-bottom: 2.5px solid var(--c); border-radius: 0; padding: 4px 4px 3px; }

/* selected: a ring in the text colour (contrasts with every branch colour), a glow and a slight lift */
.node.selected {
  box-shadow: 0 0 0 3px var(--bg), 0 0 0 6px var(--text), 0 10px 26px rgba(0,0,0,.28);
  scale: 1.06; z-index: 3;
}
.node.shape-line.selected { background: color-mix(in srgb, var(--c) 12%, transparent); border-radius: 6px 6px 0 0; }
.node.editing { cursor: text; user-select: text; -webkit-user-select: text; }
.node.editing .text { min-width: 20px; display: inline-block; }

.node.dragging { opacity: .35; }
.node.drop-child  { box-shadow: 0 0 0 4px #4cb963; }
.node.drop-before { box-shadow: 0 -5px 0 0 #4cb963; }
.node.drop-after  { box-shadow: 0 5px 0 0 #4cb963; }
.ghost {
  position: fixed; z-index: 50; pointer-events: none; opacity: .85;
  transform: translate(-50%, -50%) scale(.95); left: 0; top: 0;
}

.toggle {
  position: absolute; top: 50%; width: 22px; height: 22px; margin-top: -11px;
  border-radius: 50%; border: 2px solid var(--c); background: var(--surface); color: var(--text);
  font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; padding: 0;
}
.toggle.right { right: -30px; }
.toggle.left  { left: -30px; }
.node.shape-line .toggle { top: auto; bottom: -12px; margin-top: 0; }

/* ---------- action bar ---------- */
.actionbar {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  display: flex; gap: 2px; padding: 6px; z-index: 6;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 6px 24px rgba(0,0,0,.15); max-width: calc(100vw - 24px); overflow-x: auto;
}
.actionbar button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 58px; padding: 6px 6px; border: 0; border-radius: 10px; background: none; font-size: 12px; white-space: nowrap;
}
.actionbar button span { font-size: 20px; line-height: 1.1; }
.actionbar button em { font-style: normal; }
.actionbar button:active, .actionbar button:hover { background: var(--bg); }
.actionbar button.danger { color: var(--danger); }
.actionbar button:disabled { opacity: .3; }

.hint {
  position: absolute; left: 50%; top: 76px; transform: translateX(-50%);
  background: var(--surface); color: var(--muted); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 10px; font-size: 13px; z-index: 4;
  transition: opacity .4s; pointer-events: none; text-align: center; max-width: 90vw;
}

/* ---------- bottom sheet ---------- */
.sheet {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 0; z-index: 20;
  width: min(560px, 100vw); max-height: 70vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-bottom: 0;
  border-radius: 18px 18px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.18);
  padding-bottom: env(safe-area-inset-bottom);
}
/* tablets, and phones turned sideways (wide but short): panels dock on the right */
@media (min-width: 900px), (min-width: 640px) and (max-height: 520px) {
  .sheet {
    left: auto; right: 16px; transform: none; width: 340px;
    top: calc(env(safe-area-inset-top) + 76px); bottom: auto; max-height: calc(100vh - 100px);
    border: 1px solid var(--border); border-radius: 18px; box-shadow: 0 8px 30px rgba(0,0,0,.18);
  }
}
@media (min-width: 640px) and (max-height: 520px) {
  .sheet { top: calc(env(safe-area-inset-top) + 62px); max-height: calc(100vh - 72px); width: 320px; }
  #noteText { min-height: 140px; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 0 18px; }
.sheet-body { padding: 4px 18px 18px; }
.sheet-body label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 14px 0 8px; }
.swatches, .chips, .emojis { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent; padding: 0; }
.swatch.active { border-color: var(--text); }
.swatch.auto { background: conic-gradient(#6B64F2, #12C9B8, #F7B14C, #e8505b, #6B64F2); }
.chip { border: 1.5px solid var(--border); background: var(--bg); padding: 8px 14px; border-radius: 999px; }
.chip.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, var(--surface)); }
.emojis button { width: 42px; height: 42px; font-size: 22px; border: 1.5px solid transparent; background: var(--bg); border-radius: 10px; padding: 0; }
.emojis button.active { border-color: var(--accent); }

/* ---------- notes, links, tasks ---------- */
.node .note-badge, .node .link-badge { margin-left: 6px; font-size: .85em; cursor: pointer; }
.node .task-box {
  display: inline-block; width: 17px; height: 17px; margin-right: 7px; vertical-align: -3px;
  border: 2px solid var(--c); border-radius: 4px; background: var(--surface);
  color: #fff; font-size: 12px; font-weight: 700; line-height: 13px; text-align: center; cursor: pointer;
  overflow: hidden; /* same vertical alignment whether or not the box holds a ✓ */
}
.node .task-box.done { background: var(--c); }
.node.shape-filled .task-box { border-color: var(--fg); background: transparent; }
.node.shape-filled .task-box.done { background: var(--fg); color: var(--c); }
.node.task-done .text { text-decoration: line-through; opacity: .6; }
.node .progress {
  display: inline-block; margin-left: 8px; padding: 1px 7px; border-radius: 999px; vertical-align: 1px;
  font-size: 11px; font-weight: 700; line-height: 16px;
  background: color-mix(in srgb, var(--c) 18%, transparent); color: var(--text);
}
.node .progress.complete { background: #4cb963; color: #fff; }
.node.shape-filled .progress { background: rgba(255,255,255,.25); color: var(--fg); }

/* hidden from others: faded and dashed for the owner */
.node.is-hidden { opacity: .45; border-style: dashed; }
.node.is-hidden.shape-filled { outline: 2px dashed var(--c); outline-offset: 2px; }
.node .hidden-badge { margin-left: 6px; font-size: .85em; }

/* status banners (others' view, format painting) */
.banner {
  position: absolute; left: 50%; transform: translateX(-50%); top: 12px; z-index: 6;
  display: flex; align-items: center; gap: 12px; padding: 6px 6px 6px 14px; max-width: calc(100vw - 24px);
  background: var(--surface); border: 1.5px solid var(--accent); border-radius: 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,.15); font-size: 14px;
}
.banner .btn { padding: 6px 12px; font-size: 14px; }
.icon-btn.active { background: var(--accent); color: #fff; }
#viewport.painting .node { cursor: copy; }
#viewport.exporting .node.selected { scale: none; } /* exports measure topics at their real size */
#noteTitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 80%; }
#noteText {
  display: block; width: 100%; min-height: 220px; margin-top: 8px; resize: vertical;
  font: inherit; line-height: 1.5; padding: 12px; border: 1.5px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text); outline: none;
}
#noteText:focus { border-color: var(--accent); }
@media (min-width: 900px) { #noteText { min-height: 360px; } }
.note-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; color: var(--muted); }
.note-foot .btn { padding: 6px 12px; font-size: 14px; }

/* ---------- search ---------- */
.searchbar { position: relative; z-index: 7; background: var(--surface); border-bottom: 1px solid var(--border); }
.search-row { display: flex; align-items: center; gap: 4px; padding: 6px 12px; }
#searchInput {
  flex: 1; min-width: 0; font: inherit; padding: 9px 12px; border: 1.5px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text); outline: none;
}
#searchInput:focus { border-color: var(--accent); }
.search-count { font-size: 13px; color: var(--muted); white-space: nowrap; padding: 0 6px; }
.search-results {
  position: absolute; left: 12px; right: 12px; top: 100%; max-height: min(50vh, 380px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 0 0 14px 14px;
  box-shadow: 0 10px 24px rgba(0,0,0,.15);
}
.search-results button {
  display: block; width: 100%; text-align: left; border: 0; background: none; padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.search-results button:last-child { border-bottom: 0; }
.search-results button:hover, .search-results button.active { background: var(--bg); }
.search-results small { display: block; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-results .empty-result { padding: 14px; color: var(--muted); }
.search-results mark { background: #FFD24F; color: #1f2633; border-radius: 3px; padding: 0 1px; }
.node.search-hit { outline: 3px solid #FFD24F; outline-offset: 3px; }
.node.search-current { outline-color: #F7B14C; outline-width: 4px; }

/* ---------- pop-up menu (fold options, levels) ---------- */
.pop-menu {
  position: fixed; z-index: 35; min-width: 240px; max-width: calc(100vw - 16px);
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0,0,0,.22); padding: 6px;
}
.pop-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 8px 12px 4px; }
.pop-menu > button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 12px; border-radius: 8px; }
.pop-menu > button:hover:not(:disabled), .pop-menu > button:active:not(:disabled) { background: var(--bg); }
.pop-menu button:disabled { opacity: .35; }
.pop-row { display: flex; gap: 6px; padding: 6px; }
.pop-row button { flex: 1; min-width: 44px; height: 44px; border: 1.5px solid var(--border); background: var(--bg); border-radius: 10px; font-weight: 700; }
.pop-row button:active, .pop-row button:hover { border-color: var(--accent); }

/* ---------- phones ---------- */
#btnMore { display: none; }
.more-menu {
  position: absolute; right: 8px; top: calc(100% + 4px); z-index: 30; min-width: 230px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.2); padding: 6px;
}
.more-menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 12px 12px; border-radius: 8px; }
.more-menu button:active, .more-menu button:hover { background: var(--bg); }
.more-menu button.on { color: var(--accent); font-weight: 600; }
#editor .topbar { position: relative; }

/* bigger touch areas for the small things on a topic */
.node .toggle, .node .task-box, .node .note-badge, .node .link-badge { position: relative; }
.node .toggle::after, .node .task-box::after, .node .note-badge::after, .node .link-badge::after {
  content: ""; position: absolute; inset: -9px;
}
.node .toggle { position: absolute; } /* keeps its place beside the topic */
@media (pointer: coarse) { .node .toggle::after { inset: -16px; } } /* fingers: the fold bubble sits in empty space, so it can grow */

@media (max-width: 600px) {
  .tb-extra { display: none !important; }
  #btnMore { display: block; }
  .topbar { gap: 2px; padding-left: 6px; padding-right: 6px; }
  .icon-btn { min-width: 40px; }
  .map-title { max-width: none; flex: 1; min-width: 0; text-align: left; font-size: 16px; padding: 6px 4px; }
  #editor .topbar .spacer { display: none; }

  /* landing page */
  .home-wrap { padding-left: 14px; padding-right: 14px; }
  .hero { padding: 24px 18px; border-radius: 20px; }
  .hero-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .hero-actions .btn { padding: 12px 8px; }
  .stat { flex: 1; min-width: 0; }
  .map-grid { grid-template-columns: 1fr; }
  .new-card { min-height: 90px; }
  .family-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .biz-card { min-height: 170px; padding: 14px; }
  .tpl-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .tpl-card .thumb { height: 80px; }
  .tpl-card .tpl-actions .btn { padding: 7px 6px; font-size: 13px; }
  .tpl-outline { columns: 1; }

  /* bottom bar: two rows, every button visible */
  .actionbar {
    display: grid; grid-template-columns: repeat(6, 1fr); gap: 0;
    left: 8px; right: 8px; transform: none; max-width: none; padding: 4px; overflow: visible;
  }
  .actionbar button { min-width: 0; padding: 5px 2px; font-size: 11px; }
  .actionbar button span { font-size: 18px; }

  .banner { flex-wrap: wrap; justify-content: center; text-align: center; padding: 8px 10px; gap: 6px 10px; font-size: 13px; width: max-content; }
}

/* ---------- dialog ---------- */
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card { background: var(--surface); border-radius: 16px; padding: 20px; width: min(400px, 100%); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal-card h3 { margin: 0 0 8px; }
.modal-card p { margin: 0 0 12px; color: var(--muted); }
.modal-card p:empty { display: none; }
.modal-card input { width: 100%; font: inherit; padding: 10px 12px; border: 1.5px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#exportDialog .modal-card { width: min(480px, 100%); } /* room for all four export buttons on one row */
.modal-card .check { display: flex; align-items: center; gap: 10px; padding: 8px 0; cursor: pointer; }
.modal-card .check input { width: 20px; height: 20px; flex: none; padding: 0; accent-color: var(--accent); margin: 0; }
