/* ============================================================
   Meu Português — дизайн-система «тёплый современный бразильский город»
   Палитра из style bible. Светлая/тёмная тема, safe areas, a11y.
   ============================================================ */

:root {
  --verde: #176B55;
  --turquesa: #20A58A;
  --sol: #F6C84C;
  --coral: #EF7465;
  --ceu: #67B8D8;
  --fundo: #FFF9EF;
  --texto: #20312D;
  --cartao: #FFFFFF;

  --texto-2: #5C6B66;
  --linha: #E8E0D0;
  --verde-suave: #E3F2EC;
  --sol-suave: #FCF0D2;
  --coral-suave: #FCE4E0;
  --ceu-suave: #E4F2F8;
  --sombra: 0 2px 10px rgba(32, 49, 45, 0.08);
  --sombra-up: 0 -2px 12px rgba(32, 49, 45, 0.07);

  --r-lg: 22px;
  --r-md: 16px;
  --r-sm: 10px;

  --fs-base: 16px;
  --tap: 48px;

  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

:root[data-theme="dark"] {
  --fundo: #14201C;
  --texto: #F0EFE6;
  --texto-2: #A3B3AC;
  --cartao: #1D2C27;
  --linha: #2C3E38;
  --verde-suave: #1B3A30;
  --sol-suave: #3A331A;
  --coral-suave: #3C2622;
  --ceu-suave: #1D3340;
  --sombra: 0 2px 10px rgba(0, 0, 0, 0.35);
  --sombra-up: 0 -2px 12px rgba(0, 0, 0, 0.3);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --fundo: #14201C;
    --texto: #F0EFE6;
    --texto-2: #A3B3AC;
    --cartao: #1D2C27;
    --linha: #2C3E38;
    --verde-suave: #1B3A30;
    --sol-suave: #3A331A;
    --coral-suave: #3C2622;
    --ceu-suave: #1D3340;
    --sombra: 0 2px 10px rgba(0, 0, 0, 0.35);
    --sombra-up: 0 -2px 12px rgba(0, 0, 0, 0.3);
  }
}

:root[data-textsize="large"] { --fs-base: 19px; }
:root[data-textsize="xlarge"] { --fs-base: 22px; }

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html { font-size: var(--fs-base); }

body {
  font-family: "Avenir Next", Avenir, "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--fundo);
  color: var(--texto);
  line-height: 1.45;
  min-height: 100dvh;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}

:root[data-motion="off"] *, :root[data-motion="off"] *::before, :root[data-motion="off"] *::after {
  animation: none !important;
  transition: none !important;
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, select, textarea { font: inherit; }
img, svg { max-width: 100%; display: block; }
a { color: var(--verde); }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- каркас ---------- */

#app { display: flex; flex-direction: column; min-height: 100dvh; }

.screen {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--sat) + 14px) 16px calc(96px + var(--sab));
  animation: screen-in 0.22s ease;
}
.screen.no-tabs { padding-bottom: calc(24px + var(--sab)); }

@keyframes screen-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ---------- нижняя навигация ---------- */

#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: var(--cartao);
  border-top: 1px solid var(--linha);
  box-shadow: var(--sombra-up);
  padding-bottom: var(--sab);
}
#tabbar .row {
  display: flex; max-width: 560px; margin: 0 auto;
}
.tab-btn {
  flex: 1; min-height: 58px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--texto-2);
  font-size: 0.68rem; font-weight: 600;
}
.tab-btn .ico { font-size: 1.35rem; line-height: 1; }
.tab-btn[aria-current="page"] { color: var(--verde); }
.tab-btn[aria-current="page"] .ico { transform: translateY(-1px); }

/* ---------- типографика ---------- */

h1 { font-size: 1.5rem; line-height: 1.2; letter-spacing: -0.01em; }
h2 { font-size: 1.18rem; line-height: 1.25; }
h3 { font-size: 1rem; }
.muted { color: var(--texto-2); }
.small { font-size: 0.85rem; }
.tiny { font-size: 0.75rem; }
.pt-text { font-weight: 700; }

/* ---------- карточки и кнопки ---------- */

.card {
  background: var(--cartao);
  border-radius: var(--r-lg);
  border: 1px solid var(--linha);
  box-shadow: var(--sombra);
  padding: 16px;
}
.card + .card { margin-top: 12px; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap);
  padding: 12px 20px;
  border-radius: var(--r-md);
  font-weight: 700;
  font-size: 1rem;
  transition: transform 0.08s ease, filter 0.15s ease;
  width: 100%;
  text-align: center;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--verde); color: #fff; }
.btn-primary:disabled { background: var(--linha); color: var(--texto-2); cursor: default; }
.btn-sun { background: var(--sol); color: #4a3a08; }
.btn-coral { background: var(--coral); color: #fff; }
.btn-ghost { background: transparent; color: var(--verde); border: 2px solid var(--verde); }
.btn-soft { background: var(--verde-suave); color: var(--verde); }
.btn-plain { background: transparent; color: var(--texto-2); font-weight: 600; min-height: 40px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--verde-suave); color: var(--verde);
  border-radius: 999px; padding: 5px 12px;
  font-size: 0.82rem; font-weight: 700;
}
.chip.sun { background: var(--sol-suave); color: #8a6a10; }
.chip.coral { background: var(--coral-suave); color: #b0402f; }
.chip.ceu { background: var(--ceu-suave); color: #2b6d8c; }

/* ---------- шапка экранов ---------- */

.topline { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.topline .stats { display: flex; gap: 8px; }

.back-btn {
  min-width: var(--tap); min-height: var(--tap);
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: var(--cartao); border: 1px solid var(--linha);
  font-size: 1.1rem;
}

/* ---------- онбординг ---------- */

.ob-progress { display: flex; gap: 6px; margin: 10px 0 20px; }
.ob-progress i { flex: 1; height: 6px; border-radius: 3px; background: var(--linha); }
.ob-progress i.on { background: var(--turquesa); }

.opt-list { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.opt {
  display: flex; align-items: center; gap: 12px;
  min-height: var(--tap);
  background: var(--cartao); border: 2px solid var(--linha);
  border-radius: var(--r-md); padding: 13px 16px;
  font-weight: 600; text-align: left; width: 100%;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.opt .ico { font-size: 1.3rem; }
.opt[aria-pressed="true"] { border-color: var(--turquesa); background: var(--verde-suave); }

/* ---------- карта Bairro Vivo ---------- */

.section-band {
  border-radius: var(--r-lg);
  padding: 18px 16px;
  margin-bottom: 14px;
  color: #fff;
  position: relative;
  overflow: hidden;
}
.section-band .cefr {
  position: absolute; top: 12px; right: 14px;
  background: rgba(255, 255, 255, 0.22);
  border-radius: 999px; padding: 3px 10px;
  font-size: 0.75rem; font-weight: 700;
}
.section-band h2 { margin-bottom: 2px; }
.section-band .small { opacity: 0.9; }

.map-scroll { position: relative; padding: 8px 0 30px; }

.map-node {
  display: flex; align-items: center; gap: 14px;
  width: 100%;
  padding: 6px 8px;
  margin-bottom: 6px;
  border-radius: var(--r-md);
  text-align: left;
}
.map-node .bubble {
  width: 62px; height: 62px; flex: none;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
  border: 3px solid var(--linha);
  background: var(--cartao);
  box-shadow: var(--sombra);
  position: relative;
}
.map-node.side .bubble { width: 52px; height: 52px; font-size: 1.2rem; margin-left: 34px; }
.map-node.done .bubble { border-color: var(--turquesa); background: var(--verde-suave); }
.map-node.current .bubble { border-color: var(--sol); background: var(--sol-suave); animation: pulse 2s infinite; }
.map-node.locked { opacity: 0.55; }
.map-node .info { flex: 1; min-width: 0; }
.map-node .t { font-weight: 700; }
.map-node .check {
  position: absolute; right: -4px; bottom: -4px;
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--turquesa); color: #fff;
  font-size: 0.8rem; display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--cartao);
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(246, 200, 76, 0.5); }
  50% { box-shadow: 0 0 0 10px rgba(246, 200, 76, 0); }
}

.unit-head {
  display: flex; align-items: center; gap: 10px;
  margin: 20px 0 10px; color: var(--texto-2);
  font-size: 0.85rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
}
.unit-head::before, .unit-head::after { content: ""; flex: 1; height: 1px; background: var(--linha); }

.locked-section {
  opacity: 0.7; filter: saturate(0.6);
}

/* ---------- урок ---------- */

.lesson-top { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.lesson-progress { flex: 1; height: 10px; border-radius: 5px; background: var(--linha); overflow: hidden; }
.lesson-progress i { display: block; height: 100%; background: var(--turquesa); border-radius: 5px; transition: width 0.3s ease; }

.ex-prompt { margin: 6px 0 16px; }
.ex-phrase {
  font-size: 1.3rem; font-weight: 700; margin: 8px 0;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}

.audio-btn {
  width: 46px; height: 46px; flex: none;
  border-radius: 50%;
  background: var(--ceu-suave); color: #2b6d8c;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.25rem;
}
.audio-btn.big { width: 84px; height: 84px; font-size: 2rem; margin: 10px auto; background: var(--ceu); color: #fff; }
.audio-btn.slow { font-size: 1rem; }

.answer-list { display: flex; flex-direction: column; gap: 10px; }
.answer {
  min-height: var(--tap);
  background: var(--cartao); border: 2px solid var(--linha);
  border-radius: var(--r-md); padding: 12px 16px;
  font-weight: 600; width: 100%; text-align: left;
  display: flex; align-items: center; gap: 10px;
}
.answer.sel { border-color: var(--ceu); background: var(--ceu-suave); }
.answer.ok { border-color: var(--turquesa); background: var(--verde-suave); }
.answer.bad { border-color: var(--coral); background: var(--coral-suave); }

.word-bank, .word-slots { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; min-height: 46px; }
.word-slots { padding: 10px; border-radius: var(--r-md); background: var(--verde-suave); align-items: flex-start; }
.w-token {
  background: var(--cartao); border: 2px solid var(--linha);
  border-radius: var(--r-sm); padding: 8px 14px; font-weight: 700;
  min-height: 42px;
}
.w-token.ghost { opacity: 0.25; pointer-events: none; }

.pairs-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pairs-grid .answer { justify-content: center; text-align: center; }
.pairs-grid .answer.matched { opacity: 0.35; pointer-events: none; border-color: var(--turquesa); }

.type-input {
  width: 100%; min-height: 54px;
  border: 2px solid var(--linha); border-radius: var(--r-md);
  background: var(--cartao); color: var(--texto);
  padding: 12px 16px; font-size: 1.1rem; font-weight: 600;
}
.type-input:focus { outline: none; border-color: var(--turquesa); }

.feedback {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  background: var(--cartao);
  border-top-left-radius: var(--r-lg); border-top-right-radius: var(--r-lg);
  box-shadow: var(--sombra-up);
  padding: 18px 16px calc(16px + var(--sab));
  animation: sheet-in 0.2s ease;
}
.feedback .inner { max-width: 560px; margin: 0 auto; }
.feedback.ok { border-top: 4px solid var(--turquesa); }
.feedback.bad { border-top: 4px solid var(--coral); }
.feedback h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }

@keyframes sheet-in { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- персонаж на сцене ---------- */

.stage {
  display: flex; flex-direction: column; align-items: center;
  padding: 8px 0 4px;
}
.stage .char-holder { width: 168px; height: 168px; }
.stage.small .char-holder { width: 110px; height: 110px; }
.speech-bubble {
  position: relative;
  background: var(--cartao); border: 1px solid var(--linha);
  border-radius: var(--r-lg); padding: 14px 16px;
  box-shadow: var(--sombra);
  margin-top: 8px;
  max-width: 100%;
}
.speech-bubble::before {
  content: ""; position: absolute; top: -8px; left: 50%; margin-left: -8px;
  width: 16px; height: 16px; background: inherit;
  border-left: 1px solid var(--linha); border-top: 1px solid var(--linha);
  transform: rotate(45deg);
}

.karaoke { font-size: 1.25rem; font-weight: 700; line-height: 1.5; }
.karaoke .w { border-radius: 6px; padding: 1px 3px; }
.karaoke .w.now { background: var(--sol-suave); color: #8a6a10; }
.karaoke .w.good { background: var(--verde-suave); color: var(--verde); }
.karaoke .w.mid { background: var(--sol-suave); color: #8a6a10; }
.karaoke .w.poor { background: var(--coral-suave); color: #b0402f; }

.rate-row { display: flex; gap: 8px; justify-content: center; margin: 12px 0; }
.rate-row .chipbtn {
  border: 2px solid var(--linha); border-radius: 999px;
  padding: 8px 16px; font-weight: 700; font-size: 0.9rem;
  background: var(--cartao); min-height: 42px;
}
.rate-row .chipbtn.on { border-color: var(--turquesa); background: var(--verde-suave); color: var(--verde); }

.mic-btn {
  width: 84px; height: 84px; border-radius: 50%;
  background: var(--coral); color: #fff; font-size: 2rem;
  display: flex; align-items: center; justify-content: center;
  margin: 14px auto 6px;
  box-shadow: var(--sombra);
}
.mic-btn.rec { animation: recpulse 1s infinite; }
@keyframes recpulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 116, 101, 0.55); }
  50% { box-shadow: 0 0 0 16px rgba(239, 116, 101, 0); }
}

/* ---------- диалог ---------- */

.dlg-log { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.dlg-msg { display: flex; gap: 10px; align-items: flex-end; }
.dlg-msg .avatar { width: 40px; height: 40px; flex: none; border-radius: 50%; overflow: hidden; background: var(--verde-suave); }
.dlg-msg .txt {
  background: var(--cartao); border: 1px solid var(--linha);
  border-radius: var(--r-md); border-bottom-left-radius: 4px;
  padding: 10px 14px; max-width: 82%;
}
.dlg-msg.me { flex-direction: row-reverse; }
.dlg-msg.me .txt {
  background: var(--verde); color: #fff; border-color: var(--verde);
  border-bottom-left-radius: var(--r-md); border-bottom-right-radius: 4px;
}
.dlg-msg .ru { font-size: 0.8rem; opacity: 0.75; margin-top: 3px; }

/* ---------- профиль и статистика ---------- */

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-tile { background: var(--cartao); border: 1px solid var(--linha); border-radius: var(--r-md); padding: 12px 14px; }
.stat-tile .v { font-size: 1.4rem; font-weight: 800; }

.skill-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--linha); }
.skill-row:last-child { border-bottom: 0; }
.skill-row .name { flex: 1; font-weight: 600; }
.skill-bar { width: 110px; height: 8px; border-radius: 4px; background: var(--linha); overflow: hidden; }
.skill-bar i { display: block; height: 100%; border-radius: 4px; background: var(--turquesa); }

.list-row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: var(--tap); padding: 12px 4px;
  border-bottom: 1px solid var(--linha); text-align: left; font-weight: 600;
}
.list-row:last-child { border-bottom: 0; }
.list-row .ico { font-size: 1.25rem; width: 30px; text-align: center; }
.list-row .grow { flex: 1; min-width: 0; }
.list-row .arr { color: var(--texto-2); }

/* ---------- paywall ---------- */

.plan-card { border: 2px solid var(--linha); border-radius: var(--r-lg); padding: 16px; background: var(--cartao); }
.plan-card + .plan-card { margin-top: 12px; }
.plan-card.hot { border-color: var(--sol); position: relative; }
.plan-card.hot .tag {
  position: absolute; top: -11px; left: 16px;
  background: var(--sol); color: #4a3a08;
  border-radius: 999px; padding: 2px 12px; font-size: 0.75rem; font-weight: 800;
}
.plan-card ul { margin: 10px 0 0 2px; list-style: none; }
.plan-card li { padding: 3px 0 3px 26px; position: relative; font-size: 0.92rem; }
.plan-card li::before { content: "✓"; position: absolute; left: 2px; color: var(--turquesa); font-weight: 800; }

.price-line { display: flex; align-items: baseline; gap: 6px; margin-top: 6px; }
.price-line .p { font-size: 1.3rem; font-weight: 800; }

/* ---------- разное ---------- */

.hero-panel {
  border-radius: var(--r-lg); overflow: hidden; position: relative;
  background: linear-gradient(135deg, var(--verde), var(--turquesa));
  color: #fff; padding: 20px 18px; margin-bottom: 14px;
}
.hero-panel h1 { color: #fff; }

.toast {
  position: fixed; top: calc(var(--sat) + 12px); left: 50%; transform: translateX(-50%);
  background: var(--texto); color: var(--fundo);
  border-radius: 999px; padding: 10px 20px; font-weight: 700; font-size: 0.9rem;
  z-index: 90; box-shadow: var(--sombra); max-width: 92vw; text-align: center;
  animation: toast-in 0.25s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }

.modal-back {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(20, 32, 28, 0.55);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade-in 0.2s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--fundo); width: 100%; max-width: 560px;
  border-top-left-radius: var(--r-lg); border-top-right-radius: var(--r-lg);
  padding: 20px 16px calc(20px + var(--sab));
  max-height: 88dvh; overflow-y: auto;
  animation: sheet-in 0.25s ease;
}
.modal .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--linha); margin: 0 auto 14px; }

.divider { height: 1px; background: var(--linha); margin: 14px 0; }

.badge-dot {
  min-width: 20px; height: 20px; border-radius: 10px;
  background: var(--coral); color: #fff; font-size: 0.7rem; font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center; padding: 0 6px;
}

.empty-state { text-align: center; padding: 36px 16px; color: var(--texto-2); }
.empty-state .big { font-size: 2.6rem; margin-bottom: 10px; }

.ad-slot {
  border: 2px dashed var(--linha); border-radius: var(--r-md);
  padding: 14px; text-align: center; color: var(--texto-2); font-size: 0.85rem;
  margin-top: 14px;
}

.confetti-pop { animation: pop 0.45s ease; }
@keyframes pop { 0% { transform: scale(0.6); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }

.focus-pips { display: inline-flex; gap: 3px; }
.focus-pips i { width: 10px; height: 10px; border-radius: 50%; background: var(--linha); }
.focus-pips i.on { background: var(--sol); }

table.cmp { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.cmp th, table.cmp td { padding: 7px 6px; text-align: center; border-bottom: 1px solid var(--linha); }
table.cmp td:first-child, table.cmp th:first-child { text-align: left; }

@media (min-width: 700px) {
  .screen { max-width: 640px; }
}
