*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html, body { width: 100%; height: 100%; overflow: hidden; }

:root { --bar: 52px; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #f0f2ec;
  user-select: none;
}

/* ── Canvases — full screen, behind the top bar ─────────────────────────── */
#sky-canvas,
#tree-canvas {
  display: block;
  position: fixed;
  top: 0; left: 0;
  width:  100vw;
  height: 100vh;        /* fallback для старых браузеров */
  height: 100dvh;       /* dvh = реальная видимая высота (без адресной строки браузера) */
}
#sky-canvas      { z-index: 0; }
#tree-canvas     { z-index: 1; background: transparent; cursor: grab; }
#tree-canvas:active { cursor: grabbing; }
#tree-canvas-3d  { display: none; z-index: 1; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; }

/* ── Loading progress bar ───────────────────────────────────────────────── */
#load-bar {
  position: fixed;
  top: var(--bar);
  left: 0; right: 0;
  z-index: 45;
  height: 28px;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(74,156,54,0.18);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  opacity: 0;
  transform: translateY(-100%);
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
#load-bar.visible { opacity: 1; transform: translateY(0); }

#load-bar-track {
  flex: 1;
  height: 5px;
  background: rgba(74,156,54,0.15);
  border-radius: 3px;
  overflow: hidden;
}
#load-bar-fill {
  height: 100%;
  background: #4a9c36;
  border-radius: 3px;
  width: 0%;
  transition: width .12s ease-out;
}
/* Indeterminate phase: bar crawls toward 85% while server is processing */
@keyframes loadCrawl {
  0%   { width:  0%; }
  15%  { width: 25%; }
  40%  { width: 50%; }
  65%  { width: 68%; }
  85%  { width: 78%; }
  100% { width: 85%; }
}
#load-bar-fill.indeterminate {
  animation: loadCrawl 12s cubic-bezier(0.08, 0.35, 0.25, 1) forwards;
  transition: none;
}
#load-bar-label {
  font-size: 11px;
  font-weight: 700;
  color: #3a7a28;
  min-width: 120px;
  text-align: right;
  white-space: nowrap;
}

/* ── App loading overlay (visible before JS loads, removed after init) ───── */
#app-loader {
  position: fixed; inset: 0;
  z-index: 9999;
  background: linear-gradient(160deg, #eaf5e2 0%, #d2eac6 55%, #c6e2ba 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.45s ease;
}
#app-loader.fade-out { opacity: 0; pointer-events: none; }
.al-box {
  display: flex; flex-direction: column;
  align-items: center; gap: 20px;
}
.al-icon {
  font-size: 76px; line-height: 1;
  filter: drop-shadow(0 6px 16px rgba(74,156,54,0.22));
  animation: alPulse 2.6s ease-in-out infinite;
}
@keyframes alPulse {
  0%, 100% { transform: scale(1) translateY(0); }
  50%       { transform: scale(1.07) translateY(-5px); }
}
.al-ring {
  width: 38px; height: 38px;
  border: 3px solid rgba(74,156,54,0.22);
  border-top-color: #4a9c36;
  border-radius: 50%;
  animation: alSpin 0.72s linear infinite;
}
@keyframes alSpin { to { transform: rotate(360deg); } }
.al-text {
  color: #357a24;
  font-size: 14px; font-weight: 600;
  letter-spacing: 0.03em;
}

/* ── Top bar ─────────────────────────────────────────────────────────────── */
#top-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--bar);
  z-index: 10;

  display: flex;
  align-items: center;
  padding: 0 18px;

  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

/* Title sits in the flex flow, takes remaining space, centred within it */
#top-title {
  flex: 1;
  text-align: center;
  font-size: 18px;
  font-weight: 800;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.2px;
  pointer-events: none;
  text-shadow: 0 1px 6px rgba(0,0,0,0.45), 0 0 20px rgba(0,0,0,0.20);
}

/* Controls on the right, never shrink below natural size */
#top-controls {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Deed count */
#leaf-display {
  display: flex;
  align-items: baseline;
  gap: 5px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.40);
  border-radius: 20px;
  padding: 4px 13px;
}
#leaf-placed {
  font-size: 17px;
  font-weight: 800;
  color: #2a5a18;
  line-height: 1;
}
#leaf-sep {
  font-size: 11px;
  color: #5a8a48;
  font-weight: 600;
}
#leaf-count {
  font-size: 17px;
  font-weight: 800;
  color: #2a5a18;
  opacity: 0.55;
  line-height: 1;
}
#count-label {
  font-size: 11px;
  color: #5a8a48;
  font-weight: 600;
  letter-spacing: 0.2px;
}

/* ── Search overlay ──────────────────────────────────────────────────────── */
#search-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  z-index: 20; display: flex; align-items: flex-start; justify-content: center;
  padding-top: calc(var(--bar) + 10px);
  pointer-events: none; opacity: 0;
  transition: opacity .2s;
}
#search-overlay.open { pointer-events: auto; opacity: 1; }

#search-box {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,0.92); backdrop-filter: blur(12px);
  border: 1.5px solid rgba(0,0,0,0.12); border-radius: 28px;
  padding: 8px 10px 8px 18px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  width: min(480px, 90vw);
}
#search-input {
  flex: 1; border: none; background: none; outline: none;
  font-size: 15px; font-family: inherit; color: #222;
}
#search-count {
  font-size: 12px; color: #888; white-space: nowrap; font-weight: 600;
}
#search-close {
  background: none; border: none; cursor: pointer;
  font-size: 16px; color: #aaa; padding: 0 4px;
  transition: color .12s;
}
#search-close:hover { color: #555; }

/* ── Org filter button ───────────────────────────────────────────────────── */
#org-btn {
  background: rgba(255,255,255,0.55);
  border: 1.5px solid rgba(0,0,0,0.14);
  border-radius: 20px;
  padding: 5px 13px;
  font-size: 13px;
  font-weight: 700;
  color: #2a5a18;
  cursor: pointer;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background .15s, transform .12s, border-color .15s, color .15s;
}
#org-btn:hover  { background: rgba(255,255,255,0.90); border-color: rgba(0,0,0,0.22); transform: scale(1.04); }
#org-btn:active { transform: scale(0.96); }
#org-btn.active {
  background: rgba(50,100,220,0.20);
  border-color: rgba(50,100,220,0.38);
  color: #1a3a9a;
}

/* ── Org dropdown ────────────────────────────────────────────────────────── */
#org-dropdown {
  position: fixed;
  z-index: 30;
  background: rgba(255,255,255,0.96);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.16);
  min-width: 230px;
  max-height: 380px;
  overflow-y: auto;
  padding: 6px 0;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
  transition: opacity .15s, transform .15s;
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,0.15) transparent;
}
#org-dropdown.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.org-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  color: #222;
  cursor: pointer;
  transition: background .1s;
}
.org-item:hover { background: rgba(0,0,0,0.05); }
.org-item.selected { color: #1a4090; font-weight: 700; }
.org-check { width: 16px; font-size: 14px; flex-shrink: 0; color: #1a4090; }
.org-sep { height: 1px; background: rgba(0,0,0,0.08); margin: 4px 0; }

/* B&W environment button (3D-only) */
#bw-btn {
  background: rgba(255,255,255,0.55);
  border: 1.5px solid rgba(0,0,0,0.14);
  border-radius: 20px;
  padding: 5px 13px;
  font-size: 12px;
  font-weight: 700;
  color: #444;
  cursor: pointer;
  transition: background .15s, transform .12s, border-color .15s, color .15s;
  letter-spacing: 0.5px;
}
#bw-btn:hover  { background: rgba(255,255,255,0.90); border-color: rgba(0,0,0,0.22); transform: scale(1.05); }
#bw-btn:active { transform: scale(0.96); }
#bw-btn.active {
  background: rgba(0,0,0,0.18);
  border-color: rgba(0,0,0,0.35);
  color: #111;
}
#bw-btn.active:hover { background: rgba(0,0,0,0.28); }

/* Mode toggle button (2D / 3D) */
#mode-btn {
  background: rgba(255,255,255,0.55);
  border: 1.5px solid rgba(0,0,0,0.14);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 13px;
  font-weight: 700;
  color: #2a5a18;
  cursor: pointer;
  transition: background .15s, transform .12s, border-color .15s, color .15s;
  letter-spacing: 0.4px;
}
#mode-btn:hover  { background: rgba(255,255,255,0.90); border-color: rgba(0,0,0,0.22); transform: scale(1.05); }
#mode-btn:active { transform: scale(0.96); }
#mode-btn.active {
  background: rgba(50,100,220,0.20);
  border-color: rgba(50,100,220,0.38);
  color: #1a3a9a;
}
#mode-btn.active:hover { background: rgba(50,100,220,0.32); }

/* Login + settings icon buttons */
#login-btn,
#settings-btn {
  background: rgba(255,255,255,0.55);
  border: 1.5px solid rgba(0,0,0,0.14);
  border-radius: 20px;
  padding: 5px 11px;
  font-size: 13px;
  font-weight: 700;
  color: #444;
  cursor: pointer;
  white-space: nowrap;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background .15s, transform .12s, border-color .15s, color .15s;
}
#login-btn:hover, #settings-btn:hover {
  background: rgba(255,255,255,0.90); border-color: rgba(0,0,0,0.22); transform: scale(1.05);
}
#login-btn:active, #settings-btn:active { transform: scale(0.96); }
#login-btn.active {
  background: rgba(50,130,220,0.20); border-color: rgba(50,130,220,0.38); color: #1a3a9a;
}

/* ── Org-admin login modal ────────────────────────────────────────────────── */
#login-modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,0.45); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
#login-modal.open { opacity: 1; pointer-events: auto; }

#login-box {
  background: #fff; border-radius: 18px;
  padding: 30px 28px 24px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.22);
  width: min(360px, 90vw);
  display: flex; flex-direction: column; gap: 12px;
}
#login-title { font-size: 18px; font-weight: 800; color: #2a5a18; text-align: center; margin-bottom: 4px; }
#login-error { font-size: 13px; color: #c62828; min-height: 18px; text-align: center; }
#login-input, #login-pw {
  width: 100%; padding: 10px 14px; border: 1.5px solid #dde; border-radius: 9px;
  font-size: 14px; font-family: inherit; outline: none;
  transition: border-color .15s;
}
#login-input:focus, #login-pw:focus { border-color: #4a9c36; }
#login-pw-wrap { position: relative; }
#login-pw-wrap #login-pw { padding-right: 42px; margin-bottom: 0; }
#login-pw-toggle {
  position: absolute; right: 1px; top: 1px; bottom: 1px;
  width: 40px; background: none; border: none; border-radius: 0 8px 8px 0;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: #aaa; transition: color .15s; padding: 0;
}
#login-pw-toggle:hover { color: #4a9c36; background: none; transform: none; }
#login-submit {
  background: #4a9c36; color: #fff; border: none; border-radius: 9px;
  padding: 11px; font-size: 15px; font-weight: 700; cursor: pointer;
  font-family: inherit; transition: background .15s;
}
#login-submit:hover { background: #3d8a2c; }
#login-close-btn {
  background: none; border: none; color: #aaa; font-size: 13px; cursor: pointer;
  font-family: inherit; text-align: center;
  transition: color .12s;
}
#login-close-btn:hover { color: #555; }

/* ── Tree settings panel ─────────────────────────────────────────────────── */
#settings-panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 40;
  width: min(320px, 92vw);
  background: rgba(255,255,255,0.97); backdrop-filter: blur(16px);
  box-shadow: -4px 0 32px rgba(0,0,0,0.18);
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform .3s cubic-bezier(0.22,0.85,0.32,1);
  overflow: hidden;
}
#settings-panel.open { transform: translateX(0); }

#sp-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
  flex-shrink: 0;
}
#sp-title { font-size: 16px; font-weight: 800; color: #2a5a18; }
#sp-close {
  background: rgba(0,0,0,0.06); border: none; border-radius: 50%;
  width: 30px; height: 30px; font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s;
}
#sp-close:hover { background: rgba(0,0,0,0.12); }

#sp-body {
  flex: 1; overflow-y: auto; padding: 16px 20px;
  scrollbar-width: thin; scrollbar-color: rgba(0,0,0,0.12) transparent;
}
.sp-section { margin-bottom: 20px; }
.sp-label { font-size: 12px; font-weight: 700; color: #888; text-transform: uppercase;
            letter-spacing: 0.6px; margin-bottom: 8px; }
.sp-slider-label {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; font-weight: 600; color: #333; margin-bottom: 6px;
}
.sp-slider-label span { font-size: 12px; color: #4a9c36; font-weight: 700; }

input[type=range] {
  width: 100%; accent-color: #4a9c36;
  height: 6px; cursor: pointer;
}

#sp-textures  { display: flex; gap: 8px; flex-wrap: wrap; }
#sp-bg-options { display: flex; gap: 8px; flex-wrap: wrap; }
.sp-tex-opt {
  display: flex; align-items: center; gap: 5px;
  font-size: 13px; font-weight: 500; color: #333; cursor: pointer;
  padding: 6px 12px;
  border: 1.5px solid rgba(0,0,0,0.12); border-radius: 20px;
  transition: border-color .12s, background .12s;
}
.sp-tex-opt input[type=radio] { display: none; }
.sp-tex-opt:has(input:checked) {
  border-color: #4a9c36; background: rgba(74,156,54,0.10); color: #2a7018;
  font-weight: 700;
}

#sp-leaf-colors { display: flex; gap: 8px; flex-wrap: wrap; }
.sp-color-opt {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 500; color: #333; cursor: pointer;
  padding: 6px 12px;
  border: 1.5px solid rgba(0,0,0,0.12); border-radius: 20px;
  transition: border-color .12s, background .12s;
}
.sp-color-opt input[type=radio] { display: none; }
.sp-color-opt:has(input:checked) {
  border-color: #4a9c36; background: rgba(74,156,54,0.08); font-weight: 700;
}
.sp-color-dot {
  width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.15);
}
.sp-check-opt {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 500; color: #333; cursor: pointer;
  padding: 6px 10px; border-radius: 8px; margin-bottom: 4px;
  border: 1.5px solid transparent;
  transition: border-color .12s, background .12s;
}
.sp-check-opt:hover { background: rgba(74,156,54,0.06); }
.sp-check-opt:has(input:checked) {
  border-color: #4a9c36; background: rgba(74,156,54,0.08); font-weight: 700;
}
.sp-check-opt input[type=checkbox] { accent-color: #4a9c36; width: 15px; height: 15px; cursor: pointer; }

#sp-footer {
  display: flex; gap: 10px; padding: 14px 20px;
  border-top: 1px solid rgba(0,0,0,0.08); flex-shrink: 0;
}
#sp-save {
  flex: 1; background: #4a9c36; color: #fff; border: none; border-radius: 9px;
  padding: 11px; font-size: 14px; font-weight: 700; cursor: pointer;
  font-family: inherit; transition: background .15s;
}
#sp-save:hover { background: #3d8a2c; }
#sp-logout {
  background: rgba(0,0,0,0.06); border: none; border-radius: 9px;
  padding: 11px 16px; font-size: 13px; font-weight: 600; color: #666;
  cursor: pointer; font-family: inherit; transition: background .15s;
}
#sp-logout:hover { background: rgba(0,0,0,0.12); }
.sp-sep { height: 1px; background: rgba(0,0,0,0.08); margin: 8px 0 12px; }

#sp-save-msg {
  text-align: center; font-size: 13px; color: #4a9c36; font-weight: 600;
  min-height: 20px; padding: 0 20px 10px;
}

/* Icon buttons (night / regen) */
#cards-btn,
#tree-btn,
#search-btn,
#night-btn,
#regen-btn {
  background: rgba(255,255,255,0.55);
  border: 1.5px solid rgba(0,0,0,0.14);
  border-radius: 50%;
  width: 36px; height: 36px;
  font-size: 17px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, transform .12s, border-color .15s;
  padding: 0;
}
#cards-btn:hover, #tree-btn:hover, #night-btn:hover, #regen-btn:hover {
  background: rgba(255,255,255,0.95);
  border-color: rgba(0,0,0,0.18);
  transform: scale(1.10);
  text-decoration: none;
  color: inherit;
}
#cards-btn:active, #tree-btn:active, #night-btn:active, #regen-btn:active { transform: scale(0.95); }
#cards-btn, #tree-btn { text-decoration: none; color: inherit; font-size: 16px; }

#night-btn.day { background: rgba(255,200,40,0.18); border-color: rgba(220,160,20,0.35); }

/* Search button — active filter state */
#search-btn { position: relative; }
#search-btn.active {
  background: rgba(220,100,20,0.18);
  border-color: rgba(200,80,10,0.45);
}
#search-btn.active:hover { background: rgba(220,100,20,0.32); }
/* Diagonal strikethrough line */
#search-btn.active::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 140%; height: 2px;
  background: rgba(180,50,10,0.70);
  transform: translate(-50%, -50%) rotate(-45deg);
  border-radius: 1px;
  pointer-events: none;
}

/* Add deed button */
#add-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px 6px 10px;
  background: #4a9c36;
  color: #fff;
  border: none;
  border-radius: 20px;
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
  transition: background .15s, transform .12s;
  line-height: 1;
}
#add-btn:hover  { background: #3d8a2c; transform: scale(1.04); }
#add-btn:active { transform: scale(0.97); }
.add-icon { font-size: 20px; font-weight: 300; line-height: 1; margin-top: -1px; }

/* ── Timeline button ─────────────────────────────────────────────────────── */
#timeline-btn {
  background: rgba(255,255,255,0.55);
  border: 1.5px solid rgba(0,0,0,0.14);
  border-radius: 50%;
  width: 36px; height: 36px;
  font-size: 17px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, transform .12s, border-color .15s;
  padding: 0;
}
#timeline-btn:hover  { background: rgba(255,255,255,0.95); border-color: rgba(0,0,0,0.18); transform: scale(1.10); }
#timeline-btn:active { transform: scale(0.95); }
#timeline-btn.active { background: rgba(74,156,54,0.20); border-color: rgba(74,156,54,0.45); }

/* ── Timeline bar ────────────────────────────────────────────────────────── */
#timeline-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 15;
  height: 48px;
  background: rgba(255,255,255,0.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 10px;
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(0.22,0.85,0.32,1);
}
#timeline-bar.open { transform: translateY(0); }

#tl-play, #tl-close {
  background: rgba(0,0,0,0.06); border: none; border-radius: 50%;
  width: 30px; height: 30px; cursor: pointer; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background .12s;
}
#tl-play:hover, #tl-close:hover { background: rgba(0,0,0,0.14); }

#tl-track { flex: 1; }
#tl-track input[type=range] { width: 100%; margin: 0; }

#tl-info {
  font-size: 12px; font-weight: 600; color: #3a7a28;
  white-space: nowrap; min-width: 160px; text-align: center;
}

/* ── Toast notifications ─────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 64px; right: 18px;
  z-index: 60;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  background: rgba(255,255,255,0.96);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(74,156,54,0.25);
  border-left: 4px solid #4a9c36;
  border-radius: 12px;
  padding: 10px 14px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.14);
  display: flex; align-items: flex-start; gap: 10px;
  max-width: 300px;
  pointer-events: auto;
  cursor: pointer;
  animation: toastIn .3s cubic-bezier(0.22,0.85,0.32,1);
  transition: opacity .3s, transform .3s;
}
.toast.hiding { opacity: 0; transform: translateX(20px); }
.toast-icon { font-size: 20px; flex-shrink: 0; line-height: 1.3; }
.toast-body { flex: 1; }
.toast-title { font-size: 12px; font-weight: 700; color: #2a5a18; margin-bottom: 2px; }
.toast-text  { font-size: 12px; color: #444; line-height: 1.4; }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── QR / share modal ────────────────────────────────────────────────────── */
#qr-modal {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(0,0,0,0.45); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
#qr-modal.open { opacity: 1; pointer-events: auto; }
#qr-box {
  background: #fff; border-radius: 18px;
  padding: 28px 24px 22px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.22);
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  width: min(320px, 90vw);
}
#qr-title { font-size: 16px; font-weight: 800; color: #2a5a18; }
#qr-canvas canvas, #qr-canvas img { border-radius: 8px; }
#qr-link {
  width: 100%; padding: 8px 10px; border: 1.5px solid #dde; border-radius: 8px;
  font-size: 12px; font-family: inherit; color: #444; background: #f8f8f8;
  outline: none; cursor: text;
}
#qr-actions { display: flex; gap: 8px; width: 100%; }
#qr-copy {
  flex: 1; background: #4a9c36; color: #fff; border: none; border-radius: 8px;
  padding: 9px; font-size: 13px; font-weight: 700; cursor: pointer; font-family: inherit;
  transition: background .15s;
}
#qr-copy:hover { background: #3d8a2c; }
#qr-close-btn {
  background: rgba(0,0,0,0.06); border: none; border-radius: 8px;
  padding: 9px 14px; font-size: 13px; cursor: pointer; font-family: inherit;
  transition: background .12s;
}
#qr-close-btn:hover { background: rgba(0,0,0,0.12); }

/* QR button in deed panel */
#dp-qr {
  background: rgba(255,255,255,0.12); border: none; color: #fff;
  border-radius: 50%; width: 30px; height: 30px; font-size: 14px;
  cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s; margin-right: 4px;
}
#dp-qr:hover { background: rgba(255,255,255,0.22); }

/* ── Bottom deed panel ───────────────────────────────────────────────────── */
#deed-panel {
  position: fixed;
  bottom: 0; left: 0;
  width: 100vw;
  max-height: 55vh;
  min-height: 180px;
  z-index: 20;

  background: rgba(8, 18, 4, 0.84);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: #fff;

  border-top: 1px solid rgba(255,255,255,0.12);
  border-radius: 20px 20px 0 0;

  transform: translateY(100%);
  transition: transform 0.38s cubic-bezier(0.22, 0.85, 0.32, 1);

  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#deed-panel.open { transform: translateY(0); }

#dp-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 18px 26px 12px;
  border-bottom: 1px solid rgba(255,255,255,0.10);
  flex-shrink: 0;
}
#dp-title-block { display: flex; flex-direction: column; gap: 4px; }
#dp-name  { font-size: 17px; font-weight: 700; line-height: 1.2; }
#dp-meta  { font-size: 12px; color: rgba(255,255,255,0.55); }

#dp-close {
  background: rgba(255,255,255,0.10);
  border: none; color: #fff;
  border-radius: 50%; width: 30px; height: 30px;
  font-size: 14px; cursor: pointer; flex-shrink: 0;
  transition: background .15s;
  display: flex; align-items: center; justify-content: center;
}
#dp-close:hover { background: rgba(255,255,255,0.22); }

#dp-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

#dp-text {
  flex: 1;
  padding: 14px 26px 18px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.2) transparent;
}
#dp-short {
  font-size: 14px; color: rgba(255,255,255,0.90);
  line-height: 1.55; margin-bottom: 10px; font-weight: 500;
}
#dp-full {
  font-size: 13px; color: rgba(255,255,255,0.65);
  line-height: 1.6; white-space: pre-line;
}
#dp-full:empty { display: none; }

#dp-photos {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 14px 20px 14px 0;
  overflow-x: auto;
  overflow-y: hidden;
  flex-shrink: 0;
  max-width: 45%;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.15) transparent;
}
#dp-photos:empty { display: none; }

.dp-photos-row {
  display: flex;
  gap: 10px;
  align-items: center;
}
.dp-photo {
  height: 110px; width: auto; min-width: 80px;
  object-fit: cover; border-radius: 10px;
  cursor: pointer; flex-shrink: 0;
  transition: opacity .15s, transform .15s;
  border: 1.5px solid rgba(255,255,255,0.12);
}
.dp-photo:hover { opacity: .85; transform: scale(1.05); }

#dp-loading {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8,18,4,0.84);
  font-size: 14px; color: rgba(255,255,255,0.5);
  pointer-events: none; opacity: 0; transition: opacity .15s;
}
#dp-loading.show { opacity: 1; }

/* ── Fullscreen photo ────────────────────────────────────────────────────── */
#photo-fs {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.92);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
#photo-fs.open { opacity: 1; pointer-events: all; }
#photo-fs-img {
  max-width: 92vw; max-height: 92vh;
  object-fit: contain; border-radius: 8px;
  box-shadow: 0 8px 64px rgba(0,0,0,0.7);
}
#photo-fs-close {
  position: absolute; top: 20px; right: 24px;
  background: rgba(255,255,255,0.12); border: none; color: #fff;
  border-radius: 50%; width: 38px; height: 38px;
  font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
#photo-fs-close:hover { background: rgba(255,255,255,0.25); }

/* ── Mobile responsive top bar ───────────────────────────────────────────── */
@media (max-width: 620px) {
  :root { --bar: 86px; }

  #top-bar {
    height: auto;
    padding: 7px 10px;
    flex-wrap: wrap;
    row-gap: 5px;
    align-items: center;
  }

  /* Title: full-width first row */
  #top-title {
    flex: 0 0 100%;
    font-size: 14px;
    order: -1;
  }

  /* Controls: second row, centred, wrapping allowed */
  #top-controls {
    flex: 0 0 100%;
    justify-content: center;
    flex-wrap: wrap;
    gap: 5px;
  }

  /* Drop verbose labels to save space */
  #count-label { display: none; }
  .add-label   { display: none; }

  /* Compact icon buttons */
  #search-btn, #night-btn, #regen-btn, #timeline-btn {
    width: 30px; height: 30px; font-size: 14px;
  }

  /* Compact text pills */
  #org-btn      { font-size: 11px; padding: 4px 9px;  max-width: 100px; }
  #login-btn    { font-size: 11px; padding: 4px 9px;  max-width: 90px; }
  #settings-btn { font-size: 11px; padding: 4px 9px;  }
  #bw-btn       { font-size: 11px; padding: 4px 9px;  }
  #mode-btn     { font-size: 11px; padding: 4px 11px; }

  /* Add button — icon only */
  #add-btn  { padding: 5px 10px; }
  .add-icon { font-size: 16px; }

  /* Count badge — smaller digits */
  #leaf-placed, #leaf-count { font-size: 14px; }
  #leaf-display { padding: 3px 10px; }
}
