:root {
  --bg: #f7f4fb;
  --surface: #ffffff;
  --surface-2: #f1ebf8;
  --ink: #231b2d;
  --muted: #70677a;
  --line: #ded5e8;
  --purple: #4b2779;
  --purple-2: #6f3ba8;
  --amber: #a65c00;
  --green: #147a57;
  --red: #b32d4b;
  --blue: #285d9b;
  --shadow: 0 18px 50px rgba(54, 33, 77, .10);
  --radius: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { min-height: 100%; -webkit-text-size-adjust: 100%; }
body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 8% 0%, rgba(111, 59, 168, .13), transparent 28rem),
    radial-gradient(circle at 96% 26%, rgba(255, 177, 43, .13), transparent 26rem),
    var(--bg);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: default; }

.caderno-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 24px;
  align-items: center;
  min-height: 72px;
  padding: 10px clamp(16px, 4vw, 44px);
  border-bottom: 1px solid rgba(222, 213, 232, .9);
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 5px 18px rgba(54, 33, 77, .06);
  backdrop-filter: blur(18px);
}
.caderno-back {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--purple);
  background: #fff;
  font-size: .8rem;
  font-weight: 850;
  text-decoration: none;
}
.caderno-back:hover { border-color: var(--purple-2); background: var(--surface-2); }
.back-label-short { display: none; }
.caderno-context { min-width: 0; text-align: center; }
.caderno-context span,
.caderno-context strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.caderno-context span { color: var(--muted); font-size: .7rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.caderno-context strong { margin-top: 3px; font-size: .92rem; }

.app-header {
  position: sticky;
  top: 72px;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 13px clamp(12px, 3vw, 30px);
  border-bottom: 1px solid rgba(222, 213, 232, .9);
  background: rgba(247, 244, 251, .91);
  backdrop-filter: blur(18px);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 13px;
  color: #fff;
  background: linear-gradient(145deg, var(--purple), var(--purple-2));
  box-shadow: 0 8px 20px rgba(75, 39, 121, .25);
  font-size: 1.35rem;
  font-weight: 900;
}

h1 { margin: 0; font-size: clamp(1.05rem, 2.4vw, 1.48rem); line-height: 1.08; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: .82rem; }
.primary {
  border-color: var(--purple) !important;
  color: #fff !important;
  background: var(--purple) !important;
}
.stats { display: grid; grid-template-columns: repeat(4, minmax(64px, 1fr)); gap: 7px; }
.stats div {
  min-height: 48px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255, 255, 255, .8);
}
.stats strong { display: block; font-size: 1.05rem; line-height: 1; }
.stats span { display: block; margin-top: 4px; color: var(--muted); font-size: .65rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }

.app-layout {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  gap: 18px;
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 18px clamp(10px, 2.8vw, 30px) 38px;
}

.filters, .question-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .9);
  box-shadow: var(--shadow);
}

.filters {
  position: sticky;
  top: 159px;
  align-self: start;
  max-height: calc(100vh - 178px);
  padding: 14px;
  overflow: auto;
}

.filters > label, .answer-label {
  display: block;
  margin: 14px 0 6px;
  color: #52465f;
  font-size: .71rem;
  font-weight: 850;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.filters input, .filters select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
}
.filters input, .filters select { min-height: 43px; padding: 0 11px; }
textarea { min-height: 160px; padding: 13px; resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(111, 59, 168, .16); border-color: var(--purple-2); }

.drawer-button {
  display: grid;
  grid-template-columns: 1fr 28px;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 50px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--ink);
  background: var(--surface-2);
  text-align: left;
}
.drawer-button strong, .drawer-button small { display: block; }
.drawer-button small { margin-top: 2px; color: var(--muted); }
.drawer-button > span:last-child { font-size: 1.25rem; text-align: center; transition: transform .18s ease; }
.drawer-button[aria-expanded="true"] > span:last-child { transform: rotate(180deg); }

.question-list { display: grid; gap: 6px; max-height: 320px; margin-top: 8px; overflow: auto; }
.question-list.collapsed { display: none; }
.list-item {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) 10px;
  gap: 8px;
  align-items: center;
  width: 100%;
  min-height: 38px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--ink);
  background: #fff;
  text-align: left;
}
.list-item > span { color: var(--purple); font-weight: 900; }
.list-item > strong { overflow: hidden; font-size: .8rem; text-overflow: ellipsis; white-space: nowrap; }
.list-item > i { width: 9px; height: 9px; border-radius: 50%; background: #d5cddd; }
.list-item > i.done { background: var(--green); }
.list-item > i.wrong { background: var(--red); }
.list-item > i.flagged { background: #f3a928; }
.list-item.active { border-color: var(--purple); background: #f3ecfa; }

.progress-row { display: grid; grid-template-columns: 70px 1fr; gap: 12px; align-items: center; margin-top: 16px; }
.progress-ring {
  position: relative;
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: conic-gradient(var(--purple) calc(var(--progress) * 1%), #e7dfed 0);
}
.progress-ring::after { content: ""; position: absolute; inset: 7px; border-radius: inherit; background: #fff; }
.progress-ring strong { position: relative; z-index: 1; }
.progress-row p { margin: 0; line-height: 1.35; }
.progress-row p span { color: var(--muted); font-size: .75rem; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 14px; }
.actions button, .check, .try-again, .reveal, .self-grade button {
  min-height: 41px;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: #fff;
  font-weight: 800;
}
.actions button:last-child { grid-column: 1 / -1; color: var(--red); }

.legend { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.legend summary { color: var(--purple); cursor: pointer; font-size: .78rem; font-weight: 850; }
.legend p { margin: 10px 0 0; color: var(--muted); font-size: .75rem; line-height: 1.35; }
.dot { display: inline-block; width: 9px; height: 9px; margin-right: 6px; border-radius: 50%; }
.dot.verified { background: var(--green); }
.dot.ambiguous { background: var(--amber); }
.dot.model { background: var(--blue); }

.study { min-width: 0; }
.question-nav { display: grid; grid-template-columns: 48px minmax(0, 1fr) 48px; gap: 9px; align-items: stretch; margin-bottom: 11px; }
.question-nav button, .question-nav div {
  min-height: 49px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255,255,255,.82);
}
.question-nav button { color: var(--purple); font-size: 1.7rem; font-weight: 900; }
.question-nav button:disabled { opacity: .45; }
.question-nav div { min-width: 0; padding: 8px 12px; }
.question-nav span { display: block; color: var(--muted); font-size: .74rem; }
.question-nav strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.question-card { min-height: 570px; padding: clamp(17px, 3.2vw, 32px); }
.card-top { display: flex; gap: 14px; align-items: flex-start; justify-content: space-between; }
.badges { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; }
.badges span {
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #51455c;
  background: var(--surface-2);
  font-size: .74rem;
  font-weight: 800;
}
.badges .status.verified { border-color: rgba(20,122,87,.25); color: #0e6748; background: #ebf8f3; }
.badges .status.ambiguous { border-color: rgba(166,92,0,.28); color: #8a4d00; background: #fff5e7; }
.badges .status.model { border-color: rgba(40,93,155,.28); color: #245487; background: #edf5ff; }
.stem { max-width: 1050px; margin: 0 0 22px; font-size: clamp(1.08rem, 2.15vw, 1.34rem); font-weight: 780; line-height: 1.48; white-space: pre-line; }
.flag {
  flex: 0 0 auto;
  width: 44px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: #bc7a13;
  background: #fff;
  font-size: 1.18rem;
}
.flag.active { border-color: #e3a13a; background: #fff5de; }

.answers { display: grid; gap: 9px; }
.answer {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  min-height: 62px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  background: #fff;
  text-align: left;
  line-height: 1.42;
}
.answer:not(:disabled):hover { border-color: #9f8fb1; transform: translateY(-1px); }
.answer.selected { border-color: var(--blue); background: #edf5ff; box-shadow: inset 4px 0 0 var(--blue); }
.answer.correct { border: 2px solid var(--green); background: #eefaf5; box-shadow: inset 4px 0 0 var(--green); }
.answer.wrong { border: 2px solid var(--red); background: #fff0f3; box-shadow: inset 4px 0 0 var(--red); }
.answer.possible { border: 2px solid var(--amber); background: #fff7e9; box-shadow: inset 4px 0 0 var(--amber); }
.answer.muted { opacity: .55; }
.letter { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; color: #fff; background: var(--purple); font-weight: 900; }
.answer.correct .letter { background: var(--green); }
.answer.wrong .letter { background: var(--red); }
.answer.possible .letter { background: var(--amber); }
.answer em { min-width: max-content; color: var(--muted); font-size: .71rem; font-style: normal; font-weight: 900; letter-spacing: .04em; text-transform: uppercase; }

.association-key {
  display: grid;
  gap: 6px;
  margin: -4px 0 17px;
  padding: 13px 15px;
  border-left: 4px solid var(--purple);
  border-radius: 0 11px 11px 0;
  background: var(--surface-2);
  font-weight: 800;
}
.grid-question { display: grid; gap: 10px; }
.grid-row {
  display: grid;
  grid-template-columns: auto minmax(190px, 1fr) minmax(150px, auto);
  gap: 11px;
  align-items: center;
  min-height: 70px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}
.grid-row.row-correct { border-color: rgba(20,122,87,.5); background: #f1faf6; }
.grid-row.row-wrong { border-color: rgba(179,45,75,.45); background: #fff4f6; }
.grid-row > strong { line-height: 1.38; }
.blank {
  display: inline-flex;
  min-width: 52px;
  justify-content: center;
  color: var(--purple);
  font-weight: 900;
  white-space: nowrap;
}
.grid-choices { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.grid-choice {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 39px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--ink);
  background: #fff;
  font-weight: 850;
}
.grid-choice:not(:disabled):hover { border-color: var(--purple-2); }
.grid-choice.selected { border: 2px solid var(--blue); color: var(--blue); background: #edf5ff; }
.grid-choice.correct { border: 2px solid var(--green); color: var(--green); background: #eaf8f2; }
.grid-choice.wrong { border: 2px solid var(--red); color: var(--red); background: #fff0f3; }
.grid-choice.muted { opacity: .45; }
.grid-choice em { font-size: .65rem; font-style: normal; text-transform: uppercase; }

.check, .try-again, .reveal { margin-top: 14px; }
.check:disabled { opacity: .48; }
.try-again { color: var(--purple); }
.feedback, .model-answer {
  margin-top: 17px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  line-height: 1.55;
}
.feedback.correct { border-color: rgba(20,122,87,.35); background: #effaf6; }
.feedback.wrong { border-color: rgba(179,45,75,.3); background: #fff2f5; }
.feedback.neutral { border-color: rgba(166,92,0,.35); background: #fff7ea; }
.feedback p, .model-answer p { margin: 7px 0 0; }
.callout { padding-top: 9px; border-top: 1px solid rgba(166,92,0,.2); font-size: .86rem; }

.model-answer { border-color: rgba(40,93,155,.3); background: #f3f8ff; }
.checklist { display: grid; gap: 7px; margin-top: 16px; padding-top: 13px; border-top: 1px solid #cfdeef; }
.checklist > strong { margin-bottom: 2px; }
.checklist label { display: flex; gap: 8px; align-items: flex-start; }
.checklist input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--blue); }
.self-grade { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 16px; }
.self-grade > span { margin-right: 3px; font-weight: 800; }
.self-grade button.active { border-color: var(--blue); color: #fff; background: var(--blue); }

.question-card footer { display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: space-between; margin-top: 23px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: .73rem; }
.question-card footer a { color: var(--purple); font-weight: 750; }
.empty { display: grid; min-height: 480px; place-content: center; text-align: center; }
.empty p { color: var(--muted); }
.study-note { margin: 10px 3px 0; color: var(--muted); font-size: .72rem; text-align: center; }

@media (max-width: 1020px) {
  .app-header { grid-template-columns: minmax(0, 1fr) auto; }
  .stats { grid-column: 1 / -1; }
  .stats div { min-height: 42px; }
  .app-layout { grid-template-columns: 276px minmax(0, 1fr); }
  .filters { top: 217px; max-height: calc(100vh - 236px); }
}

@media (max-width: 760px) {
  .caderno-bar {
    grid-template-areas: "context" "back";
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    min-height: 108px;
    padding-block: 10px;
  }
  .caderno-context { grid-area: context; }
  .caderno-back { grid-area: back; justify-self: start; }
  .app-header { position: relative; grid-template-columns: 1fr auto; gap: 10px; padding-bottom: 10px; }
  .brand p { display: none; }
  .brand-mark { width: 42px; height: 42px; }
  .stats { grid-column: 1 / -1; gap: 5px; }
  .stats div { min-width: 0; min-height: 40px; padding: 6px 7px; }
  .stats strong { font-size: .95rem; }
  .stats span { font-size: .56rem; }
  .app-layout { display: block; padding: 10px 9px 26px; }
  .filters { position: static; max-height: none; margin-bottom: 10px; box-shadow: 0 8px 28px rgba(54,33,77,.08); }
  .filters > label, .filters > input, .filters > select, .progress-row, .actions, .legend { display: none; }
  .filters:has(.drawer-button[aria-expanded="true"]) > label,
  .filters:has(.drawer-button[aria-expanded="true"]) > input,
  .filters:has(.drawer-button[aria-expanded="true"]) > select,
  .filters:has(.drawer-button[aria-expanded="true"]) > .progress-row,
  .filters:has(.drawer-button[aria-expanded="true"]) > .actions,
  .filters:has(.drawer-button[aria-expanded="true"]) > .legend { display: grid; }
  .filters:has(.drawer-button[aria-expanded="true"]) > label { display: block; }
  .question-list { max-height: 260px; }
  .question-nav { grid-template-columns: 44px minmax(0,1fr) 44px; }
  .question-card { min-height: 500px; padding: 16px 13px; }
  .card-top { gap: 8px; }
  .stem { font-size: 1.04rem; }
  .answer { grid-template-columns: 34px minmax(0,1fr); gap: 9px; min-height: 58px; padding: 10px; }
  .answer em { grid-column: 2; justify-self: start; }
  .letter { width: 31px; height: 31px; }
  .grid-row { grid-template-columns: auto minmax(0, 1fr); gap: 8px; align-items: start; }
  .grid-row > strong { padding-top: 2px; }
  .grid-choices { grid-column: 1 / -1; justify-content: flex-start; }
  .grid-choice { flex: 1 1 auto; }
  .feedback, .model-answer { padding: 13px; }
  .question-card footer { display: grid; }
}

@media (max-width: 380px) {
  .back-label-full { display: none; }
  .back-label-short { display: inline; }
  h1 { font-size: .98rem; }
  .brand { gap: 8px; }
  .brand-mark { width: 38px; height: 38px; border-radius: 10px; }
  .stats span { letter-spacing: .03em; }
  .question-nav div { padding-inline: 8px; }
  .question-nav strong { font-size: .82rem; }
  .badges span { font-size: .68rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
