/* Palette is lifted from the answer sheet: black print, drop-out red rules,
   pale pink tint. The interface should feel like the paper it reads. */
:root {
  --ink: #000;
  --ink-2: #4a4d55;
  --ink-3: #82868f;
  --paper: #fff;
  --surface: #f1f2f5;
  --rule: #d9dbe1;
  --red: #e63946;
  --pink: #fce5e5;
  --green: #157a4a;
  --amber: #b5770a;
  --focus: #1b4fd8;

  --bn: "Hind Siliguri", "Noto Sans Bengali", system-ui, sans-serif;
  --sans: "Spline Sans", system-ui, -apple-system, sans-serif;

  --r: 6px;
  --gap: 20px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--bn);
  font-size: 16px;
  line-height: 1.6;
  font-variant-numeric: tabular-nums;
}

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

/* ---------- chrome ---------- */

.topbar {
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px 8px;
  font-weight: 600;
  font-size: 18px;
  text-decoration: none;
}

/* A filled bubble — the thing the whole app is looking for. */
.brand-mark {
  width: 16px;
  height: 16px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 0 3px var(--pink);
  flex: none;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 10px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tabs a {
  padding: 8px 12px 10px;
  text-decoration: none;
  color: var(--ink-2);
  white-space: nowrap;
  border-bottom: 3px solid transparent;
}
.tabs a[aria-current="page"] {
  color: var(--ink);
  font-weight: 600;
  border-bottom-color: var(--red);
}

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: var(--gap) 16px 80px;
}

/* ---------- type ---------- */

h1 { font-size: 26px; margin: 0 0 4px; font-weight: 600; }
h2 { font-size: 19px; margin: 28px 0 10px; font-weight: 600; }
h3 { font-size: 16px; margin: 0 0 8px; font-weight: 600; }
p  { margin: 0 0 12px; max-width: 68ch; }
.lede { color: var(--ink-2); margin-bottom: 20px; }
.muted { color: var(--ink-3); }
.en { font-family: var(--sans); }

/* ---------- panels ---------- */

.panel {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--r);
  padding: 18px;
  margin-bottom: 16px;
}

.panel > :last-child { margin-bottom: 0; }

.grid-2 { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.spread { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }

/* ---------- form ---------- */

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 14px; color: var(--ink-2); margin-bottom: 4px; }

input[type=text], input[type=number], select, textarea {
  width: 100%;
  padding: 9px 11px;
  font: inherit;
  font-family: var(--bn);
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--r);
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

button, .btn {
  font: inherit;
  font-family: var(--bn);
  font-weight: 500;
  padding: 9px 16px;
  border-radius: var(--r);
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button.primary, .btn.primary { background: var(--ink); color: #fff; }
button.danger { border-color: var(--red); color: var(--red); }
button.ghost { border-color: var(--rule); color: var(--ink-2); }
button[disabled] { opacity: .45; cursor: not-allowed; }

input[type=range] { width: 100%; accent-color: var(--red); }

/* ---------- tables ---------- */

.table-scroll { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 15px;
}
table.data th, table.data td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}
table.data th { font-weight: 600; color: var(--ink-2); font-size: 14px; }
table.data tbody tr:hover { background: var(--surface); }

.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 99px;
  font-size: 13px;
  border: 1px solid var(--rule);
  color: var(--ink-2);
}
.tag.warn { border-color: var(--amber); color: var(--amber); background: #fdf6e6; }
.tag.ok   { border-color: var(--green); color: var(--green); background: #ecf7f1; }

.empty {
  border: 1px dashed var(--rule);
  border-radius: var(--r);
  padding: 28px 18px;
  text-align: center;
  color: var(--ink-2);
  background: var(--paper);
}

/* ---------- scanner ---------- */

.stage {
  position: relative;
  background: #14151a;
  border-radius: var(--r);
  overflow: hidden;
  aspect-ratio: 3 / 4;
  display: grid;
  place-items: center;
}
@media (min-width: 760px) { .stage { aspect-ratio: 4 / 3; } }

.stage video, .stage canvas, .stage img {
  max-width: 100%;
  max-height: 100%;
  display: block;
}
.stage .hint {
  position: absolute;
  inset: auto 0 0 0;
  padding: 10px 14px;
  color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,.72));
  font-size: 14px;
}

#corner-layer { position: absolute; inset: 0; touch-action: none; }

.handle {
  position: absolute;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: rgba(230, 57, 70, .55);
  cursor: grab;
  touch-action: none;
}

.readout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin: 14px 0;
}
.readout .cell {
  border: 1px solid var(--rule);
  border-radius: var(--r);
  padding: 8px 10px;
  background: var(--paper);
}
.readout .cell b { display: block; font-size: 21px; line-height: 1.2; }
.readout .cell span { font-size: 13px; color: var(--ink-3); }

/* answer review grid */
.answers {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 6px;
}
.qrow {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  border: 1px solid var(--rule);
  border-radius: var(--r);
  background: var(--paper);
}
.qrow.flag { border-color: var(--amber); background: #fdf7ea; }
.qrow .qn { width: 26px; font-size: 13px; color: var(--ink-3); text-align: right; }
.qrow .opt {
  width: 26px; height: 26px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  padding: 0;
  font-size: 13px;
  line-height: 1;
  display: grid;
  place-items: center;
}
.qrow .opt[aria-pressed="true"] { background: var(--ink); color: #fff; }
.qrow .opt.keyed { box-shadow: 0 0 0 2px var(--green); }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 14px; color: var(--ink-2); }
.legend i { width: 12px; height: 12px; display: inline-block; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 99px;
  font-size: 15px;
  z-index: 60;
}

details.tuning summary { cursor: pointer; font-weight: 500; }
details.tuning[open] summary { margin-bottom: 12px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
