:root {
  --primary: #1d6fb8;
  --primary-dark: #155689;
  --accent: #e63946;
  --bg: #f7f9fc;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #5b6b7b;
  --border: #dde4ec;
  --success: #2a9d8f;
  --solution-bg: #eef6ff;
  --solution-border: #b6d4f0;
  --print-action: #6a4c93;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.62;
}

header {
  padding: 3rem 1.5rem 2.5rem;
  background: linear-gradient(135deg, #3a5a7a 0%, #243f5a 100%);
  color: #fff;
  text-align: center;
}

header .logo {
  display: block;
  width: 75%;
  max-width: 400px;
  height: auto;
  margin: 0 auto 1.4rem;
}

header h1 {
  margin: 0 0 .6rem;
  font-size: 2.1rem;
  font-weight: 700;
  letter-spacing: -.01em;
}

header p {
  margin: 0;
  font-size: 1rem;
  opacity: .95;
}

header .site {
  margin-top: .9rem;
  font-size: .88rem;
  opacity: .85;
}

header a {
  color: inherit;
}

main {
  width: min(100%, 968px);
  margin: 0 auto;
  padding: 1.5rem;
}

.source-assurance {
  margin: 0 0 1.25rem;
  padding: .8rem 1rem;
  border: 1px solid var(--solution-border);
  border-left: 4px solid var(--primary);
  border-radius: 7px;
  background: #f3f8ff;
  font-size: .95rem;
}

.toc {
  margin: 0 0 1.25rem;
  padding: 1rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}

.toc h2 {
  margin: 0 0 .45rem;
  color: var(--primary-dark);
  font-size: 1.08rem;
}

.toc ol {
  margin: 0;
  padding-left: 1.35rem;
}

.toc li + li {
  margin-top: .2rem;
}

.toc a {
  color: var(--primary-dark);
  text-decoration: none;
}

.toc a:hover {
  text-decoration: underline;
}

.controlos {
  margin: 1rem 0 2rem;
  text-align: center;
}

.controlos button {
  margin: .2rem .25rem;
  padding: .5rem 1rem;
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: #fff;
  color: var(--primary);
  cursor: pointer;
  font-weight: 600;
}

.controlos button:hover {
  background: var(--primary);
  color: #fff;
}

.controlos button.imprimir {
  border-color: var(--print-action);
  color: var(--print-action);
}

.controlos button.imprimir:hover {
  border-color: var(--print-action);
  background: var(--print-action);
  color: #fff;
}

section.tema {
  margin-bottom: 1.5rem;
  padding: 1.5rem 1.5rem .8rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .04);
}

section.tema h2 {
  margin: 0;
  padding-bottom: .45rem;
  border-bottom: 3px solid var(--primary);
  color: var(--primary-dark);
  font-size: 1.35rem;
}

.exercicio {
  padding: 1.1rem 0 .3rem;
}

.ex-cabecalho {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
}

.ex-num {
  display: flex;
  flex: 0 0 2rem;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: .9rem;
  font-weight: 700;
}

.ex-corpo {
  flex: 1 1 auto;
  min-width: 0;
}

.exam-tag,
.tipo-tag {
  display: inline-block;
  margin: 0 .35rem .7rem 0;
  padding: .2rem .6rem;
  border-radius: 4px;
  font-size: .77rem;
  font-weight: 600;
  letter-spacing: .25px;
}

.exam-tag {
  border: 1px solid var(--solution-border);
  background: #eef6ff;
  color: var(--primary-dark);
}

.tipo-tag {
  border: 1px solid #f0cdb4;
  background: #fff4ec;
  color: #a9491b;
}

.enunciado p {
  margin: .42rem 0;
  text-align: justify;
  text-justify: inter-word;
}

.enunciado ul {
  margin: .45rem 0;
  padding-left: 1.35rem;
}

.enunciado li + li {
  margin-top: .2rem;
}

.quoted-statement {
  margin: .65rem 1rem;
  font-style: normal;
}

.formula-original {
  margin: .65rem 0;
  text-align: center;
  overflow-x: auto;
}

.exam-figure {
  margin: 1rem auto;
  text-align: center;
}

.exam-figure img {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}

.exam-figure figcaption {
  margin-top: .35rem;
  font-size: .88rem;
}

.subquestion {
  margin-top: .9rem !important;
}

.table-scroll {
  width: 100%;
  margin: .8rem 0;
  overflow-x: auto;
}

.table-title {
  margin: .8rem 0 .25rem !important;
  text-align: center !important;
}

table.exam-table,
table.solution-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  font-size: .91rem;
}

table.exam-table th,
table.exam-table td,
table.solution-table th,
table.solution-table td {
  padding: .38rem .48rem;
  border: 1px solid #66717d;
  text-align: center;
  vertical-align: middle;
}

table.exam-table th,
table.solution-table th {
  background: #eef1f4;
  font-weight: 700;
}

table.exam-table .left,
table.solution-table .left {
  text-align: left;
}

.choices {
  display: grid;
  grid-template-columns: repeat(4, minmax(90px, 1fr));
  gap: .45rem;
  margin: .75rem 0;
  font-weight: 600;
}

.choices span {
  white-space: nowrap;
}

button.toggle {
  margin-top: .8rem;
  padding: .48rem .95rem;
  border: 0;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-size: .88rem;
  font-weight: 600;
  transition: background .2s;
}

button.toggle:hover {
  background: var(--primary-dark);
}

button.toggle::before {
  content: "▶ ";
}

button.toggle.aberto::before {
  content: "▼ ";
}

.resolucao {
  display: none;
  margin-top: .7rem;
  padding: .95rem 1.1rem;
  border: 1px solid var(--solution-border);
  border-radius: 8px;
  background: var(--solution-bg);
  font-size: .96rem;
}

.resolucao.aberta {
  display: block;
}

.resolucao p {
  margin: .35rem 0;
  text-align: justify;
  text-justify: inter-word;
}

.resolucao ul,
.resolucao ol {
  margin: .45rem 0;
  padding-left: 1.35rem;
}

.intro {
  margin: .1rem 0 .8rem;
  padding: .65rem .9rem;
  border: 1px solid var(--solution-border);
  border-left: 4px solid var(--primary);
  border-radius: 6px;
  background: #f8fbff;
}

.intro strong,
.step-title {
  color: var(--primary-dark);
}

.step-title {
  display: block;
  margin-top: .95rem;
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
}

.step-title:first-child {
  margin-top: 0;
}

.math-block {
  margin: .55rem 0;
  padding: .6rem .8rem;
  border: 1px solid var(--solution-border);
  border-radius: 6px;
  background: #fff;
  text-align: center;
  overflow-x: auto;
}

.conclusao {
  margin-top: .75rem;
  padding: .55rem .8rem;
  border-left: 4px solid var(--success);
  border-radius: 4px;
  background: #fff;
  font-weight: 600;
}

footer {
  margin-top: 2rem;
  padding: 2rem 1rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: .9rem;
  text-align: center;
}

footer p {
  margin: .25rem 0;
}

footer a {
  color: var(--primary);
  text-decoration: none;
}

@media (max-width: 700px) {
  header {
    padding: 2rem 1rem 1.8rem;
  }

  header h1 {
    font-size: 1.45rem;
  }

  main {
    padding: 1rem;
  }

  section.tema {
    padding: 1.1rem 1rem .6rem;
  }

  .ex-cabecalho {
    gap: .55rem;
  }

  .choices {
    grid-template-columns: repeat(2, minmax(90px, 1fr));
  }

  table.exam-table,
  table.solution-table {
    min-width: 610px;
    font-size: .84rem;
  }

  table.compact-mobile {
    min-width: 470px;
  }
}

@media print {
  @page {
    size: A4;
    margin: 12mm;
  }

  * {
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }

  body {
    background: #fff;
    color: #000;
    font-size: 10.5pt;
    line-height: 1.42;
  }

  header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 0 .8rem;
    border-bottom: 2px solid #000;
    background: #fff !important;
    color: #000 !important;
    text-align: left;
  }

  header .logo {
    width: 120px;
    margin: 0;
  }

  header h1 {
    margin: 0 0 .2rem;
    font-size: 16pt;
  }

  header p,
  header .site {
    margin: .1rem 0;
    font-size: 9.5pt;
    opacity: 1;
  }

  main {
    width: auto;
    max-width: none;
    padding: 0;
  }

  .source-assurance,
  .toc,
  .controlos,
  button.toggle,
  footer {
    display: none !important;
  }

  section.tema {
    margin: .6rem 0 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    break-inside: auto;
  }

  section.tema h2 {
    margin: .7rem 0 .4rem;
    border-bottom: 1.5px solid #000;
    color: #000;
    font-size: 12.5pt;
    break-after: avoid;
  }

  .exercicio {
    padding: .35rem 0;
  }

  .exam-tag,
  .tipo-tag {
    border-color: #999;
    background: #f0f0f0 !important;
    color: #000 !important;
  }

  .ex-num {
    width: 1.5rem;
    height: 1.5rem;
    flex-basis: 1.5rem;
    background: #000 !important;
    font-size: .76rem;
  }

  .table-scroll {
    overflow: visible;
  }

  table.exam-table,
  table.solution-table {
    min-width: 0;
    font-size: 8.8pt;
  }

  table.exam-table th,
  table.exam-table td,
  table.solution-table th,
  table.solution-table td {
    padding: .25rem .32rem;
  }

  .resolucao,
  .resolucao.aberta {
    display: none !important;
  }

  p,
  li {
    orphans: 3;
    widows: 3;
  }

  table,
  .choices,
  .formula-original,
  .exam-figure {
    break-inside: avoid;
  }
}
