:root {
  --neutral-50: #fafafa;
  --neutral-100: #f5f5f5;
  --neutral-200: #e5e5e5;
  --neutral-300: #d4d4d4;
  --neutral-400: #a3a3a3;
  --neutral-500: #737373;
  --neutral-600: #525252;
  --neutral-700: #404040;
  --neutral-800: #262626;
  --neutral-900: #171717;
  --red-50: #fef2f2;
  --red-600: #dc2626;
  --red-700: #b91c1c;
  --amber-100: #fef3c7;
  --amber-700: #b45309;
  --amber-800: #92400e;
  --green-700: #15803d;
  --radius: 0.75rem;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--neutral-50);
  color: var(--neutral-900);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; }

.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--neutral-200);
  background: #fff;
}
.topnav-brand { font-weight: 600; text-decoration: none; }
.topnav-links { display: flex; align-items: center; gap: 1rem; font-size: 0.9rem; }
.topnav-links a { text-decoration: none; color: var(--neutral-700); }
.topnav-links a:hover { text-decoration: underline; }

.main { flex: 1; width: 100%; max-width: 720px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }
.main-centered { display: flex; align-items: center; justify-content: center; padding-top: 3rem; }
.main-centered > .card { width: 100%; max-width: 420px; }

.stack { display: flex; flex-direction: column; gap: 1.5rem; }
.stack-sm { display: flex; flex-direction: column; gap: 0.75rem; }
.row { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; }

.card { background: #fff; border: 1px solid var(--neutral-200); border-radius: var(--radius); padding: 1rem; }
.card-highlight { border: 2px solid var(--neutral-900); border-radius: var(--radius); padding: 1.25rem; background: #fff; }
.card-dashed { border: 2px dashed var(--neutral-300); border-radius: var(--radius); padding: 1.5rem; text-align: center; color: var(--neutral-500); }
.card-link { display: flex; align-items: center; justify-content: space-between; border: 1px solid var(--neutral-200); border-radius: var(--radius); padding: 0.9rem 1.1rem; background: #fff; text-decoration: none; box-shadow: 0 1px 2px rgba(0,0,0,.03); transition: border-color .15s; }
.card-link:hover { border-color: var(--neutral-400); }

h1 { font-size: 1.5rem; font-weight: 600; margin: 0.25rem 0 0; }
h2.section-title { font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--neutral-500); margin: 0; }
.back-link { font-size: 0.875rem; color: var(--neutral-500); text-decoration: none; }
.back-link:hover { text-decoration: underline; }
.muted { color: var(--neutral-500); font-size: 0.875rem; }
.small { font-size: 0.8rem; }

label { font-size: 0.875rem; font-weight: 500; color: var(--neutral-700); display: block; margin-bottom: 0.25rem; }
input, select, textarea {
  font: inherit;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--neutral-300);
  border-radius: 0.5rem;
  color: var(--neutral-900);
  background: #fff;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--neutral-900); }
.field { display: flex; flex-direction: column; gap: 0.25rem; }
.field-row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.field-row .field { flex: 1; min-width: 140px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border-radius: 0.5rem;
  padding: 0.55rem 1rem;
  font: inherit;
  font-weight: 500;
  border: 1px solid var(--neutral-300);
  background: #fff;
  color: var(--neutral-800);
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--neutral-50); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--neutral-900); color: #fff; border-color: var(--neutral-900); }
.btn-primary:hover { background: var(--neutral-700); }
.btn-danger { color: var(--red-600); border-color: var(--red-600); background: #fff; }
.btn-danger:hover { background: var(--red-50); }
.link-button { background: none; border: none; color: var(--neutral-500); font: inherit; cursor: pointer; padding: 0; }
.link-button:hover { text-decoration: underline; }
.btn-icon { background: none; border: none; color: var(--neutral-400); cursor: pointer; font-size: 1rem; padding: 0 0.25rem; }
.btn-icon:hover { color: var(--red-600); }

.chip { display: inline-flex; align-items: center; gap: 0.4rem; background: var(--neutral-100); border-radius: 999px; padding: 0.3rem 0.75rem; font-size: 0.85rem; }
.chip-outline { display: inline-flex; align-items: center; gap: 0.4rem; border: 1px solid var(--neutral-200); border-radius: 999px; padding: 0.15rem 0.6rem 0.15rem 0.15rem; font-size: 0.85rem; background: #fff; }
.badge { display: inline-block; border-radius: 999px; padding: 0.15rem 0.55rem; font-size: 0.75rem; background: var(--neutral-100); color: var(--neutral-600); }
.badge-amber { background: var(--amber-100); color: var(--amber-800); }

.error { color: var(--red-700); font-size: 0.875rem; }
.success { color: var(--green-700); font-size: 0.875rem; }
.flash { padding: 0.6rem 0.9rem; border-radius: 0.5rem; font-size: 0.875rem; margin-bottom: 1rem; }
.flash-error { background: var(--red-50); color: var(--red-700); }
.flash-success { background: #f0fdf4; color: var(--green-700); }

.avatar { border-radius: 999px; object-fit: cover; background: var(--neutral-200); display: inline-flex; align-items: center; justify-content: center; color: var(--neutral-600); font-weight: 600; flex-shrink: 0; }
.avatar-sm { width: 2rem; height: 2rem; font-size: 0.75rem; }
.avatar-md { width: 3rem; height: 3rem; font-size: 1rem; }
.avatar-lg { width: 5rem; height: 5rem; font-size: 1.5rem; }

.tree-unit { display: inline-flex; align-items: center; gap: 0.75rem; border: 1px solid var(--neutral-200); border-radius: var(--radius); padding: 0.5rem 0.75rem; background: #fff; }
.tree-unit.focused { border: 2px solid var(--neutral-900); }
.tree-children { margin: 0.75rem 0 0 1.25rem; padding-left: 1.25rem; border-left: 2px solid var(--neutral-200); list-style: none; display: flex; flex-direction: column; gap: 0.75rem; }
.tree-roots { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1rem; }
.person-name { font-size: 0.9rem; font-weight: 500; }
.person-years { font-size: 0.75rem; color: var(--neutral-400); }

.qz-question { font-size: 1.4rem; font-weight: 600; }
.qz-options { display: grid; grid-template-columns: 1fr; gap: 0.5rem; margin: 0; padding: 0; list-style: none; }
@media (min-width: 480px) { .qz-options { grid-template-columns: 1fr 1fr; } }
.qz-option { border: 1px solid var(--neutral-200); background: var(--neutral-50); border-radius: 0.5rem; padding: 0.75rem 1rem; text-align: left; font: inherit; cursor: pointer; }
.qz-option:hover:not(:disabled) { border-color: var(--neutral-400); }
.qz-option.selected { border-color: var(--neutral-900); background: #fff; }
.qz-option.correct { border-color: var(--green-700); background: #f0fdf4; }
.qz-option:disabled { cursor: default; }
.joincode { font-family: ui-monospace, monospace; letter-spacing: 0.3em; font-weight: 700; }

.install-banner {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: flex; justify-content: center; padding: 1rem;
  padding-bottom: calc(1rem + env(safe-area-inset-bottom));
}
.install-banner-card {
  width: 100%; max-width: 420px; background: #fff; border: 1px solid var(--neutral-200);
  border-radius: var(--radius); padding: 1rem; box-shadow: 0 8px 24px rgba(0,0,0,.12);
  display: flex; align-items: flex-start; gap: 0.75rem;
}

@media (max-width: 480px) {
  .field-row { flex-direction: column; }
}
