:root {
  --paper: #f4f6f3;
  --surface: #ffffff;
  --ink: #1b2b2e;
  --muted: #5e6b6d;
  --line: #d6ddd9;
  --teal: #0b6a6f;
  --teal-soft: #e3efee;
  --amber: #b87d00;
  --amber-soft: #fbf1db;
  --ok: #2e7d4f;
  --ok-soft: #e4f2e9;
  --bad: #b3261e;
  --bad-soft: #fbe7e5;
  --read: "Iowan Old Style", "Source Serif Pro", "Charter", Georgia, serif;
  --ui: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121a1b; --surface: #1a2426; --ink: #e5ecea; --muted: #9aa8a8; --line: #2c3a3c;
    --teal: #5fb8bb; --teal-soft: #1d3334; --amber: #e0b24a; --amber-soft: #33291a;
    --ok: #6fc193; --ok-soft: #1d3326; --bad: #f08a80; --bad-soft: #3a2220;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--paper); color: var(--ink); font: 16px/1.5 var(--ui); -webkit-text-size-adjust: 100%; }
a { color: var(--teal); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

.btn { border: 1px solid var(--line); background: var(--surface); padding: .55rem .9rem; border-radius: 8px; cursor: pointer; }
.btn:hover { border-color: var(--teal); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.small { padding: .3rem .6rem; font-size: .9rem; }
.btn[disabled] { opacity: .5; cursor: default; }

/* ---------- Login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 1.5rem; }
.login form { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.75rem; }
.login h1 { font: 600 1.4rem/1.2 var(--read); margin: 0 0 .25rem; }
.login p { color: var(--muted); margin: 0 0 1.25rem; font-size: .95rem; }
.login label { display: block; font-size: .9rem; margin: .8rem 0 .3rem; }
.login input { width: 100%; padding: .65rem .75rem; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); }
.login input[name=code] { letter-spacing: .3em; font-family: var(--mono); }
.login .btn { width: 100%; margin-top: 1.25rem; }
.login .error { color: var(--bad); font-size: .9rem; min-height: 1.3em; margin-top: .75rem; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100%; }
.nav { border-right: 1px solid var(--line); padding: 1.25rem .75rem; display: flex; flex-direction: column; gap: .15rem; position: sticky; top: 0; height: 100vh; }
.nav .brand { font: 600 1.05rem/1.25 var(--read); padding: 0 .6rem .9rem; }
.nav .brand small { display: block; font: 400 .8rem var(--ui); color: var(--muted); }
.nav a { text-decoration: none; color: var(--ink); padding: .5rem .6rem; border-radius: 8px; }
.nav a:hover { background: var(--teal-soft); }
.nav a.active { background: var(--teal); color: #fff; }
.nav .spacer { flex: 1; }
.nav .logout { font-size: .9rem; color: var(--muted); background: none; border: 0; text-align: left; padding: .5rem .6rem; cursor: pointer; }
main { padding: 2rem clamp(1rem, 4vw, 3rem) 5rem; max-width: 980px; width: 100%; }
h2.view { font: 600 1.6rem/1.2 var(--read); margin: 0 0 1.25rem; }
.muted { color: var(--muted); }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .nav { position: fixed; bottom: 0; left: 0; right: 0; top: auto; height: auto; flex-direction: row; justify-content: space-around; border-right: 0; border-top: 1px solid var(--line); background: var(--surface); padding: .35rem .25rem calc(.35rem + env(safe-area-inset-bottom)); z-index: 10; }
  .nav .brand, .nav .spacer, .nav .logout { display: none; }
  .nav a { font-size: .85rem; padding: .45rem .5rem; }
  main { padding: 1.25rem 1rem 6rem; }
}

/* ---------- Hoje ---------- */
.countdown { display: flex; align-items: baseline; gap: .75rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.countdown strong { font: 600 3rem/1 var(--read); color: var(--amber); }
.countdown span { color: var(--muted); }
.timeline { position: relative; margin: 1.5rem 0 2.25rem; padding: 2.4rem 0 2.6rem; }
.timeline .track { height: 4px; background: var(--line); border-radius: 2px; position: relative; }
.timeline .done { position: absolute; left: 0; top: 0; bottom: 0; background: var(--teal); border-radius: 2px; }
.timeline .ev { position: absolute; top: 50%; transform: translate(-50%, -50%); }
.timeline .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 3px solid var(--teal); margin: auto; }
.timeline .ev.past .dot { background: var(--teal); }
.timeline .ev.exam .dot { width: 18px; height: 18px; border-color: var(--amber); background: var(--amber); }
.timeline .ev.seb .dot { border-color: var(--amber); }
.timeline .lbl { position: absolute; left: 50%; transform: translateX(-50%); white-space: nowrap; font-size: .75rem; color: var(--muted); text-align: center; line-height: 1.2; }
.timeline .ev:nth-child(odd) .lbl { bottom: 18px; }
.timeline .ev:nth-child(even) .lbl { top: 18px; }
.timeline .ev.exam .lbl, .timeline .ev.seb .lbl { color: var(--amber); font-weight: 600; }
.timeline .ev.near-today .lbl { visibility: hidden; }
.timeline .today { position: absolute; top: -10px; bottom: -10px; width: 2px; background: var(--ink); }
.timeline .today span { position: absolute; top: -1.2rem; left: 50%; transform: translateX(-50%); font-size: .75rem; font-weight: 600; }
@media (max-width: 760px) { .timeline .lbl { font-size: .65rem; } .timeline .ev:not(.exam):not(.seb):not(.next) .lbl { display: none; } }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; }
.panel h3 { margin: 0 0 .6rem; font-size: 1rem; }
.stat { font: 600 2rem/1.1 var(--read); }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; margin: .35rem 0; }
.bar i { display: block; height: 100%; background: var(--teal); }
.weak li { margin: .35rem 0; }

/* ---------- Matéria ---------- */
.search { width: 100%; padding: .7rem .9rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); margin-bottom: 1.25rem; }
.block { margin-bottom: 1.5rem; }
.block h3 { font-size: .95rem; color: var(--muted); font-weight: 600; margin: 0 0 .5rem; }
.topics { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.topics li + li { border-top: 1px solid var(--line); }
.topics a { display: flex; gap: .75rem; align-items: center; padding: .7rem 1rem; text-decoration: none; color: var(--ink); }
.topics a:hover { background: var(--teal-soft); }
.topics .st { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--line); flex: none; }
.topics .st.a_estudar { border-color: var(--amber); background: var(--amber-soft); }
.topics .st.dominado { border-color: var(--ok); background: var(--ok); }
.topics .len { margin-left: auto; font-size: .8rem; color: var(--muted); }
.hits a { display: block; padding: .6rem 0; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.hits small { color: var(--muted); display: block; }

.topic-head { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.topic-head .status { display: flex; gap: .35rem; margin-left: auto; }
.status .btn.on { background: var(--teal); color: #fff; border-color: var(--teal); }
.prose { font: 1.05rem/1.65 var(--read); max-width: 72ch; }
.prose h1, .prose h2, .prose h3, .prose h4 { font-family: var(--ui); line-height: 1.25; margin: 2rem 0 .6rem; }
.prose h3 { font-size: 1.2rem; } .prose h4 { font-size: 1.02rem; }
.prose table { border-collapse: collapse; font: .92rem/1.45 var(--ui); display: block; overflow-x: auto; margin: 1rem 0; }
.prose th, .prose td { border: 1px solid var(--line); padding: .45rem .6rem; vertical-align: top; text-align: left; }
.prose th { background: var(--teal-soft); }
.prose pre { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .75rem 1rem; overflow-x: auto; font: .9rem/1.5 var(--mono); }
.prose code { font-family: var(--mono); font-size: .9em; }
.ask-row { display: flex; gap: .5rem; flex-wrap: wrap; margin: 1.5rem 0; }

/* ---------- Treino ---------- */
.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1.25rem; align-items: center; }
.filters select { padding: .5rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.q { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; }
.q .de { font: 600 1.1rem/1.45 var(--read); margin: 0 0 .35rem; }
.q .pt { color: var(--muted); margin: 0 0 1rem; font-size: .95rem; }
.q .meta { font-size: .8rem; color: var(--muted); margin-bottom: .75rem; }
.opt { display: flex; gap: .6rem; align-items: flex-start; padding: .65rem .8rem; border: 1px solid var(--line); border-radius: 8px; margin: .45rem 0; cursor: pointer; }
.opt:hover { border-color: var(--teal); }
.opt input { margin-top: .3rem; }
.opt small { display: block; color: var(--muted); }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.q textarea { width: 100%; min-height: 110px; padding: .7rem; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); }
.feedback { margin-top: 1rem; padding: .9rem 1rem; border-radius: 8px; }
.feedback.ok { background: var(--ok-soft); } .feedback.bad { background: var(--bad-soft); } .feedback.neutral { background: var(--teal-soft); }
.q-actions { display: flex; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
.score { font-size: .9rem; color: var(--muted); margin-left: auto; }

/* ---------- Tutor ---------- */
.chat { display: flex; flex-direction: column; gap: .8rem; margin-bottom: 1rem; }
.msg { max-width: 85%; padding: .75rem 1rem; border-radius: 12px; }
.msg.user { align-self: flex-end; background: var(--teal); color: #fff; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); }
.msg.assistant p:first-child { margin-top: 0; } .msg.assistant p:last-child { margin-bottom: 0; }
.msg.assistant table { border-collapse: collapse; font-size: .9rem; display: block; overflow-x: auto; }
.msg.assistant td, .msg.assistant th { border: 1px solid var(--line); padding: .3rem .5rem; }
.msg.thinking { color: var(--muted); font-style: italic; }
.composer { display: flex; gap: .5rem; position: sticky; bottom: 0; background: var(--paper); padding: .5rem 0; }
.composer textarea { flex: 1; min-height: 3rem; max-height: 10rem; padding: .7rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); resize: vertical; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .75rem; }
.chips button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: .35rem .8rem; font-size: .88rem; cursor: pointer; }
.chips button:hover { border-color: var(--teal); }
.notice { background: var(--amber-soft); border-radius: 8px; padding: .8rem 1rem; }
@media (max-width: 760px) { .composer { bottom: 3.6rem; } .msg { max-width: 95%; } }

/* ---------- Calculadora ---------- */
.calc table.in { border-collapse: collapse; margin: 1rem 0; }
.calc .in th, .calc .in td { border: 1px solid var(--line); padding: .5rem .7rem; text-align: center; }
.calc .in th { background: var(--teal-soft); font-weight: 600; font-size: .9rem; }
.calc input { width: 5.5rem; padding: .45rem; border: 1px solid var(--line); border-radius: 6px; text-align: center; background: var(--surface); }
.results { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .75rem; }
.results .panel b { font: 600 1.4rem var(--read); display: block; }
.results .panel small { color: var(--muted); }
