:root {
  --green: #3b4a2f; --green-2: #55683f; --khaki: #c9b98a; --sand: #f4f1e8;
  --bg: #f4f1e8; --card: #fff; --text: #1d2118; --muted: #6b6f63; --line: #ddd8c8;
  --red: #b3261e; --pass: #2e7d32; --fail: #b3261e; --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #171a14; --card: #22261d; --text: #ecebe4; --muted: #a3a697; --line: #3a3f32; --sand: #2a2e24; }
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); line-height: 1.45; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1rem; margin-top: 1.4em; }
.muted { color: var(--muted); font-weight: normal; }
.err { color: var(--red); min-height: 1em; margin: 0; }
.center { text-align: center; }
[hidden] { display: none !important; }

.bar { background: var(--green); color: #fff; display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; gap: 12px; position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--khaki); color: var(--green); font-weight: 800; font-size: .75rem; letter-spacing: .08em; padding: 4px 7px; border-radius: 6px; }
.who { display: flex; align-items: center; gap: 10px; font-size: .9rem; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 16px; }
.narrow { max-width: 560px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.grid2 .card { margin-bottom: 0; } .grid2 { margin-bottom: 16px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.wrapr { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 4px; }

label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; font-weight: 600; }
label.check { flex-direction: row; align-items: center; font-weight: 500; }
input, select, textarea { font: inherit; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--text); width: 100%; }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--green); transform: scale(1.3); }
input.short { width: 110px; }
textarea { resize: vertical; }
.row input:not([type]), .row input[type=text] { flex: 1; }

.btn { font: inherit; font-weight: 600; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--sand); color: var(--text); cursor: pointer; text-decoration: none; display: inline-block; white-space: nowrap; }
.btn:hover { filter: brightness(.96); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { color: var(--red); }
.btn.small { padding: 5px 9px; font-size: .82rem; }
.btn.big { padding: 14px 20px; font-size: 1.05rem; flex: 1; }
.btn:disabled { opacity: .45; cursor: default; }
.bar .btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }

.tabs { display: flex; gap: 4px; margin-bottom: 16px; overflow-x: auto; }
.tabs button { font: inherit; font-weight: 600; background: none; border: 0; padding: 10px 16px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.tabs button.active { background: var(--card); color: var(--green); border: 1px solid var(--line); }
@media (prefers-color-scheme: dark) { .tabs button.active { color: var(--khaki); } }

.list { list-style: none; padding: 0; margin: 12px 0; }
.list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }

.qrgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.qrcard { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; position: relative; }
.qrcard.closed { opacity: .55; }
.qrcard .qr { background: #fff; border-radius: 8px; padding: 6px; }
.qrcard .qr svg { width: 100%; height: auto; display: block; }
.link { font-size: .75rem; word-break: break-all; color: var(--muted); }
.tag { display: inline-block; font-size: .78rem; font-weight: 700; padding: 3px 8px; border-radius: 99px; background: var(--sand); }
.qrcard > .tag { position: absolute; top: 10px; right: 10px; }
.tag.pass { background: #e3f1e4; color: var(--pass); } .tag.fail { background: #fbe6e4; color: var(--fail); }

.qedit { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 8px; }
.qedit > .row { align-items: flex-start; }
.qn { min-width: 30px; padding-top: 8px; }
.optrow { padding-left: 38px; align-items: center; }
.qedit > [data-addo] { align-self: flex-start; margin-left: 38px; }
.example { background: var(--sand); padding: 10px; border-radius: 8px; font-size: .85rem; white-space: pre-wrap; margin: 0; }
.sticky { position: sticky; bottom: 0; background: var(--card); padding-top: 12px; margin-top: 12px; border-top: 1px solid var(--line); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin: 12px 0; }
.stats div { background: var(--sand); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; }
.stats b { font-size: 1.5rem; }
.stats span { color: var(--muted); font-size: .85rem; }
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }

dialog { border: 0; border-radius: var(--radius); max-width: 640px; width: calc(100% - 32px); background: var(--card); color: var(--text); padding: 20px; }
dialog::backdrop { background: rgba(0,0,0,.5); }
.review { padding: 10px; border-radius: 8px; margin: 8px 0; border-left: 4px solid; }
.review.ok { border-color: var(--pass); background: rgba(46,125,50,.08); }
.review.bad { border-color: var(--fail); background: rgba(179,38,30,.08); }

/* Cadet test page */
.take .card h2 { font-size: 1.25rem; }
.opts { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.opt { font: inherit; text-align: left; display: flex; gap: 12px; align-items: center; padding: 14px; border: 2px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text); cursor: pointer; }
.opt span { flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--sand); display: grid; place-items: center; font-weight: 700; }
.opt.sel { border-color: var(--green); background: rgba(59,74,47,.08); }
.opt.sel span { background: var(--green); color: #fff; }
.progress { height: 6px; background: var(--line); border-radius: 99px; margin-bottom: 14px; overflow: hidden; }
.progress div { height: 100%; background: var(--green-2); transition: width .2s; }
.dots { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 16px; justify-content: center; }
.dots button { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-size: .8rem; cursor: pointer; }
.dots button.ans { background: var(--sand); font-weight: 700; }
.dots button.cur { outline: 2px solid var(--green); }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; background: rgba(255,255,255,.15); padding: 4px 10px; border-radius: 8px; }
.timer.low { background: var(--red); }
.bigscore { font-size: 4rem; font-weight: 800; margin: 10px 0; }
.bigscore.pass { color: var(--pass); } .bigscore.fail { color: var(--fail); }

/* roles, archive */
body.detachment [data-admin] { display: none !important; }
.seg { display: inline-flex; background: var(--sand); border-radius: 9px; padding: 3px; }
.seg button { font: inherit; font-weight: 600; border: 0; background: none; padding: 6px 14px; border-radius: 7px; cursor: pointer; color: var(--muted); }
.seg button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.filters { margin-top: 12px; }
.bulkbar { margin-bottom: 8px; }
.rolepill { font-size: .75rem; font-weight: 700; padding: 2px 7px; border-radius: 99px; background: var(--sand); color: var(--muted); margin-left: 6px; }
.filters select { width: auto; min-width: 200px; flex: 0 1 auto; }

.brand .logo { width: 30px; height: 30px; flex: none; display: block; }

/* iPhone / iPad: keep content clear of the notch, Dynamic Island and home bar */
.bar { padding-top: calc(10px + env(safe-area-inset-top)); padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
body { padding-bottom: env(safe-area-inset-bottom); }
/* stop iOS zooming into inputs (needs 16px+) and tidy tap highlights */
input, select, textarea { font-size: max(16px, 1em); }
button, .btn, .opt { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

/* ---------- phones (iPhone portrait) ---------- */
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green-2); outline-offset: 1px; }
.brand span:last-child { white-space: nowrap; }
.rolepill { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; display: inline-block; }
@media (max-width: 640px) {
  .whoname { display: none; }
  .rolepill { max-width: 150px; }
  .wrap { padding: 12px; }
  .card { padding: 14px; }
  .tabs button { padding: 9px 12px; }
  .filters select { min-width: 0; flex: 1; }
  .bulkbar .btn { flex: 1; text-align: center; }
  /* results as cards */
  #resTable thead { display: none; }
  #resTable, #resTable tbody { display: block; }
  #resTable tr { display: grid; grid-template-columns: 28px 1fr auto; grid-template-areas: "sel name score" "sel test test" "sel when when" "sel det det" "sel act act";
    column-gap: 10px; row-gap: 3px; border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; background: var(--card); }
  #resTable td { border: 0; padding: 0; white-space: normal; }
  #resTable td[colspan] { grid-column: 1 / -1; }
  .c-sel { grid-area: sel; padding-top: 2px !important; } .c-name { grid-area: name; font-weight: 700; }
  .c-score { grid-area: score; } .c-test { grid-area: test; } .c-when { grid-area: when; color: var(--muted); font-size: .85rem; }
  .c-det { grid-area: det; color: var(--muted); font-size: .85rem; } .c-act { grid-area: act; padding-top: 6px !important; }
  .qrgrid { grid-template-columns: 1fr; }
}
@media (max-width: 440px) { .brand .long { display: none; } }

/* ---------- top banners (like the testing sheets site) ---------- */
#topbanners { position: relative; z-index: 6; }
.updbanner { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 10px 18px;
  background: #2b2d2a; color: #f1efe8; font-size: .95rem; text-align: center;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top)); }
.updbanner b { font-weight: 800; }
.upd-reload { font: inherit; font-weight: 700; font-size: .9rem; color: #fff; background: transparent; border: 1.5px solid #f1efe8;
  padding: 7px 14px; cursor: pointer; }
.upd-reload:hover { background: #f1efe8; color: #2b2d2a; }
.updbanner a { color: #fff; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.devbanner { background: repeating-linear-gradient(135deg, #e8a33d 0 14px, #d9912a 14px 28px); color: #1d1406; font-weight: 800; font-size: .8rem;
  letter-spacing: .06em; text-align: center; padding: 6px 12px; }
#topbanners > .devbanner:first-child { padding-top: calc(6px + env(safe-area-inset-top)); }
#topbanners + .bar { padding-top: 10px; }

.verfoot { text-align: center; font-size: .78rem; color: var(--muted); padding: 18px 16px 26px; }
.verfoot a { color: var(--green-2); font-weight: 700; }

/* ---------- What's new page (like the testing sheets site) ---------- */
.clpage { --accent: #55683f; }
@media (prefers-color-scheme: dark) { .clpage { --accent: #c9b98a; } }
.clpanel { max-width: 1100px; margin: 28px auto 0; padding: 40px 56px 50px; background: var(--card); border: 1px solid var(--line); }
.clback { display: inline-block; color: var(--muted); font-weight: 700; text-decoration: none; margin-bottom: 18px; }
.clback:hover { color: var(--text); }
.clkick { font-weight: 800; letter-spacing: .16em; font-size: .9rem; color: var(--accent); }
.clh1 { font-size: clamp(2.6rem, 7vw, 4rem); font-weight: 900; text-transform: uppercase; letter-spacing: -.01em; line-height: 1; margin: 10px 0 18px; }
.clrule { height: 5px; background: var(--accent); margin-bottom: 8px; }
.clv { padding: 24px 0 22px; border-bottom: 1px solid var(--line); }
.clv:last-child { border-bottom: 0; }
.clv.current { border-left: 5px solid var(--accent); padding-left: 26px; margin-top: 12px; }
.clv h2 { font-size: 1.9rem; font-weight: 800; margin: 0; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.clbadge { font-size: .75rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; border: 1.5px solid var(--accent);
  color: var(--text); padding: 4px 10px; }
.cldate { color: var(--muted); margin: 6px 0 10px; }
.clv ul { margin: 0; padding-left: 22px; }
.clv li { font-size: 1.12rem; line-height: 1.55; margin: 6px 0; }
@media (max-width: 640px) {
  .clpanel { margin: 0; padding: 24px 18px 34px; border-left: 0; border-right: 0; }
  .clv.current { padding-left: 16px; }
  .clv h2 { font-size: 1.5rem; } .clv li { font-size: 1rem; }
}
