/* ===========================================================
   Provas de Concurso — styles
   No framework, no build. Mobile first; scales to 4K.
   =========================================================== */

:root {
  --ink:            #14181f;
  --ink-soft:       #4a5462;
  --ink-faint:      #78828f;
  --paper:          #ffffff;
  --canvas:         #f4f5f7;
  --line:           #e0e3e8;
  --line-strong:    #c8cdd6;

  --accent:         #1f5f8b;
  --accent-soft:    #e8f1f7;
  --accent-ink:     #16455f;

  --good:           #1c7a4a;
  --good-soft:      #e5f4ec;
  --bad:            #b3261e;
  --bad-soft:       #fbeae9;
  --void:           #7a5a12;
  --void-soft:      #fbf1da;

  --radius:         14px;
  --radius-sm:      9px;
  --shadow:         0 1px 2px rgba(20,24,31,.06), 0 8px 24px -12px rgba(20,24,31,.18);

  --gap:            clamp(1rem, 2.5vw, 1.75rem);
  --wrap:           min(1180px, 100% - 2rem);

  /* Long legal prose: fluid but never wider than comfortable. */
  --body-size:      clamp(1rem, 0.94rem + 0.28vw, 1.2rem);
  --measure:        68ch;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink:          #e8ecf1;
    --ink-soft:     #aeb7c2;
    --ink-faint:    #8b95a2;
    --paper:        #171b22;
    --canvas:       #0f1218;
    --line:         #2a313b;
    --line-strong:  #3b444f;

    --accent:       #6fb3dc;
    --accent-soft:  #17303f;
    --accent-ink:   #a8d3ee;

    --good:         #62c48d;
    --good-soft:    #12301f;
    --bad:          #f0857c;
    --bad-soft:     #331715;
    --void:         #d9b463;
    --void-soft:    #2e2611;

    --shadow:       0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.7);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: var(--body-size);
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.wrap { width: var(--wrap); margin-inline: auto; }

main.wrap { flex: 1; padding-block: var(--gap) calc(var(--gap) * 2); }

.skip-link {
  position: absolute; left: -9999px;
  background: var(--accent); color: #fff;
  padding: .6rem 1rem; border-radius: 0 0 var(--radius-sm) 0; z-index: 100;
}
.skip-link:focus { left: 0; top: 0; }

/* ── header ─────────────────────────────────────────────── */

.app-header {
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
  padding-top: env(safe-area-inset-top);
}

.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; min-height: 60px;
}

.brand {
  display: flex; align-items: center; gap: .7rem;
  background: none; border: 0; padding: .4rem 0; cursor: pointer;
  color: inherit; text-align: left; font: inherit;
  border-radius: var(--radius-sm);
}
.brand-mark {
  font-size: 1.5rem; line-height: 1;
  color: var(--accent);
}
.brand-text { display: flex; flex-direction: column; }
.brand-name { font-weight: 650; letter-spacing: -.01em; font-size: .98rem; }
.brand-sub  { font-size: .8rem; color: var(--ink-faint); }
.brand-sub:empty { display: none; }

.lang-toggle {
  display: inline-flex; border: 1px solid var(--line-strong);
  border-radius: 999px; overflow: hidden; background: var(--canvas);
}
.lang-btn {
  font: inherit; font-size: .78rem; font-weight: 600; letter-spacing: .04em;
  padding: .38rem .8rem; border: 0; background: none; cursor: pointer;
  color: var(--ink-soft); min-height: 34px;
}
.lang-btn[aria-pressed="true"] { background: var(--accent); color: #fff; }

/* ── views ──────────────────────────────────────────────── */

.view[hidden] { display: none; }

/* The picker screens hold little content — keep them a readable column
   and centred, so they don't strand at the left edge of a wide display. */
#view-types, #view-exams { max-width: 62rem; margin-inline: auto; }

.view-title {
  font-size: clamp(1.4rem, 1.1rem + 1.4vw, 2.1rem);
  line-height: 1.2; letter-spacing: -.02em;
  margin: .5rem 0 .35rem;
}
.view-lede { color: var(--ink-soft); margin: 0 0 var(--gap); max-width: var(--measure); }

.back-link {
  display: inline-flex; align-items: center; gap: .4rem;
  background: none; border: 0; padding: .5rem 0; cursor: pointer;
  color: var(--accent); font: inherit; font-size: .9rem; font-weight: 550;
  border-radius: var(--radius-sm);
}
.back-link:hover { text-decoration: underline; }

/* ── choice cards ───────────────────────────────────────── */

.card-grid {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
}

.choice-card {
  display: flex; flex-direction: column; gap: .5rem;
  text-align: left; font: inherit; color: inherit; cursor: pointer;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.25rem;
  box-shadow: var(--shadow);
  transition: border-color .15s, transform .15s;
}
.choice-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.choice-card:active { transform: none; }

.choice-year {
  font-size: clamp(1.6rem, 1.3rem + 1vw, 2.2rem);
  font-weight: 680; letter-spacing: -.03em; line-height: 1;
  color: var(--accent);
}
.choice-title { font-size: 1.05rem; font-weight: 640; letter-spacing: -.01em; }
.choice-desc  { color: var(--ink-soft); font-size: .9rem; margin: 0; }
.choice-meta  {
  display: flex; flex-wrap: wrap; gap: .4rem .9rem;
  color: var(--ink-faint); font-size: .82rem; margin-top: .25rem;
}

/* ── practice ───────────────────────────────────────────── */

.practice-bar {
  display: flex; align-items: center; gap: 1rem;
  flex-wrap: wrap; margin-bottom: 1rem;
}
.score {
  margin-inline-start: auto; font-size: .88rem; color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.score b { color: var(--ink); font-weight: 650; }

.ghost-btn {
  font: inherit; font-size: .85rem; font-weight: 550;
  padding: .5rem .9rem; min-height: 40px;
  border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--paper); color: var(--ink-soft); cursor: pointer;
}
.ghost-btn:hover { border-color: var(--accent); color: var(--accent); }

.practice-layout { display: grid; gap: var(--gap); align-items: start; }

.question-card {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: clamp(1.1rem, 3vw, 2.2rem);
}

.q-head {
  display: flex; align-items: baseline; gap: .75rem;
  flex-wrap: wrap; margin-bottom: 1rem;
  padding-bottom: .9rem; border-bottom: 1px solid var(--line);
}
.q-id { display: flex; align-items: baseline; gap: .4rem; }
.q-number { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; }
.q-total  { color: var(--ink-faint); font-size: .85rem; }
.q-tags { display: flex; flex-wrap: wrap; gap: .35rem; margin-inline-start: auto; }

.tag {
  font-size: .72rem; font-weight: 600; letter-spacing: .02em;
  padding: .25rem .6rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-ink); white-space: nowrap;
}
.tag.void { background: var(--void-soft); color: var(--void); }

.q-stem {
  max-width: var(--measure);
  margin-bottom: 1.5rem;
  white-space: pre-wrap;
  hyphens: auto;
}

/* options */

.options { display: flex; flex-direction: column; gap: .6rem; max-width: var(--measure); }

.option {
  display: flex; gap: .85rem; align-items: flex-start; width: 100%;
  text-align: left; font: inherit; color: inherit; cursor: pointer;
  background: var(--paper); border: 1.5px solid var(--line);
  border-radius: var(--radius-sm); padding: .85rem 1rem;
  transition: border-color .12s, background .12s;
}
.option:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.option:disabled { cursor: default; }

.option-letter {
  flex: none; width: 1.85em; height: 1.85em;
  display: grid; place-items: center;
  border: 1.5px solid var(--line-strong); border-radius: 50%;
  font-size: .82rem; font-weight: 700; color: var(--ink-soft);
}
.option-text { flex: 1; }

.option.chosen        { border-color: var(--accent); background: var(--accent-soft); }
.option.chosen .option-letter { border-color: var(--accent); background: var(--accent); color: #fff; }

.option.is-correct    { border-color: var(--good); background: var(--good-soft); }
.option.is-correct .option-letter { border-color: var(--good); background: var(--good); color: #fff; }

.option.is-wrong      { border-color: var(--bad); background: var(--bad-soft); }
.option.is-wrong .option-letter { border-color: var(--bad); background: var(--bad); color: #fff; }

.option-mark { flex: none; font-weight: 700; }
.option.is-correct .option-mark { color: var(--good); }
.option.is-wrong   .option-mark { color: var(--bad); }

/* feedback */

.feedback {
  margin-top: 1.25rem; padding: .9rem 1.1rem;
  border-radius: var(--radius-sm); border-inline-start: 4px solid var(--line-strong);
  background: var(--canvas); max-width: var(--measure);
}
.feedback[hidden] { display: none; }
.feedback.good { border-color: var(--good); background: var(--good-soft); }
.feedback.bad  { border-color: var(--bad);  background: var(--bad-soft); }
.feedback.void { border-color: var(--void); background: var(--void-soft); }
.feedback-head { font-weight: 650; margin: 0 0 .2rem; }
.feedback p { margin: 0; font-size: .92rem; color: var(--ink-soft); }

/* commentary */

.commentary {
  margin-top: 1.5rem; padding-top: 1.25rem;
  border-top: 1px solid var(--line); max-width: var(--measure);
}
.commentary[hidden] { display: none; }
.commentary-title { font-size: 1rem; font-weight: 650; margin: 0 0 .15rem; }
.commentary-lede  { margin: 0 0 .8rem; font-size: .85rem; color: var(--ink-faint); }
.commentary-list  { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }

.commentary-link {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  padding: .7rem .9rem; border: 1px solid var(--line);
  border-radius: var(--radius-sm); text-decoration: none; color: inherit;
  background: var(--canvas);
}
.commentary-link:hover { border-color: var(--accent); }
.commentary-name { font-weight: 600; color: var(--accent); }
.commentary-note { font-size: .84rem; color: var(--ink-faint); flex: 1 1 12rem; }
.commentary-count {
  font-size: .76rem; font-weight: 600; padding: .15rem .55rem;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink);
  white-space: nowrap;
}

/* question nav */

.q-nav { display: flex; gap: .75rem; margin-top: 1.75rem; }
.nav-btn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  font: inherit; font-weight: 600; font-size: .92rem;
  padding: .8rem 1rem; min-height: 48px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--paper); color: var(--ink); cursor: pointer;
}
.nav-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.nav-btn:disabled { opacity: .4; cursor: default; }
.nav-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.nav-btn.primary:hover:not(:disabled) { background: var(--accent-ink); color: #fff; }

/* navigator panel */

.nav-panel {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.1rem; display: none;
}
.nav-panel.open { display: block; }
.nav-panel-title { font-size: .95rem; font-weight: 650; margin: 0 0 .6rem; }

.legend { display: flex; flex-wrap: wrap; gap: .4rem .9rem; margin-bottom: .9rem; font-size: .78rem; color: var(--ink-faint); }
.legend-item { display: inline-flex; align-items: center; gap: .35rem; }
.dot { width: .7em; height: .7em; border-radius: 50%; display: inline-block; }
.dot.correct { background: var(--good); }
.dot.wrong   { background: var(--bad); }
.dot.void    { background: var(--void); }

.q-grid {
  display: grid; gap: .35rem;
  grid-template-columns: repeat(auto-fill, minmax(2.6rem, 1fr));
}
.q-cell {
  font: inherit; font-size: .82rem; font-weight: 600;
  aspect-ratio: 1; min-height: 2.4rem;
  display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--paper); color: var(--ink-soft); cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.q-cell:hover { border-color: var(--accent); color: var(--accent); }
.q-cell.current { outline: 2px solid var(--accent); outline-offset: 1px; }
.q-cell.correct { background: var(--good-soft); border-color: var(--good); color: var(--good); }
.q-cell.wrong   { background: var(--bad-soft);  border-color: var(--bad);  color: var(--bad); }
.q-cell.void    { background: var(--void-soft); border-color: var(--void); color: var(--void); }

.shortcuts { margin-top: 1.25rem; font-size: .8rem; color: var(--ink-faint); text-align: center; }

/* ── states ─────────────────────────────────────────────── */

.loading { padding: 3rem 0; text-align: center; color: var(--ink-faint); }
.loading[hidden] { display: none; }

.error-box {
  padding: 1rem 1.2rem; border-radius: var(--radius-sm);
  background: var(--bad-soft); border-inline-start: 4px solid var(--bad);
  color: var(--ink);
}
.error-box[hidden] { display: none; }

.app-footer {
  border-top: 1px solid var(--line);
  padding: 1.25rem 0 calc(1.25rem + env(safe-area-inset-bottom));
  color: var(--ink-faint); font-size: .8rem; background: var(--paper);
}
.app-footer p { margin: 0; }
.app-footer a { color: inherit; }

/* ── focus ──────────────────────────────────────────────── */

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ── breakpoints ────────────────────────────────────────── */

/* tablet and up: navigator sits beside the question */
@media (min-width: 900px) {
  .practice-layout { grid-template-columns: minmax(0, 1fr) 22rem; }
  .nav-panel { display: block; position: sticky; top: 5rem; }
  #toggle-nav { display: none; }
  .q-grid { grid-template-columns: repeat(auto-fill, minmax(2.4rem, 1fr)); }
}

/* large desktop: a touch more room */
@media (min-width: 1500px) {
  :root { --wrap: min(1500px, 100% - 4rem); --measure: 76ch; }
  .practice-layout { grid-template-columns: minmax(0, 1fr) 26rem; }
}

/* 4K and ultrawide: cap the line length, let the app breathe */
@media (min-width: 2200px) {
  :root {
    --wrap: min(1900px, 100% - 6rem);
    --body-size: 1.28rem;
    --measure: 80ch;
  }
  .practice-layout { grid-template-columns: minmax(0, 1fr) 30rem; }
  .q-grid { grid-template-columns: repeat(auto-fill, minmax(3rem, 1fr)); }
}

/* phones: tighter chrome, full-width buttons */
@media (max-width: 560px) {
  .header-inner { min-height: 54px; }
  .brand-name { font-size: .92rem; }
  .question-card { border-radius: var(--radius); }
  .q-number { font-size: 1.3rem; }
  .q-tags { margin-inline-start: 0; width: 100%; }
  .shortcuts { display: none; }
}

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

@media print {
  .app-header, .app-footer, .nav-panel, .q-nav, .practice-bar, .shortcuts { display: none; }
  .question-card { box-shadow: none; border: 0; }
}
