:root {
  --bg: #f1efec;
  --panel: #ffffff;
  --ink: #1e2226;
  --muted: #6d7278;
  --line: #e2dfd9;
  --brand: #3c4654;       /* raccoon slate-grey fur */
  --brand-dark: #252c36;  /* charcoal mask */
  --accent: #b1773f;      /* warm raccoon tan */
  --accent-soft: #f6ecdf;
  --accent-line: #e7d2b4;
  --good: #2f8f6b;
  --shadow: 0 1px 3px rgba(30, 25, 20, .08), 0 6px 18px rgba(30, 25, 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); }
i { color: var(--brand-dark); font-style: italic; }

.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 12px 24px; background: var(--brand-dark);
  border-bottom: 3px solid var(--accent); position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 800; color: #fff; font-size: 19px; letter-spacing: .2px;
  display: flex; align-items: center; gap: 8px; }
.brand:hover { text-decoration: none; color: #fff; }
.brand-mark { width: 26px; height: 26px; display: block; }
.searchbar { flex: 1; display: flex; gap: 8px; max-width: 680px; }
.searchbar input { flex: 1; padding: 9px 12px; border: 1px solid var(--brand);
  border-radius: 8px; font-size: 14px; background: #fff; }
.searchbar button, .filters button {
  padding: 9px 16px; border: 0; border-radius: 8px; background: var(--accent);
  color: #fff; font-weight: 600; cursor: pointer; }
.searchbar button:hover, .filters button:hover { background: #976127; }

.topnav { display: flex; align-items: center; gap: 14px; }
.navlink { color: #e9e6e1; font-weight: 600; font-size: 14px; padding: 6px 12px;
  border: 1px solid rgba(255, 255, 255, .25); border-radius: 8px; }
.navlink:hover { text-decoration: none; background: rgba(255, 255, 255, .12); color: #fff; }

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

.hero h1 { font-size: 32px; margin: 6px 0; display: flex; align-items: center; gap: 12px; }
.hero-mark { width: 38px; height: 38px; display: block; }
.next-random { margin-left: auto; }
.btn.small { padding: 5px 12px; font-size: 13px; }
.list-nav { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.lead { color: var(--muted); max-width: 720px; font-size: 16px; }
.statline { color: var(--muted); margin-top: 10px; }
.statline b { color: var(--brand-dark); }
.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; }

.results-head h1 { font-size: 22px; margin-bottom: 8px; }
.empty { color: var(--muted); padding: 30px 0; }
.notice { background: var(--accent-soft); border: 1px solid var(--accent-line); color: #7a5417;
  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: 380px; overflow: hidden; }
.row-q img { width: 100%; display: block; }
.row-mid { flex: 0 0 156px; display: flex; flex-direction: column; gap: 8px;
  padding: 14px; border-left: 1px solid var(--line); border-right: 1px solid var(--line);
  background: #faf9f7; }
.row-meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.row-ms { flex: 1 1 0; min-width: 0; padding: 12px; background: #faf9f7; }
.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: #eef0f3; }
.btn.block { width: 100%; }
.btn.active { background: var(--brand-dark); }

/* Single question page: question left, controls and reveals right */
.qpage-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.qpage-head h1 { margin: 0; font-size: 24px; }
.back { font-size: 13px; }
.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; }
.ms-img { border: 1px solid var(--line); border-radius: 6px; margin-bottom: 10px; }
.control-block { margin-bottom: 6px; }
.reveal { margin-top: 12px; }
.reveal[hidden] { display: none; }

/* Similar questions (precomputed nearest neighbours) */
.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(--accent); 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; }

/* "The whole den" question browser: a striped raccoon-tail band per paper, then the
   questions grouped into per-session stashes of little tiles. */
.browse h1 { font-size: 26px; margin-bottom: 4px; }
.den-block { margin: 22px 0 8px; border: 1px solid var(--line); border-radius: 14px;
  overflow: hidden; box-shadow: var(--shadow); background: var(--panel); }
.den-band { display: flex; align-items: center; gap: 12px; padding: 14px 18px; color: #fff;
  /* ringtail stripes */
  background:
    repeating-linear-gradient(115deg, var(--brand-dark) 0 22px, var(--brand) 22px 44px); }
.paper2 .den-band {
  background:
    repeating-linear-gradient(115deg, #5a3a17 0 22px, var(--accent) 22px 44px); }
.den-paper { font-weight: 800; font-size: 18px; background: rgba(0, 0, 0, .28);
  padding: 4px 12px; border-radius: 8px; }
.den-name { font-weight: 600; font-size: 15px; }
.den-count { margin-left: auto; font-size: 13px; opacity: .9; background: rgba(0, 0, 0, .22);
  padding: 3px 11px; border-radius: 999px; }
.stash-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px; padding: 16px 18px; }
.stash-label { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .02em;
  text-transform: uppercase; margin-bottom: 8px; }
.tile-row { display: flex; flex-wrap: wrap; gap: 6px; }
.qtile { width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
  border-radius: 9px; font-weight: 700; font-size: 14px; color: #fff; background: var(--brand);
  transition: transform .06s, background .1s; }
.qtile:hover { text-decoration: none; transform: translateY(-2px) scale(1.06); background: var(--brand-dark); }
.paper2 .qtile { background: var(--accent); }
.paper2 .qtile:hover { background: #8f5d27; }

/* ------------------------------- test maker ------------------------------- */
.badge { font-size: 12px; padding: 2px 9px; border-radius: 999px; font-weight: 600; }
.badge.on { background: #e3f1ea; color: var(--good); }
.active-test { background: var(--accent-soft); color: #7a5417; padding: 5px 12px; border-radius: 999px;
  font-size: 13px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn.tiny { padding: 4px 10px; font-size: 12px; }
.btn.done { background: var(--good); border-color: var(--good); }
.btn.danger { border-color: #b03029; color: #b03029; background: #fff; }
.spacer { flex: 1; }

.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; }

.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-dark); 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; flex-wrap: wrap; }
.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; }

/* Crop / white-out modal */
.modal { position: fixed; inset: 0; background: rgba(20, 18, 14, .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(60, 70, 84, .12); }
.sel-box.erase { border: 1px dashed #888; background: rgba(255, 255, 255, .92); }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; }

@media (max-width: 820px) {
  .item { flex-direction: column; }
  .item-thumb { flex: none; width: 100%; }
}

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