:root {
  --bg: #f6f4f4;
  --panel: #ffffff;
  --ink: #211a1a;
  --muted: #7a6f6f;
  --line: #e9e0e0;
  --brand: #c0271f;
  --brand-dark: #9a1c16;
  --agree: #1f9d57;
  --disagree: #c0271f;
  --shadow: 0 1px 3px rgba(60, 20, 20, .08), 0 6px 18px rgba(60, 20, 20, .06);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  color: var(--ink); background: var(--bg); line-height: 1.5;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { color: var(--ink); }

.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 12px 24px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 800; color: var(--brand); font-size: 18px; letter-spacing: .2px; }
.brand:hover { text-decoration: none; }
.searchbar { flex: 1; display: flex; gap: 8px; max-width: 640px; }
.searchbar input { flex: 1; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 14px; }

button, .btn, .bigbutton { font-family: inherit; }
.searchbar button, .filters button {
  padding: 9px 16px; border: 0; border-radius: 8px; background: var(--brand);
  color: #fff; font-weight: 600; cursor: pointer; }
.searchbar button:hover, .filters button:hover { background: var(--brand-dark); }

main { max-width: 1100px; margin: 0 auto; padding: 24px; }

.hero h1 { font-size: 30px; margin: 6px 0; }
.lead { color: var(--muted); max-width: 680px; font-size: 16px; }
.statline { color: var(--muted); margin-top: 10px; }
.statline b { color: var(--brand); }
.statline span { color: var(--line); margin: 0 4px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 20px; margin: 18px 0; box-shadow: var(--shadow); }
.panel h2 { margin: 0 0 14px; font-size: 18px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 4px; }
.filters select { padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 14px; background: #fff; }

.bigbutton { display: inline-block; background: var(--brand); color: #fff; padding: 11px 22px;
  border-radius: 8px; font-weight: 600; }
.bigbutton:hover { background: var(--brand-dark); text-decoration: none; }

.results-head h1 { font-size: 22px; margin-bottom: 8px; }
.empty { color: var(--muted); padding: 30px 0; }
.notice { background: #fff7e6; border: 1px solid #f0d99b; color: #7a5b00;
  padding: 9px 14px; border-radius: 8px; font-size: 14px; margin: 6px 0 4px; }

/* Search results: question on the left, buttons in the middle, mark scheme on the right */
.rows { display: flex; flex-direction: column; gap: 14px; margin-top: 14px; }
.row { background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); display: flex; align-items: stretch; overflow: hidden; }
.row-q { flex: 1 1 0; min-width: 0; padding: 12px; max-height: 360px; overflow: hidden; }
.row-q img { width: 100%; display: block; }
.row-mid { flex: 0 0 150px; display: flex; flex-direction: column; gap: 8px;
  padding: 14px; border-left: 1px solid var(--line); border-right: 1px solid var(--line);
  background: #fbf8f8; }
.row-meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.row-ms { flex: 1 1 0; min-width: 0; padding: 12px; background: #fbf8f8; }
.row-ms[hidden] { display: none; }
.row-ms img { width: 100%; display: block; }

.btn { padding: 8px 14px; border: 1px solid var(--brand); background: var(--brand); color: #fff;
  border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 14px; text-align: center; }
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn.ghost { background: #fff; color: var(--brand); }
.btn.ghost:hover { background: #fdeeee; }
.btn.block { width: 100%; }
.btn.active { background: var(--brand-dark); }
.btn.tiny { padding: 4px 10px; font-size: 12px; }

/* Single question page: question left, controls and reveals right */
.qpage-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.qpage-head h1 { margin: 0; font-size: 24px; }
.back { font-size: 13px; }
.topic-tag { background: #fdeeee; color: var(--brand-dark); padding: 3px 10px; border-radius: 999px; font-size: 12px; }
.qcols { display: grid; grid-template-columns: 1.1fr 1fr; gap: 18px; align-items: start; }
.qcol-left, .qcol-right { background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.bigimg { width: 100%; display: block; margin: 0 auto; }
.control-block { margin-bottom: 18px; }
.control-block h3 { margin: 4px 0 10px; font-size: 16px; }
.reveal { margin-top: 12px; }
.reveal[hidden] { display: none; }

.generator { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.generator select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }

.solution { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin: 10px 0; }
.solution.human_checked { border-color: var(--agree); }
.sol-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.sol-body { white-space: pre-wrap; font-size: 15px; }
.final-answer { margin-top: 10px; padding: 10px 14px; background: #fdeeee;
  border: 1px solid #f3c9c6; border-radius: 8px; font-size: 16px; font-weight: 600; }
.final-answer span { display: block; font-size: 11px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--brand-dark); margin-bottom: 2px; }
.check-note { margin-top: 8px; }
.next-random { margin-left: auto; }

/* Top nav and active test */
.topnav { display: flex; align-items: center; gap: 14px; }
.topnav a { font-weight: 600; font-size: 14px; }
.active-test { background: #fdeeee; color: var(--brand-dark); padding: 5px 12px; border-radius: 999px;
  font-size: 13px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn.done { background: var(--agree); border-color: var(--agree); }

/* Tests list */
.newtest { display: flex; gap: 8px; }
.newtest input { flex: 1; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.tests-table { width: 100%; border-collapse: collapse; }
.tests-table th, .tests-table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); font-size: 14px; }
.tests-table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.row-actions { display: flex; gap: 6px; }
.btn.danger { border-color: #b03029; color: #b03029; background: #fff; }
.spacer { flex: 1; }

/* Test editor */
.itemlist { display: flex; flex-direction: column; gap: 12px; }
.item { display: flex; gap: 14px; align-items: flex-start; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; box-shadow: var(--shadow); }
.item-rank { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 40px; }
.item-rank .num { font-weight: 800; color: var(--brand); font-size: 18px; }
.mv { border: 1px solid var(--line); background: #fff; border-radius: 6px; cursor: pointer;
  width: 30px; height: 24px; line-height: 1; color: var(--muted); }
.mv:hover { color: var(--brand); border-color: var(--brand); }
.item-thumb { flex: 0 0 280px; max-height: 200px; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; }
.item-thumb img { width: 100%; display: block; }
.item-info { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.ms-toggle { font-size: 13px; color: var(--ink); display: flex; align-items: center; gap: 6px; }
.item-buttons { display: flex; gap: 8px; align-items: center; }

/* Crop modal */
.modal { position: fixed; inset: 0; background: rgba(20, 10, 10, .55); display: flex;
  align-items: center; justify-content: center; z-index: 50; }
.modal[hidden] { display: none; }
.modal-box { background: #fff; border-radius: 12px; padding: 20px; max-width: 760px; width: 92%; max-height: 90vh; overflow: auto; }
.modal-box h3 { margin: 0 0 6px; }
.crop-stage { position: relative; display: inline-block; max-width: 100%; cursor: crosshair; user-select: none; }
.crop-stage img { max-width: 100%; display: block; }
.sel-box { position: absolute; box-sizing: border-box; }
.sel-box.keep { border: 2px solid var(--brand); background: rgba(192, 39, 31, .10); }
.sel-box.erase { border: 1px dashed #888; background: rgba(255, 255, 255, .92); }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; }
.item-move { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.item-move select { padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; font-size: 12px; max-width: 200px; }

.list-nav { display: flex; align-items: center; gap: 10px; margin-left: auto; }

/* Similar questions (precomputed nearest neighbours) */
.similar { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.similar h3 { margin: 0 0 10px; font-size: 15px; }
.similar-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.similar-card { display: flex; flex-direction: column; gap: 4px; border: 1px solid var(--line);
  border-radius: 8px; padding: 6px; background: #fff; overflow: hidden; }
.similar-card:hover { border-color: var(--brand); text-decoration: none; }
.similar-card img { width: 100%; height: 110px; object-fit: cover; object-position: top;
  border-radius: 4px; display: block; }

/* Beehive question browser (pointy-top hexagons in interlocking rows) */
.browse h1 { font-size: 24px; margin-bottom: 4px; }
.hive-block { margin: 18px 0 28px; }
.hive-block h2 { font-size: 18px; margin-bottom: 8px; }
.hive { overflow-x: auto; padding-bottom: 6px; }
.hexrow { display: flex; }
.hexrow:nth-child(even) { margin-left: 23px; }
.hexrow + .hexrow { margin-top: -13px; }
.hex { width: 46px; height: 52px; flex: 0 0 auto;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 12px; font-weight: 700; margin-right: 2px;
  transition: transform .06s; }
.hex:hover { text-decoration: none; transform: scale(1.12); z-index: 2; position: relative; }
.hive-core .hex { background: #c0271f; }
.hive-core .hex:hover { background: #e23b30; }
.hive-extended .hex { background: #b8860b; }
.hive-extended .hex:hover { background: #d4a017; }
.hex span { pointer-events: none; }

@media (max-width: 820px) {
  .item { flex-direction: column; }
  .item-thumb { flex: none; width: 100%; }
}
.badge { font-size: 12px; padding: 2px 9px; border-radius: 999px; font-weight: 600; }
.badge.draft { background: #f3eaea; color: var(--muted); }
.badge.human_checked { background: #e6f6ec; color: var(--agree); }
.badge.agree { background: #e6f6ec; color: var(--agree); }
.badge.disagree { background: #fdeaea; color: var(--disagree); }
.badge.task { background: #e7f3ee; color: #18794e; }
.badge.test { background: #fef3d6; color: #8a6100; }

/* Book tab: a honey accent to set it apart from the red past-paper bank */
:root { --honey: #e0a712; --honey-dark: #b8860b; }
.book-tab { border-color: var(--honey-dark) !important; color: var(--honey-dark) !important; }
.book-tab:hover { background: #fdf6e3 !important; }
.book-hero h1 { color: var(--honey-dark); }
.book-search { display: flex; gap: 8px; flex-wrap: wrap; }
.book-search input { flex: 1; min-width: 220px; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 14px; }
.book-search select { padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; background: #fff; }
.book-search button { padding: 9px 16px; border: 0; border-radius: 8px; background: var(--honey-dark);
  color: #fff; font-weight: 600; cursor: pointer; }
.book-search button:hover { background: #8a6100; }
.unit-list { display: flex; flex-wrap: wrap; gap: 8px; }

/* Cool chapter cards: numbered honeycomb-style tiles */
.chapter-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.chapter-card { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 12px;
  background: linear-gradient(135deg, #fffdf6, #fdf3da); border: 1px solid #efdfae; color: var(--ink);
  transition: transform .1s, box-shadow .1s, border-color .1s; }
.chapter-card:hover { text-decoration: none; transform: translateY(-3px); border-color: var(--honey-dark);
  box-shadow: 0 6px 18px rgba(184, 134, 11, .18); }
.chapter-num { flex: 0 0 auto; width: 44px; height: 50px; display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 20px; color: #fff; background: var(--honey-dark);
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%); }
.chapter-info { display: flex; flex-direction: column; min-width: 0; }
.chapter-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chapter-count { font-size: 12px; color: var(--muted); }
.chap-num { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px;
  font-size: 14px; font-weight: 800; color: #fff; background: var(--honey-dark); border-radius: 8px;
  margin-right: 8px; vertical-align: middle; }
.unit-pill { display: inline-flex; align-items: center; gap: 8px; background: #fff;
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 11px; font-size: 13px; color: var(--ink); }
.unit-pill:hover { border-color: var(--honey-dark); text-decoration: none; }

.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-top: 14px; }
.book-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); overflow: hidden; color: var(--ink); }
.book-card:hover { border-color: var(--honey-dark); text-decoration: none; }
.book-thumb { height: 160px; overflow: hidden; border-bottom: 1px solid var(--line); }
.book-thumb img { width: 100%; display: block; object-fit: cover; object-position: top; }
.book-card-meta { display: flex; align-items: center; gap: 8px; padding: 10px 12px; font-size: 14px; }
.badge.book-exercise { background: #e7f3ee; color: #18794e; }
.badge.book-exam { background: #fef3d6; color: #8a6100; }
.badge.book-revision { background: #e8eefc; color: #2952cc; }

/* On-the-spot task isolation */
.isolate-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.isolate-stage { position: relative; display: inline-block; width: 100%; user-select: none; }
.isolate-stage:not(.locked) { cursor: crosshair; }
.isolate-stage img { width: 100%; display: block; }
#suggestLayer[hidden] { display: none; }
.suggest-box { position: absolute; box-sizing: border-box; border: 2px dashed var(--honey-dark);
  background: rgba(224, 167, 18, .10); border-radius: 4px; cursor: pointer; transition: background .1s; }
.suggest-box:hover { background: rgba(224, 167, 18, .24); }
.suggest-box.added { border-style: solid; border-color: var(--agree); background: rgba(31, 157, 87, .14); cursor: default; }
.suggest-box.saving { opacity: .5; }
.suggest-tag { position: absolute; top: -10px; left: -2px; background: var(--honey-dark); color: #fff;
  font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; }
.suggest-box.added .suggest-tag { background: var(--agree); }
.draw-box { position: absolute; box-sizing: border-box; border: 2px solid var(--brand);
  background: rgba(192, 39, 31, .10); }

.task-card { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 10px; background: #fff; }
.task-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.task-head b { margin-right: auto; }
.task-img { width: 100%; display: block; border: 1px solid var(--line); border-radius: 6px; }
.task-answer { margin-top: 8px; padding: 8px 12px; background: #fdf6e3; border: 1px solid #eed999;
  border-radius: 8px; font-size: 15px; }
.task-answer[hidden] { display: none; }
.task-answer > span { display: block; font-size: 11px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: #8a6100; margin-bottom: 6px; }
.task-answer img { width: 100%; display: block; border: 1px solid #eed999; border-radius: 6px;
  max-height: 460px; object-fit: contain; background: #fff; }
.task-answer a { display: inline-block; margin-top: 6px; }
.task-model-row { display: flex; align-items: center; gap: 8px; margin: 4px 0 12px; flex-wrap: wrap; }
.task-model-row select { padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
.task-solve { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
.tsolutions:empty { display: none; }

/* Full-width recommendation rows (similar questions / sections) with bigger boxes */
.cross-block { margin-top: 26px; border-top: 1px solid var(--line); padding-top: 16px; }
.cross-block h2 { font-size: 19px; margin: 0 0 4px; }
.big-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 12px; }
.big-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); overflow: hidden; color: var(--ink); }
.big-card:hover { border-color: var(--brand); text-decoration: none; transform: translateY(-2px);
  transition: transform .08s; }
.big-thumb { height: 240px; overflow: hidden; border-bottom: 1px solid var(--line); background: #fff; }
.big-thumb img { width: 100%; display: block; object-fit: cover; object-position: top; }
.big-meta { padding: 12px 14px; font-size: 14px; font-weight: 600; }
@media (max-width: 820px) { .big-grid { grid-template-columns: 1fr; } }

@media (max-width: 820px) {
  .qcols { grid-template-columns: 1fr; }
  .row { flex-direction: column; }
  .row-mid { flex-direction: row; flex-wrap: wrap; border: 0; border-top: 1px solid var(--line); }
}
