:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --text: #1b2430;
  --muted: #4b5563;
  --border: #c9d1dc;
  --primary: #1d4ed8;
  --primary-dark: #1e3a8a;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --warn-bg: #fff3cd;
  --warn-text: #5b3a00;
  --ok-bg: #e7f5ec;
  --focus: #0b3fd1;
  --mono: ui-monospace, "Cascadia Mono", "Consolas", "DejaVu Sans Mono", monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { font-size: 18px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 0.5rem; top: -4rem; background: var(--surface); color: var(--text);
  padding: 0.5rem 1rem; border: 2px solid var(--focus); border-radius: 6px; z-index: 50;
}
.skip-link:focus { top: 0.5rem; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.page { max-width: 62rem; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 1.5rem 1.75rem; box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}
#screen-entry, #screen-waiting, #screen-rules, #screen-finished, #screen-ended, #screen-loading {
  max-width: 40rem; margin: 2.5rem auto 0;
}
h1 { font-size: 1.5rem; margin: 0 0 0.75rem; line-height: 1.25; }
h1:focus { outline: none; }
.lead { font-size: 1.1rem; margin-top: 0; }
.muted { color: var(--muted); }
.error { color: var(--danger); background: var(--danger-bg); border-radius: 6px; padding: 0.5rem 0.75rem; margin: 0.75rem 0 0; }

label { display: block; font-weight: 600; margin-bottom: 0.35rem; }
input[type="text"] {
  width: 100%; font: inherit; padding: 0.6rem 0.75rem; color: var(--text);
  border: 2px solid var(--border); border-radius: 8px; background: #fff;
}
input[type="text"]:focus-visible { border-color: var(--focus); }
#entry-form .btn, #code-form .btn { margin-top: 1rem; }

.btn {
  font: inherit; font-weight: 600; padding: 0.6rem 1.25rem; border-radius: 8px; cursor: pointer;
  border: 2px solid var(--border); background: #fff; color: var(--text);
}
.btn:hover:not(:disabled) { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.large { font-size: 1.15rem; padding: 0.75rem 2rem; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.rules-list { padding-left: 1.25rem; }

.resume-code-box { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.resume-code-box form { margin-top: 0.75rem; }
input[type="text"].code-input { width: 9rem; font-family: var(--mono); font-size: 1.3rem; letter-spacing: 0.25em; }
#entry-notice { margin: 0 0 1rem; font-weight: 600; }
.q-status.ok { color: var(--muted); }
.rules-list li { margin-bottom: 0.6rem; }

.banner {
  position: sticky; top: 0; z-index: 30; background: var(--warn-bg); color: var(--warn-text);
  border-bottom: 2px solid #e0b100; padding: 0.6rem 1.25rem; text-align: center; font-weight: 600;
}
.notice {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%); z-index: 40;
  background: var(--text); color: #fff; padding: 0.75rem 1.25rem; border-radius: 8px; font-weight: 600;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

/* Pergunta */
.q-header {
  display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem;
  position: sticky; top: 0; z-index: 20; background: var(--bg); padding: 0.5rem 0 0.75rem;
}
.q-header h1 { margin: 0; }
.q-type {
  margin: 0.15rem 0 0; display: inline-block; font-size: 0.85rem; font-weight: 700; color: var(--primary-dark);
  background: #e0e9ff; border-radius: 999px; padding: 0.1rem 0.7rem;
}
.timer-box { text-align: right; }
.timer-label { display: block; font-size: 0.8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.timer {
  font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 3rem; font-weight: 700; line-height: 1.1;
  padding: 0.1rem 0.9rem; border-radius: 10px; background: var(--surface); border: 2px solid var(--border);
}
.timer.warning { color: var(--danger); background: var(--danger-bg); border-color: var(--danger); }
.timer-warning { margin: 0 0 0.75rem; color: var(--danger); font-weight: 700; }

.q-body { padding-bottom: 1.25rem; }
.q-prompt { font-size: 1.1rem; margin-top: 0; white-space: pre-wrap; }
.code-block, .code-template {
  font-family: var(--mono); font-size: 0.95rem; background: #f6f8fa; border: 1px solid var(--border);
  border-radius: 8px; padding: 0.85rem 1rem; overflow-x: auto; margin: 0.75rem 0; white-space: pre; line-height: 1.7;
}

.options { border: 0; padding: 0; margin: 0.5rem 0 0; }
.options legend { font-weight: 600; margin-bottom: 0.5rem; padding: 0; }
.option {
  display: flex; align-items: flex-start; gap: 0.75rem; padding: 0.7rem 0.9rem; margin-bottom: 0.5rem;
  border: 2px solid var(--border); border-radius: 10px; cursor: pointer; font-weight: 400;
}
.option:hover { border-color: var(--primary); }
.option:has(input:checked) { border-color: var(--primary); background: #eef3ff; }
.option:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.option input { margin-top: 0.3rem; width: 1.1rem; height: 1.1rem; accent-color: var(--primary); }
.option span { font-family: var(--mono); font-size: 0.98rem; }

input[type="text"].blank {
  font-family: var(--mono); font-size: 0.95rem; padding: 0.1rem 0.4rem; margin: 0 0.15rem;
  width: 11ch; border: 2px solid var(--primary); border-radius: 6px; background: #fff; color: var(--text);
  vertical-align: baseline;
}
.code-template { white-space: pre-wrap; }

.editor-wrap { margin-top: 0.75rem; }
.editor-hint { font-size: 0.85rem; color: var(--muted); margin: 0.4rem 0 0; }
.code-fallback { width: 100%; font-family: var(--mono); font-size: 0.95rem; border: 2px solid var(--border); border-radius: 8px; padding: 0.75rem; }

.q-actions { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-top: 1rem; }
.q-status { margin: 0; font-weight: 600; color: var(--danger); }

.dialog {
  border: 2px solid var(--border); border-radius: 12px; padding: 1.5rem; max-width: 28rem; color: var(--text);
}
.dialog::backdrop { background: rgba(15, 23, 42, 0.55); }
.dialog h2 { margin-top: 0; font-size: 1.25rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.75rem; margin-top: 1.25rem; }

@media (max-width: 720px) {
  html { font-size: 16px; }
  .q-header { flex-direction: column; align-items: stretch; }
  .timer-box { text-align: left; }
  .timer { font-size: 2.25rem; }
}
@media (max-height: 760px) {
  .timer { font-size: 2.4rem; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }

/* ======================= Painel do professor ======================= */
.admin-body { font-size: 0.85rem; }
.admin-body .page.admin { max-width: 82rem; padding-top: 1rem; }
.admin-body h1 { font-size: 1.45rem; }
.admin-body h2 { font-size: 1.1rem; margin: 0 0 0.6rem; }
.admin-body h3 { font-size: 1rem; margin: 0 0 0.25rem; }
.admin-body h4 { font-size: 0.95rem; margin: 0.9rem 0 0.35rem; }
.admin-body .card.narrow { max-width: 28rem; margin: 2.5rem auto 0; }
.admin-body #main:focus { outline: none; }
.admin-body #view-login h1:focus,
.admin-body .admin h1:focus { outline: none; }

.admin-header {
  display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap;
  background: var(--surface); border-bottom: 1px solid var(--border); padding: 0.55rem 1.25rem;
  position: sticky; top: 0; z-index: 25;
}
.admin-header .brand { margin: 0; font-weight: 700; }
.admin-header nav { flex: 1; }
.nav-list { display: flex; gap: 0.4rem; list-style: none; margin: 0; padding: 0; }
.nav-list a {
  display: inline-block; padding: 0.4rem 0.9rem; border-radius: 8px; color: var(--text);
  text-decoration: none; font-weight: 600; border: 2px solid transparent;
}
.nav-list a:hover { border-color: var(--border); }
.nav-list a[aria-current="page"] { background: #e0e9ff; color: var(--primary-dark); border-color: var(--primary); }

.admin input[type="password"], .admin input[type="number"], .admin input[type="text"][readonly], .admin select,
.admin-body dialog input[type="text"] {
  font: inherit; padding: 0.4rem 0.55rem; color: var(--text); background: #fff;
  border: 2px solid var(--border); border-radius: 8px;
}
.admin input[type="password"] { width: 100%; }
.admin input[type="number"] { width: 7.5rem; }
.admin input[aria-invalid="true"] { border-color: var(--danger); }
.admin select:focus-visible, .admin input:focus-visible { border-color: var(--focus); }
#login-form .btn { margin-top: 1rem; }
.admin-body dialog input[type="text"] { width: 100%; font-family: var(--mono); font-size: 0.8rem; }

.btn.small { padding: 0.3rem 0.75rem; font-size: 0.85rem; border-width: 2px; }

.panel { margin-bottom: 1.5rem; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.4rem; }
.panel-head h2 { margin: 0; }
.count { font-weight: 400; color: var(--muted); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
table.data { border-collapse: collapse; width: 100%; }
table.data th, table.data td { text-align: left; padding: 0.45rem 0.7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
table.data thead th { background: #eaeff6; font-weight: 700; white-space: nowrap; }
table.data tbody th { font-weight: 600; }
table.data tbody tr:last-child th, table.data tbody tr:last-child td { border-bottom: 0; }
table.data td.actions { white-space: nowrap; }
table.data td.actions .btn + .btn { margin-left: 0.4rem; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.th-button { font: inherit; font-weight: 700; background: none; border: 0; padding: 0; cursor: pointer; color: inherit; }
.th-button:hover { text-decoration: underline; }
#results-empty { margin: 0.5rem 0 0; }

.admin a { color: var(--primary); }
.admin a:hover { color: var(--primary-dark); }

/* Realce de linhas e etiquetas de alerta */
tr.flag > th, tr.flag > td { background: var(--warn-bg); }
tr.flag > th:first-child { box-shadow: inset 5px 0 0 #b45309; }
tr.flag-neutral > th, tr.flag-neutral > td { background: #e8edf3; }
tr.flag-neutral > th:first-child { box-shadow: inset 5px 0 0 #64748b; }
.flag-tag {
  display: inline-block; margin-left: 0.5rem; font-size: 0.75rem; font-weight: 700; padding: 0.05rem 0.5rem;
  border-radius: 999px; background: #fde68a; color: #5b3a00; border: 1px solid #b45309;
}
tr.flag-neutral .flag-tag { background: #fff; color: #334155; border: 1px dashed #475569; }
tr.alert-row.neutral > th, tr.alert-row.neutral > td { background: #f1f4f8; }

.type-tag {
  display: inline-block; font-size: 0.78rem; font-weight: 700; padding: 0.05rem 0.55rem; border-radius: 999px;
  border: 1px solid var(--border); background: #fff; color: var(--text); white-space: nowrap;
}
.type-tag.alert, .type-tag.bad, .type-tag.run-error { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.type-tag.ok, .type-tag.run-done { background: var(--ok-bg); color: #14532d; border-color: #15803d; }
.type-tag.neutral { background: #fff; color: #334155; border: 1px dashed #475569; }
.type-tag.chosen { background: #e0e9ff; color: var(--primary-dark); border-color: var(--primary); }
.type-tag.run-queued { background: var(--warn-bg); color: var(--warn-text); border-color: #b45309; }

/* Avisos */
.toasts {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 60; display: flex; flex-direction: column; gap: 0.5rem;
  max-width: min(26rem, calc(100vw - 2rem));
}
.toast {
  display: flex; align-items: flex-start; gap: 0.75rem; padding: 0.65rem 0.85rem; border-radius: 8px;
  background: var(--text); color: #fff; font-weight: 600; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  border-left: 6px solid #93c5fd;
}
.toast.alert { background: #7f1d1d; border-left-color: #fecaca; }
.toast.neutral { background: #334155; border-left: 6px dashed #cbd5e1; }
.toast.error { background: #7f1d1d; border-left-color: #fecaca; }
.toast-text { flex: 1; }
.toast-close { font: inherit; background: none; border: 0; color: inherit; cursor: pointer; font-size: 1.2rem; line-height: 1; padding: 0 0.25rem; }
.toast-close:focus-visible { outline-color: #fff; }

.note-box { background: #eef3ff; border: 1px solid var(--primary); border-radius: 8px; padding: 0.55rem 0.8rem; }
.resume-code { font-family: var(--mono); font-size: 2.4rem; font-weight: 700; letter-spacing: 0.3em; margin: 0.4rem 0; color: var(--primary-dark); }
.dup-tag { display: inline-block; margin-left: 0.4rem; padding: 0 0.4rem; border-radius: 4px; font-size: 0.75rem; font-weight: 700; background: var(--warn-bg); color: var(--warn-text); border: 1px solid #b45309; }
tr.dup > th, tr.dup > td { background: var(--warn-bg); }
.extend-group { display: inline-flex; gap: 0.3rem; margin-left: 0.4rem; }
#view-sala td.actions .btn + .btn { margin-left: 0; }
.note-box.warn { background: var(--warn-bg); color: var(--warn-text); border-color: #b45309; }
.error.inline { margin: 0.35rem 0 0; font-size: 0.85rem; }
.totals { font-weight: 700; font-size: 1rem; margin: 0.5rem 0 0.25rem; }

/* Detalhe */
.summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); gap: 0.6rem 1rem; margin: 0.5rem 0 1rem; }
.summary > div { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 0.4rem 0.7rem; }
.summary dt { font-size: 0.75rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.summary dd { margin: 0; font-weight: 700; font-size: 1rem; }
.detail-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 0.35rem; }
.items { display: grid; gap: 1rem; margin-bottom: 1.5rem; }
.item.card { padding: 1rem 1.25rem; }
.item .prompt { white-space: pre-wrap; margin: 0.25rem 0 0.5rem; }
.item .code-block { margin: 0.4rem 0; font-size: 0.82rem; }
.cell-pre { margin: 0 !important; padding: 0.3rem 0.5rem !important; min-width: 6rem; font-size: 0.8rem !important; }
.option-list { margin: 0.4rem 0; padding-left: 1.2rem; }
.score-form { margin-top: 0.9rem; padding-top: 0.7rem; border-top: 1px solid var(--border); }
.scores { margin: 0 0 0.5rem; }
.score-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.score-row label { margin: 0; }
.tests-table td, .blanks-table td { max-width: 18rem; }

/* Configuração */
.tabs { display: flex; gap: 0.35rem; margin: 0.75rem 0; }
.tabs [role="tab"] {
  font: inherit; font-weight: 600; padding: 0.45rem 1.1rem; border-radius: 8px 8px 0 0; cursor: pointer;
  background: #fff; color: var(--text); border: 2px solid var(--border); border-bottom-width: 0;
}
.tabs [role="tab"][aria-selected="true"] { background: #e0e9ff; color: var(--primary-dark); border-color: var(--primary); }
#config-panel:focus { outline: none; }
.type-forms { display: grid; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); gap: 0.75rem; margin-bottom: 1.25rem; }
.type-form { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.7rem 0.9rem; }
.cfg-row { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.cfg-row label { margin: 0; font-weight: 600; }
.prompt-cell { min-width: 16rem; max-width: 30rem; }
.prompt-details summary { cursor: pointer; }
.prompt-details[open] summary { font-weight: 600; margin-bottom: 0.3rem; }
.prompt-details .prompt { white-space: pre-wrap; margin: 0.25rem 0; }

@media (max-width: 720px) {
  .admin-body { font-size: 0.8rem; }
  .panel-head { flex-wrap: wrap; }
}
