:root {
  --ink: #f4f8f5;
  --muted: rgba(236, 246, 239, .68);
  --panel: rgba(8, 30, 21, .76);
  --line: rgba(255, 255, 255, .12);
  --lime: #b7df4c;
  --forest: #174f31;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: #8db5dd;
}

* { box-sizing: border-box; }
html, body, #app { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: linear-gradient(#87b0e8 0%, #cfe1d7 58%, #355d3a 100%); }
button, input { font: inherit; }

#app { position: relative; isolation: isolate; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; }
#labels { position: absolute; inset: 0; pointer-events: none; z-index: 4; }

.glass {
  background: linear-gradient(135deg, rgba(8, 28, 20, .84), rgba(11, 38, 27, .66));
  border: 1px solid var(--line);
  box-shadow: 0 22px 55px rgba(0, 17, 10, .26);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
}

.topbar {
  position: absolute;
  z-index: 10;
  top: 18px;
  left: 18px;
  right: 18px;
  min-height: 64px;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { width: 48px; height: 48px; object-fit: contain; filter: drop-shadow(0 6px 14px rgba(0,0,0,.2)); }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 15px; letter-spacing: .01em; }
.brand span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.status { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 0 0 rgba(183,223,76,.45); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 10px rgba(183,223,76,0); } 100% { box-shadow: 0 0 0 0 rgba(183,223,76,0); } }

.control-panel {
  position: absolute;
  z-index: 9;
  top: 100px;
  left: 18px;
  width: min(370px, calc(100vw - 36px));
  max-height: calc(100vh - 136px);
  overflow: auto;
  border-radius: 22px;
  padding: 24px;
  scrollbar-width: thin;
}

.eyebrow { margin: 0 0 8px; color: var(--lime); font-size: 10px; font-weight: 800; letter-spacing: .18em; }
h1 { font-size: clamp(27px, 3vw, 42px); line-height: .98; letter-spacing: -.045em; margin: 0; }
.intro { color: var(--muted); line-height: 1.55; font-size: 13px; margin: 16px 0 18px; }

.actions { display: grid; gap: 8px; }
button {
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 13px;
  color: var(--ink);
  background: rgba(255,255,255,.06);
  padding: 12px 14px;
  cursor: pointer;
  transition: .2s ease;
  text-align: left;
}
button:hover { transform: translateY(-1px); border-color: rgba(255,255,255,.28); background: rgba(255,255,255,.11); }
button:active { transform: translateY(0); }
button span { display: inline-block; width: 24px; color: var(--lime); }
button.primary { color: #14321f; background: linear-gradient(135deg, #c7eb62, #8fca45); border-color: transparent; font-weight: 800; box-shadow: 0 12px 28px rgba(133, 194, 66, .17); }
button.primary span { color: #14321f; }
button.compact { display: inline-block; width: auto; padding: 10px 13px; text-align: center; }

.toggles { display: grid; gap: 9px; margin: 18px 0; padding: 15px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.toggles label { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 12px; cursor: pointer; }
.toggles input { appearance: none; width: 30px; height: 17px; border-radius: 99px; background: rgba(255,255,255,.12); position: relative; outline: none; transition: .2s; }
.toggles input::after { content: ""; position: absolute; width: 11px; height: 11px; top: 3px; left: 3px; border-radius: 50%; background: white; transition: .2s; }
.toggles input:checked { background: #87bb3f; }
.toggles input:checked::after { transform: translateX(13px); }

.legend { display: grid; gap: 8px; color: var(--muted); font-size: 11px; }
.legend div { display: flex; align-items: center; gap: 9px; }
.zone { width: 20px; height: 3px; border-radius: 3px; box-shadow: 0 0 12px currentColor; }
.z1 { color: #ff6659; background: currentColor; }
.z2 { color: #5dc9ff; background: currentColor; }
.z3 { color: #f1d655; background: currentColor; }
.control-panel small { display: block; margin-top: 17px; color: rgba(236,246,239,.45); font-size: 10px; line-height: 1.5; }

.marker-label {
  position: absolute;
  transform: translate(-50%, -100%);
  pointer-events: auto;
  border: 1px solid rgba(255,255,255,.24);
  border-radius: 10px;
  padding: 7px 9px;
  color: white;
  background: rgba(4, 24, 16, .78);
  box-shadow: 0 10px 28px rgba(0,0,0,.22);
  backdrop-filter: blur(10px);
  white-space: nowrap;
  font-size: 10px;
  cursor: pointer;
  transition: opacity .2s, transform .2s;
}
.marker-label::after { content: ""; position: absolute; width: 7px; height: 7px; left: calc(50% - 3px); bottom: -4px; transform: rotate(45deg); background: rgba(4,24,16,.78); border-right: 1px solid rgba(255,255,255,.18); border-bottom: 1px solid rgba(255,255,255,.18); }
.marker-label:hover { transform: translate(-50%, -100%) scale(1.04); }
.marker-label b { color: var(--lime); }

.species-card {
  position: absolute;
  z-index: 12;
  right: 22px;
  bottom: 22px;
  width: min(380px, calc(100vw - 44px));
  border-radius: 22px;
  padding: 23px;
  opacity: 0;
  transform: translateY(18px) scale(.98);
  pointer-events: none;
  transition: .35s cubic-bezier(.2,.8,.2,1);
}
.species-card.open { opacity: 1; transform: none; pointer-events: auto; }
.species-card h2 { font-size: 30px; margin: 0 0 9px; font-style: italic; letter-spacing: -.03em; }
.species-card > p:not(.eyebrow) { color: var(--muted); font-size: 13px; line-height: 1.55; }
.species-card dl { display: grid; gap: 9px; margin: 16px 0; }
.species-card dl div { display: grid; grid-template-columns: 130px 1fr; gap: 10px; border-top: 1px solid var(--line); padding-top: 8px; font-size: 11px; }
.species-card dt { color: var(--muted); }
.species-card dd { margin: 0; }
.verified { color: var(--lime); }
.close { position: absolute; top: 10px; right: 10px; border: 0; background: transparent; font-size: 24px; padding: 5px 9px; color: var(--muted); }

.hint { position: absolute; z-index: 8; left: 50%; bottom: 20px; transform: translateX(-50%); border-radius: 99px; padding: 8px 13px; color: var(--muted); font-size: 10px; white-space: nowrap; }
.credit { position: absolute; right: 20px; top: 92px; z-index: 5; color: rgba(255,255,255,.48); font-size: 9px; text-shadow: 0 1px 8px rgba(0,0,0,.4); }

@media (max-width: 760px) {
  .topbar { top: 10px; left: 10px; right: 10px; min-height: 56px; border-radius: 15px; }
  .brand img { width: 40px; height: 40px; }
  .status { display: none; }
  .control-panel { top: auto; bottom: 12px; left: 10px; width: calc(100vw - 20px); max-height: 44vh; padding: 17px; border-radius: 18px; }
  .control-panel h1 { font-size: 27px; }
  .intro, .legend, .control-panel small { display: none; }
  .actions { grid-template-columns: 1fr 1fr 1fr; }
  .actions button { padding: 10px; text-align: center; font-size: 10px; }
  .actions button span { display: block; width: auto; margin-bottom: 3px; font-size: 15px; }
  .toggles { grid-template-columns: repeat(4, 1fr); margin: 12px 0 0; padding: 12px 0 0; border-bottom: 0; }
  .toggles label { flex-direction: column; text-align: center; gap: 5px; font-size: 9px; }
  .species-card { right: 10px; bottom: 12px; width: calc(100vw - 20px); }
  .hint, .credit { display: none; }
}

.scene-error {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 100;
  transform: translate(-50%, -50%);
  width: min(520px, calc(100vw - 36px));
  padding: 18px 20px;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 18px;
  background: rgba(18,31,24,.93);
  box-shadow: 0 20px 70px rgba(0,0,0,.36);
  color: #fff;
  font: 500 14px/1.5 system-ui, sans-serif;
}
.scene-error strong,
.scene-error span { display:block; }
.scene-error strong { margin-bottom:5px; font-size:16px; }
.scene-error[hidden] { display:none !important; }


.dem-loading {
  position: fixed;
  z-index: 90;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: min(390px, calc(100vw - 36px));
  padding: 17px 20px;
  border-radius: 18px;
  transition: opacity .35s ease, transform .35s ease;
}
.dem-loading.done { opacity: 0; transform: translate(-50%, -46%); pointer-events: none; }
.dem-loading strong, .dem-loading small { display: block; }
.dem-loading strong { font-size: 14px; }
.dem-loading small { color: var(--muted); margin-top: 3px; font-size: 10px; }
.dem-spinner { width: 25px; height: 25px; flex: 0 0 auto; border: 3px solid rgba(255,255,255,.18); border-top-color: var(--lime); border-radius: 50%; animation: demspin .8s linear infinite; }
@keyframes demspin { to { transform: rotate(360deg); } }
