:root {
  --charcoal: #2C2E35;
  --teal: #007B85;
  --tiffany: #0ABAB6;
  --slate: #8E9794;
  --gold: #F5B942;
  --coral: #E8665A;
  --green: #2DB37A;
  --bg: #F3F6F6;
  --card: #FFFFFF;
  --text: #2C2E35;
  --muted: #6B7471;
  --line: #E1E7E6;
  --shadow: 0 4px 0 rgba(44, 46, 53, .08), 0 8px 24px rgba(44, 46, 53, .06);
  --radius: 20px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, select { font: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.15; font-weight: 900; }
p { margin: 0 0 10px; }
ul, ol { margin: 6px 0 10px; padding-left: 20px; }
li { margin: 4px 0; }
.hidden { display: none !important; }

#app { min-height: 100vh; min-height: 100dvh; }
.screen {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 96px);
  animation: fadeIn .25s ease;
}
.screen.still { animation: none; }
.screen.full { padding-bottom: calc(var(--safe-bottom) + 24px); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Buttons ---------- */
.btn {
  display: block; width: 100%;
  padding: 16px 20px;
  border-radius: 16px;
  font-weight: 900; font-size: 17px; letter-spacing: .2px;
  text-align: center;
  background: var(--teal); color: #fff;
  box-shadow: 0 5px 0 #005A61;
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #005A61; }
.btn.secondary { background: #fff; color: var(--teal); box-shadow: 0 5px 0 var(--line); border: 2px solid var(--line); }
.btn.secondary:active { box-shadow: 0 1px 0 var(--line); }
.btn.gold { background: var(--gold); color: var(--charcoal); box-shadow: 0 5px 0 #C8922B; }
.btn.gold:active { box-shadow: 0 1px 0 #C8922B; }
.btn:disabled { background: #C9D1CF; box-shadow: 0 5px 0 #AEB8B5; color: #fff; }
.btn + .btn { margin-top: 12px; }
.linkbtn { color: var(--teal); font-weight: 800; padding: 8px 0; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

/* ---------- Top HUD ---------- */
.hud {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 14px;
}
.hud .avatar {
  width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center; font-size: 26px;
  background: #fff; box-shadow: var(--shadow); flex: none;
}
.hud .who { flex: 1; min-width: 0; }
.hud .who b { display: block; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud .who small { color: var(--teal); font-weight: 800; }
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  background: #fff; border-radius: 999px; padding: 6px 12px;
  font-weight: 900; box-shadow: var(--shadow); white-space: nowrap;
}
.xpbar { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.xpbar i { display: block; height: 100%; background: linear-gradient(90deg, var(--tiffany), var(--teal)); border-radius: 99px; transition: width .6s; }

/* ---------- House ---------- */
.house-card {
  background: linear-gradient(180deg, #CFF1EF 0%, #F3FBFA 70%);
  border-radius: var(--radius);
  padding: 10px 10px 4px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  position: relative;
  overflow: hidden;
}
.house-card.night { background: linear-gradient(180deg, #2C2E35 0%, #3F4E59 75%); }
.house-card svg { display: block; width: 100%; height: auto; }
.house-card .caption {
  text-align: center; font-weight: 800; font-size: 14px; color: var(--teal);
  padding: 2px 0 8px;
}
.house-card.night .caption { color: var(--gold); }
.ghost { fill: none; stroke: #8E9794; stroke-dasharray: 5 5; stroke-width: 1.5; opacity: .45; }
.built { animation: pop .6s cubic-bezier(.2, 1.6, .4, 1); transform-origin: center bottom; transform-box: fill-box; }
@keyframes pop { from { transform: scale(.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* ---------- Quest map ---------- */
.map { position: relative; padding: 4px 0 10px; }
.map svg.path { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; }
.node-row { position: relative; z-index: 1; display: flex; height: 112px; align-items: center; }
.node {
  display: flex; align-items: center; gap: 12px;
  width: 78%;
}
.node-row:nth-child(4n+2) .node { margin-left: 0; }
.node-row:nth-child(4n+3) .node { margin-left: 11%; }
.node-row:nth-child(4n+4) .node { margin-left: 22%; flex-direction: row-reverse; text-align: right; }
.node-row:nth-child(4n+5) .node { margin-left: 11%; }
.bubble {
  width: 76px; height: 76px; flex: none;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 34px;
  background: var(--teal);
  box-shadow: 0 6px 0 #005A61;
  position: relative;
  transition: transform .1s;
}
.bubble:active { transform: translateY(4px); box-shadow: 0 2px 0 #005A61; }
.node.done .bubble { background: var(--gold); box-shadow: 0 6px 0 #C8922B; }
.node.locked .bubble { background: #D5DCDA; box-shadow: 0 6px 0 #B9C3C0; filter: grayscale(1); }
.node.current .bubble::after {
  content: ""; position: absolute; inset: -8px; border-radius: 50%;
  border: 3px solid var(--tiffany); animation: pulse 1.6s infinite;
}
@keyframes pulse { 0% { transform: scale(.92); opacity: 1; } 100% { transform: scale(1.18); opacity: 0; } }
.bubble .lock { position: absolute; bottom: -4px; right: -4px; font-size: 20px; }
.bubble .boss-tag {
  position: absolute; top: -8px; right: -10px;
  background: var(--coral); color: #fff; font-size: 10px; font-weight: 900;
  padding: 2px 6px; border-radius: 8px; letter-spacing: .5px;
}
.node .label { min-width: 0; }
.node .label b { display: block; font-size: 16px; }
.node .label small { color: var(--muted); font-size: 13px; display: block; line-height: 1.25; }
.stars { color: var(--gold); letter-spacing: 1px; font-size: 15px; }
.stars .off { color: #D5DCDA; }

/* ---------- CTA strip ---------- */
.cta {
  display: flex; gap: 12px; align-items: center;
  background: var(--charcoal); color: #fff;
  border-radius: var(--radius); padding: 16px; margin: 10px 0 14px;
}
.cta .ico { font-size: 30px; }
.cta b { display: block; }
.cta small { color: #C7CFCD; }
.cta .go { margin-left: auto; background: var(--tiffany); color: var(--charcoal); font-weight: 900; padding: 10px 14px; border-radius: 12px; white-space: nowrap; }

/* ---------- Level screens ---------- */
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.topbar .x { font-size: 26px; color: var(--slate); width: 36px; height: 36px; display: grid; place-items: center; }
.progress { flex: 1; height: 14px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--tiffany); border-radius: 99px; transition: width .35s; }
.phase-tag { font-size: 12px; font-weight: 900; letter-spacing: 1px; text-transform: uppercase; color: var(--teal); margin-bottom: 6px; }

.lesson-card { min-height: 52vh; display: flex; flex-direction: column; }
.lesson-card h2 { font-size: 25px; margin-bottom: 12px; }
.lesson-card .body { font-size: 17px; flex: 1; }
.lesson-card .body b { color: var(--teal); }
.tip {
  background: #FFF6E0; border-radius: 14px; padding: 12px 14px; margin-top: 14px;
  font-size: 15px; display: flex; gap: 10px;
}
.tip::before { content: "💡"; }

.question { font-size: 21px; font-weight: 900; margin: 4px 0 18px; }
.option {
  display: block; width: 100%; text-align: left;
  background: #fff; border: 2px solid var(--line); border-radius: 16px;
  padding: 14px 16px; margin-bottom: 10px; font-weight: 700; font-size: 16px;
  box-shadow: 0 4px 0 var(--line);
  transition: transform .08s;
}
.option:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }
.option.correct { border-color: var(--green); background: #E5F7EF; box-shadow: 0 4px 0 #A9E2C9; }
.option.wrong { border-color: var(--coral); background: #FDECEA; box-shadow: 0 4px 0 #F4B9B3; }
.option.dim { opacity: .55; }
.option:disabled { cursor: default; }

.feedback {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 18px 16px calc(var(--safe-bottom) + 18px);
  border-radius: 24px 24px 0 0;
  animation: slideUp .25s ease;
  z-index: 20;
}
.feedback .inner { max-width: 560px; margin: 0 auto; }
.feedback.good { background: #DDF5EA; }
.feedback.bad { background: #FCE3E0; }
.feedback h3 { font-size: 20px; margin-bottom: 6px; }
.feedback.good h3 { color: #17885A; }
.feedback.bad h3 { color: #C2453A; }
.feedback p { font-size: 15px; margin-bottom: 14px; }
.feedback.good .btn { background: var(--green); box-shadow: 0 5px 0 #17885A; }
.feedback.bad .btn { background: var(--coral); box-shadow: 0 5px 0 #C2453A; }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: none; } }

/* Boss */
.boss-banner {
  background: linear-gradient(135deg, var(--charcoal), #44485A);
  color: #fff; border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
  display: flex; align-items: center; gap: 12px;
}
.boss-banner .face { font-size: 42px; }
.boss-banner small { color: var(--gold); font-weight: 900; letter-spacing: 1px; text-transform: uppercase; font-size: 12px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.stat { background: #fff; border-radius: 14px; padding: 10px; text-align: center; box-shadow: var(--shadow); }
.stat small { display: block; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.stat b { font-size: 16px; }
.stat.flash { animation: flash .6s; }
@keyframes flash { 50% { background: #FFF1C9; transform: scale(1.06); } }
.scenario { font-size: 18px; font-weight: 800; margin-bottom: 16px; }

/* Results */
.result { text-align: center; padding-top: 20px; }
.result .big { font-size: 72px; animation: pop .7s cubic-bezier(.2, 1.6, .4, 1); }
.result h1 { font-size: 30px; margin: 8px 0; }
.result .bigstars { font-size: 44px; letter-spacing: 6px; margin: 8px 0 4px; }
.result .bigstars span { display: inline-block; animation: pop .5s backwards cubic-bezier(.2, 1.6, .4, 1); }
.result .bigstars span:nth-child(2) { animation-delay: .15s; }
.result .bigstars span:nth-child(3) { animation-delay: .3s; }
.reward-row { display: flex; gap: 10px; justify-content: center; margin: 16px 0 20px; flex-wrap: wrap; }
.reward { background: #fff; border-radius: 16px; padding: 12px 16px; box-shadow: var(--shadow); font-weight: 900; }
.reward small { display: block; color: var(--muted); font-weight: 800; font-size: 12px; }

/* ---------- Onboarding ---------- */
.hero { text-align: center; padding: 24px 0 10px; }
.hero .logo { font-size: 64px; }
.hero h1 { font-size: 36px; margin: 8px 0 6px; }
.hero h1 span { color: var(--teal); }
.hero p { color: var(--muted); font-size: 17px; }
.brandline { text-align: center; color: var(--slate); font-weight: 800; font-size: 13px; letter-spacing: 1px; text-transform: uppercase; margin-top: 8px; }
.char {
  display: flex; gap: 14px; align-items: center; width: 100%; text-align: left;
  background: #fff; border: 3px solid transparent; border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.char.sel { border-color: var(--tiffany); background: #EFFBFA; }
.char .em { font-size: 40px; }
.char small { color: var(--muted); display: block; font-size: 13px; }
.char .mini { font-size: 12px; color: var(--teal); font-weight: 800; margin-top: 2px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-weight: 800; font-size: 14px; margin-bottom: 6px; color: var(--muted); }
.field input, .field select {
  width: 100%; padding: 14px; border-radius: 14px; border: 2px solid var(--line);
  background: #fff; font-size: 17px; font-weight: 700; color: var(--text);
  -webkit-appearance: none; appearance: none;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--tiffany); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Tools ---------- */
.seg { display: flex; background: var(--line); border-radius: 14px; padding: 4px; margin-bottom: 16px; }
.seg button { flex: 1; padding: 10px 6px; border-radius: 11px; font-weight: 800; font-size: 14px; color: var(--muted); }
.seg button.on { background: #fff; color: var(--teal); box-shadow: 0 2px 6px rgba(0,0,0,.08); }
.total { text-align: center; padding: 6px 0 10px; }
.total small { color: var(--muted); font-weight: 800; }
.total b { display: block; font-size: 40px; color: var(--teal); }
.breakdown { width: 100%; border-collapse: collapse; font-size: 15px; }
.breakdown td { padding: 8px 0; border-bottom: 1px solid var(--line); }
.breakdown td:last-child { text-align: right; font-weight: 800; }
.breakdown tr:last-child td { border-bottom: 0; }
.bar-stack { display: flex; height: 14px; border-radius: 99px; overflow: hidden; margin: 6px 0 14px; }
.bar-stack i { display: block; height: 100%; }
.note { font-size: 13px; color: var(--muted); }

/* ---------- Glossary ---------- */
.search { width: 100%; padding: 14px 16px; border-radius: 16px; border: 2px solid var(--line); font-size: 17px; margin-bottom: 14px; background: #fff; }
.search:focus { outline: none; border-color: var(--tiffany); }
.term { background: #fff; border-radius: 16px; padding: 14px 16px; margin-bottom: 10px; box-shadow: var(--shadow); }
.term b { color: var(--teal); display: block; margin-bottom: 2px; }
.term p { margin: 0; font-size: 15px; }

/* ---------- Me ---------- */
.badges { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.badge { text-align: center; font-size: 11px; font-weight: 800; color: var(--muted); }
.badge .b {
  width: 58px; height: 58px; margin: 0 auto 4px; border-radius: 50%;
  display: grid; place-items: center; font-size: 26px; background: var(--line); filter: grayscale(1); opacity: .5;
}
.badge.on .b { background: #FFF1C9; filter: none; opacity: 1; box-shadow: 0 3px 0 #EAC675; }
.badge.on { color: var(--text); }
.check { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); width: 100%; text-align: left; font-size: 15px; font-weight: 700; }
.check:last-child { border-bottom: 0; }
.check .box { width: 24px; height: 24px; border-radius: 8px; border: 2px solid var(--slate); flex: none; display: grid; place-items: center; font-size: 14px; color: #fff; }
.check.on .box { background: var(--green); border-color: var(--green); }
.check.on span { color: var(--muted); text-decoration: line-through; }
.section-title { font-size: 20px; margin: 22px 0 10px; }
.disclaimer { font-size: 12px; color: var(--muted); text-align: center; margin: 24px 0 8px; line-height: 1.5; }
.contact-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.contact-btns a { text-decoration: none; text-align: center; padding: 12px; border-radius: 14px; background: var(--tiffany); color: var(--charcoal); font-weight: 900; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: rgba(255, 255, 255, .94);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 8px 8px calc(var(--safe-bottom) + 8px);
}
.tabbar button { display: flex; flex-direction: column; align-items: center; font-size: 11px; font-weight: 800; color: var(--slate); padding: 2px 12px; }
.tabbar button span { font-size: 24px; filter: grayscale(1); opacity: .6; }
.tabbar button.on { color: var(--teal); }
.tabbar button.on span { filter: none; opacity: 1; }

/* ---------- Toast & confetti ---------- */
.toast {
  position: fixed; left: 50%; top: calc(var(--safe-top) + 14px); transform: translate(-50%, -150%);
  background: var(--charcoal); color: #fff; padding: 12px 18px; border-radius: 14px; font-weight: 800;
  z-index: 50; transition: transform .3s; max-width: 90vw; text-align: center;
}
.toast.show { transform: translate(-50%, 0); }
.confetti { position: fixed; top: -12px; width: 10px; height: 14px; z-index: 40; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Agent card + team picker */
.agent-head { display: flex; gap: 12px; align-items: center; }
.avatar { width: 52px; height: 52px; border-radius: 50%; flex: none; object-fit: cover;
  background: var(--teal); color: #fff; font-weight: 900; font-size: 18px;
  display: flex; align-items: center; justify-content: center; }
.team-row { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.team-row:first-child { border-top: 0; padding-top: 0; }
.team-row .avatar { width: 42px; height: 42px; font-size: 15px; }
.team-row .t { flex: 1; min-width: 0; }
.team-row .go { background: var(--tiffany); color: var(--charcoal); font-weight: 900; padding: 8px 14px; border-radius: 12px; white-space: nowrap; }
.install ol { margin: 6px 0 12px; padding-left: 22px; }
.install ol li { margin: 4px 0; }
.install p { margin: 0 0 10px; }
.install .note { margin: 0; }
