:root {
  --navy: #0b1b2b;
  --panel: rgba(11, 27, 43, 0.78);
  --panel-solid: #0f2336;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f3efe7;
  --muted: #b7c2cc;
  --teal: #14b8a6;
  --gold: #e8b04a;
  --red: #e06a5a;
  --amber: #e8a33a;
  --radius: 14px;
  --gutter: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--navy);
  color: var(--text);
  font-family: 'Cairo', system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app, #app canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

button { font: inherit; cursor: pointer; }

/* ---------- Loader ---------- */
#loader {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-content: center; justify-items: center; gap: 14px;
  background: radial-gradient(circle at 50% 40%, #16324a, var(--navy) 70%);
  transition: opacity 0.6s ease;
}
#loader.done { opacity: 0; pointer-events: none; }
#loader p { margin: 0; color: var(--muted); font-size: 15px; }
.tent-mark {
  width: 64px; height: 54px;
  background: linear-gradient(135deg, var(--gold), #f6d28c);
  clip-path: polygon(50% 0, 100% 100%, 64% 100%, 50% 62%, 36% 100%, 0 100%);
  animation: breathe 1.6s ease-in-out infinite;
}
@keyframes breathe { 50% { transform: scale(0.92); opacity: 0.7; } }

/* ---------- Top bar ---------- */
.topbar {
  position: fixed; top: max(12px, env(safe-area-inset-top)); inset-inline: var(--gutter);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  pointer-events: none; z-index: 10;
}
.brand, .badge { pointer-events: auto; }
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 14px 6px 8px; border-radius: 999px;
  background: var(--panel); backdrop-filter: blur(10px); border: 1px solid var(--line);
  color: var(--text); text-decoration: none;
}
.logo { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; background: var(--teal); color: #fff; }
.logo svg { width: 20px; height: 20px; }
.brand-text { display: grid; line-height: 1.15; }
.brand-text b { font-size: 17px; font-weight: 800; }
.brand-text small { font-size: 12px; color: var(--muted); }
.badge {
  font-size: 12px; font-weight: 600; padding: 6px 12px; border-radius: 999px;
  background: rgba(232, 176, 74, 0.16); color: var(--gold); border: 1px solid rgba(232, 176, 74, 0.35);
  white-space: nowrap;
}

/* ---------- Stats ---------- */
.stats {
  position: fixed; top: calc(max(12px, env(safe-area-inset-top)) + 58px); inset-inline-start: var(--gutter);
  display: flex; gap: 8px; flex-wrap: wrap; max-width: min(560px, calc(100vw - 2 * var(--gutter)));
  z-index: 10;
}
.stat {
  display: flex; align-items: baseline; gap: 6px;
  padding: 6px 12px; border-radius: 10px;
  background: var(--panel); backdrop-filter: blur(10px); border: 1px solid var(--line);
  font-size: 13px; color: var(--muted);
}
.stat b { color: var(--text); font-size: 16px; font-weight: 800; }

/* ---------- Controls + hint ---------- */
.controls {
  position: fixed; bottom: max(16px, env(safe-area-inset-bottom)); inset-inline-start: var(--gutter);
  display: flex; gap: 8px; z-index: 10;
}
.controls button {
  padding: 9px 16px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel); backdrop-filter: blur(10px); color: var(--text); font-size: 14px; font-weight: 600;
}
.controls button:hover { border-color: rgba(20, 184, 166, 0.6); }
.controls button[aria-pressed='true'] { background: var(--teal); border-color: var(--teal); }
.hint {
  position: fixed; bottom: max(22px, env(safe-area-inset-bottom)); inset-inline-end: var(--gutter);
  margin: 0; max-width: 360px; font-size: 12.5px; color: var(--muted); text-align: end;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); z-index: 5; pointer-events: none;
}

/* ---------- Family card ---------- */
.card {
  position: fixed; top: calc(max(12px, env(safe-area-inset-top)) + 58px); inset-inline-end: var(--gutter);
  width: min(360px, calc(100vw - 2 * var(--gutter)));
  max-height: calc(100vh - 150px); overflow: auto;
  padding: 18px 18px 16px; border-radius: var(--radius);
  background: var(--panel); backdrop-filter: blur(14px); border: 1px solid var(--line);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  opacity: 0; transform: translateY(-8px); transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 20;
}
.card.open { opacity: 1; transform: none; }
.card h2 { margin: 0 0 2px; font-size: 20px; font-weight: 800; }
.card h3 { margin: 16px 0 8px; font-size: 14px; color: var(--muted); font-weight: 600; }
.card .sub { margin: 0 0 12px; color: var(--muted); font-size: 13.5px; }
.close {
  position: absolute; top: 10px; inset-inline-end: 10px; width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--line); background: transparent; color: var(--text); font-size: 20px; line-height: 1;
}
.members { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.member {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 10px; background: rgba(255, 255, 255, 0.05);
}
.member .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--muted); }
.member-father .dot { background: #5a8fd0; }
.member-mother .dot { background: #d07ab0; }
.member-child .dot { background: var(--gold); }
.member-grandparent .dot { background: #9aa5ae; }
.who { display: grid; line-height: 1.3; flex: 1; min-width: 0; }
.who b { font-size: 14.5px; }
.who small { color: var(--muted); font-size: 12.5px; }
.chip { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.chip-injured { background: rgba(224, 106, 90, 0.18); color: #f29a8d; }
.chip-sick { background: rgba(232, 163, 58, 0.18); color: #f2c27a; }
.needs { display: flex; flex-wrap: wrap; gap: 6px; }
.need { font-size: 13px; padding: 5px 11px; border-radius: 999px; border: 1px solid rgba(20, 184, 166, 0.45); color: #7fe3d6; }
.donate {
  display: block; margin-top: 16px; padding: 12px; border-radius: 12px; text-align: center;
  background: linear-gradient(135deg, var(--teal), #0f8f82); color: #fff; font-weight: 800; text-decoration: none;
}
.note { margin: 10px 0 0; font-size: 12px; color: var(--muted); }

/* ---------- About dialog ---------- */
.about {
  width: min(520px, calc(100vw - 2 * var(--gutter))); padding: 22px; border-radius: var(--radius);
  background: var(--panel-solid); color: var(--text); border: 1px solid var(--line);
  font-size: 15px; line-height: 1.8;
}
.about::backdrop { background: rgba(0, 0, 0, 0.55); }
.about h2 { margin-top: 0; }
.about ul { padding-inline-start: 20px; }
.about button {
  margin-top: 8px; padding: 9px 22px; border-radius: 999px; border: 0; background: var(--teal); color: #fff; font-weight: 700;
}

.debug {
  position: fixed; bottom: 70px; inset-inline-start: var(--gutter); z-index: 30;
  font: 12px/1.4 ui-monospace, monospace; direction: ltr; padding: 4px 8px; border-radius: 6px; background: rgba(0, 0, 0, 0.6);
}
.noscript { position: fixed; inset: 40% 0 auto; text-align: center; }

/* ---------- Phones ---------- */
@media (max-width: 760px) {
  .badge { font-size: 11px; padding: 5px 9px; }
  .brand-text small { display: none; }
  .stats {
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; max-width: calc(100vw - 2 * var(--gutter));
    top: calc(max(12px, env(safe-area-inset-top)) + 54px);
  }
  .stats::-webkit-scrollbar { display: none; }
  .stat { flex: none; padding: 5px 10px; font-size: 12px; }
  .stat b { font-size: 14px; }
  .hint { display: none; }
  .controls { inset-inline: var(--gutter); justify-content: center; }
  .controls button { padding: 8px 12px; font-size: 13px; }
  .card {
    top: auto; bottom: 0; inset-inline: 0; width: 100%; max-height: 62vh;
    border-radius: 18px 18px 0 0; padding-bottom: max(16px, env(safe-area-inset-bottom));
    transform: translateY(24px);
  }
}
