:root {
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --border: #dcdfe4;
  --border-strong: #b9bec7;
  --text: #1c2430;
  --muted: #5f6b7a;
  --accent: #1f4e8c;
  --accent-hover: #183f72;
  --accent-soft: #eaf1fb;
  --ok: #1d7a46;
  --ok-soft: #e8f5ee;
  --bad: #b42318;
  --bad-soft: #fdecea;
  --warn: #9a6700;
  --radius: 6px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--accent); }

.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.brand { font-weight: 600; font-size: 16px; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.container { max-width: 1100px; margin: 0 auto; padding: 24px 16px 48px; }
.narrow { max-width: 520px; }

h1 { font-size: 22px; font-weight: 600; margin: 0 0 16px; }
h2 { font-size: 18px; font-weight: 600; margin: 0 0 12px; }

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  background: var(--bg);
}
.card + .card { margin-top: 16px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-soft); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { color: var(--bad); border-color: #e3b4ae; }
.btn-danger:hover { background: var(--bad-soft); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-lg { padding: 12px 22px; font-size: 16px; }
.btn-link { border: none; background: none; color: var(--accent); padding: 4px 6px; }
.btn-link:hover { background: none; text-decoration: underline; }

input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  font: inherit;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible {
  outline: 2px solid var(--accent-soft);
  outline-offset: 0;
  border-color: var(--accent);
}
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

.alert { padding: 10px 14px; border-radius: var(--radius); border: 1px solid; margin: 12px 0; }
.alert-error { background: var(--bad-soft); border-color: #f1c0ba; color: var(--bad); }
.alert-info { background: var(--accent-soft); border-color: #c9daf3; color: var(--accent); }
.hidden { display: none !important; }

.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .grid2 { grid-template-columns: 1fr; } }

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--muted);
  white-space: nowrap;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); border-color: #b9dfc9; }
.badge-bad { background: var(--bad-soft); color: var(--bad); border-color: #f1c0ba; }
.badge-accent { background: var(--accent-soft); color: var(--accent); border-color: #c9daf3; }

table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: 13px; font-weight: 600; color: var(--muted); background: var(--bg-soft); }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: var(--bg-soft); }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.table-wrap .table tr:last-child td { border-bottom: none; }

.pre { white-space: pre-wrap; }

/* modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 28, 40, .45);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px;
}
.modal { background: #fff; border-radius: var(--radius); max-width: 460px; width: 100%; padding: 22px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.lightbox { max-width: 95vw; max-height: 92vh; background: #fff; padding: 8px; border-radius: var(--radius); }
.lightbox img { max-width: 100%; max-height: 88vh; display: block; }

/* question images */
.q-images { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }
.q-images img {
  max-width: 100%; max-height: 360px; border: 1px solid var(--border); border-radius: 4px; cursor: zoom-in;
}
.opt-images img { max-height: 160px; }

/* exam */
.exam-layout { display: grid; grid-template-columns: 1fr 260px; gap: 20px; align-items: start; }
@media (max-width: 860px) { .exam-layout { grid-template-columns: 1fr; } .exam-side { order: -1; } }
.timer { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 18px; }
.timer.low { color: var(--bad); }
.q-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.q-text { font-size: 16px; white-space: pre-wrap; }
.options { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.option {
  display: flex; gap: 12px; align-items: flex-start; text-align: left;
  border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px;
  cursor: pointer; background: #fff; font: inherit; color: inherit; width: 100%;
}
.option:hover { border-color: var(--border-strong); background: var(--bg-soft); }
.option.selected { border-color: var(--accent); background: var(--accent-soft); }
.option .letter {
  flex: 0 0 26px; height: 26px; border-radius: 50%; border: 1px solid var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px;
}
.option.selected .letter { background: var(--accent); border-color: var(--accent); color: #fff; }
.option .opt-body { white-space: pre-wrap; padding-top: 1px; }
.nav-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 6px; }
.nav-cell {
  height: 34px; border: 1px solid var(--border); border-radius: 4px; background: #fff; cursor: pointer;
  font: inherit; font-size: 13px; color: var(--text);
}
.nav-cell.answered { background: var(--accent-soft); border-color: #a9c3e8; }
.nav-cell.current { outline: 2px solid var(--accent); outline-offset: -1px; font-weight: 600; }
.exam-footer { display: flex; justify-content: space-between; margin-top: 20px; gap: 8px; }

.result-score { font-size: 40px; font-weight: 600; margin: 8px 0; font-variant-numeric: tabular-nums; }

/* admin editor */
.editor-col { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.opt-edit { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 10px; }
.opt-edit.correct { background: var(--ok-soft); border-radius: 4px; padding: 10px; border-top-color: transparent; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.thumb { position: relative; border: 1px solid var(--border); border-radius: 4px; padding: 2px; }
.thumb img { height: 70px; display: block; }
.thumb button {
  position: absolute; top: -8px; right: -8px; width: 20px; height: 20px; border-radius: 50%;
  border: 1px solid var(--border-strong); background: #fff; cursor: pointer; font-size: 12px; line-height: 1; padding: 0;
}
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff;
  padding: 10px 16px; border-radius: var(--radius); z-index: 200; font-size: 14px;
}
