:root {
  --nav-surface: oklch(0.2 0.035 250 / 0.97);
  --surface-soft: oklch(0.98 0.01 250 / 0.06);
  --surface-shadow: 0 8px 30px oklch(0 0 0 / 0.18);
  --accent-text: oklch(0.8 0.13 235);
  --success-text: oklch(0.78 0.17 150);
  --active-surface: oklch(0.64 0.2 235 / 0.16);
  --on-accent: oklch(1 0 0);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: oklch(0.17 0.045 255);
  --bg2: oklch(0.21 0.05 255);
  --fg: oklch(0.95 0.012 250);
  --cd: oklch(0.98 0.01 250 / 0.06);
  --mu: oklch(0.73 0.03 250);
  --bd: oklch(0.98 0.01 250 / 0.13);
  --ac: oklch(0.77 0.14 225);
  --ac2: oklch(0.52 0.23 255);
  --ok: oklch(0.75 0.18 150);
  --bad: oklch(0.7 0.19 25);
  --glow: 0 0 24px oklch(0.6 0.2 235 / 0.2);
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: oklch(0.97 0.006 250);
  --bg2: oklch(0.94 0.012 250);
  --fg: oklch(0.25 0.025 250);
  --cd: oklch(1 0 0);
  --mu: oklch(0.49 0.03 250);
  --bd: oklch(0.84 0.018 250);
  --ac: oklch(0.48 0.2 235);
  --ac2: oklch(0.45 0.21 255);
  --ok: oklch(0.48 0.14 150);
  --bad: oklch(0.5 0.19 25);
  --glow: 0 8px 24px oklch(0.5 0.12 235 / 0.1);
  --nav-surface: oklch(1 0 0 / 0.97);
  --surface-soft: oklch(0.95 0.008 250);
  --surface-shadow: 0 8px 30px oklch(0.3 0.02 250 / 0.07);
  --accent-text: oklch(0.47 0.18 235);
  --success-text: oklch(0.43 0.12 150);
  --active-surface: oklch(0.52 0.2 235 / 0.09);
}
body { background: linear-gradient(180deg,var(--bg),var(--bg2)); padding-bottom: calc(156px + env(safe-area-inset-bottom,0px)); }
#app { max-width: 1320px; width: 100%; padding: 20px; }
header { gap: 16px; margin-bottom: 20px; }
header h1 { font-size: 24px; background: none; color: var(--fg); }
.header-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.appearance-switch { display: inline-flex; gap: 3px; border: 1px solid var(--bd); border-radius: 8px; padding: 3px; background: var(--cd); }
.appearance-switch button { width: 40px; height: 38px; padding: 0; font-size: 24px; border-radius: 5px; color: var(--mu); background: none; box-shadow: none; }
.appearance-switch button[aria-pressed="true"] { color: var(--ac); background: var(--active-surface); }
button:focus-visible, select:focus-visible { outline: 3px solid var(--ac); outline-offset: 3px; }
.card { box-shadow: var(--surface-shadow); }
input,select,textarea,button.g,.o,.ch,.rank-row,.quiz-box,.quiz-item,.quiz-item .opt,.fc-stats > div,.fb-order-item,.fb-node,.fb-legend span { background: var(--surface-soft); }
option { background: var(--bg); color: var(--fg); }
#nav { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); background: var(--nav-surface); overflow: visible; padding: 6px max(8px,calc((100% - 1320px)/2)) calc(6px + env(safe-area-inset-bottom,0px)); gap: 4px; }
#nav button { min-width: 0; min-height: 62px; font-size: 13px; padding: 6px 2px; border-radius: 8px; color: var(--mu); }
#nav button.on { background: var(--active-surface); color: var(--ac); }
#nav span { font-size: 25px; line-height: 30px; margin-bottom: 3px; }
.row > * { min-width: 0; }
.question-timing { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; color: var(--mu); padding: 10px 0; border-bottom: 1px solid var(--bd); }
.question-timing output { color: var(--fg); font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 6ch; margin-left: auto; text-align: right; }
.question-timing-summary { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; padding: 16px 0; border-block: 1px solid var(--bd); }
.question-timing-summary span { display: block; color: var(--mu); font-size: 13px; }
.question-timing-summary b { display: block; color: var(--fg); background: none; font-size: 22px; font-variant-numeric: tabular-nums; }
.rank-row { flex-wrap: wrap; padding: 16px; gap: 12px; }
.rank-row .name { overflow-wrap: anywhere; min-width: 100px; }
.rank-row .val { color: var(--success-text); }
.rank-row .pos.silver { color: var(--mu); }
.fishbone { background: var(--cd); border-color: var(--bd); box-shadow: var(--surface-shadow); }
.fb-node { border-color: var(--bd); }
.read-text h4,.read-text strong,.quiz-box .qhead { color: var(--accent-text); border-color: var(--accent-text); }
.read-text em { color: var(--success-text); }
.read-card h3,.fb-head h3 { background: none; color: var(--accent-text); }
#login,#splash { background: linear-gradient(180deg,var(--bg),var(--bg2)); }
.login-box { background: var(--cd); border-color: var(--bd); box-shadow: var(--surface-shadow); }
#mc-auth { background: linear-gradient(180deg,var(--bg),var(--bg2)) !important; color: var(--fg) !important; }
#mc-auth .bx { background: var(--cd) !important; border-color: var(--bd) !important; box-shadow: var(--surface-shadow); }
#mc-auth p { color: var(--mu) !important; }
#mc-auth input { background: var(--surface-soft) !important; color: var(--fg) !important; border-color: var(--bd) !important; }
#mc-auth .lk { color: var(--accent-text) !important; }
#mc-auth #mc-gg { color: var(--fg) !important; background: var(--surface-soft) !important; border-color: var(--bd) !important; }
#mc-auth .msg { color: var(--bad) !important; }
#mc-auth .msg.ok { color: var(--ok) !important; }
@media (min-width:768px) {
  body { font-size: 17px; padding-bottom: calc(110px + env(safe-area-inset-bottom,0px)); }
  #app { padding: 32px; }
  header h1 { font-size: 28px; }
  h2 { font-size: 21px; }
  .mu { font-size: 15px; }
  button,input,select,textarea { font-size: 16px; }
  .pill,.btn-install { font-size: 14px; padding: 9px 14px; }
  .card { padding: 24px; }
  #nav { grid-template-columns: repeat(8,minmax(0,1fr)); padding-top: 10px; padding-bottom: calc(10px + env(safe-area-inset-bottom,0px)); }
  #nav button { min-height: 72px; font-size: 15px; }
  #nav span { font-size: 29px; line-height: 34px; }
  .stat b { font-size: 30px; }
  .read-text { font-size: 18px; }
  .read-text p { max-width: 90ch; }
}
@media (min-width:1100px) {
  .view-content { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 20px; align-items: start; }
  .view-content > .card { margin: 0; }
  .view-content > .card:first-child,.view-content > :not(.card) { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion:reduce) { *,*::before,*::after { scroll-behavior: auto !important; transition: none !important; } }
/* Mission dashboard: shared tokens keep both appearances coherent. */
:root {
  --mission-blue: oklch(0.66 0.17 245);
  --mission-cyan: oklch(0.78 0.13 220);
  --mission-purple: oklch(0.7 0.16 300);
  --mission-green: oklch(0.74 0.15 160);
  --mission-gold: oklch(0.8 0.14 85);
  --mission-red: oklch(0.72 0.17 20);
  --mission-heading: linear-gradient(100deg,var(--mission-blue),var(--mission-cyan));
}
body { background: var(--bg); letter-spacing: 0; }
button { border-radius: 8px; box-shadow: none; color: var(--on-accent); }
button.g { color: var(--fg); }
.card,.read-card,.fishbone,.quiz-box,.fl-face,.rank-row { border-radius: 8px; }
.card { background: var(--cd); backdrop-filter: none; box-shadow: none; }
header { display: grid; grid-template-columns: minmax(0,1fr); border-bottom: 1px solid var(--bd); padding-bottom: 20px; }
.brand { display: flex; gap: 12px; align-items: center; min-width: 0; }
.brand img { width: 48px; height: 48px; border-radius: 8px; flex-shrink: 0; }
.brand h1 { font-size: 21px; line-height: 1.1; font-weight: 900; }
.brand h1 em { display: block; color: var(--ac); font-style: normal; }
.brand small { color: var(--mu); font-size: 11px; }
.header-actions { gap: 8px; }
.pill { color: var(--fg); background: var(--surface-soft); border: 1px solid var(--bd); border-radius: 6px; box-shadow: none; white-space: normal; overflow-wrap: anywhere; }
.btn-install { background: var(--active-surface); color: var(--ac); box-shadow: none; border-radius: 6px; }
.course-select { margin: 0 0 20px; max-width: 420px; }
.mission-welcome { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 20px; align-items: center; padding: 16px 0 28px; }
.mission-welcome h2 { font-size: 26px; margin: 6px 0; line-height: 1.25; }
.mission-welcome p { color: var(--mu); margin: 6px 0 18px; }
.mission-eyebrow { color: var(--ac); font-size: 12px; font-weight: 800; }
.mission-mark { width: 74px; height: 74px; color: var(--ac); }
.mission-mark svg { width: 100%; height: 100%; }
.bar { background: var(--surface-soft); height: 6px; }
.bar i { background: var(--mission-heading); }
.mission-progress { display: flex; justify-content: space-between; gap: 8px; color: var(--mu); font-size: 12px; margin-bottom: 8px; }
.mission-shortcuts { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 12px; }
.mission-tile { --tile: var(--mission-blue); position: relative; display: flex; flex-direction: column; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px; min-height: 145px; text-align: left; background: color-mix(in oklch,var(--tile) 12%,var(--bg)); border: 1px solid color-mix(in oklch,var(--tile) 32%,var(--bd)); color: var(--fg); overflow: hidden; transition: border-color .18s,transform .18s; }
.mission-tile:hover { border-color: var(--tile); transform: translateY(-2px); }
.mission-tile svg { width: 32px; height: 32px; color: var(--tile); }
.mission-tile strong { display: block; font-size: 17px; }
.mission-tile small { display: block; color: var(--mu); font-weight: 400; font-size: 12px; margin-top: 4px; }
.mission-tile .tile-arrow { position: absolute; right: 16px; top: 20px; color: var(--tile); font-size: 22px; }
.mission-tile.cards { --tile: var(--mission-purple); }
.mission-tile.mapas { --tile: var(--mission-green); }
.mission-tile.estudos { --tile: var(--mission-gold); }
.mission-tile.favs { --tile: var(--mission-red); }
.mission-tile.ranking { --tile: var(--mission-purple); }
.mission-stats { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 12px; padding: 24px 0; border-bottom: 1px solid var(--bd); margin-bottom: 12px; }
.mission-stats .stat { text-align: left; border-right: 1px solid var(--bd); }
.mission-stats .stat:last-child { border: 0; }
.stat b,.fc-stats b { background: none; color: var(--fg); }
#nav { grid-template-columns: repeat(4,minmax(0,1fr)); border-color: var(--bd); }
#nav svg { width: 23px; height: 23px; display: block; margin: 0 auto 5px; }
#nav .nav-brand,#nav .nav-footer { display: none; }
#nav button { font-size: 11px; }
.mission-setup { margin: 0; padding: 12px 0; }
.mission-setup h2 { font-size: 19px; }
.fl-frente { background: var(--mission-heading); }
.fl-verso { background: linear-gradient(120deg,var(--mission-green),var(--mission-blue)); }
#mc-auth .bx { border-radius: 8px !important; }
#mc-auth h1 { color: var(--fg) !important; background: none !important; }
@media (min-width:768px) {
  header { grid-template-columns: minmax(0,1fr) auto; }
  .brand h1 { font-size: 22px; }
  .mission-shortcuts { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .mission-tile { min-height: 164px; padding: 24px; }
  .mission-welcome h2 { font-size: 30px; }
  .mission-mark { width: 90px; height: 90px; }
}
@media (min-width:1100px) {
  body[data-study] { padding-left: 238px; padding-bottom: 0; }
  #app { max-width: 1280px; padding: 28px 40px; }
  #nav { top: 0; bottom: 0; right: auto; width: 238px; display: flex; flex-direction: column; gap: 6px; padding: 30px 18px; border-top: 0; border-right: 1px solid var(--bd); overflow-y: auto; }
  #nav button { flex: 0 0 auto; display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 12px; font-size: 14px; text-align: left; }
  #nav svg { margin: 0; width: 22px; height: 22px; flex-shrink: 0; }
  #nav .nav-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 38px; font-weight: 900; font-size: 16px; line-height: 1.2; }
  .nav-brand img { width: 40px; height: 40px; border-radius: 6px; }
  .nav-brand em { display: block; color: var(--ac); font-style: normal; }
  #nav .nav-footer { display: block; margin-top: auto; padding: 24px 12px 0; color: var(--mu); font-size: 12px; }
  .view-content.mission-home { display: block; }
}
@media (max-width:400px) {
  #app { padding: 14px; }
  .mission-welcome { gap: 10px; }
  .mission-welcome h2 { font-size: 23px; }
  .mission-mark { width: 50px; height: 50px; }
  .mission-tile { padding: 15px; }
  .mission-tile strong { font-size: 15px; }
  .question-timing-summary { gap: 8px; }
  .question-timing-summary b { font-size: 18px; }
}

/* Compact lateral rail on phones; the full sidebar remains on notebooks. */
@media (max-width:1099px) {
  body[data-study] { padding-left: 80px; padding-bottom: env(safe-area-inset-bottom,0px); }
  #nav { top: 0; bottom: 0; left: 0; right: auto; width: 80px; display: flex; flex-direction: column; gap: 6px; padding: calc(16px + env(safe-area-inset-top,0px)) 6px calc(16px + env(safe-area-inset-bottom,0px)); border-top: 0; border-right: 1px solid var(--bd); overflow-y: auto; }
  #nav button { flex: 0 0 auto; min-height: 64px; width: 100%; padding: 9px 2px; font-size: 11px; overflow-wrap: anywhere; }
  #nav svg { width: 23px; height: 23px; margin: 0 auto 6px; }
  #nav .nav-brand { display: flex; justify-content: center; margin-bottom: 16px; }
  #nav .nav-brand img { width: 40px; height: 40px; border-radius: 6px; }
  #nav .nav-brand > div { display: none; }
  header { grid-template-columns: minmax(0,1fr); }
  .mission-welcome { grid-template-columns: minmax(0,1fr); }
  .mission-mark { display: none; }
  .mission-shortcuts { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .mission-tile { padding: 16px; }
  .mission-tile strong { overflow-wrap: anywhere; }
}
@media (max-width:440px) {
  .mission-shortcuts { grid-template-columns: minmax(0,1fr); }
  .mission-tile { min-height: 125px; }
  .brand { gap: 8px; }
  .brand img { width: 36px; height: 36px; }
  .brand h1 { font-size: 18px; }
  .mission-stats { gap: 8px; }
  .mission-stats .mu { font-size: 11px; }
  .question-timing-summary { grid-template-columns: minmax(0,1fr); }
}
