:root {
  --bg: #0f1412;
  --bg2: #17201c;
  --panel: #1c2923;
  --line: #2f443a;
  --text: #e8f0ea;
  --muted: #9bb0a4;
  --accent: #3dba7a;
  --accent2: #d4a017;
  --danger: #e25b5b;
  --ok: #3dba7a;
  --warn: #e0a84a;
  --radius: 14px;
  --font: "Segoe UI", "Bahnschrift", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(900px 500px at 10% -10%, #1e3a2e 0%, transparent 55%),
    radial-gradient(700px 400px at 100% 0%, #3a2e14 0%, transparent 50%),
    var(--bg);
}

a { color: var(--accent); }
button, input, select, textarea { font: inherit; }
.hidden { display: none !important; }

.shell { max-width: 1100px; margin: 0 auto; padding: 20px 18px 60px; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 22px; flex-wrap: wrap;
}
.brand { display: flex; flex-direction: column; gap: 2px; }
.brand strong { letter-spacing: 0.04em; font-size: 1.15rem; }
.brand span { color: var(--muted); font-size: 0.85rem; }
code { font-family: ui-monospace, Consolas, monospace; }
.pin { letter-spacing: 0.12em; color: var(--accent2); }
.nav { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.nav button, .btn {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}
.nav button.active, .btn.primary {
  background: linear-gradient(135deg, #2f9e66, #247a4f);
  border-color: transparent;
}
.btn.danger { border-color: var(--danger); color: #ffd0d0; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.card {
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}
.card h2, .card h3 { margin: 0 0 10px; }
.muted { color: var(--muted); }
.grid { display: grid; gap: 12px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.login-card { width: min(420px, 100%); }
.login-card label { display: block; margin: 12px 0 6px; color: var(--muted); font-size: 0.9rem; }
.login-card input, .field input, .field select, .field textarea {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
}
.field { margin-bottom: 12px; }
.field label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 0.9rem; }

.exam-meta {
  display: flex; gap: 14px; flex-wrap: wrap; align-items: center;
  padding: 10px 0 16px; border-bottom: 1px solid var(--line); margin-bottom: 16px;
}
.timer {
  font-variant-numeric: tabular-nums;
  font-size: 1.35rem;
  color: var(--accent2);
  font-weight: 700;
}
.timer.warn { color: var(--danger); }

.q {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
  background: #15201b;
}
.q .n { color: var(--accent); font-weight: 700; margin-bottom: 6px; }
.opts { display: grid; gap: 8px; margin-top: 12px; }
.opt {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); cursor: pointer; background: var(--bg2);
}
.opt:hover { border-color: var(--accent); }
.opt.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.opt input { margin-top: 3px; }
.opt .orig-letter {
  color: var(--muted, #9aa3ad);
  font-weight: 600;
  margin-right: 4px;
  text-transform: lowercase;
}
.opt.ok { border-color: var(--ok); background: #163225; }
.opt.bad { border-color: var(--danger); background: #321818; }

.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table th, .table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 0.78rem; border: 1px solid var(--line);
}
.badge.ok { color: #b6ffd2; border-color: #2f7a52; }
.badge.bad { color: #ffc4c4; border-color: #8a3a3a; }

.chat {
  display: grid; grid-template-rows: 1fr auto; height: min(70vh, 620px);
}
.chat-log {
  overflow: auto; padding: 8px; border: 1px solid var(--line);
  border-radius: 12px; background: #121a16; margin-bottom: 10px;
}
.msg { padding: 10px 12px; border-radius: 10px; margin-bottom: 8px; white-space: pre-wrap; line-height: 1.45; }
.msg.user { background: #24352c; }
.msg.bot { background: #1a2430; border: 1px solid #2a3b4d; }
.chat-form { display: flex; gap: 8px; }
.chat-form textarea { flex: 1; min-height: 70px; resize: vertical; }

.normativa {
  max-height: 70vh; overflow: auto;
  line-height: 1.5; font-size: 0.92rem; color: #d7e4dc;
  border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; background: #121a16;
}
.normativa-html { white-space: normal; }
.boe-jump {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin: 12px 0 14px;
}
.boe-jump label { color: var(--muted); }
.boe-jump select, .boe-jump input[type="search"] {
  background: var(--bg2);
  border: 1px solid var(--accent2);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: min(100%, 280px);
  flex: 1;
}
.boe-jump select { min-width: min(100%, 420px); flex: 2; }
.boe-part {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--accent); margin-bottom: 4px;
}
.boe-sec {
  padding: 10px 0 16px;
  border-bottom: 1px solid var(--line);
  scroll-margin-top: 8px;
}
.boe-sec h3 {
  margin: 0 0 8px; font-size: 1.02rem; color: #f0f6f2;
}
.boe-body { white-space: pre-wrap; color: #c5d4cb; }
.boe-sec.flash {
  outline: 1px solid var(--accent2);
  background: color-mix(in srgb, var(--accent2) 12%, transparent);
  border-radius: 8px;
  padding-left: 8px; padding-right: 8px;
}

.ai-explain {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid #2a3b4d;
  background: #1a2430;
  white-space: pre-wrap;
  line-height: 1.45;
  color: #d7e4f0;
  font-size: 0.92rem;
}

@media (max-width: 640px) {
  .shell { padding: 14px 12px 40px; }
  .timer { font-size: 1.15rem; }
}
