:root {
  --navy: #0b2545;
  --blue: #1d70b8;
  --blue-light: #e8f1fb;
  --green: #00703c;
  --green-light: #e6f4ec;
  --red: #d4351c;
  --red-light: #fcebe8;
  --amber: #f4a100;
  --grey: #505a5f;
  --line: #b1b4b6;
  --bg: #f3f2f1;
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 18px; line-height: 1.45; color: #0b0c0c; background: var(--bg);
  min-height: 100vh; display: flex; flex-direction: column;
}
main { flex: 1; width: 100%; max-width: 860px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.8rem; margin: 0.4em 0; }
h2 { font-size: 1.35rem; margin: 1.2em 0 0.5em; }
p { margin: 0.5em 0; }
.muted { color: var(--grey); }
.site-footer { font-size: 13px; color: var(--grey); text-align: center; padding: 16px; max-width: 860px; margin: 0 auto; }

/* Buttons */
.btn {
  font: inherit; font-weight: 700; border: 0; border-radius: var(--radius); cursor: pointer;
  padding: 12px 20px; background: var(--blue); color: #fff; box-shadow: 0 2px 0 #003078;
}
.btn:hover { filter: brightness(1.08); }
.btn:focus-visible, .option:focus-visible, .tile:focus-visible { outline: 3px solid #ffdd00; outline-offset: 2px; }
.btn.secondary { background: #fff; color: var(--navy); box-shadow: 0 2px 0 var(--line); border: 1px solid var(--line); }
.btn.green { background: var(--green); box-shadow: 0 2px 0 #002d18; }
.btn.danger { background: var(--red); box-shadow: 0 2px 0 #7a1b0f; }
.btn.small { padding: 8px 14px; font-size: 0.9rem; }
.btn[disabled] { opacity: 0.45; cursor: default; }
.btn-row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 16px; }

/* Home */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); gap: 14px; margin-top: 16px; }
.card { background: #fff; border-radius: var(--radius); padding: 18px; border: 1px solid #ddd; display: flex; flex-direction: column; gap: 8px; }
.card h2 { margin: 0; font-size: 1.2rem; }
.card .btn { margin-top: auto; align-self: flex-start; }
.panel { background: #fff; border-radius: var(--radius); padding: 18px; border: 1px solid #ddd; margin-top: 16px; }
.topic-row { display: grid; grid-template-columns: 1fr 140px 56px; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid #eee; font-size: 0.95rem; }
.bar { height: 10px; background: #e5e5e5; border-radius: 5px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--blue); }
.bar.good > span { background: var(--green); }
.bar.bad > span { background: var(--red); }

/* Exam layout */
.exam-bar {
  position: sticky; top: 0; z-index: 5; background: var(--navy); color: #fff; padding: 10px 14px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; border-radius: 0 0 var(--radius) var(--radius);
  margin: -16px -16px 16px;
}
.exam-bar .count { font-weight: 700; }
.exam-bar .spacer { flex: 1; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; background: rgba(255,255,255,0.12); padding: 6px 10px; border-radius: 6px; }
.timer.warn { background: var(--amber); color: #000; }
.bar-btn { font: inherit; font-size: 0.9rem; font-weight: 700; background: #fff; color: var(--navy); border: 0; border-radius: 6px; padding: 7px 12px; cursor: pointer; }
.bar-btn.on { background: var(--amber); }

.question-box { background: #fff; border-radius: var(--radius); padding: 20px; border: 1px solid #ddd; }
.topic-tag { display: inline-block; font-size: 0.8rem; font-weight: 700; color: var(--blue); background: var(--blue-light); padding: 3px 8px; border-radius: 4px; margin-bottom: 8px; }
.question-text { font-size: 1.25rem; font-weight: 700; margin: 0 0 12px; }
.sign { width: 150px; height: 150px; margin: 6px auto 14px; }
.sign svg { width: 100%; height: 100%; }
.instruction { font-weight: 700; color: var(--grey); margin: 6px 0 10px; }
.options { display: grid; gap: 10px; }
.option {
  font: inherit; text-align: left; display: flex; gap: 12px; align-items: flex-start; width: 100%;
  padding: 14px; background: #fff; border: 2px solid var(--line); border-radius: var(--radius); cursor: pointer;
}
.option:hover { border-color: var(--blue); }
.option .box { flex: 0 0 26px; height: 26px; border: 2px solid var(--grey); border-radius: 4px; display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.option.selected { border-color: var(--blue); background: var(--blue-light); }
.option.selected .box { background: var(--blue); border-color: var(--blue); color: #fff; }
.option.correct { border-color: var(--green); background: var(--green-light); }
.option.correct .box { background: var(--green); border-color: var(--green); color: #fff; }
.option.wrong { border-color: var(--red); background: var(--red-light); }
.option.wrong .box { background: var(--red); border-color: var(--red); color: #fff; }
.option[disabled] { cursor: default; color: inherit; opacity: 1; }
.feedback { margin-top: 14px; padding: 14px; border-radius: var(--radius); border-left: 6px solid; }
.feedback.good { background: var(--green-light); border-color: var(--green); }
.feedback.bad { background: var(--red-light); border-color: var(--red); }
.feedback strong { display: block; margin-bottom: 4px; }
.nav-row { display: flex; justify-content: space-between; gap: 12px; margin-top: 16px; }

/* Review grid */
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 0.9rem; margin: 8px 0 12px; }
.legend span::before { content: ''; display: inline-block; width: 14px; height: 14px; border-radius: 3px; margin-right: 6px; vertical-align: -2px; border: 2px solid var(--line); }
.legend .l-ans::before { background: var(--blue); border-color: var(--blue); }
.legend .l-flag::before { background: var(--amber); border-color: var(--amber); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 8px; }
.tile { font: inherit; font-weight: 700; padding: 10px 0; border-radius: 6px; border: 2px solid var(--line); background: #fff; cursor: pointer; position: relative; }
.tile.answered { background: var(--blue); border-color: var(--blue); color: #fff; }
.tile.flagged { box-shadow: inset 0 -6px 0 var(--amber); }
.tile.right { background: var(--green); border-color: var(--green); color: #fff; }
.tile.wrongt { background: var(--red); border-color: var(--red); color: #fff; }

/* Results */
.result-banner { border-radius: var(--radius); padding: 22px; color: #fff; text-align: center; }
.result-banner.pass { background: var(--green); }
.result-banner.fail { background: var(--red); }
.result-banner .big { font-size: 2.6rem; font-weight: 700; }
.review-item { background: #fff; border: 1px solid #ddd; border-left: 6px solid; border-radius: var(--radius); padding: 14px; margin-top: 10px; }
.review-item.ok { border-left-color: var(--green); }
.review-item.no { border-left-color: var(--red); }
.review-item .sign { width: 90px; height: 90px; margin: 6px 0; }
.review-item p { margin: 4px 0; }

/* Forms */
.check-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); gap: 6px 16px; }
.check-list label, .radio-row label { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.check-list input, .radio-row input { width: 20px; height: 20px; }
.radio-row { display: flex; gap: 18px; flex-wrap: wrap; }
table.history { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
table.history td, table.history th { padding: 6px 4px; border-bottom: 1px solid #eee; text-align: left; }

@media (max-width: 560px) {
  body { font-size: 16px; }
  .topic-row { grid-template-columns: 1fr 80px 44px; }
  .question-text { font-size: 1.1rem; }
  .sign { width: 120px; height: 120px; }
}

/* In-page dialog */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: #fff; border-radius: var(--radius); padding: 22px; max-width: 420px; width: 100%; box-shadow: 0 10px 30px rgba(0,0,0,0.3); }
.modal p { font-size: 1.1rem; margin: 0 0 6px; }
.modal .btn-row { justify-content: flex-end; }

/* Review answers page */
.verdict { display: inline-block; font-size: 0.8rem; font-weight: 700; padding: 3px 8px; border-radius: 4px; margin: 0 0 8px 6px; }
.verdict.good { background: var(--green-light); color: var(--green); }
.verdict.bad { background: var(--red-light); color: var(--red); }
div.option { cursor: default; }
div.option:hover { border-color: var(--line); }
div.option.correct:hover { border-color: var(--green); }
div.option.wrong:hover { border-color: var(--red); }
.opt-text { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.tag { font-size: 0.75rem; font-weight: 700; padding: 2px 7px; border-radius: 4px; color: #fff; }
.tag.mine { background: var(--grey); }
.tag.right { background: var(--green); }
.feedback strong + strong { margin-top: -2px; }
.tile.current { outline: 3px solid var(--navy); outline-offset: 2px; }
.tile[disabled] { opacity: 0.25; cursor: default; }
.legend .l-right::before { background: var(--green); border-color: var(--green); }
.legend .l-wrong::before { background: var(--red); border-color: var(--red); }

/* Topic breakdown with correct / incorrect split */
.topic-row { grid-template-columns: 1fr 120px 48px 96px; }
.topic-split { font-size: 0.85rem; white-space: nowrap; }
.topic-split .ok { color: var(--green); font-weight: 700; }
.topic-split .no { color: var(--red); font-weight: 700; margin-left: 6px; }
button.topic-btn { font: inherit; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid #eee; cursor: pointer; color: inherit; }
button.topic-btn:hover { background: var(--blue-light); }
.topic-select select { font: inherit; padding: 6px; border-radius: 6px; border: 1px solid var(--line); max-width: 100%; }
.topic-select { flex-wrap: wrap; }

/* History cards */
.history-card { border: 1px solid #ddd; border-radius: var(--radius); padding: 12px 14px; margin-top: 10px; }
.history-head { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.badge { font-size: 0.8rem; font-weight: 700; color: #fff; padding: 3px 8px; border-radius: 4px; }
.badge.pass { background: var(--green); }
.badge.fail { background: var(--red); }
.history-card details { margin-top: 8px; }
.history-card summary { cursor: pointer; font-weight: 700; color: var(--blue); }
.history-card .btn-row { margin-top: 10px; }

@media (max-width: 560px) {
  .topic-row { grid-template-columns: 1fr 60px 40px; }
  .topic-split { grid-column: 1 / -1; margin-top: -4px; }
}

/* App header with logo */
.app-header { display: flex; align-items: center; gap: 16px; margin: 4px 0 8px; }
.app-header .logo { width: 84px; height: 84px; flex: 0 0 auto; }
.app-header h1 { margin: 0; line-height: 1.15; }
@media (max-width: 560px) { .app-header .logo { width: 64px; height: 64px; } .app-header h1 { font-size: 1.45rem; } }

/* Login and account */
.login-wrap { max-width: 420px; margin: 24px auto; text-align: center; }
.login-logo { width: 120px; height: 120px; }
.login-wrap h1 { font-size: 1.5rem; }
.login-form { text-align: left; display: grid; gap: 12px; max-width: 420px; }
.login-form h2 { margin: 0; }
.login-form label { display: grid; gap: 4px; font-weight: 700; }
.login-form input { font: inherit; font-weight: 400; padding: 10px; border: 2px solid var(--line); border-radius: 6px; }
.login-form input:focus { outline: 3px solid #ffdd00; outline-offset: 0; border-color: var(--navy); }
.form-error { background: var(--red-light); border-left: 5px solid var(--red); padding: 8px 10px; margin: 0; }
.form-msg { background: var(--blue-light); border-left: 5px solid var(--blue); padding: 8px 10px; margin: 0; }
.switch { margin: 0; }
.link-btn { font: inherit; background: none; border: 0; padding: 0; color: var(--blue); text-decoration: underline; cursor: pointer; }
.small { font-size: 0.9rem; }
.user-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; background: #fff; border: 1px solid #ddd; border-radius: var(--radius); padding: 8px 12px; margin: 8px 0; font-size: 0.95rem; }
.user-bar .btn { margin-left: auto; }
.delete-btn { color: var(--red) !important; }

/* Admin page */
.badge.admin { background: var(--navy); }
.user-card p { margin: 4px 0 0; }
.admin-form { max-width: none; }
.login-form label.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.login-form label.check input { width: 20px; height: 20px; }
.modal-input { font: inherit; width: 100%; padding: 10px; border: 2px solid var(--line); border-radius: 6px; margin: 8px 0; }
.user-bar .btn.small { margin-left: 0; }
.user-bar .btn.secondary { margin-left: auto; }

/* Personal-use notice on the login page */
.use-notice { margin: 16px auto 0; padding: 10px 14px; max-width: 420px; background: #fff8e1; border: 1px solid #f4d27a; border-radius: var(--radius); font-size: 0.95rem; color: #4a3b00; }
