/* Hides the page while a saved Khmer preference is pending translation
   (see the inline script in index.html's <head>) -- otherwise the
   English defaults baked into the HTML would paint first. Removed by
   applyTranslations() in js/i18n.js once the real text is in place. */
html.lang-pending body { visibility: hidden; }

/* Bundled webfonts. Every Khmer face guarantees correct Khmer shaping;
   Latin faces are paired with a Khmer fallback in FONT_STACKS (state.js)
   so Khmer text still renders no matter which font is chosen. */
@font-face { font-family: 'Angkor'; src: url('../fonts/angkor-khmer-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Battambang'; src: url('../fonts/battambang-khmer-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Bayon'; src: url('../fonts/bayon-khmer-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Bokor'; src: url('../fonts/bokor-khmer-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Content'; src: url('../fonts/content-khmer-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Hanuman'; src: url('../fonts/hanuman-khmer-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Inter'; src: url('../fonts/inter-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Kantumruy Pro'; src: url('../fonts/kantumruy-pro-khmer-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Koulen'; src: url('../fonts/koulen-khmer-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Lato'; src: url('../fonts/lato-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Merriweather'; src: url('../fonts/merriweather-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Montserrat'; src: url('../fonts/montserrat-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Moul'; src: url('../fonts/moul-khmer-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Nokora'; src: url('../fonts/nokora-khmer-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Noto Sans Khmer'; src: url('../fonts/noto-sans-khmer-khmer-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Noto Serif Khmer'; src: url('../fonts/noto-serif-khmer-khmer-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Nunito'; src: url('../fonts/nunito-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Open Sans'; src: url('../fonts/open-sans-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Oswald'; src: url('../fonts/oswald-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Playfair Display'; src: url('../fonts/playfair-display-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Poppins'; src: url('../fonts/poppins-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Preahvihear'; src: url('../fonts/preahvihear-khmer-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Raleway'; src: url('../fonts/raleway-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Roboto'; src: url('../fonts/roboto-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Roboto Mono'; src: url('../fonts/roboto-mono-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Siemreap'; src: url('../fonts/siemreap-khmer-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Source Sans 3'; src: url('../fonts/source-sans-3-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Suwannaphum'; src: url('../fonts/suwannaphum-khmer-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Taprom'; src: url('../fonts/taprom-khmer-400-normal.woff2') format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Noto Sans Khmer'; src: url('../fonts/noto-sans-khmer-khmer-700-normal.woff2') format('woff2'); font-weight: 700; font-display: swap; }

/* Teal/coral theme -- a bright cyan-teal accent for primary actions, a warm
   coral for destructive ones, both themes sharing the same underlying hue
   (light is a tinted-white take on the dark theme's deep teal, rather than
   two unrelated palettes) so switching themes feels like the same product. */
:root {
  --bg: #eef5f5;
  --surface: #ffffff;
  --surface-alt: #e6f2f2;
  --border: #cfe3e3;
  --border-strong: #b9d8d8;
  --text: #10282b;
  --text-muted: #5b7d80;
  --accent: #0e93a1;
  --accent-hover: #0b7883;
  --accent-fg: #ffffff;
  --accent-soft: #e0f7f8;
  --danger: #e2653a;
  --hint-bg: #fff2d1;
  --hint-border: #d9a441;
  --armed-bg: #ffe7a8;
  --armed-border: #d9a441;
  --shadow: rgba(15, 40, 45, 0.18);
  --shadow-soft: rgba(15, 40, 45, 0.10);
  --overlay: rgba(10, 30, 33, 0.45);
  --busy-overlay: rgba(255, 255, 255, 0.75);
  --label-badge-bg: rgba(255, 255, 255, 0.85);
}
[data-theme='dark'] {
  --bg: #0c1e21;
  --surface: #152d31;
  --surface-alt: #1c3a3f;
  --border: #2a4a4f;
  --border-strong: #35595f;
  --text: #e8f5f4;
  --text-muted: #8fb0b3;
  --accent: #16a8b3;
  --accent-hover: #0e8791;
  --accent-fg: #ffffff;
  --accent-soft: #123d42;
  --danger: #f2794d;
  --hint-bg: #3f3313;
  --hint-border: #c99a2e;
  --armed-bg: #4a3b16;
  --armed-border: #c99a2e;
  --shadow: rgba(2, 14, 16, 0.6);
  --shadow-soft: rgba(2, 14, 16, 0.4);
  --overlay: rgba(2, 14, 16, 0.75);
  --busy-overlay: rgba(12, 30, 33, 0.85);
  --label-badge-bg: rgba(21, 45, 49, 0.85);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}
body.lang-km { font-family: 'Noto Sans Khmer', system-ui, -apple-system, 'Segoe UI', sans-serif; }
/* Native checkboxes/radios (OCR language picker, shape-fill toggle, etc.)
   otherwise render in the browser's default blue regardless of theme. */
input[type=checkbox], input[type=radio] { accent-color: var(--accent); }
/* This button's own label is always "ខ្មែរ" regardless of the active UI
   language (a language switcher conventionally names each option in its
   own script), so it needs the Khmer font even when body.lang-km isn't
   applied -- otherwise it renders as tofu on systems with no Khmer font
   of their own. */
#lang-km { font-family: 'Noto Sans Khmer', system-ui, sans-serif; }

#topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border-strong);
  position: sticky;
  top: 0;
  z-index: 50;
  /* A single row, left to right, with Save/Print pinned to the right via
     .topbar-spacer -- wrapping would break that (the wrapped line starts
     over at the left, ignoring the spacer), so overflow scrolls instead. */
  flex-wrap: nowrap;
  overflow-x: auto;
}
.topbar-spacer { flex: 1; min-width: 16px; }
.topbar-tools { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.topbar-view { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.topbar-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
#account { display: flex; align-items: center; flex-shrink: 0; }
#account[hidden], #account [hidden] { display: none; }
.account-btn { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 3px; border-radius: 999px; }
.account-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  overflow: hidden; flex-shrink: 0;
  background: var(--accent); color: var(--accent-fg);
  font-size: 13px; font-weight: 700;
}
.account-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
#account-name { max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#account-menu {
  position: fixed; z-index: 120;
  min-width: 200px; max-width: min(320px, 92vw);
  padding: 12px; border-radius: 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px var(--shadow);
}
#account-menu-name { font-weight: 600; overflow-wrap: anywhere; }
#account-menu-email { color: var(--text-muted); font-size: 13px; margin-bottom: 10px; overflow-wrap: anywhere; }
#btn-sign-out { width: 100%; }
.brand, #lang-toggle, #theme-toggle, #mode-tabs { flex-shrink: 0; }
.brand { font-weight: 700; font-size: 16px; }

#mode-tabs .tab, #lang-toggle .tab, #theme-toggle .tab, #sig-styles .tab, #draw-shape-kinds .tab {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  padding: 6px 10px;
  cursor: pointer;
}
/* Full pill ends, matching the theme's rounder buttons/badges -- the whole
   segmented group reads as one pill-shaped control rather than a row of
   square tabs with only faintly rounded outer corners. */
#mode-tabs .tab:first-child, #lang-toggle .tab:first-child, #theme-toggle .tab:first-child, #sig-styles .tab:first-child { border-radius: 999px 0 0 999px; }
#mode-tabs .tab:last-child, #lang-toggle .tab:last-child, #theme-toggle .tab:last-child, #sig-styles .tab:last-child { border-radius: 0 999px 999px 0; margin-left: -1px; }
#mode-tabs .tab.active, #lang-toggle .tab.active, #theme-toggle .tab.active, #sig-styles .tab.active, #draw-shape-kinds .tab.active { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
#sig-styles { display: flex; flex-wrap: wrap; }
#sig-styles .tab { border-radius: 0; }
#sig-styles .tab:not(:first-child) { margin-left: -1px; }
#sig-styles .tab:first-child { border-radius: 999px 0 0 999px; }
#sig-styles .tab:last-child { border-radius: 0 999px 999px 0; }
/* Wraps to a 2x2 grid at the sidebar's width, so each button just gets a
   uniform radius rather than the single-row first/last-child scheme above
   (which would round only the outer two corners of the whole 2x2 block). */
#draw-shape-kinds { display: flex; flex-wrap: wrap; gap: 1px; margin: 4px 0; }
#draw-shape-kinds .tab { border-radius: 8px; flex: 1 0 calc(50% - 1px); text-align: center; margin-left: 0; }

/* The 6 tool buttons as a 2-column grid instead of stacked full-width --
   keeps the section compact and groups the 4 freehand tools visually
   apart from Shapes/Eraser (which end up alone on their own row). */
#draw-tool-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#draw-tool-grid button { width: 100%; }

#draw-settings { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; padding-top: 8px; border-top: 1px solid var(--border); }
#draw-settings label:not(#draw-fill-row) { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; }
#draw-settings select { font: inherit; padding: 4px 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
#draw-settings input[type=range] { flex: 1; }
#draw-fill-row { display: flex; align-items: center; gap: 6px; font-size: 13px; }
#draw-color-swatches { display: flex; gap: 6px; flex-wrap: wrap; }
.color-swatch {
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
}
.color-swatch.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }


#view-mode { font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
.zoom-group { display: flex; align-items: center; }
.zoom-group button { padding: 6px 10px; }
.zoom-group button:first-child { border-radius: 6px 0 0 6px; }
.zoom-group button:last-child { border-radius: 0 6px 6px 0; }
.zoom-group button:not(:first-child) { border-left: none; margin-left: 0; }
#zoom-level { min-width: 52px; }
#page-nav { display: flex; align-items: center; gap: 6px; }
#page-indicator { font-variant-numeric: tabular-nums; color: var(--text-muted); min-width: 64px; text-align: center; }

.compress-field { font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
.compress-estimate { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.topbar-compress { display: flex; align-items: center; gap: 8px; }
button {
  font: inherit;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
button:hover:not(:disabled) { background: var(--surface-alt); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
button.primary:hover:not(:disabled) { background: var(--accent-hover); }
button.tool-armed { background: var(--armed-bg); border-color: var(--armed-border); }

/* Blocks native pinch/double-tap zoom over the document area specifically
   (normal one-finger scrolling in both directions still works) -- the app
   already has its own zoom (the +/- controls), which re-renders each page
   at the new zoom x devicePixelRatio for a crisp result, unlike native
   browser zoom, which just stretches whatever bitmap is already on screen
   and looks progressively blurrier the further in it goes. */
#main { flex: 1; overflow: auto; touch-action: pan-x pan-y; }

#dropzone {
  height: 100%;
  min-height: 400px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#dropzone.dragover .dz-inner { border-color: var(--accent); background: var(--accent-soft); }
.dz-inner {
  border: 2px dashed var(--text-muted);
  border-radius: 18px;
  padding: 60px 80px;
  text-align: center;
  background: var(--surface);
}
.dz-title { font-size: 20px; font-weight: 600; margin: 0 0 8px; }
.dz-sub { color: var(--text-muted); margin: 0 0 12px; }

#hint-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--hint-bg);
  border-bottom: 1px solid var(--hint-border);
  padding: 6px 16px;
  text-align: center;
}

/* ---------- Edit view ---------- */
#edit-view { padding: 24px 0 80px; }
.page-wrap {
  position: relative;
  margin: 0 auto 24px;
  /* Always white, regardless of theme: this represents the actual page
     background of the document being edited, not app chrome. */
  background: #fff;
  box-shadow: 0 4px 18px var(--shadow);
}
/* Sized to the spread itself (max-content) rather than wrapping, so past
   roughly 100% zoom -- including the 200% default -- the two pages stay side
   by side and #main scrolls sideways across them, instead of the spread
   falling onto separate rows and turning into continuous view. min-width
   keeps it centred when it does fit; centring via the container's own width
   rather than justify-content alone is what keeps the left page reachable
   once the spread is wider than the window. */
#edit-view.view-double {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 24px;
  width: max-content;
  min-width: 100%;
}
#edit-view.view-double .page-wrap { margin: 0; }
/* Grid: every page, two per row. Each page is half the pane wide (see
   baseWidth in editor.js), so at the default zoom the grid fits the screen;
   zoomed past that it's sized to its content and #main scrolls sideways,
   like the spread above. */
#edit-view.view-grid {
  display: grid;
  grid-template-columns: repeat(2, max-content);
  justify-content: center;
  align-items: start;
  gap: 24px;
  width: max-content;
  min-width: 100%;
}
#edit-view.view-grid .page-wrap { margin: 0; }
.page-wrap canvas.page-canvas { display: block; }
.page-wrap.placing { cursor: crosshair; touch-action: none; }
.page-num {
  position: absolute;
  top: 4px;
  left: -44px;
  color: var(--text-muted);
  font-size: 12px;
  /* Purely a label. In double-page mode and on narrow/mobile screens (below)
     it's repositioned inside the page, directly over the canvas -- without
     this it silently swallows the pointerdown that starts text/image/
     signature placement, highlight drawing, and OCR area-select, since
     onPagePointerDown only accepts the page-wrap or canvas as its target. */
  pointer-events: none;
}
/* The left-margin position above assumes a single centered column; in
   double-page mode the left page has little to no left margin to sit in,
   which clips the label off-screen. Anchor it inside the page instead. */
#edit-view.view-double .page-num,
#edit-view.view-grid .page-num {
  left: 6px;
  background: var(--label-badge-bg);
  padding: 1px 6px;
  border-radius: 4px;
}

/* Overlay items */
.item {
  position: absolute;
  cursor: move;
  border: 1px dashed transparent;
  touch-action: none;
}
.item:hover, .item.selected { border-color: var(--accent); }
.item .item-del {
  position: absolute;
  top: -12px;
  right: -12px;
  width: 22px;
  height: 22px;
  line-height: 19px;
  padding: 0;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  border: none;
  font-size: 14px;
  display: none;
}
.item .item-resize {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  cursor: nwse-resize;
  display: none;
}
.item.selected .item-del, .item.selected .item-resize { display: block; }
.item img, .item svg, .item canvas { width: 100%; height: 100%; display: block; pointer-events: none; }
.item.item-highlight .highlight-fill {
  position: absolute;
  inset: 0;
  /* mix-blend-mode alone made the highlight look fully opaque on some
     mobile browsers, where blending over the page canvas doesn't reliably
     apply. Explicit opacity (matching the exported PDF's 0.45) gives plain
     alpha-compositing translucency everywhere, with multiply layered on
     top for browsers that do support it. */
  opacity: 0.45;
  mix-blend-mode: multiply;
  border-radius: 2px;
  pointer-events: none;
}
.item .text-content {
  font-family: 'Noto Sans Khmer', 'Khmer OS', system-ui, sans-serif;
  white-space: pre;
  outline: none;
  min-width: 20px;
  min-height: 1em;
  line-height: 1.6;
  user-select: text;
}
.item-toolbar {
  position: absolute;
  top: -38px;
  left: 0;
  display: none;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px 6px;
  align-items: center;
  white-space: nowrap;
  box-shadow: 0 4px 14px var(--shadow-soft);
}
.item.selected .item-toolbar { display: flex; }
.item-toolbar input[type=number] { width: 54px; font: inherit; padding: 2px 4px; }
.item-toolbar select { font: inherit; font-size: 12px; padding: 2px 4px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); color: var(--text); }
.item-toolbar input[type=color] { width: 28px; height: 24px; padding: 0; border: 1px solid var(--border); }
.item-toolbar input[type=range] { width: 70px; }
.item-fill-label { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; cursor: pointer; }

/* Transient rectangle shown while dragging out an OCR area selection --
   not a saved item, just visual feedback during the drag. */
.ocr-select-box {
  position: absolute;
  border: 2px dashed var(--accent);
  /* Translucent, not the opaque --accent-soft, since this sits directly
     over the page (always white -- see .page-wrap) and needs to still show
     the content underneath while the selection is being dragged out. */
  background: rgba(20, 168, 179, 0.15);
  pointer-events: none;
  z-index: 5;
}

/* ---------- Pages view ---------- */
#pages-view {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding: 24px;
  align-content: flex-start;
}
.thumb {
  position: relative;
  /* Always white, same reasoning as .page-wrap above. */
  background: #fff;
  border: 2px solid var(--border-strong);
  border-radius: 10px;
  padding: 6px 6px 24px;
  cursor: grab;
  user-select: none;
  touch-action: none;
}
.thumb.selected { border-color: var(--accent); background: var(--accent-soft); }
.thumb.drag-over { outline: 3px solid var(--accent); }
.thumb.dragging { opacity: 0.5; }
.thumb canvas { display: block; pointer-events: none; }
.thumb .thumb-label {
  position: absolute;
  bottom: 3px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}
.thumb .thumb-check {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 18px;
  height: 18px;
}

/* ---------- Modals ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  /* Deliberately no align-items:center here: centering a flex item that way
     clips it at the top once it's taller than the container, with no way
     to scroll to the clipped part -- exactly the "cropped on a short
     viewport" bug this is fixing. margin:auto on .modal-box centers it the
     same way when it fits, but degrades to plain top-aligned + scrollable
     when it doesn't, so nothing is ever unreachable. */
  justify-content: center;
  z-index: 100;
  padding: 16px;
  overflow-y: auto;
}
.modal-box {
  background: var(--surface);
  color: var(--text);
  border-radius: 16px;
  padding: 16px;
  max-width: min(640px, 92vw);
  width: 560px;
  margin: auto 0; /* keeps it centered when it fits, scrolled-to-top when it doesn't */
  box-shadow: 0 12px 40px var(--shadow);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  margin: -16px -16px 10px;
  padding: 16px 16px 10px;
  position: sticky;
  top: -16px;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  z-index: 1;
}
.modal-close { border: none; background: none; color: var(--text); font-size: 22px; padding: 0 4px; }
#sig-toolbar { display: flex; align-items: center; flex-wrap: wrap; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
#sig-color-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
#sig-color-swatches { display: flex; gap: 4px; }
/* Undo/redo icon buttons -- plain Unicode arrow glyphs (↶ ↷) render
   inconsistently across platforms/fonts, some barely legible; an inline SVG
   (currentColor stroke, so it follows the button's own text/disabled color)
   looks the same everywhere and matches the weight of the app's other UI. */
.icon-btn { display: inline-flex; align-items: center; justify-content: center; }
.icon-btn svg { display: block; }
.icon-flip { transform: scaleX(-1); }
#sig-canvas {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  touch-action: none;
  background: #fff;
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 12px; }

/* Saved signatures: a row of tiles above the pad -- click one to use it,
   × to delete it. Tiles are always white like the pad itself, since a
   signature is dark ink meant for a white page, whatever the app theme. */
#sig-saved { margin-bottom: 10px; }
/* Wide enough for all four actions on one row once signed in (Save adds one). */
#sig-modal .modal-box { width: 640px; }
#sig-saved[hidden], #sig-saved [hidden] { display: none; }
#sig-saved-head { font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
#sig-saved-signin { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 14px; }
#sig-saved-list { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; }
#sig-saved-status { font-size: 13px; color: var(--text-muted); }
.sig-saved-item { position: relative; flex-shrink: 0; }
.sig-saved-use {
  width: 132px; height: 60px; padding: 4px;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.sig-saved-use:hover:not(:disabled) { background: #fff; border-color: var(--accent); }
.sig-saved-use img { max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.sig-saved-delete {
  position: absolute; top: -6px; right: -6px;
  width: 20px; height: 20px; padding: 0; border-radius: 50%;
  font-size: 14px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--border);
}
.sig-saved-delete:hover:not(:disabled) { background: var(--danger); border-color: var(--danger); color: #fff; }

/* Features modal: wider than the default modal-box, and the iframe fills
   it edge-to-edge -- so this overrides the box's own padding rather than
   reusing it, since .modal-head's negative-margin trick assumes exactly
   the default 16px padding it's compensating for. */
#features-modal .modal-box { max-width: min(1000px, 96vw); width: 1000px; padding: 0; }
#features-modal .modal-head { margin: 0; top: 0; padding: 12px 16px; }

/* ---------- Save modal ---------- */
.save-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 13px; }
.save-field input[type=text] { font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
#save-modal .menu-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
#save-modal .menu-note { font-size: 11px; color: var(--text-muted); line-height: 1.4; margin: 0 0 12px; }
#features-frame { display: block; width: 100%; height: 80vh; border: 0; }
#ocr-output {
  width: 100%;
  height: 260px;
  font: 15px/1.8 'Noto Sans Khmer', 'Khmer OS', system-ui, sans-serif;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  resize: vertical;
  background: var(--surface);
  color: var(--text);
}
#ocr-progress { margin-bottom: 10px; background: var(--surface-alt); border-radius: 8px; position: relative; height: 22px; overflow: hidden; }
#ocr-progress-bar { position: absolute; inset: 0 100% 0 0; background: var(--accent); opacity: 0.55; transition: inset 0.2s; }
#ocr-progress-label { position: relative; display: block; text-align: center; font-size: 12px; line-height: 22px; }

#busy {
  position: fixed;
  inset: 0;
  background: var(--busy-overlay);
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.spinner {
  width: 36px;
  height: 36px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Narrow screens ---------- */
@media (max-width: 640px) {
  #topbar { padding: 8px 12px; gap: 6px; }
  .topbar-spacer { flex: 0 0 8px; }


  /* Same off-screen clipping bug the double-page label had: on a phone the
     page fills nearly the full width, leaving no left margin for the
     label. Anchor it inside the page instead, in every view mode. */
  .page-num {
    left: 6px;
    background: var(--label-badge-bg);
    padding: 1px 6px;
    border-radius: 4px;
  }

  /* Slightly larger touch targets for the small per-item controls. */
  .item .item-del { width: 28px; height: 28px; line-height: 25px; top: -14px; right: -14px; font-size: 16px; }
  .item .item-resize { width: 22px; height: 22px; right: -11px; bottom: -11px; }
  .item-toolbar input[type=color] { width: 36px; height: 32px; }
  .item-toolbar input[type=number] { width: 60px; padding: 5px 4px; }

  .dz-inner { padding: 32px 20px; }
  .dz-title { font-size: 18px; }
}

/* ---------- Recognize (OCR) dropdown menu ---------- */
#btn-recognize .caret { opacity: 0.6; font-size: 11px; }
#ocr-menu {
  position: fixed;
  z-index: 90;
  min-width: 230px;
  max-width: min(300px, calc(100vw - 16px));
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 6px 20px var(--shadow);
}
#ocr-menu .menu-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 6px 8px 4px;
}
#ocr-menu .menu-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  border-radius: 8px;
  padding: 8px;
}
#ocr-menu .menu-item:hover { background: var(--surface-alt); }
#ocr-menu .menu-sep { height: 1px; background: var(--border); margin: 6px 4px; }
#ocr-menu .menu-radio {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
}
#ocr-menu .menu-radio:hover { background: var(--surface-alt); }
#ocr-menu .menu-radio input { margin: 0; flex-shrink: 0; }
#ocr-menu .menu-note {
  font-size: 11px;
  color: var(--text-muted);
  padding: 6px 8px 2px;
  line-height: 1.4;
}

/* ---------- OCR result views (plain text / LaTeX / rendered math) ---------- */
#ocr-views { display: flex; gap: 4px; margin-bottom: 8px; }
.ocr-view-tab {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-alt);
}
.ocr-view-tab.active { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
#ocr-rendered {
  min-height: 120px;
  max-height: 260px;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
#ocr-rendered .math-line { padding: 6px 2px; }
#ocr-rendered .math-line + .math-line { border-top: 1px dashed var(--border); }
/* KaTeX ships its own colours; inherit the app's text colour instead so
   formulas stay legible in dark mode. */
#ocr-rendered .katex { color: var(--text); font-size: 1.15em; }
#ocr-rendered .math-raw { color: var(--text-muted); font-size: 12px; font-style: italic; }

/* ---------- Document tabs ---------- */
#doc-tabs {
  display: flex;
  gap: 4px;
  padding: 6px 12px 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border-strong);
  overflow-x: auto;
}
.doc-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  max-width: 220px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 12px 12px 0 0;
  background: var(--surface-alt);
  color: var(--text);
  cursor: pointer;
  font: inherit;
}
.doc-tab .doc-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-tab.active { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
.doc-tab .doc-close {
  border: none;
  background: none;
  color: inherit;
  opacity: 0.65;
  padding: 0 2px;
  font-size: 15px;
  line-height: 1;
  border-radius: 4px;
}
.doc-tab .doc-close:hover { opacity: 1; background: rgba(127,127,127,0.28); }

/* ---------- Left sidebar ---------- */
#workspace { flex: 1; display: flex; min-height: 0; }
/* Doc tabs live above the document only, not the sidebar, so the sidebar's
   top edge sits flush against the top bar instead of being pushed down by
   the tab strip. */
/* min-width: 0 so a page wider than the window (any zoom past roughly fit,
   including the 200% default) scrolls inside #main -- without it this column
   keeps flex's default min-width: auto, stretches to the page's width, and
   the whole document scrolls sideways instead, panning the sidebar and top
   bar off-screen with it. */
#content-col { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
#sidebar {
  flex: 0 0 234px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 10px;
  background: var(--surface);
  border-right: 1px solid var(--border-strong);
}
.side-sec + .side-sec { margin-top: 6px; }
.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: none;
  border: none;
  padding: 8px 6px;
  border-radius: 8px;
}
.side-head:hover:not(:disabled) { background: var(--surface-alt); }
/* Chevron shows collapsed state; rotates when the section is open. */
.side-head::after {
  content: '▸';
  font-size: 11px;
  transition: transform 0.15s;
}
.side-head[aria-expanded="true"]::after { transform: rotate(90deg); }
.side-body { display: flex; flex-direction: column; gap: 6px; padding: 2px 2px 8px; }
.side-body > button { width: 100%; text-align: left; }
.side-body .zoom-group { display: flex; }
.side-body .zoom-group button { flex: 1; text-align: center; }
.side-body #page-nav { display: flex; align-items: center; gap: 6px; }
.side-body #page-nav button { flex: 0 0 auto; }
.side-body #page-indicator { flex: 1; }
.side-body select { width: 100%; font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
#sidebar .menu-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); padding: 6px 2px 2px; }
#sidebar .menu-radio { display: flex; align-items: center; gap: 8px; padding: 5px 2px; cursor: pointer; font-size: 13px; }
#sidebar .menu-note { font-size: 11px; color: var(--text-muted); line-height: 1.4; padding-top: 4px; }

/* Inline text editing affordance */
.item-toolbar .item-edit.editing { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.item .text-content[contenteditable="plaintext-only"] { box-shadow: 0 0 0 2px var(--accent) inset; }

.item-toolbar .item-edit { font-size: 12px; padding: 3px 8px; border-radius: 4px; }

/* Pinned to the sidebar's bottom edge (margin-top:auto in a flex column);
   when the sections overflow it simply follows at the end of the scroll
   instead of overlapping content. */
.side-bottom-btn {
  display: block;
  margin-top: auto;
  padding: 8px 12px;
  text-align: center;
  text-decoration: none;
  font: inherit;
  color: var(--text);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.side-bottom-btn:hover { background: var(--accent-soft); border-color: var(--accent); }

/* ---------- Dates and saved names on text boxes ---------- */
.item-toolbar .icon-btn { width: 28px; height: 26px; padding: 0; border-radius: 6px; }
.item-toolbar .item-save-name.saved { color: var(--accent); }
.item-toolbar .item-save-name.saved svg { fill: currentColor; }
/* Saved names need sign-in, which only exists on Firebase Hosting. */
.item-save-name, .item-names { display: none !important; }
.account-on .item-save-name, .account-on .item-names { display: inline-flex !important; }

.text-popover {
  position: fixed; z-index: 110;
  width: min(300px, calc(100vw - 16px));
  display: flex; flex-direction: column; gap: 10px;
  padding: 12px; border-radius: 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); box-shadow: 0 10px 30px var(--shadow);
}
.text-popover[hidden] { display: none; }
#names-pop-list { display: flex; flex-direction: column; gap: 8px; max-height: min(50vh, 320px); overflow-y: auto; }
#names-pop-list:empty { display: none; }
#names-pop-signin { display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
#names-pop-status { font-size: 13px; color: var(--text-muted); }
.date-pop-title { font-weight: 600; }
#date-today { width: 100%; min-height: 40px; }
.date-pick-row { display: flex; gap: 8px; }
.date-pick-row input { flex: 1; min-width: 0; font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); color-scheme: light dark; }
.date-format-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--text-muted); }
.date-format-row select { flex: 1; min-width: 0; font: inherit; color: var(--text); padding: 6px 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }

.name-item { display: flex; align-items: center; gap: 8px; }
.name-use {
  flex: 1; min-width: 0; min-height: 52px; padding: 8px 14px;
  text-align: left; font-size: 22px; line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: #fff; border: 1px solid var(--border); border-radius: 12px; /* white like the page it lands on */
}
.name-use:hover:not(:disabled) { background: #fff; border-color: var(--accent); }
.name-delete { width: 34px; height: 34px; padding: 0; border-radius: 50%; font-size: 18px; flex-shrink: 0; }
.name-delete:hover:not(:disabled) { background: var(--danger); border-color: var(--danger); color: #fff; }
#names-pop-add { display: flex; gap: 8px; }
#names-pop-add[hidden] { display: none; }
#names-pop-add input { flex: 1; min-width: 0; font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); }

/* ---------- Phone app layout (≤640px; behaviour in js/mobile.js) ----------
   An app bar on top, a tab bar at the bottom, tools and dialogs in bottom
   sheets, and padding for the notch / home indicator (viewport-fit=cover).
   Wider screens never see any of it. */
#mobile-nav, #more-sheet, #sheet-backdrop, #btn-mobile-more, .sheet-grabber, .sheet-done, .brand-short, #pages-layout { display: none; }

@media (max-width: 640px) {
  @supports (height: 100dvh) { body { height: 100dvh; } }
  html, body { overscroll-behavior: none; }
  button { -webkit-tap-highlight-color: transparent; }
  /* iOS zooms the whole page into any focused field smaller than 16px. */
  input, select, textarea { font-size: 16px; }
  #main { overscroll-behavior: contain; }

  /* App bar: title, undo/redo, Save, ⋯ -- everything else moves to More. */
  #topbar {
    min-height: 52px;
    padding: calc(6px + env(safe-area-inset-top)) calc(8px + env(safe-area-inset-right)) 6px calc(14px + env(safe-area-inset-left));
    gap: 4px;
  }
  #topbar .brand { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; }
  #topbar .brand-full { display: none; }
  #topbar .brand-short { display: inline; }
  .topbar-spacer, #mode-tabs { display: none !important; }
  #topbar-undo-redo button { width: 38px; height: 38px; padding: 0; }
  #btn-export { padding: 8px 14px; border-radius: 999px; font-weight: 600; }
  #btn-mobile-more {
    display: inline-flex; flex-shrink: 0;
    width: 40px; height: 40px; padding: 0;
    border: none; border-radius: 50%; background: transparent;
  }
  #btn-mobile-more:hover:not(:disabled) { background: var(--surface-alt); }
  #doc-tabs { padding: 4px 10px 0; }

  /* Bottom tab bar */
  #mobile-nav:not([hidden]) {
    display: grid; grid-template-columns: repeat(5, 1fr);
    flex: 0 0 auto; position: relative; z-index: 60;
    background: var(--surface);
    border-top: 1px solid var(--border-strong);
    padding: 4px calc(4px + env(safe-area-inset-right)) env(safe-area-inset-bottom) calc(4px + env(safe-area-inset-left));
  }
  .nav-btn {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    min-height: 58px; padding: 6px 2px;
    border: none; border-radius: 14px; background: none;
    color: var(--text-muted); font-size: 11px; font-weight: 600;
  }
  .nav-btn:hover:not(:disabled) { background: none; }
  .nav-btn svg { width: 24px; height: 24px; padding: 3px 14px; border-radius: 14px; box-sizing: content-box; transition: background .2s; }
  .nav-btn span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .nav-btn.active { color: var(--accent); }
  .nav-btn.active svg { background: var(--accent-soft); }

  /* Bottom sheets: the sidebar (one section at a time) and More. */
  #sidebar, .sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 96;
    display: block; width: auto; flex: none;
    max-height: min(80dvh, 640px); overflow-y: auto; overscroll-behavior: contain;
    padding: 0 calc(16px + env(safe-area-inset-right)) calc(14px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
    background: var(--surface); color: var(--text);
    border: none; border-radius: 22px 22px 0 0;
    box-shadow: 0 -12px 40px var(--shadow);
    transform: translateY(105%); visibility: hidden;
    transition: transform .3s cubic-bezier(.2, .8, .2, 1), visibility 0s linear .3s;
  }
  #sidebar.sheet-open, .sheet.sheet-open { transform: none; visibility: visible; transition: transform .3s cubic-bezier(.2, .8, .2, 1); }
  #sidebar.dragging, .sheet.dragging { transition: none; }
  #more-sheet { display: block; } /* beats the id-level hide rule above */
  #sheet-backdrop {
    display: block; position: fixed; inset: 0; z-index: 95;
    background: var(--overlay); opacity: 0; pointer-events: none; transition: opacity .3s;
  }
  #sheet-backdrop.show { opacity: 1; pointer-events: auto; }
  .sheet-grabber {
    display: block; position: sticky; top: 0; z-index: 1;
    height: 22px; margin: 0 -16px; background: var(--surface); cursor: grab; touch-action: none;
  }
  .sheet-grabber::before { content: ''; display: block; width: 40px; height: 5px; margin: 8px auto 0; border-radius: 3px; background: var(--border-strong); }
  .sheet-title { font-size: 17px; font-weight: 700; padding: 2px 2px 12px; touch-action: none; }
  .sheet-done {
    display: block; width: 100%; min-height: 48px; margin-top: 14px;
    font-size: 16px; font-weight: 600; border-radius: 14px;
    background: var(--accent); border-color: var(--accent); color: var(--accent-fg);
  }
  .sheet-done:hover:not(:disabled) { background: var(--accent-hover); }

  #sidebar .side-sec, #sidebar .side-bottom-btn { display: none; }
  #sidebar .side-sec.sheet-current:not([hidden]) { display: block; }
  #sidebar .side-sec + .side-sec { margin-top: 0; }
  #sidebar .sheet-current > .side-head {
    padding: 2px 2px 12px; background: none; border: none; cursor: default; touch-action: none;
    font-size: 17px; font-weight: 700; letter-spacing: 0; text-transform: none; color: var(--text);
  }
  #sidebar .sheet-current > .side-head::after { display: none; }
  #sidebar .side-body { gap: 8px; padding: 0; }
  #sidebar .side-body > button, #draw-tool-grid button { min-height: 50px; font-size: 16px; border-radius: 14px; padding: 10px 14px; }
  #draw-tool-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  #draw-tool-grid button { padding: 10px 4px; text-align: center; }
  #draw-settings label:not(#draw-fill-row) { font-size: 15px; min-height: 40px; }
  #draw-settings input[type=range] { flex: 1; max-width: 60%; }
  #draw-settings select { min-height: 40px; }
  #draw-settings .color-swatch, #draw-color-swatches .color-swatch { width: 32px; height: 32px; }

  /* More sheet */
  .more-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 2px; border-top: 1px solid var(--border); font-size: 15px; }
  .more-group { padding: 12px 2px; border-top: 1px solid var(--border); }
  .more-group:empty, #more-account-slot:has(> #account[hidden]) { display: none; }
  .more-label { font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 8px; }
  #more-sheet .tab { min-height: 40px; padding: 8px 16px; font-size: 15px; }
  #more-view-slot .topbar-view { display: flex; flex-wrap: wrap; gap: 8px; }
  #more-view-slot #view-mode { flex: 1 1 100%; min-height: 44px; padding: 8px 10px; border-radius: 12px; }
  #more-view-slot .zoom-group { display: flex; flex: 1 1 100%; }
  #more-view-slot .zoom-group button { flex: 1; min-height: 44px; font-size: 17px; }
  #more-view-slot #page-nav:not([hidden]) { display: flex; flex: 1 1 100%; align-items: center; gap: 8px; }
  #more-view-slot #page-nav button { min-width: 48px; min-height: 44px; }
  #more-view-slot #page-indicator { flex: 1; text-align: center; }
  #more-account-slot #account { display: block; }
  #more-account-slot #btn-sign-in, #more-account-slot .account-btn { width: 100%; min-height: 48px; justify-content: center; font-size: 16px; border-radius: 14px; }
  #more-account-slot #account-name { max-width: none; }
  .more-actions { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--border); }
  .more-actions > button { width: 100%; min-height: 48px; margin: 0; font-size: 16px; border-radius: 14px; }
  #more-sheet.no-doc #btn-print { display: none; }

  /* A selected item's toolbar can be wider than the screen (text boxes have
     size, edit, font, colour, date and save); let it wrap, growing upward
     from the item instead of covering it. */
  .item-toolbar { top: auto; bottom: calc(100% + 6px); flex-wrap: wrap; white-space: normal; max-width: calc(100vw - 24px); width: max-content; }
  .item-toolbar .icon-btn { width: 36px; height: 34px; }

  /* Pages tab: thumbnails fill the width, two per row or one (pagesMode.js
     sizes each canvas from the measured cell). Press-and-hold reorders, so
     a plain swipe scrolls -- hence pan-y rather than the desktop's none. */
  #pages-layout:not([hidden]) {
    display: flex; justify-content: center; gap: 0;
    position: sticky; top: 0; z-index: 5;
    padding: 10px 16px; background: var(--bg);
  }
  #pages-layout .tab { display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 6px 16px; border: 1px solid var(--border); background: var(--surface-alt); color: var(--text); }
  #pages-layout .tab:first-child { border-radius: 999px 0 0 999px; }
  #pages-layout .tab:last-child { border-radius: 0 999px 999px 0; border-left: none; }
  #pages-layout .tab.active { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
  #pages-view { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 4px 16px calc(24px + env(safe-area-inset-bottom)); }
  #pages-view.layout-column { grid-template-columns: minmax(0, 1fr); }
  .thumb { touch-action: pan-y; -webkit-touch-callout: none; justify-self: center; }
  .thumb .thumb-check { width: 22px; height: 22px; }

  /* Dialogs become bottom sheets too. */
  .modal { padding: env(safe-area-inset-top) 0 0; }
  .modal-box, #sig-modal .modal-box {
    width: 100%; max-width: 100%;
    margin: auto 0 0;
    border-radius: 22px 22px 0 0;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    animation: sheet-up .3s cubic-bezier(.2, .8, .2, 1);
  }
  .modal-head { border-radius: 22px 22px 0 0; }
  .modal-actions > button { flex: 1 1 auto; min-height: 46px; }
  #features-modal .modal-box { border-radius: 22px 22px 0 0; }
}
@keyframes sheet-up { from { transform: translateY(30%); opacity: .5; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  #sidebar, .sheet, #sheet-backdrop, .modal-box { transition: none !important; animation: none !important; }
}
