/* ═══════════════════════════════════════════════
   FísicaQuest v2 — Mobile-First PWA Stylesheet
═══════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:        #3949ab;
  --blue-dark:   #283593;
  --blue-light:  #e8eaf6;
  --blue-mid:    #5c6bc0;
  --green:       #2e7d32;
  --green-light: #e8f5e9;
  --red:         #c62828;
  --red-light:   #ffebee;
  --orange:      #e65100;
  --orange-light:#fff3e0;
  --yellow:      #ffc107;
  --text:        #212121;
  --text-muted:  #607d8b;
  --border:      #c5cae9;
  --bg:          #f0f4ff;
  --white:       #ffffff;
  --radius:      14px;
  --radius-sm:   8px;
  --nav-h:       64px;
  --header-h:    56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { -webkit-tap-highlight-color: transparent; }
body {
  font-family: 'Nunito', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overscroll-behavior: none;
}

/* ─── SCREENS ─────────────────────────────────── */
.screen { display: none; }
.screen.active { display: block; }

/* ─── LOGIN ───────────────────────────────────── */
.login-bg {
  min-height: 100vh;
  min-height: 100dvh;
  background: linear-gradient(145deg, #1a237e 0%, #3949ab 60%, #1565c0 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem 1rem;
}
.login-card {
  background: white;
  border-radius: 20px;
  padding: 2rem 1.5rem;
  width: 100%; max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-logo { text-align: center; margin-bottom: 1.5rem; }
.logo-icon-sm { font-size: 44px; line-height: 1; margin-bottom: .3rem; }
.login-title {
  font-family: 'Fredoka One', cursive;
  font-size: 34px; color: var(--blue);
}
.login-sub { font-size: 14px; color: var(--text-muted); margin-top: 2px; }

.auth-tabs {
  display: flex; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); overflow: hidden; margin-bottom: 1.25rem;
}
.auth-tab {
  flex: 1; padding: 8px; font-size: 14px; font-weight: 700;
  font-family: 'Nunito', sans-serif; border: none;
  background: white; color: var(--text-muted); cursor: pointer;
  transition: all .2s;
}
.auth-tab.active { background: var(--blue); color: white; }

.auth-form { display: none; flex-direction: column; gap: 10px; }
.auth-form.active { display: flex; }

.auth-input {
  width: 100%; padding: 11px 14px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: 15px; font-family: 'Nunito', sans-serif;
  color: var(--text); background: white; outline: none;
  transition: border-color .2s;
}
.auth-input:focus { border-color: var(--blue); }
select.auth-input { cursor: pointer; }
textarea.auth-input { resize: vertical; min-height: 80px; }

.auth-error { font-size: 13px; color: var(--red); min-height: 18px; font-weight: 600; }
.btn-auth {
  width: 100%; padding: 12px; border: none; border-radius: var(--radius-sm);
  background: var(--blue); color: white; font-size: 16px;
  font-weight: 800; font-family: 'Nunito', sans-serif;
  cursor: pointer; transition: background .2s, transform .1s; margin-top: 4px;
}
.btn-auth:hover { background: var(--blue-dark); }
.btn-auth:active { transform: scale(.98); }
.btn-auth:disabled { opacity: .6; cursor: not-allowed; }

/* ─── APP SHELL ───────────────────────────────── */
#app-shell {
  display: flex; flex-direction: column;
  min-height: 100vh; min-height: 100dvh;
}

/* ─── TOP HEADER ──────────────────────────────── */
.app-header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-h);
  background: var(--blue);
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.header-brand { display: flex; align-items: center; gap: 8px; }
.header-logo { font-size: 22px; }
.header-title-text { font-family: 'Fredoka One', cursive; font-size: 20px; color: white; letter-spacing: 1px; }
.header-user { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.header-user-info { display: flex; flex-direction: column; align-items: flex-end; }
.header-user-name { font-size: 13px; font-weight: 700; color: white; line-height: 1.2; }
.header-user-role { font-size: 11px; color: rgba(255,255,255,.7); }
.header-pts { display: flex; flex-direction: column; align-items: center;
  background: rgba(255,255,255,.15); border-radius: var(--radius-sm);
  padding: 4px 10px; border: 1px solid rgba(255,255,255,.25); }
.pts-label { font-size: 10px; color: rgba(255,255,255,.7); }
.pts-val { font-size: 18px; font-weight: 800; color: white; line-height: 1; }

/* ─── SCREENS WRAP ────────────────────────────── */
.screens-wrap {
  flex: 1; overflow-y: auto;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + .5rem);
}

/* ─── BOTTOM NAV ──────────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: white;
  border-top: 1.5px solid var(--border);
  display: flex; align-items: stretch;
  z-index: 100;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
}
.nav-btn {
  flex: 1; border: none; background: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; cursor: pointer; color: var(--text-muted);
  font-family: 'Nunito', sans-serif;
  transition: color .2s, background .2s;
  padding: 6px 4px;
}
.nav-btn.active { color: var(--blue); background: var(--blue-light); }
.nav-icon { font-size: 22px; line-height: 1; }
.nav-label { font-size: 11px; font-weight: 700; }

/* ─── HOME ────────────────────────────────────── */
.home-container { padding: 1.25rem 1rem; max-width: 600px; margin: 0 auto; }
.home-welcome { margin-bottom: 1.25rem; }
.home-greeting { font-size: 22px; font-weight: 800; }
.home-subtitle { font-size: 14px; color: var(--text-muted); margin-top: 2px; }

.home-stats-row {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 10px; margin-bottom: 1.25rem;
}
.home-stat {
  background: white; border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: .75rem .5rem;
  text-align: center;
}
.home-stat-num { font-size: 26px; font-weight: 800; color: var(--blue); }
.home-stat-label { font-size: 12px; color: var(--text-muted); font-weight: 600; }

.home-section { margin-bottom: 1rem; }
.section-label { font-size: 13px; font-weight: 700; color: var(--text-muted); display: block; margin-bottom: 6px; }
.turma-select { width: 100%; }
.codigo-row { display: flex; gap: 8px; }
.btn-sm-action {
  white-space: nowrap; padding: 11px 16px;
  background: var(--blue); color: white; border: none;
  border-radius: var(--radius-sm); font-weight: 800;
  font-family: 'Nunito', sans-serif; font-size: 14px; cursor: pointer;
  transition: background .2s;
}
.btn-sm-action:hover { background: var(--blue-dark); }

.home-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 1.5rem; }
.home-action-card {
  background: white; border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem 1rem;
  cursor: pointer; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  transition: transform .2s, box-shadow .2s; border: none;
  box-shadow: 0 2px 8px rgba(57,73,171,.08);
}
.home-action-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(57,73,171,.15); }
.action-icon { font-size: 36px; }
.action-name { font-size: 16px; font-weight: 800; color: var(--blue); }
.action-desc { font-size: 12px; color: var(--text-muted); }

.btn-logout {
  width: 100%; padding: 12px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); background: white;
  color: var(--text-muted); font-size: 14px; font-weight: 700;
  font-family: 'Nunito', sans-serif; cursor: pointer; transition: all .2s;
}
.btn-logout:hover { border-color: var(--red); color: var(--red); background: var(--red-light); }

/* ─── GAME ────────────────────────────────────── */
.game-container { padding: 1rem; max-width: 720px; margin: 0 auto; }
.section-title-big { font-size: 18px; font-weight: 800; margin-bottom: 1rem; color: var(--blue); }

.progress-area { display: flex; align-items: center; gap: 10px; margin-bottom: 1rem; }
.progress-wrap { flex: 1; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.progress-bar { height: 100%; background: linear-gradient(90deg, var(--blue), #42a5f5); border-radius: 4px; transition: width .6s; }
.progress-text { font-size: 12px; color: var(--text-muted); white-space: nowrap; font-weight: 700; }

.filter-bar { display: flex; gap: 6px; flex-wrap: nowrap; overflow-x: auto; margin-bottom: 1rem; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.filter-bar::-webkit-scrollbar { display: none; }
.filter-btn {
  flex-shrink: 0; background: white; border: 1.5px solid var(--border);
  color: var(--blue); border-radius: 20px; padding: 5px 14px;
  font-size: 13px; font-weight: 700; font-family: 'Nunito', sans-serif;
  cursor: pointer; transition: all .2s; white-space: nowrap;
}
.filter-btn:hover { background: var(--blue-light); }
.filter-btn.active { background: var(--blue); color: white; border-color: var(--blue); }

.puzzle-list { display: flex; flex-direction: column; gap: 1rem; }
.puzzle-card {
  background: white; border: 1.5px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 2px 8px rgba(57,73,171,.07);
  transition: transform .2s, box-shadow .2s;
}
.puzzle-card.solved { border-color: #a5d6a7; }
.puzzle-scene { position: relative; height: 170px; overflow: hidden; }
.puzzle-scene svg { width: 100%; height: 100%; }
.puzzle-badge {
  position: absolute; top: 10px; left: 12px;
  background: rgba(255,255,255,.88); border-radius: 20px;
  padding: 3px 12px; font-size: 12px; font-weight: 800; color: var(--blue-dark);
}
.puzzle-pts {
  position: absolute; top: 10px; right: 12px;
  background: var(--yellow); border-radius: 20px;
  padding: 3px 10px; font-size: 12px; font-weight: 800; color: #5d4037;
}
.puzzle-solved-badge {
  position: absolute; bottom: 10px; right: 12px;
  background: var(--green); color: white; border-radius: 20px;
  padding: 3px 10px; font-size: 12px; font-weight: 800;
}
.puzzle-body { padding: 1rem 1.1rem 1.1rem; }
.puzzle-q { font-size: 15px; font-weight: 700; line-height: 1.5; margin-bottom: 10px; }
.puzzle-hint {
  background: var(--blue-light); border-left: 3px solid var(--blue);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 7px 12px; font-size: 13px; color: var(--blue-dark);
  margin-bottom: 10px; font-weight: 600;
}
.formula-chip {
  display: inline-block; background: #e3f2fd; color: #0d47a1;
  font-family: 'Courier New', monospace; font-size: 13px; font-weight: 700;
  border-radius: var(--radius-sm); padding: 3px 12px; margin-bottom: 12px; border: 1px solid #bbdefb;
}
.answer-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.answer-input {
  flex: 1; min-width: 0; padding: 10px 12px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: 17px; font-family: 'Nunito', sans-serif; font-weight: 700;
  color: var(--text); outline: none; transition: border-color .2s;
}
.answer-input:focus { border-color: var(--blue); }
.answer-input:disabled { opacity: .5; }
.unit-tag { font-size: 13px; font-weight: 700; color: var(--text-muted); min-width: 36px; white-space: nowrap; }
.btn-check {
  background: var(--blue); color: white; border: none;
  border-radius: var(--radius-sm); padding: 10px 18px;
  font-size: 14px; font-weight: 800; font-family: 'Nunito', sans-serif;
  cursor: pointer; transition: background .2s, transform .1s; white-space: nowrap;
}
.btn-check:hover { background: var(--blue-dark); }
.btn-check:active { transform: scale(.97); }
.btn-check:disabled { opacity: .5; cursor: not-allowed; }
.btn-check.done { background: var(--green); }
.feedback-msg { font-size: 13px; font-weight: 700; border-radius: var(--radius-sm); padding: 7px 12px; display: none; margin-bottom: 8px; line-height: 1.5; }
.feedback-msg.show { display: block; }
.feedback-msg.correct { background: var(--green-light); color: var(--green); }
.feedback-msg.wrong   { background: var(--red-light);   color: var(--red); }
.feedback-msg.partial { background: var(--orange-light); color: var(--orange); }
.stars-row { display: flex; gap: 6px; }
.star-ico { font-size: 20px; filter: grayscale(1) opacity(.3); transition: filter .3s, transform .3s; }
.star-ico.lit { filter: none; transform: scale(1.15); }

/* ─── RANKING ─────────────────────────────────── */
.ranking-table { border: 1.5px solid var(--border); border-radius: var(--radius); overflow: hidden; background: white; }
.ranking-header {
  display: grid; grid-template-columns: 44px 1fr 64px 64px 48px;
  background: var(--blue); color: white;
  padding: 10px 12px; font-size: 12px; font-weight: 800;
}
.ranking-row {
  display: grid; grid-template-columns: 44px 1fr 64px 64px 48px;
  padding: 10px 12px; font-size: 14px;
  border-top: 1px solid var(--bg); align-items: center;
  transition: background .15s;
}
.ranking-row:hover { background: var(--bg); }
.ranking-row.top3 { background: #fffde7; font-weight: 700; }

/* ─── TEACHER ─────────────────────────────────── */
.teacher-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 1.25rem; }
.teacher-tab-btn {
  padding: 7px 16px; border: 1.5px solid var(--border);
  border-radius: 20px; background: white; color: var(--blue);
  font-size: 13px; font-weight: 700; font-family: 'Nunito', sans-serif; cursor: pointer;
  transition: all .2s;
}
.teacher-tab-btn.active { background: var(--blue); color: white; border-color: var(--blue); }

.create-turma-box { display: flex; gap: 8px; margin-bottom: 1rem; }
.btn-primary {
  background: var(--blue); color: white; border: none;
  border-radius: var(--radius-sm); padding: 11px 20px;
  font-size: 14px; font-weight: 800; font-family: 'Nunito', sans-serif;
  cursor: pointer; transition: background .2s, transform .1s; white-space: nowrap;
}
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:active { transform: scale(.97); }

.teacher-card {
  background: white; border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: .75rem;
  cursor: pointer; transition: transform .2s, box-shadow .2s;
}
.teacher-card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(57,73,171,.1); }
.turma-header { display: flex; align-items: center; justify-content: space-between; }
.turma-nome { font-size: 16px; font-weight: 800; }
.turma-codigo { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.turma-stats { display: flex; gap: 12px; }
.turma-stat { text-align: center; font-size: 20px; font-weight: 800; color: var(--blue); }
.turma-stat small { display: block; font-size: 11px; color: var(--text-muted); font-weight: 600; }

/* Relatório */
.rel-header { margin-bottom: 1rem; }
.rel-stats-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; margin-bottom: 1.25rem; }
.rel-stat-card { background: var(--blue-light); border-radius: var(--radius-sm); padding: .75rem; text-align: center; }
.rel-stat-num { font-size: 24px; font-weight: 800; color: var(--blue); }
.rel-stat-label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.rel-section-title { font-size: 15px; font-weight: 800; color: var(--blue); margin: 1.25rem 0 .75rem; }

.puzzle-stats-list { display: flex; flex-direction: column; gap: 8px; }
.puzzle-stat-row { display: flex; align-items: center; gap: 10px; }
.puzzle-stat-name { min-width: 120px; font-size: 13px; font-weight: 700; display: flex; flex-direction: column; }
.puzzle-stat-name small { font-size: 11px; color: var(--text-muted); font-weight: 400; }
.puzzle-stat-bar-wrap { flex: 1; height: 10px; background: var(--border); border-radius: 5px; overflow: hidden; }
.puzzle-stat-bar { height: 100%; border-radius: 5px; transition: width .6s; }
.puzzle-stat-pct { font-size: 13px; font-weight: 800; min-width: 42px; text-align: right; }

/* Admin puzzles */
.admin-puzzle-row {
  display: flex; align-items: center; justify-content: space-between;
  background: white; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: .75rem 1rem; margin-bottom: .5rem;
}
.admin-puzzle-row strong { display: block; font-size: 14px; }
.admin-puzzle-row small { font-size: 12px; color: var(--text-muted); }
.btn-sm { padding: 5px 12px; border: 1.5px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; font-weight: 700; font-family: 'Nunito', sans-serif; cursor: pointer; background: white; }
.btn-edit:hover { background: var(--blue-light); border-color: var(--blue); }
.btn-del:hover  { background: var(--red-light);  border-color: var(--red); color: var(--red); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-full { grid-column: 1 / -1; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 12px; font-weight: 700; color: var(--text-muted); }

/* ─── MODAL ────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 999; backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: white; border-radius: 20px;
  padding: 2rem 1.5rem; text-align: center;
  max-width: 340px; width: 90%;
  box-shadow: 0 12px 40px rgba(0,0,0,.2);
  animation: popIn .3s cubic-bezier(.34,1.56,.64,1);
}
@keyframes popIn { from{transform:scale(.7);opacity:0} to{transform:scale(1);opacity:1} }
.modal-emoji { font-size: 52px; margin-bottom: .5rem; }
.modal-title { font-family: 'Fredoka One', cursive; font-size: 26px; color: var(--blue); margin-bottom: .4rem; }
.modal-text { font-size: 14px; color: var(--text-muted); margin-bottom: 1rem; line-height: 1.6; }
.modal-stars { font-size: 26px; margin-bottom: 1rem; }

/* ─── TOAST ────────────────────────────────────── */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 12px + var(--safe-bottom));
  left: 50%; transform: translateX(-50%) translateY(20px);
  background: #212121; color: white;
  padding: 10px 20px; border-radius: 20px;
  font-size: 14px; font-weight: 700;
  opacity: 0; transition: all .3s; z-index: 9999;
  white-space: nowrap; max-width: 90vw;
  text-overflow: ellipsis; overflow: hidden;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-success { background: var(--green); }
.toast-error   { background: var(--red); }

/* ─── INSTALL BANNER ───────────────────────────── */
.install-banner {
  background: var(--blue); color: white;
  padding: 10px 1rem; font-size: 13px; font-weight: 700;
  display: flex; align-items: center; gap: 10px;
  position: sticky; top: 0; z-index: 200;
}
.install-banner span { flex: 1; }
.install-banner button {
  background: white; color: var(--blue); border: none;
  border-radius: var(--radius-sm); padding: 5px 14px;
  font-size: 13px; font-weight: 800; cursor: pointer;
  font-family: 'Nunito', sans-serif;
}
.btn-dismiss { background: transparent !important; color: white !important; font-size: 16px !important; padding: 4px 8px !important; }

/* ─── MISC ─────────────────────────────────────── */
.loading-spinner {
  width: 36px; height: 36px; border: 3px solid var(--border);
  border-top-color: var(--blue); border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 2rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { text-align: center; padding: 2rem 1rem; color: var(--text-muted); }
.error-msg { color: var(--red); font-size: 14px; font-weight: 600; text-align: center; padding: 1rem; }

/* ─── RESPONSIVE ───────────────────────────────── */
@media (min-width: 600px) {
  .home-actions { grid-template-columns: repeat(2, 1fr); }
  .ranking-header, .ranking-row { grid-template-columns: 44px 1fr 80px 80px 60px; }
}
@media (max-width: 380px) {
  .form-grid { grid-template-columns: 1fr; }
  .home-stat-num { font-size: 22px; }
}

/* ─── ANIMATIONS ───────────────────────────────── */
@keyframes float { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-10px)} }
@keyframes fall  { 0%{transform:translateY(0)} 100%{transform:translateY(72px)} }
@keyframes wavePulse { 0%,100%{opacity:1} 50%{opacity:.5} }
.anim-float { animation: float 2s ease-in-out infinite; }
.anim-fall  { animation: fall 1.4s ease-in infinite alternate; }
.anim-wave  { animation: wavePulse 1.5s ease-in-out infinite; }
