/* Coverdraft mobile layer (phones and small tablets).
   Loaded last on purpose: it is the single source of truth for the small-screen layout, so the
   older breakpoints in app.css no longer need to be reasoned about.

   Design rules, and why:
   - 44px touch targets (Apple HIG 44pt, Material 48dp, WCAG 2.5.8 minimum 24px) on every control.
   - Primary actions sit in the thumb zone: "Edit details" is a bottom pill, not a top-left icon.
   - 16px form text, otherwise iOS Safari zooms the page when a field gets focus.
   - dvh units, otherwise the browser's bottom bar hides modal buttons (100vh is taller than the visible area).
   - No blur/backdrop-filter and only short transitions: cheaper to paint, so interactions stay under ~100ms. */

.sheet-head,
.mobile-edit-fab {
  display: none;
}

@media screen and (max-width: 760px) {
  :root {
    --tap: 36px;
    --gap: 4px;
    --safe-b: env(safe-area-inset-bottom, 0px);
  }

  html,
  html body {
    touch-action: pan-x pan-y;
  }

  html body {
    height: 100dvh;
    width: 100%;
    -webkit-tap-highlight-color: transparent;
  }

  /* No transitions or animations on phones: every change is instant */
  html body *,
  html body *::before,
  html body *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }

  html body :is(button, a, select, input, label, .chip, .view-tab) {
    touch-action: manipulation;
  }

  html body :is(.select-box, .input-box, input[type="text"], input[type="search"], textarea) {
    font-size: 16px;
  }

  /* ---------- Header: one line, four actions ---------- */
  html body .top-nav {
    height: auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    gap: var(--gap) 4px;
    padding: 4px 8px;
    align-items: center;
  }

  html body .brand-block {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
    gap: 0;
    padding-left: 4px;
  }

  html body .brand-block .sidebar-toggle-btn,
  html body .brand-block .mode-switch-wrapper,
  html body .brand-block .save-status,
  html body .brand-block .offline-status {
    display: none !important;
  }

  html body .brand-title {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -.3px;
    line-height: 36px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    user-select: none;
  }

  html body .nav-actions {
    grid-column: 2;
    grid-row: 1;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    width: auto;
    min-width: max-content;
  }

  html body .nav-actions > #tabViewBatch {
    display: none !important;
  }

  html body:not(.simple-mode) .nav-actions > .menu-wrap {
    display: flex !important;
    flex: 0 0 auto;
    width: var(--tap);
    height: var(--tap);
  }

  html body .nav-actions > .menu-wrap .btn-icon,
  html body .nav-actions > #sharePdfBtn,
  html body .nav-actions > #openMergerBtn {
    flex: 0 0 var(--tap);
    width: var(--tap);
    min-width: var(--tap);
    height: var(--tap);
    min-height: var(--tap);
    padding: 0;
    gap: 0;
    justify-content: center;
    border-radius: 10px;
  }

  html body .nav-actions .btn .lbl,
  html body #exportPdfBtn .lbl {
    display: none;
  }

  html body .nav-actions .btn svg {
    width: 17px;
    height: 17px;
  }

  /* Download: icon + arrow only */
  html body .nav-actions .download-control {
    position: relative;
    display: inline-flex;
    flex: 0 0 auto;
    width: calc(var(--tap) + 30px);
    min-width: calc(var(--tap) + 30px);
    height: var(--tap);
  }

  html body .download-control #exportPdfBtn.download-main {
    flex: 0 0 var(--tap);
    width: var(--tap);
    min-width: var(--tap);
    height: var(--tap);
    padding: 0;
    gap: 0;
    justify-content: center;
    border-radius: 12px 0 0 12px;
  }

  html body .download-control #downloadOptionsBtn.download-options-toggle {
    flex: 0 0 30px;
    width: 30px;
    min-width: 30px;
    height: var(--tap);
    padding: 0;
    justify-content: center;
    border-radius: 0 12px 12px 0;
  }

  html body .download-control .download-options-toggle svg {
    width: 14px;
    height: 14px;
  }

  /* Legacy breakpoints in app.css use !important on these three; match them so the pill is exact */
  html body .nav-actions .download-control {
    flex: 0 0 calc(var(--tap) + 30px) !important;
    width: calc(var(--tap) + 30px) !important;
    min-width: calc(var(--tap) + 30px) !important;
  }

  html body .nav-actions .download-control #exportPdfBtn.download-main {
    flex: 0 0 var(--tap) !important;
    width: var(--tap) !important;
    min-width: var(--tap) !important;
    padding: 0 !important;
  }

  html body .nav-actions .download-control #downloadOptionsBtn.download-options-toggle {
    flex: 0 0 30px !important;
    width: 30px !important;
    min-width: 30px !important;
  }

  /* Menus are small popovers under their button, never full-height panels */
  html body .menu-panel,
  html body .download-menu {
    position: fixed;
    top: 46px;
    right: 8px;
    left: auto;
    bottom: auto;
    width: min(300px, calc(100vw - 16px));
    height: auto;
    min-height: 0;
    max-width: none;
    max-height: calc(100dvh - 58px);
    overflow-y: auto;
    overscroll-behavior: contain;
    border-radius: 12px;
    padding: 4px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, .5);
    z-index: 400;
  }

  html body .download-control .download-menu {
    width: 232px;
  }

  html body .menu-panel:not(.open),
  html body .download-menu[hidden] {
    display: none;
  }

  html body .menu-panel .menu-item,
  html body .download-menu .menu-item {
    min-height: 40px;
    padding: 6px 12px;
    border-radius: 8px;
  }

  html body .download-menu .menu-item small {
    display: none;
  }

  html body .menu-panel .menu-item small {
    display: block;
    margin-top: 1px;
    font-size: 11.5px;
    line-height: 1.3;
  }

  /* ---------- Page tabs: segmented control ---------- */
  html body .view-tabs {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    margin: 0;
    height: 34px;
    padding: 2px;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 3px;
    border-radius: 11px;
    overflow: hidden;
  }

  /* Plain centered labels: the number badge and icon pushed the text off-center */
  html body .view-tabs .view-tab .page-tab-num,
  html body .view-tabs .view-tab svg {
    display: none;
  }

  html body .view-tabs {
    grid-template-rows: minmax(0, 1fr);
    align-items: stretch;
  }

  html body .view-tabs .view-tab {
    height: 100% !important;
    min-height: 0 !important;
    max-height: 100%;
    margin: 0 !important;
    line-height: 1;
    text-align: center;
    height: 100%;
    min-width: 0;
    padding: 0 8px;
    justify-content: center;
    gap: 5px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 9px;
  }

  /* ---------- Subject bar: university | semester | library on one line, chips below ---------- */
  html body .subject-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 78px auto;
    grid-template-rows: var(--tap) 34px;
    gap: var(--gap);
    padding: 4px 8px;
    align-items: stretch;
  }

  html body .subject-bar .top-university-picker {
    grid-column: 1;
    grid-row: 1;
    display: flex;
    align-items: stretch;
    gap: 4px;
    min-width: 0;
    width: 100%;
    height: var(--tap);
    margin: 0;
    padding: 0 0 0 8px;
    border: 1px solid var(--border-subtle);
    background: var(--bg-surface-2);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: none;
  }

  html body .subject-bar .top-university-picker:focus-within {
    box-shadow: 0 0 0 2px var(--accent-glow);
  }

  html body .subject-bar .top-university-picker .select-box {
    flex: 1 1 auto;
    min-width: 0;
    height: 100%;
    min-height: 0;
    margin: 0;
  }

  /* Reset lives inside the same box as the dropdown, separated by a hairline */
  html body .subject-bar .top-university-reset {
    flex: 0 0 34px;
    width: 34px;
    min-width: 34px;
    height: 100%;
    min-height: 0;
    margin: 0;
    padding: 0;
    align-self: stretch;
    border: 0;
    border-left: 1px solid var(--border-subtle);
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  html body .subject-bar .top-university-reset svg {
    width: 14px;
    height: 14px;
  }

  html body .subject-bar .semester-shortcut {
    grid-column: 2;
    grid-row: 1;
    width: 100%;
    min-width: 0;
    height: var(--tap);
    min-height: 0;
    margin: 0;
  }

  html body .subject-bar .course-switcher-top-btn {
    grid-column: 3;
    grid-row: 1;
    height: var(--tap);
    min-height: 0;
    margin: 0;
    padding: 0 10px;
    white-space: nowrap;
    font-size: 12.5px;
    border-radius: 10px;
  }

  html body .subject-bar .chips {
    grid-column: 1 / -1;
    grid-row: 2;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    padding-right: 12px;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 22px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 22px), transparent);
  }

  html body .subject-bar .chips::-webkit-scrollbar {
    display: none;
  }

  /* Pin/remove live in the Subject library; on a phone they only crowded the chip */
  html body .subject-bar .chips .chip-action {
    display: none;
  }

  html body .subject-bar .chips .subject-chip-wrap {
    flex: 0 0 auto;
    display: flex;
  }

  html body .subject-bar .chips .chip {
    flex: 0 0 auto;
    min-height: 30px;
    max-width: 72vw;
    overflow: hidden;
    text-overflow: ellipsis;
    scroll-snap-align: start;
    font-size: 13px;
    padding: 4px 11px;
  }

  html body .subject-bar #pageSizeSelect {
    display: none;
  }

  /* ---------- Workspace ---------- */
  html body #stageViewport {
    padding-top: 8px;
    padding-bottom: calc(24px + var(--safe-b));
  }

  html body #canvasArea {
    margin: 4px auto 0;
  }

  html body .canvas-toolbar-overlay {
    display: none;
  }

  /* Edit details: a pencil in the bottom-right corner, floating over the page */
  html body .mobile-edit-fab {
    display: inline-flex;
    position: fixed;
    right: 12px;
    bottom: calc(12px + var(--safe-b));
    width: 46px;
    height: 46px;
    min-width: 46px;
    padding: 0;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .5);
    z-index: 150;
    cursor: pointer;
  }

  html body:has(#appSidebar.mobile-open) .mobile-edit-fab,
  html body.document-task-busy .mobile-edit-fab {
    display: none;
  }

  /* ---------- Details sheet (was a bare side drawer) ---------- */
  html body .sidebar-backdrop {
    backdrop-filter: none;
    background: rgba(0, 0, 0, .55);
  }

  html body .sidebar {
    position: fixed;
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100% !important;
    height: var(--sheet-full, 90dvh);
    border-radius: 20px 20px 0 0;
    border: 1px solid var(--border-subtle);
    border-bottom: 0;
    display: flex;
    flex-direction: column;
    transform: translateY(105%);
    will-change: transform;
    box-shadow: 0 -12px 40px rgba(0, 0, 0, .5);
    z-index: 200;
    overflow: hidden;
  }

  /* Legacy breakpoints cap the drawer at 92vw with !important; the sheet spans the full width */
  html body #appSidebar.sidebar {
    width: 100vw !important;
    max-width: 100vw !important;
    left: 0 !important;
    right: 0 !important;
  }

  html body .sidebar.mobile-open {
    transform: translateY(0);
  }

  html body .sidebar .sheet-head {
    flex: 0 0 auto;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 22px 14px 8px;
    border-bottom: 1px solid var(--border-subtle);
    touch-action: none;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
  }

  html body .sidebar .sheet-head::before {
    content: "";
    position: absolute;
    top: 8px;
    left: 50%;
    width: 44px;
    height: 5px;
    margin-left: -22px;
    border-radius: 3px;
    background: var(--text-muted);
    opacity: .55;
  }

  html body .sidebar .sheet-head strong {
    font-size: 17px;
    font-weight: 700;
  }

  html body .sidebar .sheet-head .btn {
    height: 34px;
    padding: 0 16px;
  }

  html body .sidebar .sidebar-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    /* scrolling and sheet dragging are one gesture handled in JS, so the finger can pass from one to the other */
    touch-action: none;
    scrollbar-width: none;
    margin-bottom: var(--sheet-off, 0px);
    padding-bottom: calc(24px + var(--safe-b));
  }

  html body .sidebar .sidebar-scroll::-webkit-scrollbar {
    display: none;
  }

  /* Half-height sheet: the page stays visible and usable above it */
  html body:has(#appSidebar[data-snap="half"]) .sidebar-backdrop {
    background: transparent;
    pointer-events: none;
  }

  html body:has(#appSidebar.mobile-open) .mini-toolbar {
    display: none !important;
  }

  html body:has(#appSidebar.mobile-open) #stageViewport {
    padding-bottom: calc(var(--sheet-visible, 0px) + 24px);
  }

  html body .sidebar .input-box,
  html body .sidebar .select-box {
    min-height: 40px;
  }

  /* ---------- Dialogs become bottom sheets ---------- */
  html body .modal-overlay {
    width: 100%;
    height: 100dvh;
    padding: 0 !important;
    align-items: flex-end;
    justify-content: stretch;
    backdrop-filter: none;
    background: rgba(0, 0, 0, .62);
  }

  html body .modal-overlay .modal-card {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    max-height: 92dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-radius: 20px 20px 0 0;
    border-bottom: 0;
    padding: 18px 16px calc(16px + var(--safe-b));
  }

  html body .modal-overlay .btn {
    min-height: 36px;
    padding: 6px 12px;
    font-size: 13px;
  }

  html body .modal-overlay .btn-icon {
    min-width: 36px;
    padding: 0;
  }

  /* Subject library */
  /* Subject library: full screen */
  html body #batchModal .modal-card {
    display: flex;
    flex-direction: column;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border: 0 !important;
    border-radius: 0 !important;
    padding: 10px 10px calc(10px + var(--safe-b));
    gap: 8px;
    overflow: hidden;
  }

  html body #batchModal .modal-card > div:first-child {
    margin-bottom: 0 !important;
  }

  html body #batchModal .modal-card > .grid-2 {
    margin-bottom: 0 !important;
    gap: 8px;
  }

  html body #batchModal .control-label {
    font-size: 11px;
    margin-bottom: 2px;
  }

  html body #batchModal .select-box,
  html body #batchModal .batch-search-wrap .input-box {
    height: 36px;
    min-height: 36px;
    padding-top: 0;
    padding-bottom: 0;
  }

  html body #batchModal .batch-search-count {
    margin: -4px 0 0;
    font-size: 11px;
  }

  html body #batchModal .batch-subjects-list {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  html body #batchModal .modal-card > div:last-child {
    flex: 0 0 auto;
    gap: 10px;
    margin-top: 0 !important;
    padding-top: 8px;
    border-top: 1px solid var(--border-subtle);
  }

  html body #batchModal .modal-card > div:last-child .btn-cyan {
    flex: 1 1 auto;
  }

  html body #batchModal .batch-subject-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px;
    align-items: center;
    padding: 6px 8px;
  }

  html body #batchModal .batch-subject-title {
    font-size: 13px;
    line-height: 1.25;
  }

  html body #batchModal .batch-subject-code {
    font-size: 11px;
  }

  html body #batchModal .batch-subject-controls {
    display: flex;
    align-items: center;
    gap: 6px;
  }

  html body #batchModal .batch-subject-actions {
    display: flex;
    gap: 4px;
  }

  html body #batchModal .batch-subject-action {
    width: 30px;
    height: 30px;
  }

  html body #batchModal .batch-subject-select {
    min-width: 56px;
    height: 32px;
    min-height: 32px;
    padding: 0 10px;
    font-size: 12.5px;
  }

  /* While adding/editing a subject, show only the form, with its buttons in view */
  html body #batchModal .modal-card:has(#batchCustomSubjectForm:not([hidden])) > :not(#batchCustomSubjectForm):not(:first-child) {
    display: none !important;
  }

  html body #batchCustomSubjectForm:not([hidden]) {
    flex: 1 1 auto;
    overflow-y: auto;
    margin: 0;
  }

  html body #batchCustomSubjectForm .grid-2 {
    grid-template-columns: 1fr;
  }

  html body .batch-custom-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  /* PDF preview: full screen, preview first, actions pinned and always visible */
  html body .modal-card.pdf-preview-card {
    display: flex;
    flex-direction: column;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border: 0 !important;
    border-radius: 0 !important;
    padding: 8px 10px calc(8px + var(--safe-b));
    gap: 6px;
  }

  html body .pdf-preview-body {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    gap: 14px;
  }

  html body .pdf-preview-viewer {
    order: -1;
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
  }

  html body .pdf-preview-page-wrap {
    min-height: 240px;
    max-height: 64dvh;
  }

  html body .pdf-preview-page-wrap img {
    max-width: 100%;
    height: auto;
  }

  html body .pdf-preview-side {
    overflow: visible;
    padding-right: 0;
  }

  html body .pdf-preview-footer {
    flex: 0 0 auto;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  html body .pdf-preview-footer > div {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }

  html body .pdf-preview-footer > div .btn {
    width: 100%;
    min-height: 36px;
    justify-content: center;
    text-align: center;
  }

  html body .pdf-preview-selection-actions {
    display: none;
  }

  html body .pdf-preview-header {
    gap: 8px;
  }

  html body .pdf-preview-header h3 {
    font-size: 15px;
  }

  html body .pdf-preview-header p {
    font-size: 11.5px;
    margin-top: 1px;
  }

  html body .pdf-preview-toolbar .btn {
    min-height: 32px;
    padding: 4px 10px;
    font-size: 12px;
  }

  html body .pdf-preview-selection {
    padding: 8px 10px;
    gap: 6px;
  }

  html body .pdf-preview-selection .page-row,
  html body .subject-checks label {
    min-height: 34px;
  }

  html body .pdf-preview-thumbs {
    gap: 6px;
  }

  /* ---------- Text toolbar: floats next to the selected text, two compact rows ---------- */
  html body .mini-toolbar {
    position: fixed !important;
    top: var(--tb-top, 8px) !important;
    left: var(--tb-left, 8px) !important;
    right: auto !important;
    bottom: auto !important;
    transform: none !important;
    width: max-content;
    max-width: calc(100vw - 16px);
    flex-wrap: wrap;
    overflow: visible;
    gap: 4px 6px;
    padding: 4px 6px;
    border-radius: 12px;
    backdrop-filter: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .55);
    z-index: 260 !important;
  }

  /* Row 1: font, size, colour, spacing. Row 2: B/I/U, alignment, duplicate, delete */
  html body .mini-toolbar > select { order: 1; }
  html body .mini-toolbar > div:nth-of-type(1) { order: 2; }
  html body .mini-toolbar > .color-picker-wrap { order: 3; }
  html body .mini-toolbar > .tb-spacing-group { order: 4; }
  html body .mini-toolbar > div:nth-of-type(2) { order: 5; }
  html body .mini-toolbar > div:nth-of-type(3) { order: 6; }
  html body .mini-toolbar > #tbDuplicate { order: 7; }
  html body .mini-toolbar > #tbDelete { order: 8; }

  html body .mini-toolbar .tb-sep {
    display: none;
  }

  html body .mini-toolbar select {
    height: 32px !important;
    min-height: 0 !important;
    max-width: 92px;
    padding: 0 6px !important;
    font-size: 16px;
  }

  html body .mini-toolbar .tb-group {
    height: 32px;
    padding: 0 !important;
    align-items: center;
  }

  html body .mini-toolbar .tb-spacing-group {
    height: 32px;
    padding: 0;
  }

  html body .mini-toolbar button,
  html body .mini-toolbar .tb-group button {
    width: 32px;
    min-width: 32px;
    height: 32px;
    min-height: 0;
    padding: 0;
    justify-content: center;
  }

  html body .mini-toolbar .tb-group {
    gap: 2px;
  }

  html body .mini-toolbar .size-stepper-label {
    min-width: 38px;
    text-align: center;
  }

  html body .mini-toolbar .color-picker-wrap {
    width: 32px;
    height: 32px;
  }

  /* Text toolbar floats next to the selected element (positions come from canvas-editor.js),
     instead of the old bottom dock; compact so it stays on one or two short rows */
  html body .mini-toolbar {
    position: fixed !important;
    top: var(--tb-top, 8px) !important;
    left: var(--tb-left, 8px) !important;
    right: auto !important;
    bottom: auto !important;
    width: max-content;
    max-width: calc(100vw - 16px);
    flex-wrap: wrap;
    overflow: visible;
    gap: 3px;
    padding: 3px;
    border-radius: 10px;
    backdrop-filter: none;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .55);
    z-index: 260 !important;
  }

  html body .mini-toolbar button,
  html body .mini-toolbar .tb-group button {
    min-width: 30px;
    min-height: 30px;
    height: 30px;
    padding: 0 6px;
  }

  html body .mini-toolbar select {
    height: 30px;
    min-height: 30px;
    max-width: 84px;
    font-size: 13px;
  }

  html body .mini-toolbar .tb-sep,
  html body .mini-toolbar .tb-spacing-group {
    display: none;
  }

  /* ---------- Touch editing: scroll with one finger, pinch to zoom, tap then drag ---------- */
  html body #stageViewport {
    touch-action: pan-x pan-y;
    overscroll-behavior: contain;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }

  html body #canvasArea {
    --zoom: 1;
  }

  html body .c-el {
    touch-action: pan-x pan-y;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }

  html body .c-el.selected,
  html body .c-el.dragging {
    touch-action: none;
  }

  html body .c-el[contenteditable="true"] {
    touch-action: auto;
    user-select: text;
    -webkit-user-select: text;
  }

  html body .c-el.selected {
    outline-width: calc(2px / var(--zoom, 1));
  }

  /* Finger-sized handles that stay the same size on screen at any zoom */
  html body .c-el .resize-handle {
    width: calc(34px / var(--zoom, 1));
    height: calc(34px / var(--zoom, 1));
    background: transparent;
    border: 0;
    border-radius: 0;
    touch-action: none;
  }

  html body .c-el .resize-handle::after {
    content: "";
    position: absolute;
    inset: calc(11px / var(--zoom, 1));
    background: #fff;
    border: calc(2px / var(--zoom, 1)) solid var(--accent-cyan);
    border-radius: calc(3px / var(--zoom, 1));
    box-shadow: 0 0 0 calc(1px / var(--zoom, 1)) rgba(0, 0, 0, .5);
  }

  html body .c-el .rh-nw {
    top: calc(-17px / var(--zoom, 1));
    left: calc(-17px / var(--zoom, 1));
  }

  html body .c-el .rh-ne {
    top: calc(-17px / var(--zoom, 1));
    right: calc(-17px / var(--zoom, 1));
  }

  html body .c-el .rh-se {
    bottom: calc(-17px / var(--zoom, 1));
    right: calc(-17px / var(--zoom, 1));
  }

  html body .c-el .rh-sw {
    bottom: calc(-17px / var(--zoom, 1));
    left: calc(-17px / var(--zoom, 1));
  }

  html body .c-el .rh-e {
    right: calc(-17px / var(--zoom, 1));
  }

  html body .c-el .rh-w {
    left: calc(-17px / var(--zoom, 1));
  }

  html body .c-el .el-badge {
    font-size: calc(10px / var(--zoom, 1));
    top: calc(-18px / var(--zoom, 1));
    padding: calc(1px / var(--zoom, 1)) calc(4px / var(--zoom, 1));
  }

  .zoom-hud {
    position: fixed;
    top: 40%;
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 14px;
    border-radius: 16px;
    background: rgba(9, 9, 11, .88);
    color: #fff;
    font: 600 14px/1 'Inter', sans-serif;
    pointer-events: none;
    z-index: 300;
  }

  .zoom-hud[hidden] {
    display: none;
  }

  /* ---------- PDF preview: thumbnails shown in full, no inner scrollbars, tidy footer ---------- */
  html body .pdf-preview-body,
  html body .pdf-preview-thumbs,
  html body .pdf-preview-side {
    scrollbar-width: none;
  }

  html body .pdf-preview-body::-webkit-scrollbar,
  html body .pdf-preview-thumbs::-webkit-scrollbar,
  html body .pdf-preview-side::-webkit-scrollbar {
    display: none;
  }

  html body .pdf-preview-viewer {
    overflow: visible;
    height: auto;
    min-height: 0;
  }

  html body .pdf-preview-thumbs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    overflow: visible;
    max-height: none;
    height: auto;
    padding: 2px 0 0;
  }

  html body .pdf-preview-thumb {
    flex: 0 0 auto;
    width: 72px;
    height: auto;
    overflow: visible;
    padding: 3px;
  }

  html body .pdf-preview-thumb img {
    width: 100%;
    height: auto;
    max-height: none;
  }

  /* Download PDF and Print / save sit on one line; with "combine subjects" on, Download one PDF gets its own line */
  html body .pdf-preview-footer > div #downloadPreviewPdfBtn {
    grid-column: auto;
    order: -1;
  }

  html body .pdf-preview-footer > div:has(#downloadIndividualPdfBtn:not([hidden])) {
    grid-template-columns: minmax(0, .7fr) minmax(0, 1.3fr);
  }

  html body .pdf-preview-footer > div:has(#downloadIndividualPdfBtn:not([hidden])) #downloadPreviewPdfBtn {
    grid-column: 1 / -1;
  }

  html body .pdf-preview-footer > div .btn {
    white-space: nowrap;
  }

  /* ---------- Feedback ---------- */
  html body .toast-box {
    left: 12px;
    right: 70px;
    bottom: calc(14px + var(--safe-b));
    justify-content: center;
    font-family: 'Inter', sans-serif;
    font-size: 12.5px;
    line-height: 1.3;
    padding: 8px 12px;
    text-align: left;
    border-radius: 10px;
  }
}

/* Very narrow phones: keep all four actions on one line */
@media screen and (max-width: 359px) {
  :root {
    --tap: 40px;
  }

  html body .brand-title {
    display: none;
  }

  html body .subject-bar {
    grid-template-columns: minmax(0, 1fr) 80px auto;
  }

  html body .subject-bar .course-switcher-top-btn {
    padding: 0 7px;
    font-size: 12px;
  }
}

@media screen and (max-width: 760px) and (prefers-reduced-motion: reduce) {
  html body .sidebar {
    transition: none;
  }
}

@media print {
  .mobile-edit-fab,
  .zoom-hud,
  .sheet-head {
    display: none !important;
  }
}
