:root {
  --font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  --bg-main: #f4f8fc;
  --bg-card: #ffffff;
  --text-primary: #12243a;
  --text-muted: #5e748d;
  --primary: #1464d2;
  --primary-hover: #0d4fae;
  --primary-light: #eaf3fe;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --error: #dc2626;
  --error-light: #fef2f2;
  --border-color: #dbe5ee;
  --border-focus: #288fe7;
}

* { box-sizing: border-box; }
[hidden], .loading-box[hidden], .edit-container[hidden], .results[hidden] {
  display: none !important;
}
body {
  margin: 0;
  font-family: var(--font-family);
  color: var(--text-primary);
  background: var(--bg-main);
  line-height: 1.5;
}

.shell {
  width: min(1160px, calc(100% - 40px));
  margin: auto;
}

/* Header */
.top {
  background: #fff;
  border-bottom: 1px solid var(--border-color);
}
.bar {
  height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-logo {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  object-fit: cover;
  box-shadow: 0 4px 12px rgba(20, 100, 210, 0.2);
}
.brand-icon {
  background: linear-gradient(135deg, #1464d2, #29b6f6);
  width: 44px;
  height: 44px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 800;
  font-size: 24px;
  box-shadow: 0 4px 12px rgba(20, 100, 210, 0.25);
}
.brand strong {
  display: block;
  font-size: 20px;
  letter-spacing: -0.5px;
}
.brand small {
  display: block;
  color: var(--text-muted);
  font-size: 13px;
}
.tag {
  border: 1px solid #d0e4f5;
  background: #eef7fe;
  color: #1967a5;
  font-size: 12px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 100px;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 0.95fr 1.05fr;
  gap: 32px;
  padding: 48px 0;
}
.intro {
  padding: 20px 14px 10px 0;
}
.eyebrow {
  font-size: 12px;
  font-weight: 800;
  color: #156fc5;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}
h1 {
  font-size: clamp(34px, 4.2vw, 54px);
  line-height: 1.1;
  letter-spacing: -1.8px;
  margin: 18px 0;
}
h1 em {
  font-style: normal;
  color: #1464d2;
}
.intro > p {
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-muted);
  max-width: 460px;
}
.notice {
  margin-top: 28px;
  padding: 16px 18px;
  background: #e9f4fd;
  color: #1f5782;
  border-left: 4px solid #1e88e5;
  border-radius: 8px;
  line-height: 1.55;
  max-width: 460px;
  font-size: 13px;
}

/* Panel */
.panel {
  background: var(--bg-card);
  box-shadow: 0 10px 30px rgba(18, 36, 58, 0.05);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 30px;
}
.panel-head, .section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.panel-desc {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 3px;
}
.panel h2, .section-heading h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.4px;
}
.counter {
  color: #1668aa;
  background: #eaf4fd;
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 700;
}

/* Form */
form {
  display: grid;
  gap: 18px;
  margin-top: 22px;
}
.fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
label {
  font-size: 13px;
  font-weight: 700;
  display: grid;
  gap: 7px;
  color: #2c4257;
}
input, select, textarea {
  font: inherit;
  font-size: 14px;
  background: #fbfdff;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 11px 14px;
  color: var(--text-primary);
  width: 100%;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(40, 143, 231, 0.15);
}
button {
  font: inherit;
  border: 0;
  cursor: pointer;
  border-radius: 10px;
  font-weight: 700;
  padding: 13px 18px;
  transition: all 0.15s;
}
button:disabled {
  opacity: 0.55;
  cursor: wait;
}
.primary {
  background: linear-gradient(135deg, #155dc5, #167fdf);
  color: #fff;
  box-shadow: 0 4px 14px rgba(21, 93, 197, 0.25);
}
.primary:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-1px);
}
.secondary {
  background: #eaf3fd;
  color: #155bb3;
}
.secondary:hover:not(:disabled) {
  background: #deecfc;
}
.ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}
.ghost:hover {
  background: #f0f4f9;
}
.small-btn {
  padding: 8px 14px;
  font-size: 13px;
}
.hint, .section-heading p {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.5;
}

/* Error Box */
.error-box {
  margin-top: 20px;
  background: #fef2f2;
  border: 1.5px solid #fecaca;
  border-radius: 14px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  animation: fadeIn 0.3s ease;
}
.error-icon {
  font-size: 26px;
  line-height: 1;
}
.error-content {
  flex: 1;
}
.error-content strong {
  display: block;
  font-size: 14px;
  color: #991b1b;
}
.error-content p {
  margin: 3px 0 0 0;
  font-size: 13px;
  color: #7f1d1d;
  line-height: 1.4;
}

/* Loading Box */
.loading-box {
  margin-top: 24px;
  background: #f8fbfe;
  border: 1.5px solid #d4e6f6;
  border-radius: 16px;
  padding: 22px;
  display: flex;
  align-items: center;
  gap: 20px;
  animation: fadeIn 0.3s ease;
}
.loading-spinner {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border: 4px solid #d8e9f8;
  border-top-color: #1464d2;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.loading-content {
  flex: 1;
}
.loading-title {
  font-size: 15px;
  font-weight: 700;
  color: #1459a8;
  margin-bottom: 8px;
}
.loading-progress-bar {
  height: 8px;
  background: #e2edf7;
  border-radius: 100px;
  overflow: hidden;
  margin-bottom: 8px;
}
.loading-progress-fill {
  height: 100%;
  width: 15%;
  background: linear-gradient(90deg, #1464d2, #29b6f6);
  border-radius: 100px;
  transition: width 0.4s ease;
}
.loading-tip {
  font-size: 12px;
  color: #637b94;
}

/* Results Section */
.results, .history {
  grid-column: 1 / -1;
  margin-top: 36px;
}
.result-header-card {
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 18px 18px 0 0;
  padding: 24px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #e7eff6;
  gap: 16px;
  flex-wrap: wrap;
}
.result-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.result-header-main h2 {
  margin: 4px 0 6px 0;
  font-size: 24px;
}
.result-header-main p {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* Export Banner */
.export-banner {
  background: #eef6fd;
  border-left: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  border-bottom: 2px solid #dbe8f4;
  padding: 18px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}
.export-banner-text strong {
  display: block;
  font-size: 14px;
  color: #124373;
}
.export-banner-text span {
  font-size: 12px;
  color: #4c6b8a;
}
.export-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.export-btn {
  font-size: 13px;
  padding: 10px 16px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Ficha de Revisão Teórica */
.theory-summary-card {
  background: #ffffff;
  border: 1.5px solid #cce3f8;
  border-left: 6px solid #1464d2;
  border-radius: 16px;
  padding: 24px 28px;
  margin-top: 18px;
  box-shadow: 0 4px 18px rgba(20, 100, 210, 0.06);
}
.theory-card-header {
  border-bottom: 1px solid #eef4fb;
  padding-bottom: 14px;
  margin-bottom: 18px;
}
.theory-tag {
  display: inline-block;
  background: #eaf3fe;
  color: #1464d2;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  padding: 5px 12px;
  border-radius: 100px;
  margin-bottom: 8px;
}
.theory-card-header h3 {
  margin: 0 0 4px 0;
  font-size: 18px;
  font-weight: 700;
  color: #12243a;
}
.theory-card-header p {
  margin: 0;
  font-size: 13.5px;
  color: var(--text-muted);
}
.theory-card-body {
  font-size: 15px;
  line-height: 1.7;
  color: #24384d;
}
.theory-card-body p {
  margin: 0 0 12px 0;
}
.theory-card-body p:last-child {
  margin-bottom: 0;
}
.theory-card-body ul, .theory-card-body ol {
  margin: 8px 0 14px 22px;
  padding: 0;
}
.theory-card-body li {
  margin-bottom: 6px;
}
.theory-tip-box {
  background: #fefce8;
  border: 1px solid #fef08a;
  border-left: 4px solid #eab308;
  border-radius: 10px;
  padding: 12px 16px;
  margin: 14px 0;
  color: #713f12;
  font-size: 14px;
  font-weight: 500;
}
.theory-card-footer {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px dashed #dce8f3;
  display: flex;
  justify-content: flex-end;
}
.go-quiz-btn {
  background: linear-gradient(135deg, #1464d2, #1877f2);
  font-size: 14px;
  font-weight: 700;
  padding: 12px 24px;
  border-radius: 12px;
  box-shadow: 0 4px 14px rgba(20, 100, 210, 0.25);
  transition: transform 0.15s, box-shadow 0.15s;
}
.go-quiz-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(20, 100, 210, 0.35);
}

/* Quiz Container */
.quiz-container {
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 18px;
  padding: 28px;
  margin-top: 18px;
}
.score-banner {
  background: #fbfdff;
  border: 1.5px solid #dce8f3;
  border-radius: 14px;
  padding: 18px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.score-pill {
  font-size: 17px;
  font-weight: 800;
  color: #1464d2;
}
.score-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 3px;
}
.quiz-questions-list {
  display: grid;
  gap: 22px;
}
.quiz-card {
  background: #fff;
  border: 1.5px solid var(--border-color);
  border-radius: 16px;
  padding: 24px;
  transition: border-color 0.2s;
}
.quiz-card.answered {
  border-color: #cbdbe8;
}
.quiz-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.quiz-number {
  font-size: 13px;
  font-weight: 800;
  color: #1868aa;
  background: #eaf3fb;
  padding: 4px 12px;
  border-radius: 100px;
}
.quiz-status {
  font-size: 13px;
  font-weight: 700;
}
.quiz-stem {
  font-size: 16px;
  font-weight: 600;
  color: #192e44;
  line-height: 1.6;
  margin-bottom: 18px;
}
.quiz-options {
  display: grid;
  gap: 10px;
}
.quiz-opt-btn {
  width: 100%;
  text-align: left;
  background: #fbfdff;
  border: 1.5px solid #dce6f0;
  border-radius: 12px;
  padding: 13px 16px;
  font-size: 14px;
  font-weight: 500;
  color: #1d354d;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  line-height: 1.45;
  transition: all 0.15s ease;
}
.quiz-opt-btn:hover:not(:disabled) {
  background: #f0f6fc;
  border-color: #2a8de3;
  transform: translateX(2px);
}
.quiz-opt-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  border-radius: 8px;
  background: #e8f1fa;
  color: #1a62a0;
  font-weight: 700;
  font-size: 13px;
}

/* Feedback */
.quiz-opt-btn.correct {
  background: var(--success-light) !important;
  border-color: var(--success) !important;
  color: #14532d !important;
  font-weight: 600;
}
.quiz-opt-btn.correct .quiz-opt-letter {
  background: var(--success);
  color: #fff;
}
.quiz-opt-btn.incorrect {
  background: var(--error-light) !important;
  border-color: var(--error) !important;
  color: #7f1d1d !important;
}
.quiz-opt-btn.incorrect .quiz-opt-letter {
  background: var(--error);
  color: #fff;
}
.quiz-feedback {
  margin-top: 18px;
  padding: 16px;
  border-radius: 12px;
  background: #f8fbfe;
  border: 1px solid #d7e7f6;
  font-size: 14px;
  line-height: 1.6;
  animation: fadeIn 0.3s ease;
}
.quiz-feedback.is-correct { border-left: 4px solid var(--success); }
.quiz-feedback.is-incorrect { border-left: 4px solid var(--error); }
.feedback-badge {
  font-weight: 800;
  display: block;
  margin-bottom: 6px;
}
.feedback-badge.right { color: var(--success); }
.feedback-badge.wrong { color: var(--error); }
.feedback-text { color: #27415b; }

/* Advanced Edit Accordion */
.advanced-edit-toggle {
  margin-top: 24px;
  text-align: center;
}
.advanced-edit-toggle button {
  padding: 12px 24px;
  border-radius: 100px;
  background: #fff;
  border: 1px dashed #b7cde0;
  color: #275d8d;
}
.advanced-edit-toggle button:hover {
  background: #f0f7fd;
  border-color: #1464d2;
}
.edit-container {
  margin-top: 20px;
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 18px;
  padding: 28px;
  animation: fadeIn 0.3s ease;
}
.editor-header h3 {
  margin: 0;
  font-size: 18px;
}
.editor-header p {
  margin: 4px 0 18px 0;
  font-size: 13px;
  color: var(--text-muted);
}
.questions {
  display: grid;
  gap: 18px;
}
.question {
  padding: 22px;
  border: 1px solid var(--border-color);
  background: #fbfdff;
  border-radius: 14px;
}
.question > label {
  margin-bottom: 10px;
}
.question textarea {
  min-height: 70px;
  resize: vertical;
}
.option-row {
  display: grid;
  grid-template-columns: 24px 26px 1fr;
  gap: 10px;
  align-items: center;
  margin: 8px 0;
}
.option-row input[type=radio] {
  width: 18px;
  accent-color: var(--primary);
}
.option-row b { font-size: 14px; }
.question .explain { margin-top: 14px; }
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 24px;
}

/* Finish Banner */
.finish-banner {
  margin-top: 28px;
  background: #fff;
  border: 1.5px solid var(--border-color);
  border-radius: 16px;
  padding: 22px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  box-shadow: 0 4px 16px rgba(18, 36, 58, 0.04);
}
.finish-text strong {
  display: block;
  font-size: 16px;
  color: #123456;
}
.finish-text span {
  font-size: 13px;
  color: var(--text-muted);
}
.finish-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* History */
.history-item {
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  margin: 12px 0;
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  box-shadow: 0 2px 8px rgba(18, 36, 58, 0.03);
}
.history-item strong {
  display: block;
  font-size: 15px;
}
.history-item small {
  color: var(--text-muted);
  font-size: 13px;
}
.empty {
  color: var(--text-muted);
  background: #fff;
  padding: 26px;
  border: 1px dashed var(--border-color);
  border-radius: 12px;
  text-align: center;
}

/* Toast */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  max-width: min(440px, 90vw);
  background: #112842;
  color: #fff;
  border-radius: 12px;
  padding: 14px 20px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25);
  display: none;
  z-index: 9999;
  font-size: 14px;
}
#toast.show {
  display: block;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Footer */
footer {
  text-align: center;
  padding: 38px 12px;
  color: var(--text-muted);
  font-size: 13px;
}

/* Responsive */
@media (max-width: 860px) {
  .layout {
    display: block;
    padding: 24px 0;
  }
  .intro {
    padding: 10px 0 24px;
  }
  .panel {
    padding: 22px;
  }
  .export-banner {
    flex-direction: column;
    align-items: flex-start;
  }
  .score-banner {
    flex-direction: column;
    align-items: flex-start;
  }
  .tag {
    display: none;
  }
}
@media (max-width: 500px) {
  .fields {
    grid-template-columns: 1fr;
  }
  .shell {
    width: min(100% - 24px, 1160px);
  }
  .option-row {
    grid-template-columns: 20px 20px 1fr;
  }
  .history-item {
    display: block;
  }
  .history-item button {
    margin-top: 12px;
    width: 100%;
  }
  .export-buttons {
    width: 100%;
  }
  .export-btn {
    width: 100%;
    justify-content: center;
  }
}
