/* ===== Feedback round 1: calmer filters, left-rail select, tidy answer key, calculator, tricky flags, test packs ===== */
.linkbtn { all: unset; cursor: pointer; color: var(--purple-deep); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }
.linkbtn:hover { color: var(--ink); }
.linkbtn:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* multi-select dropdown */
.ms { position: relative; display: grid; gap: 4px; min-width: 0; }
.ms-label { font-weight: 700; font-size: 13.5px; }
.ms-btn { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; padding: 8px 12px; background: #fff; border: 2px solid #8A8478; border-radius: 6px; cursor: pointer; text-align: left; font-weight: 600; }
.ms-active .ms-btn { border-color: var(--purple-deep); background: #F6EEF9; }
.ms-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ms-pop { position: absolute; z-index: 40; top: calc(100% + 4px); left: 0; min-width: 100%; width: max-content; max-width: min(92vw, 360px); max-height: 60vh; overflow: auto; background: var(--card); border: 2px solid var(--ink); border-radius: 8px; box-shadow: var(--shadow-lift); padding: 6px; }
.ms-clear { all: unset; display: block; width: calc(100% - 20px); padding: 9px 10px; cursor: pointer; font-weight: 800; border-radius: 6px; }
.ms-clear[aria-pressed="true"] { background: var(--tape); }
.ms-clear:focus-visible { outline: 3px solid var(--focus); }
.ms-opt { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 6px; cursor: pointer; min-height: 44px; }
.ms-opt:hover { background: var(--paper); }
.ms-opt input { width: 20px; height: 20px; flex: none; }
.ms-opt span { flex: 1; font-weight: 600; }
.ms-opt small { color: var(--ink-soft); font-weight: 700; }
.ms-opt.bio span { color: var(--bio); } .ms-opt.chm span { color: var(--chm); } .ms-opt.phy span { color: var(--phy); } .ms-opt.hsw span { color: var(--hsw); }

/* bank header */
.bank-head { padding-bottom: 16px; }
.bank-title { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.bank-title h1 { margin-bottom: 4px; }
.filter-row { display: grid; grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) minmax(200px, 1.4fr); gap: 12px; align-items: end; margin-top: 12px; }
.f-search { display: grid; gap: 4px; font-weight: 700; font-size: 13.5px; }
.more-filters { margin-top: 10px; }
.more-filters summary { cursor: pointer; font-weight: 700; color: var(--purple-deep); width: max-content; min-height: 32px; display: flex; align-items: center; }
.more-count { color: var(--ink-soft); font-weight: 600; margin-left: 6px; }
.result-line { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px; margin-top: 12px; padding-top: 10px; border-top: 1px dashed rgba(48, 45, 41, .22); font-weight: 700; }
.result-actions { display: flex; gap: 16px; flex-wrap: wrap; font-size: 14.5px; }

/* selection bar */
.selection-bar { gap: 10px; }
.sel-spacer { flex: 1; }
.sel-marks { color: #D8D1C0; font-weight: 600; font-size: 14px; }

/* dialogs */
.dlg { border: 2px solid var(--ink); border-radius: 10px; padding: 20px 24px; max-width: min(92vw, 460px); background: var(--card); color: var(--ink); box-shadow: var(--shadow-lift); }
.dlg::backdrop { background: rgba(48, 45, 41, .55); }
.dlg h2 { margin-top: 0; }
.dlg fieldset { border: 1px solid rgba(48, 45, 41, .2); border-radius: 8px; margin: 10px 0; padding: 8px 12px; }
.dlg legend { font-weight: 800; font-size: 13.5px; padding: 0 6px; }
.dlg fieldset:disabled { opacity: .45; }
.radio { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; padding: 8px 0; cursor: pointer; font-weight: 700; }
.radio input { width: 20px; height: 20px; align-self: center; }
.radio small { flex-basis: 100%; margin-left: 30px; color: var(--ink-soft); font-weight: 500; }

/* question card: left rail + main */
.q-card.with-rail { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 0 18px; padding: 0; overflow: hidden; }
.q-card.with-rail .q-main { padding: 22px 26px 22px 0; min-width: 0; }
.q-rail { all: unset; box-sizing: border-box; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 6px; padding: 24px 6px; background: var(--paper-deep); border-right: 1.5px dashed rgba(48, 45, 41, .28); font-weight: 800; font-size: 13px; color: var(--ink); }
.q-rail:hover { background: var(--tape); }
.q-rail:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }
.q-rail-box { width: 38px; height: 38px; border: 2.5px solid var(--ink); border-radius: 8px; background: #fff; display: grid; place-items: center; font-size: 22px; line-height: 1; }
.q-rail[aria-pressed="true"] { background: var(--purple-deep); color: #fff; border-right-style: solid; border-right-color: var(--purple-deep); }
.q-rail[aria-pressed="true"] .q-rail-box { background: #fff; color: var(--purple-deep); border-color: #fff; }
.q-card.selected { border-color: var(--purple-deep); }
.q-idtag .q-id { color: var(--ink-soft); font-weight: 600; }
.q-idtag .q-marks { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 10px; background: var(--paper-deep); font-size: 12.5px; font-weight: 700; }
.q-flag { margin-top: 10px; font-size: 14px; }
.q-flag summary { cursor: pointer; font-weight: 700; color: var(--warn); }
.q-flag ul { margin: 6px 0 0; padding-left: 18px; }

/* tidy answer key panel */
.teacher-details { padding: 0; background: var(--paper); border: 1px solid rgba(48, 45, 41, .2); border-radius: 8px; overflow: hidden; }
.teacher-details > summary { cursor: pointer; font-weight: 800; color: var(--purple-deep); padding: 11px 16px; min-height: 44px; display: flex; align-items: center; }
.teacher-details[open] > summary { border-bottom: 1px solid rgba(48, 45, 41, .16); background: var(--paper-deep); }
.td-body { display: grid; grid-template-columns: 1fr 1fr; font-size: 14.5px; }
.td-sec { padding: 14px 18px 16px; min-width: 0; }
.td-sec + .td-sec { border-left: 1px solid rgba(48, 45, 41, .14); }
.td-misc { grid-column: 1 / -1; border-left: 0 !important; border-top: 1px solid rgba(48, 45, 41, .14); }
.td-sec h4 { margin: 0 0 8px; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--red-deep); font-weight: 800; }
.td-ans { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.td-ans strong { font-size: 22px; line-height: 1.2; background: var(--good-bg); color: var(--good); padding: 2px 12px; border-radius: 6px; }
.td-ans small { font-size: 13px; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { display: inline-block; padding: 2px 10px; border-radius: 12px; background: #fff; border: 1px solid rgba(48, 45, 41, .2); font-size: 12.5px; font-weight: 700; }
.td-sec dl { margin: 0; }
.td-sec dt { font-size: 12.5px; font-weight: 800; color: var(--ink-soft); margin-top: 8px; }
.td-sec dd { margin: 1px 0 0; }
.td-misc ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.td-misc li { background: #fff; border: 1px solid rgba(48, 45, 41, .14); border-left: 4px solid var(--warn); border-radius: 6px; padding: 8px 12px; display: grid; gap: 2px; }
.td-misc li b { font-size: 13.5px; }
.td-misc li span { color: var(--ink-soft); font-size: 14px; }

/* tricky + comment widget */
.qfb { margin-top: 14px; padding-top: 10px; border-top: 1px dashed rgba(48, 45, 41, .22); }
.qfb-row { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.qfb-tricky, .qfb-toggle { cursor: pointer; min-height: 40px; padding: 6px 14px; border-radius: 20px; border: 2px solid rgba(48, 45, 41, .28); background: var(--card); font-weight: 700; font-size: 14px; }
.qfb-tricky[aria-pressed="true"] { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }
.qfb-toggle { border-style: dashed; color: var(--ink-soft); }
.qfb-box { margin-top: 8px; display: grid; gap: 6px; max-width: 560px; }
.qfb-box textarea { min-height: 76px; }
.qfb-box .btn { width: max-content; }

/* calculator */
.q-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 12px; }
.calc { position: fixed; right: 16px; bottom: 16px; z-index: 80; width: 280px; max-width: calc(100vw - 24px); background: var(--ink); color: #fff; border-radius: 14px; padding: 12px; box-shadow: var(--shadow-lift); }
.calc-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.calc-x { all: unset; cursor: pointer; font-size: 26px; line-height: 1; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 8px; }
.calc-x:hover { background: rgba(255, 255, 255, .15); }
.calc-expr { min-height: 22px; font: 500 15px/1.4 ui-monospace, Consolas, monospace; color: #D8D1C0; text-align: right; word-break: break-all; }
.calc-out { display: block; font: 800 30px/1.2 ui-monospace, Consolas, monospace; text-align: right; background: #1F1D1A; border-radius: 8px; padding: 6px 10px; margin: 4px 0 10px; overflow-x: auto; }
.calc-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.calc-keys button { min-height: 46px; border: 0; border-radius: 8px; background: #4A463F; color: #fff; font: 700 18px/1 inherit; cursor: pointer; }
.calc-keys button:active { filter: brightness(1.3); }
.calc-keys .op { background: var(--purple-deep); } .calc-keys .fn { background: #6B655A; } .calc-keys .eq { background: var(--good); }

/* print: compact layout */
.compact .q-card { padding: 10px 14px; margin: 8px 0; }
.compact .q-layout { gap: 12px; }
.compact .q-visual img, .compact .q-visual svg { max-height: 150px; }

/* ===== test packs gallery ===== */
.pack-tools { display: grid; grid-template-columns: minmax(200px, 2fr) minmax(160px, 1fr) minmax(160px, 1fr); gap: 12px; align-items: end; margin-top: 12px; }
.pack-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(268px, 1fr)); gap: 22px; margin: 18px 0; }
.pack { background: var(--card); border: 1px solid rgba(48, 45, 41, .12); border-radius: 6px; box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; transition: transform .15s, box-shadow .15s; }
.pack:hover { transform: translateY(-3px) rotate(-.3deg); box-shadow: var(--shadow-lift); }
.pack-cover { position: relative; aspect-ratio: 4 / 3; background: var(--paper-deep); display: grid; place-items: center; overflow: hidden; border-bottom: 1.5px dashed rgba(48, 45, 41, .25); }
.pack-cover img { width: 100%; height: 100%; object-fit: contain; padding: 10px; }
.pack-cover.photo img { object-fit: contain; padding: 0; }
.pack-cover.bio { background: var(--bio-bg); } .pack-cover.chm { background: var(--chm-bg); } .pack-cover.phy { background: var(--phy-bg); } .pack-cover.hsw { background: var(--hsw-bg); }
.pack-badge { position: absolute; top: 10px; left: 10px; background: var(--tape); border: 1px solid rgba(48, 45, 41, .3); padding: 2px 10px; border-radius: 4px; font-size: 12px; font-weight: 800; transform: rotate(-2deg); box-shadow: 0 1px 2px rgba(48, 45, 41, .2); }
.pack-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.pack-body h3 { margin: 0; font-size: 18px; line-height: 1.25; }
.pack-body p { margin: 0; color: var(--ink-soft); font-size: 14.5px; }
.pack-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.pack-actions { margin-top: auto; display: flex; flex-wrap: wrap; gap: 8px; padding-top: 6px; }
.pack-actions .btn { flex: 1 1 auto; }
.pack-section { margin: 26px 0 -6px; font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--red-deep); font-weight: 800; }

/* ===== tablets and phones ===== */
@media (max-width: 900px) {
  .filter-row, .pack-tools { grid-template-columns: 1fr 1fr; }
  .f-search { grid-column: 1 / -1; }
  .pack-tools > :first-child { grid-column: 1 / -1; }
  .td-body { grid-template-columns: 1fr; }
  .td-sec + .td-sec { border-left: 0; border-top: 1px solid rgba(48, 45, 41, .14); }
}
@media (max-width: 640px) {
  body { font-size: 16.5px; }
  .page { padding: 10px 12px calc(100px + env(safe-area-inset-bottom)); }
  .sheet { padding: 18px 16px; clip-path: none; }
  .q-card { padding: 16px 14px; margin: 14px 0; clip-path: none; }
  .topbar-inner { padding: 8px 12px; }
  .brand span { display: block; font-size: 12px; }
  .filter-row, .pack-tools { grid-template-columns: 1fr; }
  .bank-title .btn { width: 100%; }
  .ms-pop { position: fixed; left: 12px; right: 12px; top: auto; bottom: 12px; width: auto; max-width: none; max-height: 70vh; }
  .q-card.with-rail { grid-template-columns: 1fr; }
  .q-card.with-rail .q-main { padding: 16px 14px; }
  .q-rail { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 8px 14px; min-height: 52px; border-right: 0; border-bottom: 1.5px dashed rgba(48, 45, 41, .28); font-size: 15px; }
  .q-rail-box { width: 34px; height: 34px; }
  .q-stem { font-size: 17px; }
  .q-opt { padding: 12px; }
  .q-visual img, .q-visual svg { max-height: 240px; }
  .selection-bar { bottom: calc(62px + env(safe-area-inset-bottom)); border-radius: 12px 12px 0 0; padding: 10px 12px; margin-left: -12px; margin-right: -12px; }
  .selection-bar #sel-count { flex: 1 1 auto; }
  .selection-bar .btn { flex: 1 1 22%; padding: 6px 4px; font-size: 13px; min-height: 40px; }
  .sel-spacer { flex-basis: 100%; height: 0; }
  .actions .btn { flex: 1 1 100%; }
  .calc { left: 12px; right: 12px; bottom: calc(70px + env(safe-area-inset-bottom)); width: auto; }
  .seq-btns button { min-width: 44px; min-height: 44px; }
  .stats-strip { grid-template-columns: 1fr 1fr; }
  .pack-grid { grid-template-columns: 1fr; }
}
@media (hover: none) { .btn:hover { filter: none; } .pack:hover { transform: none; } }

@media print {
  .calc, .qfb, .q-rail, .q-tools, .q-flag { display: none !important; }
  .q-card.with-rail { display: block; }
}

/* Drag-and-drop sorter (classification questions) */
.sorter { margin: 10px 0 14px; }
.sorter-bank { display: flex; flex-wrap: wrap; gap: 10px; min-height: 58px; padding: 12px; border: 2px dashed var(--line, #c9c1ae); border-radius: 14px; background: rgba(255,255,255,.5); }
.sorter-bank:empty::after { content: 'All sorted. Drag a word back here to take it out of a box.'; color: #6b6558; font-size: 14px; align-self: center; }
.sorter-bins { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin-top: 14px; }
.sorter-bin { border: 2px solid var(--line, #c9c1ae); border-radius: 14px; background: #fff; padding: 10px 12px 12px; }
.sorter-bin h4 { margin: 0 0 8px; font-size: 15px; }
.sorter-drop { display: flex; flex-wrap: wrap; gap: 8px; min-height: 64px; padding: 8px; border-radius: 10px; background: #f6f1e4; }
.sorter-chip { font: inherit; font-weight: 700; padding: 10px 14px; border-radius: 999px; border: 2px solid #8A8478; background: #fff; color: #2a2620; cursor: grab; touch-action: none; user-select: none; box-shadow: 0 2px 0 rgba(0,0,0,.12); }
.sorter-chip:disabled { cursor: default; opacity: .8; }
.sorter-chip.sel { outline: 3px solid #6b3a8c; background: #f1e6f7; }
.sorter-chip.dragging { opacity: .35; }
.sorter-chip.ghost { position: fixed; z-index: 9999; pointer-events: none; transform: translate(-50%, -60%) rotate(-3deg); box-shadow: 0 10px 24px rgba(0,0,0,.25); }
.dz.over { border-color: #6b3a8c; background: #f6ecfb; }
.sorter.has-sel .dz { cursor: copy; }
@media (max-width: 600px) { .sorter-chip { padding: 12px 16px; } }

/* Full-screen picture viewer */
.q-visual.zoomable { position: relative; }
.q-visual.zoomable img, .q-visual.zoomable svg { cursor: zoom-in; }
.q-zoom { position: absolute; right: 8px; top: 8px; width: 40px; height: 40px; padding: 0; display: grid; place-items: center; border-radius: 6px; border: 1px solid rgba(0,0,0,.3); background: rgba(255,253,246,.94); color: #2a2620; cursor: pointer; }
.q-zoom svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.q-visual-inline { margin: 12px 0 14px; max-width: 460px; }
.q-zoom:hover, .q-zoom:focus-visible { background: #fff; outline: 2px solid #6b3a8c; }
.lightbox { position: fixed; inset: 0; z-index: 10000; background: rgba(20,17,12,.92); display: flex; align-items: center; justify-content: center; padding: 16px; }
.lightbox-stage { max-width: 96vw; max-height: 94vh; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.lightbox-stage img, .lightbox-stage svg { max-width: 96vw; max-height: 84vh; width: auto; height: auto; background: #fffdf6; border-radius: 10px; cursor: default; }
.lightbox-stage svg { width: min(96vw, 1100px); }
.lightbox-stage p { margin: 0; color: #f3eee0; font-size: 15px; text-align: center; max-width: 80ch; }
.lightbox-x { position: fixed; top: 14px; right: 14px; font: inherit; font-weight: 700; padding: 10px 18px; border-radius: 999px; border: 0; background: #fffdf6; color: #2a2620; cursor: pointer; }
body.lightbox-open { overflow: hidden; }
@media print { .q-zoom, .lightbox { display: none !important; } }

/* An open dropdown must not be cut off by the torn-paper edge or hidden under the section below */
.sheet:has(.ms-pop:not([hidden])) { position: relative; z-index: 30; clip-path: none; }

/* ===== site navigation: icons on every screen, a bottom tab bar on phones ===== */
.topnav svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nl-short { display: none; }
@media (max-width: 760px) {
  .topbar { backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--paper); }
  .topbar-inner { padding: 8px 14px; flex-wrap: nowrap; }
  .topnav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 70; margin: 0; width: auto; display: grid; grid-template-columns: repeat(5, 1fr); gap: 0; padding: 0 0 env(safe-area-inset-bottom); background: var(--card); border-top: 2px solid rgba(48, 45, 41, .3); box-shadow: 0 -6px 18px -8px rgba(48, 45, 41, .35); }
  .topnav a { flex-direction: column; justify-content: center; gap: 3px; min-height: 58px; padding: 6px 2px; border: 0; border-radius: 0; box-shadow: none; background: transparent; font-size: 12px; font-weight: 700; line-height: 1.1; text-align: center; color: var(--ink-soft); }
  .topnav a svg { width: 24px; height: 24px; }
  .topnav a[aria-current="page"] { background: var(--tape); color: var(--ink); box-shadow: inset 0 3px 0 var(--ink); }
  .topnav .desk, .nl-long { display: none; }
  .nl-short { display: inline; }
  .topbar-min .topnav { display: none; }
}

@media (max-width: 760px) {
  .selection-bar.is-empty { display: none; }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); max-width: calc(100vw - 24px); text-align: center; }
}

/* ===== phone polish: roomier controls, compact filters, tidier action bar ===== */
@media (max-width: 760px) {
  input[type="text"], input[type="search"], input[type="number"], input:not([type]), select, textarea { min-height: 44px; padding: 9px 12px; font-size: 16px; border: 1.5px solid #6B665C; border-radius: 6px; background: #fff; }
  textarea { min-height: 96px; }
  .pack-tools { grid-template-columns: 1fr 1fr; gap: 10px; }
  .pack-tools > :first-child { grid-column: 1 / -1; }
  .bank-head .sub { font-size: 15.5px; margin: 6px 0 4px; }
  a.btn.good[href="packs.html"] { display: none; }
  .selection-bar .btn { white-space: nowrap; }
  .selection-bar { gap: 8px; }
}
@media (max-width: 760px) { .pack-tools .f-search:not(:first-child) { grid-column: auto; } .pack-tools select { padding-right: 30px; } }

/* ===== paper look, round 3: miter-cut icons with a layered shadow, torn paper tab for the current page ===== */
.topnav svg { stroke-linejoin: miter; filter: drop-shadow(1.5px 1.5px 0 rgba(48, 45, 41, .25)); }
@media (max-width: 760px) {
  .topnav a[aria-current="page"] { background: none; box-shadow: none; position: relative; z-index: 0; }
  .topnav a[aria-current="page"]::before { content: ""; position: absolute; inset: 5px 6px; z-index: -1; background: var(--tape);
    clip-path: polygon(0 8%, 6% 0, 28% 5%, 52% 0, 76% 4%, 100% 0, 98% 52%, 100% 100%, 74% 95%, 50% 100%, 24% 96%, 2% 100%, 0 52%); }
}
