/* ---------- Base / theme ---------- */
:root {
  /* Palette taken from the Phởnetics logo: bowl green, basil, straw hat, broth */
  --green: #1a6b3c;        /* bowl green — primary */
  --green-dark: #0b4527;   /* deep bowl shadow */
  --brand: #013d23;        /* wordmark green */
  --basil: #3a8a2e;
  --accent: #a26d22;       /* toasted broth — speaker buttons, pronunciation hints */
  --accent-dark: #7c5116;
  --red: #d9483b;
  --gold: #e8b85c;         /* straw hat */
  --gold-dark: #c4923a;
  --ink: #1f2a22;
  --muted: #6c7369;
  --line: #e7e2d5;
  --bg: #f8f6f0;           /* logo's warm off-white */
  --card: #ffffff;
  --tint-green: #e3f0e5;
  --tint-green-line: #c3dcc8;
  --tint-gold: #fbf1dc;
  --pattern: rgba(26,107,60,0.12);  /* bowl green, faint — background doodles */
  --radius: 16px;
  --shadow: 0 2px 0 rgba(0,0,0,0.08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  padding-top: 64px;
  padding-bottom: 76px;
  min-height: 100vh;
}

/* Faint green phở doodles over the cream background (shapes in assets/pattern.svg) */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-color: var(--pattern);
  -webkit-mask: url("../assets/pattern.svg") 0 0 / 320px 320px repeat;
          mask: url("../assets/pattern.svg") 0 0 / 320px 320px repeat;
}

button { font-family: inherit; cursor: pointer; }

/* ---------- Top bar ---------- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 64px; z-index: 50;
  background: var(--card); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.brand .logo {
  width: 40px; height: 40px; flex: 0 0 auto; display: block;
  filter: drop-shadow(0 2px 3px rgba(1,61,35,0.25));
  transition: transform .15s ease;
}
.brand:hover .logo { transform: rotate(-6deg) scale(1.06); }
.brand-name {
  font-weight: 800; font-size: 20px; letter-spacing: -0.4px;
  background: linear-gradient(90deg, var(--brand), var(--green));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: var(--brand);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-tagline { font-size: 11px; font-weight: 600; color: var(--muted); white-space: nowrap; }
@media (max-width: 640px) { .brand-tagline { display: none; } }
.stats { display: flex; align-items: center; gap: 14px; }
.stat { font-weight: 700; font-size: 15px; white-space: nowrap; }

.dialect-toggle {
  display: flex; background: var(--bg); border-radius: 999px; padding: 3px;
  border: 1px solid var(--line);
}
.dialect-toggle button {
  border: none; background: transparent; padding: 6px 12px; border-radius: 999px;
  font-weight: 700; font-size: 13px; color: var(--muted);
}
.dialect-toggle button.active { background: var(--green); color: #fff; }

/* ---------- Auth gate (on-device profiles) ---------- */
body.logged-out .stats,
body.logged-out #bottomnav { display: none; }
.auth-wrap {
  max-width: 400px; margin: 28px auto 0; padding: 0 4px;
  display: flex; flex-direction: column; align-items: center;
}
.auth-hero { text-align: center; margin-bottom: 16px; }
.auth-card { width: 100%; padding: 18px; }
.google-slot { display: flex; justify-content: center; min-height: 44px; }
.btn.google-fallback { text-transform: none; letter-spacing: 0; font-size: 15px; color: var(--ink); }
.auth-note {
  font-size: 12px; color: var(--muted); text-align: center;
  margin-top: 16px; max-width: 340px; line-height: 1.5;
}

/* ---------- Bottom nav ---------- */
#bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; height: 64px; z-index: 50;
  background: var(--card); border-top: 1px solid var(--line);
  display: flex;
}
#bottomnav button {
  flex: 1; border: none; background: transparent; font-size: 22px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); border-top: 3px solid transparent;
}
#bottomnav button span { font-size: 11px; font-weight: 700; }
#bottomnav button.active { color: var(--green); border-top-color: var(--green); }

/* ---------- Layout ---------- */
#app { max-width: 640px; margin: 0 auto; padding: 20px 16px 40px; }
h1 { font-size: 26px; margin: 4px 0 2px; }
h2 { font-size: 20px; margin: 0 0 12px; }
.subtitle { color: var(--muted); margin: 0 0 20px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: 14px; padding: 14px 20px; font-weight: 800;
  font-size: 15px; text-transform: uppercase; letter-spacing: 0.5px;
  color: #fff; background: var(--green); box-shadow: 0 4px 0 var(--green-dark);
  transition: transform .05s, box-shadow .05s; width: 100%;
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--green-dark); }
.btn.secondary { background: var(--accent); box-shadow: 0 4px 0 var(--accent-dark); }
.btn.ghost { background: var(--card); color: var(--muted); box-shadow: 0 2px 0 var(--line); border: 2px solid var(--line); }
.btn.gold { background: var(--gold); box-shadow: 0 4px 0 var(--gold-dark); color: #4a3208; }
.btn:disabled { opacity: .5; pointer-events: none; }

/* ---------- Lesson map ---------- */
.dialect-banner {
  background: linear-gradient(90deg, var(--green-dark), var(--green) 55%, var(--basil)); color: #fff;
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 22px;
}
.dialect-banner b { font-size: 18px; }
.dialect-banner p { margin: 4px 0 0; opacity: .95; font-size: 14px; }

.lesson-path { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.unit-label {
  align-self: stretch; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 16px; font-weight: 800; margin: 14px 0 6px;
  display: flex; justify-content: space-between; align-items: center;
}
.unit-label small { color: var(--muted); font-weight: 600; }
.node {
  width: 84px; height: 84px; border-radius: 50%; border: none;
  font-size: 34px; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 0 var(--green-dark); background: var(--green); color: #fff;
  position: relative;
}
.node:active { transform: translateY(3px); box-shadow: 0 3px 0 var(--green-dark); }
.node.test { border-radius: 26px; width: 96px; }   /* unit tests: a wider rounded square */
.node.locked { background: #d6d2c6; box-shadow: 0 6px 0 #b7b2a4; }
.node.done { background: var(--gold); box-shadow: 0 6px 0 var(--gold-dark); }
.node .badge {
  position: absolute; bottom: -6px; right: -6px; background: #fff; border-radius: 50%;
  width: 26px; height: 26px; font-size: 14px; display: flex; align-items: center;
  justify-content: center; box-shadow: var(--shadow);
}
.node-title { font-weight: 700; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
/* zig-zag the path a little */
.node-wrap { display: flex; flex-direction: column; align-items: center; }
.node-wrap:nth-child(3n+1) { transform: translateX(-46px); }
.node-wrap:nth-child(3n+3) { transform: translateX(46px); }

/* ---------- Cards / exercises ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow);
}
.progress-bar { height: 14px; background: var(--line); border-radius: 999px; overflow: hidden; margin-bottom: 18px; }
.progress-bar > div { height: 100%; background: var(--green); width: 0; transition: width .3s; }
.exercise-header { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.exercise-header .close { font-size: 24px; background: none; border: none; color: var(--muted); }
.exercise-header .hearts { margin-left: auto; font-weight: 700; color: var(--red); }

.prompt { font-size: 15px; color: var(--muted); font-weight: 700; margin-bottom: 6px; text-transform: uppercase; letter-spacing: .5px; }
.term { font-size: 40px; font-weight: 800; margin: 6px 0; }
.term-sub { font-size: 16px; color: var(--muted); }
.ipa { display: inline-block; margin-top: 8px; color: var(--accent); font-weight: 700; }
.dialect-note {
  margin-top: 14px; background: var(--tint-green); border: 1px solid var(--tint-green-line); color: var(--green-dark);
  border-radius: 12px; padding: 10px 14px; font-size: 14px;
}
.speaker-btn {
  background: var(--accent); color: #fff; border: none; border-radius: 12px;
  padding: 12px 16px; font-size: 20px; box-shadow: 0 4px 0 var(--accent-dark); margin-top: 12px;
}
.speaker-btn.small { padding: 6px 10px; font-size: 16px; box-shadow: 0 3px 0 var(--accent-dark); width: auto; }

.options { display: grid; gap: 12px; margin-top: 20px; }
.option {
  text-align: left; background: var(--card); border: 2px solid var(--line);
  border-bottom-width: 4px; border-radius: 14px; padding: 16px; font-size: 17px; font-weight: 700;
}
.option.selected { border-color: var(--accent); background: var(--tint-gold); }
.option.correct { border-color: var(--green); background: var(--tint-green); }
.option.wrong { border-color: var(--red); background: #fbe3df; }

/* feedback footer */
.feedback {
  position: fixed; bottom: 64px; left: 0; right: 0; padding: 18px 16px;
  border-top: 2px solid var(--line); background: var(--card); z-index: 40;
}
.feedback.correct { background: var(--tint-green); }
.feedback.wrong { background: #fbe3df; }
.feedback .msg { font-weight: 800; margin-bottom: 10px; }
.feedback.correct .msg { color: var(--green-dark); }
.feedback.wrong .msg { color: var(--red); }
.feedback .inner { max-width: 640px; margin: 0 auto; }

/* ---------- Speaking / mic ---------- */
.mic-btn {
  width: 110px; height: 110px; border-radius: 50%; border: none; font-size: 44px;
  background: var(--red); color: #fff; box-shadow: 0 6px 0 #a8342a; margin: 10px auto; display: block;
}
.mic-btn.listening { animation: pulse 1s infinite; }
@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(217,72,59,.5);} 70%{box-shadow:0 0 0 20px rgba(217,72,59,0);} 100%{box-shadow:0 0 0 0 rgba(217,72,59,0);} }
.heard { font-size: 22px; font-weight: 800; margin: 12px 0; min-height: 30px; }
.score-ring { font-size: 48px; font-weight: 900; }
.score-ring.good { color: var(--green); }
.score-ring.ok { color: var(--gold); }
.score-ring.bad { color: var(--red); }

/* ---------- Chat ---------- */
.chat-scroll { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.bubble { max-width: 80%; padding: 12px 16px; border-radius: 18px; font-size: 16px; line-height: 1.35; }
.bubble .en { display: block; font-size: 13px; opacity: .7; margin-top: 4px; }
.bubble.ai { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.me { align-self: flex-end; background: var(--green); color: #fff; border-bottom-right-radius: 4px; }
.bubble.ai .replay { margin-left: 8px; cursor: pointer; }
.suggest { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.suggest button { border: 1px solid var(--green); color: var(--green); background: var(--card); border-radius: 999px; padding: 8px 14px; font-weight: 700; font-size: 14px; }

/* ---------- Misc ---------- */
.center { text-align: center; }
.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }
.pill { display: inline-block; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 13px; font-weight: 700; color: var(--muted); }
.warn { background: var(--tint-gold); border: 1px solid #efd49c; color: #7a5316; padding: 12px 14px; border-radius: 12px; font-size: 14px; margin-bottom: 16px; }
.big-emoji { font-size: 72px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.metric { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; text-align: center; }
.metric b { font-size: 30px; display: block; }
.metric span { color: var(--muted); font-size: 13px; font-weight: 700; }

/* ---------- Typing + sentence-building exercises ---------- */
.type-in { font-size: 20px; }
.build-answer {
  min-height: 56px; margin-top: 18px; padding: 8px; display: flex; flex-wrap: wrap; gap: 8px;
  border-bottom: 2px dashed var(--line); align-content: flex-start;
}
.build-bank { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.tile {
  background: var(--card); border: 2px solid var(--line); border-bottom-width: 4px;
  border-radius: 12px; padding: 10px 16px; font-size: 18px; font-weight: 700; color: var(--ink);
}
.tile.bank:active { transform: translateY(2px); }

/* ---------- Achievements ---------- */
.ach-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ach {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.ach .ach-ic { font-size: 30px; }
.ach b { font-size: 14px; }
.ach small { color: var(--muted); font-size: 12px; }
.ach.locked { opacity: .55; }
.ach.got { border-color: var(--gold); box-shadow: 0 2px 0 rgba(232,184,92,0.3); }
