@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Manrope:wght@500;600;700&family=Open+Sans:wght@400;500;600&display=swap");

:root {
  /* Typography */
  --font-primary: "Inter", "Segoe UI", sans-serif;
  --font-secondary: "Manrope", "Segoe UI", sans-serif;
  --font-tertiary: "Open Sans", "Segoe UI", sans-serif;

  /* Light theme palette */
  --color-bg-app: #f3f3f3;
  --color-text-main: #16181d;
  --color-text-muted: #586173;
  --color-text-inverse: #ffffff;
  --color-icon: var(--color-text-main);

  --color-surface-1: #ffffff;
  --color-surface-2: #f8f9fc;
  --color-surface-3: #f0f0f0;
  --color-surface-4: #dddddd;
  --color-surface-overlay: rgb(255 255 255 / 0.95);

  --color-border-soft: #dddddd;
  --color-border-mid: #d8deeb;
  --color-border-strong: #d9deea;
  --color-border-contrast: #e2e5ee;

  --color-overlay-backdrop: rgb(14 18 28 / 0.38);
  --color-scroll-track: #e6e9f0;
  --color-scroll-thumb: #adb9cf;
  --color-thumbnail-label-bg: rgb(0 0 0 / 0.55);

  --color-accent: #4f6ef7;
  --color-accent-strong: #4f6ef7;
  --color-spinner-track: #c8d3ea;
  --accent-rgb: 79 110 247;

  --shadow-floating: 0 4px 16px rgb(0 0 0 / 0.2);
  --shadow-canvas: 0 3px 12px rgb(0 0 0 / 0.15);
  --shadow-panel: 0 12px 32px rgb(16 24 40 / 0.24);
  --shadow-loader: 0 6px 18px rgb(0 0 0 / 0.14);

  --icon-size: 18px;
  --icon-stroke-width: 2;
  --button-size: 42px;
  --control-radius-button: 12px;
  --control-radius-group: 14px;
}

body.dark-mode {
  --color-bg-app: #16181c;
  --color-text-main: #e7e9ed;
  --color-text-muted: #b8bec8;
  --color-text-inverse: #f5f6f8;
  --color-icon: var(--color-text-main);

  --color-surface-1: #1f2227;
  --color-surface-2: #272b31;
  --color-surface-3: #2d3239;
  --color-surface-4: #373d45;
  --color-surface-overlay: rgb(31 34 39 / 0.96);

  --color-border-soft: #343942;
  --color-border-mid: #404752;
  --color-border-strong: #404752;
  --color-border-contrast: #404752;

  --color-overlay-backdrop: rgb(8 10 14 / 0.56);
  --color-scroll-track: #1b1f25;
  --color-scroll-thumb: #535c69;
  --color-thumbnail-label-bg: rgb(0 0 0 / 0.55);

  --color-accent: #8ca0c1;
  --color-accent-strong: #9ab0d4;
  --color-spinner-track: #5d687a;
  --accent-rgb: 140 160 193;

  --shadow-floating: 0 8px 22px rgb(0 0 0 / 0.4);
  --shadow-canvas: 0 8px 24px rgb(0 0 0 / 0.45);
  --shadow-panel: 0 14px 34px rgb(0 0 0 / 0.56);
  --shadow-loader: 0 10px 26px rgb(0 0 0 / 0.48);
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--color-bg-app);
  color: var(--color-text-main);
  font-family: var(--font-primary);
}

button,
input,
select,
textarea {
  font-family: var(--font-primary);
}

.icon {
  width: var(--icon-size);
  height: var(--icon-size);
  display: inline-block;
  flex: 0 0 auto;
  vertical-align: middle;
  color: var(--color-icon);
  fill: none;
  stroke: currentColor;
  stroke-width: var(--icon-stroke-width);
  stroke-linecap: round;
  stroke-linejoin: round;
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--color-scroll-thumb) var(--color-scroll-track);
}

*::-webkit-scrollbar {
  width: 12px;
  height: 12px;
}

*::-webkit-scrollbar-track {
  background: var(--color-scroll-track);
}

*::-webkit-scrollbar-thumb {
  border-radius: 999px;
  border: 3px solid var(--color-scroll-track);
  background: var(--color-scroll-thumb);
}

:root {
  /* width of the left sidebar that holds page previews */
  --sidebar-width: 140px;
}

.container {
  display: flex;
  height: 100vh;
}

.main-viewers {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--color-surface-1);
  border-right: 1px solid var(--color-border-soft);
  display: flex;
  flex-direction: column;
}

#thumbnails {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.thumbnail {
  margin-bottom: 10px;
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 4px;
  position: relative;
  overflow: hidden;
}

.thumbnail.active {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 2px rgb(var(--accent-rgb) / 0.3);
}

.thumbnail canvas {
  width: 100%;
  display: block;
}

.thumbnail-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--color-thumbnail-label-bg);
  color: var(--color-text-inverse);
  font-size: 14px;
  text-align: center;
  padding: 2px 0;
  pointer-events: none;
  font-family: var(--font-tertiary);
}

.thumbnail-special-badges {
  position: absolute;
  top: 4px;
  left: 4px;
  display: inline-flex;
  gap: 4px;
  z-index: 2;
  pointer-events: none;
}

.thumbnail-special-badge {
  position: relative;
  width: 23px;
  height: 29px;
  display: inline-block;
}

.thumbnail-special-badge svg {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 1px 3px rgb(0 0 0 / 0.35));
}

.thumbnail-special-badge .share-square {
  position: absolute;
  top: 4px;
  left: 1px;
  width: 21px;
  height: 21px;
  border-radius: 5px;
  background: var(--badge-color, #a6a6b0);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.35);
}

.thumbnail-special-badge path {
  fill: var(--badge-color, #a6a6b0);
  stroke: var(--badge-color, #a6a6b0);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.thumbnail-special-badge .count {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

.page-indicator {
  padding: 10px;
  border-top: 1px solid var(--color-border-soft);
  display: flex;
  justify-content: center;
  gap: 4px;
  font-size: 14px;
}

.page-indicator input {
  width: 50px;
  text-align: center;
  background: var(--color-surface-1);
  color: var(--color-text-main);
  border: 1px solid var(--color-border-mid);
  border-radius: 8px;
}

.viewer-wrapper {
  flex: 1 1 auto;
  overflow: auto;
  padding: 20px;
  min-width: 0;
  touch-action: pan-x pan-y;
  transition: flex-basis 260ms ease, padding-left 260ms ease;
}

.answers-wrapper,
.due-dates-wrapper,
.whiteboard-wrapper,
.geogebra-wrapper {
  flex: 0 0 0;
  width: 0;
  min-width: 0;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--color-surface-2);
  opacity: 0;
  transform: translateX(-8px);
  pointer-events: none;
  transition: flex-basis 250ms ease, width 250ms ease, opacity 220ms ease, transform 240ms ease;
}

.answers-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
}

.container.show-answers .answers-wrapper,
.container.show-due-dates .due-dates-wrapper,
.container.show-whiteboard .whiteboard-wrapper,
.container.show-geogebra .geogebra-wrapper {
  flex: 1 1 auto;
  width: 100%;
  border: 1px solid var(--color-border-soft);
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

.due-dates-wrapper {
  display: flex;
  flex-direction: column;
}

.geogebra-wrapper {
  display: flex;
  flex-direction: column;
}

.container.has-side-panel .main-viewers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(var(--side-panels-count, 1), minmax(0, 1fr));
  gap: 12px;
  padding: 12px;
}

.container:not(.show-answers) .answers-wrapper,
.container:not(.show-due-dates) .due-dates-wrapper,
.container:not(.show-whiteboard) .whiteboard-wrapper,
.container:not(.show-geogebra) .geogebra-wrapper {
  display: none;
}

.container.has-side-panel .answers-wrapper,
.container.has-side-panel .due-dates-wrapper,
.container.has-side-panel .whiteboard-wrapper,
.container.has-side-panel .geogebra-wrapper {
  grid-column: 1;
  min-height: 0;
}

.container.has-side-panel .viewer-wrapper {
  grid-column: 2;
  min-height: 0;
  padding: 12px;
  border: 1px solid var(--color-border-soft);
  border-radius: 12px;
  background: var(--color-surface-2);
}

.whiteboard-wrapper {
  display: flex;
  flex-direction: column;
}

.whiteboard-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 0;
}

.whiteboard-title {
  font-size: 13px;
  font-family: var(--font-secondary);
  color: var(--color-text-muted);
}

.whiteboard-size-controls {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.whiteboard-size-controls button {
  min-width: 38px;
  height: 30px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--color-border-mid);
  background: var(--color-surface-1);
  color: var(--color-text-main);
  font-family: var(--font-secondary);
  font-size: 12px;
  cursor: pointer;
}

.whiteboard-size-controls button:hover {
  border-color: var(--color-accent);
}

.whiteboard-canvas-wrap {
  flex: 1;
  margin: 8px 10px 10px;
  min-height: 110px;
  border: 1px solid var(--color-border-mid);
  border-radius: 12px;
  background: var(--color-surface-1);
  overflow: auto;
  touch-action: pan-x pan-y;
}

#whiteboardStage {
  position: relative;
  width: max-content;
  height: max-content;
  margin: 0 auto;
}

#whiteboardStage.grid-lines {
  background-color: var(--color-surface-1);
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent 0,
      transparent 27px,
      rgb(140 150 170 / 0.2) 27px,
      rgb(140 150 170 / 0.2) 28px
    ),
    repeating-linear-gradient(
      90deg,
      transparent 0,
      transparent 27px,
      rgb(140 150 170 / 0.2) 27px,
      rgb(140 150 170 / 0.2) 28px
    );
}

#whiteboardStage.grid-dots {
  background-color: var(--color-surface-1);
  background-image: radial-gradient(rgb(140 150 170 / 0.35) 1px, transparent 1px);
  background-size: 22px 22px;
}

#whiteboardCanvas {
  display: block;
  max-width: none;
}

.due-dates-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 10px 10px 0;
}

.due-dates-title {
  margin-right: auto;
  font-size: 13px;
  font-family: var(--font-secondary);
  color: var(--color-text-muted);
}

.due-dates-open-link {
  text-decoration: none;
  font-size: 12px;
  font-family: var(--font-secondary);
  color: var(--color-accent-strong);
}

.due-dates-open-link:hover {
  text-decoration: underline;
}

#dueDatesRefreshBtn,
#geogebraRefreshBtn {
  width: 36px;
  height: 36px;
}

.due-dates-empty {
  border: 1px dashed var(--color-border-mid);
  border-radius: 10px;
  background: var(--color-surface-1);
  color: var(--color-text-muted);
  display: grid;
  place-items: center;
  flex: 1;
  margin: 8px 10px 10px;
  min-height: 110px;
  padding: 14px;
  font-size: 13px;
}

.due-dates-empty[hidden] {
  display: none;
}

#dueDatesFrame,
#geogebraFrame {
  flex: 1;
  width: calc(100% - 20px);
  margin: 8px 10px 10px;
  min-height: 110px;
  border: 1px solid var(--color-border-mid);
  border-radius: 12px;
  background: var(--color-surface-1);
}

.answers-zoom-controls {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 5;
  display: none;
  gap: 10px;
  background: var(--color-surface-1);
  padding: 10px;
  border-radius: var(--control-radius-group);
  box-shadow: var(--shadow-floating);
}

.answers-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 0;
}

.answers-title {
  margin-right: auto;
}

.container.show-answers .answers-zoom-controls {
  display: flex;
}

#answersViewer {
  flex: 1;
  overflow-x: auto;
  overflow-y: auto;
  padding: 8px 10px 84px;
  touch-action: pan-x pan-y;
}

#answersContent,
#viewer {
  min-width: 100%;
  width: max-content;
}

#viewer {
  margin: 0 auto;
}

#answersContent {
  padding-bottom: 20px;
}

.pdf-page {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.book-page-layer {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

.book-page-layer-placeholder {
  background: linear-gradient(120deg, rgb(148 163 184 / 0.14), rgb(148 163 184 / 0.06), rgb(148 163 184 / 0.14));
}

.book-page-skeleton {
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 0%, rgb(255 255 255 / 0.28) 45%, transparent 100%);
  animation: page-skeleton-sweep 1.4s linear infinite;
}

@keyframes page-skeleton-sweep {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

.book-page-layer > canvas {
  display: block;
}

.annotation-canvas {
  position: absolute;
  inset: 0;
  cursor: crosshair;
}

body.marker-placement .annotation-canvas {
  pointer-events: none !important;
  cursor: copy !important;
}

body.share-placement .annotation-canvas {
  pointer-events: none !important;
  cursor: crosshair !important;
}

body.share-placement #viewer,
body.share-placement #viewer * {
  cursor: crosshair !important;
}

.question-page-marker {
  position: absolute;
  width: 16px;
  height: 16px;
  background: var(--marker-color, var(--color-accent));
  z-index: 12;
  transform: translateY(-50%);
  border-radius: 999px;
  border: 2px solid rgb(255 255 255 / 0.9);
  box-shadow:
    0 0 0 1px rgb(15 23 42 / 0.26),
    0 6px 12px rgb(2 6 23 / 0.18);
}

.question-page-marker:hover,
.question-page-marker:focus-visible {
  background: color-mix(in srgb, var(--marker-color, var(--color-accent)) 84%, black);
  border-color: rgb(255 255 255 / 0.95);
}

/* left‑side arrow pointing rightwards */
.question-page-marker.question-page-marker-left {
  left: 0;
  margin-left: -8px;
}

/* right‑side arrow pointing leftwards */
.question-page-marker.question-page-marker-right {
  right: 0;
  margin-right: -8px;
}

/* preview marker should be slightly translucent and ignore pointer events */
.question-page-marker.preview {
  opacity: 0.78;
  pointer-events: none;
}

.question-page-marker.pending {
  opacity: 0.92;
  pointer-events: none;
}

.share-page-zone {
  position: absolute;
  background: transparent;
  border: 1.5px solid color-mix(in srgb, var(--marker-color, #0ea5e9) 72%, white);
  z-index: 11;
  border-radius: 4px;
  box-shadow:
    0 6px 14px rgb(2 6 23 / 0.16),
    inset 0 1px 0 rgb(255 255 255 / 0.34),
    inset 0 -1px 0 rgb(2 6 23 / 0.12);
  pointer-events: none;
}

.share-page-mask {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  pointer-events: none;
}

.share-page-zone.preview {
  border-style: dashed;
  background: rgb(255 255 255 / 0.05);
  box-shadow:
    0 4px 10px rgb(2 6 23 / 0.12),
    inset 0 1px 0 rgb(255 255 255 / 0.3);
  pointer-events: none;
}

.marker-tooltip {
  position: absolute;
  background: var(--color-surface-1);
  border: 1px solid var(--color-border-mid);
  border-radius: 4px;
  padding: 4px 8px;
  white-space: nowrap;
  z-index: 1000;
  font-size: 12px;
  color: var(--color-text);
  box-shadow: var(--shadow-panel);
  pointer-events: none;
}


.answer-page {
  position: relative;
  display: block;
  margin: 0 auto 20px;
}

#answersViewer .answer-page canvas {
  display: block;
  max-width: none;
}

.answer-match-dot {
  position: absolute;
  left: 12px;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--color-accent);
  pointer-events: none;
  box-shadow:
    0 0 0 5px rgb(var(--accent-rgb) / 0.2),
    0 0 14px 4px rgb(var(--accent-rgb) / 0.75);
  transform: translate(-50%, -50%);
}

canvas {
  box-shadow: var(--shadow-canvas);
}

.floating {
  --floating-edge-offset: 20px;
  position: fixed;
  bottom: var(--floating-edge-offset);
  z-index: 80;
  display: flex;
  gap: 10px;
  background: var(--color-surface-1);
  padding: 10px;
  border-radius: var(--control-radius-group);
  box-shadow: var(--shadow-floating);
}

.zoom-controls {
  right: calc(var(--floating-edge-offset) + var(--zoom-pad));
  --zoom-gap: 10px;
  --zoom-pad: 10px;
  bottom: calc(var(--floating-edge-offset) + var(--zoom-pad));
  display: grid;
  grid-template-columns: repeat(4, var(--button-size));
  grid-template-rows: repeat(2, var(--button-size));
  gap: var(--zoom-gap);
  padding: 0;
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  isolation: isolate;
}

.zoom-controls::before,
.zoom-controls::after {
  content: "";
  position: absolute;
  background: var(--color-surface-1);
  border-radius: var(--control-radius-group);
}

.zoom-controls::before {
  left: calc(-1 * var(--zoom-pad));
  right: calc(-1 * var(--zoom-pad));
  bottom: calc(-1 * var(--zoom-pad));
  height: calc(var(--button-size) + (2 * var(--zoom-pad)));
  box-shadow: var(--shadow-floating);
  z-index: -2;
}

.zoom-controls::after {
  top: calc(-1 * var(--zoom-pad));
  right: calc(-1 * var(--zoom-pad));
  bottom: calc(-1 * var(--zoom-pad));
  width: calc(var(--button-size) + (2 * var(--zoom-pad)));
  z-index: -1;
}

.zoom-controls #zoomOut {
  grid-column: 1;
  grid-row: 2;
}

.zoom-controls #zoomIn {
  grid-column: 2;
  grid-row: 2;
}

.zoom-controls .resetZoomBtn {
  grid-column: 3;
  grid-row: 2;
}

.zoom-controls #fullscreenBtn {
  grid-column: 4;
  grid-row: 2;
}

.zoom-controls #annotationToggleBtn {
  grid-column: 4;
  grid-row: 1;
}

.annotation-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--button-size);
  min-width: var(--button-size);
  height: var(--button-size);
  padding: 0;
}

.annotation-toggle-btn.active {
  background: var(--color-accent);
  color: var(--color-text-inverse);
}

.annotation-panel {
  position: fixed;
  top: 18px;
  right: 18px;
  width: 240px;
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--color-border-mid);
  background: var(--color-surface-overlay);
  box-shadow: var(--shadow-floating);
  opacity: 0;
  pointer-events: none;
  transform: translateX(10px);
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 22;
}

.annotation-panel.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}

.annotation-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.annotation-panel-header h3 {
  margin: 0;
  font-size: 14px;
  font-family: var(--font-secondary);
}

#annotationCloseBtn {
  width: var(--button-size);
  min-width: var(--button-size);
  height: var(--button-size);
}

.annotation-panel-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-mid);
  border-radius: 10px;
  padding: 9px;
}

.annotation-label {
  font-size: 12px;
  color: var(--color-text-muted);
  font-family: var(--font-secondary);
}

.annotation-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.annotation-row.annotation-row-compact {
  grid-template-columns: 1fr 1.2fr 1.2fr;
}

.annotation-row.annotation-row-quad {
  grid-template-columns: repeat(4, 1fr);
}

.annotation-row button {
  width: 100%;
}

.icon-only-btn {
  min-width: var(--button-size);
  width: var(--button-size);
  height: var(--button-size);
  padding: 0;
}

#annotationDrawBtn.active,
#annotationEraseBtn.active,
#annotationVisibilityBtn.active {
  background: var(--color-accent);
  color: var(--color-text-inverse);
}

#whiteboardGridNoneBtn.active,
#whiteboardGridLinesBtn.active,
#whiteboardGridDotsBtn.active {
  background: var(--color-accent);
  color: var(--color-text-inverse);
}

.annotation-color-presets {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.annotation-color-swatch {
  width: 100%;
  height: 32px;
  border-radius: 9px;
  border: 1px solid var(--color-border-mid);
  background: var(--swatch);
  min-width: 0;
}

.annotation-color-swatch:hover,
.annotation-color-swatch:focus-visible {
  background: color-mix(in srgb, var(--swatch, var(--color-accent)) 84%, black);
}

.annotation-color-swatch.active {
  box-shadow: 0 0 0 2px rgb(var(--accent-rgb) / 0.35);
  border-color: var(--color-accent);
}

.annotation-size-row {
  display: grid;
  grid-template-columns: 1fr 32px;
  gap: 8px;
  align-items: center;
}

#annotationSize {
  width: 100%;
}

#annotationSizeValue {
  text-align: center;
  font-size: 12px;
  color: var(--color-text-muted);
  font-family: var(--font-secondary);
}

.annotation-full-btn {
  width: var(--button-size);
  min-width: var(--button-size);
  height: var(--button-size);
  align-self: stretch;
}

.annotation-full-btn.danger {
  color: #ce3a3a;
}

.annotation-panel .danger {
  color: #ce3a3a;
}

#annotationClearAllBtn {
  color: var(--color-text-main);
}

#annotationClearAllBtn .icon {
  color: #ce3a3a;
}

.annotation-panel button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#annotationVisibilityBtn .icon-hide {
  display: none;
}

#annotationVisibilityBtn.active .icon-show {
  display: none;
}

#annotationVisibilityBtn.active .icon-hide {
  display: inline-block;
}

.annotation-action-btn {
  min-width: 0;
  width: 100%;
  gap: 6px;
  padding: 0 8px;
  justify-content: flex-start;
}

.annotation-action-btn .icon {
  flex: 0 0 auto;
}

.annotation-action-label {
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

body.annotations-hidden .annotation-canvas {
  display: none;
}

.actions {
  /* replicate zoom-controls layout but anchored just to the right of the sidebar */
  --zoom-gap: 10px;
  --zoom-pad: 10px;
  --island-cavity-left: calc(var(--button-size) + var(--zoom-gap));
  --island-cavity-bottom: calc(var(--button-size) + var(--zoom-gap));
  --island-cavity-width: calc((4 * var(--button-size)) + (3 * var(--zoom-gap)));
  position: fixed;
  /* ensure the island sits immediately after the page previews sidebar
     (sidebar width defined via --sidebar-width) */
  left: calc(var(--sidebar-width) + var(--floating-edge-offset) + var(--zoom-pad));
  bottom: calc(var(--floating-edge-offset) + var(--zoom-pad));

  display: grid;
  grid-template-columns: var(--button-size) auto;
  grid-template-rows: var(--button-size) auto;
  gap: var(--zoom-gap);
  background: transparent;
  padding: 0;
  box-shadow: none;
  overflow: visible;
}

.actions::before,
.actions::after {
  content: "";
  position: absolute;
  background: var(--color-surface-1);
  border-radius: var(--control-radius-group);
}

/* horizontal bar along bottom row */
.actions::before {
  left: calc(-1 * var(--zoom-pad));
  right: calc(-1 * var(--zoom-pad));
  bottom: calc(-1 * var(--zoom-pad));
  height: calc(var(--button-size) + (2 * var(--zoom-pad)));
  box-shadow: var(--shadow-floating);
  z-index: -2;
}

/* vertical bar along first column */
.actions::after {
  top: calc(-1 * var(--zoom-pad));
  bottom: calc(-1 * var(--zoom-pad));
  left: calc(-1 * var(--zoom-pad));
  width: calc(var(--button-size) + (2 * var(--zoom-pad)));
  z-index: -1;
}

.actions-column {
  grid-column: 1;
  grid-row: 1 / span 2;
  display: grid;
  grid-template-rows: repeat(3, var(--button-size));
  gap: var(--zoom-gap);
  padding: 0;
  /* background/box-shadow now provided by parent pseudo-elements */
}

/* ensure each column child is sized like the buttons and centered */
.actions-column > * {
  display: grid;
  place-items: center;
  justify-self: center;
  width: var(--button-size);
  height: var(--button-size);
}

.actions-row {
  grid-column: 2;
  grid-row: 2;
  display: grid;
  grid-template-columns: repeat(4, var(--button-size));
  gap: var(--zoom-gap);
  padding: 0;
  /* background/box-shadow now provided by parent pseudo-elements */
  align-self: end; /* keep the horizontal row at the bottom of the container */
  justify-content: center;
}

/* ensure buttons in the left floating actions island are a consistent size */
.floating.actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--button-size);
  min-width: var(--button-size);
  height: var(--button-size);
  padding: 0;
}

.home-button-wrap {
  position: static;
}

.questions-wrap {
  position: static;
}

.recent-tray {
  position: absolute;
  left: var(--island-cavity-left);
  bottom: var(--island-cavity-bottom);
  width: min(var(--island-cavity-width), calc(100vw - 26px));
  padding: 8px;
  border-radius: var(--control-radius-group);
  border: 1px solid var(--color-border-mid);
  background: var(--color-surface-1);
  box-shadow: var(--shadow-floating);
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.actions.home-hover .recent-tray,
.home-button-wrap:hover .recent-tray,
.home-button-wrap:focus-within .recent-tray,
.recent-tray:hover {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.recent-tray-title {
  padding: 2px 2px 8px;
  font-size: 12px;
  font-family: var(--font-secondary);
  color: var(--color-text-muted);
}

.recent-quick-list {
  display: grid;
  gap: 8px;
}

.recent-card {
  text-decoration: none;
  color: inherit;
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 8px;
  align-items: center;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-mid);
  border-radius: 10px;
  padding: 6px;
}

.recent-card:hover {
  border-color: var(--color-border-strong);
  background: var(--color-surface-3);
}

.recent-thumb-slot {
  width: 44px;
  height: 44px;
}

.recent-thumb {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  border: 1px solid var(--color-border-soft);
  background: var(--color-surface-3);
  display: block;
  object-fit: cover;
}

.recent-card.link-item .recent-thumb {
  border-radius: 12px;
}

.recent-fallback {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  border: 1px solid var(--color-border-soft);
  background: var(--color-surface-3);
  font-size: 10px;
  font-family: var(--font-secondary);
  color: var(--color-text-muted);
}

.recent-title {
  min-width: 0;
  font-size: 12px;
  font-family: var(--font-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recent-type {
  margin-top: 2px;
  font-size: 11px;
  color: var(--color-text-muted);
}

.recent-empty {
  border: 1px dashed var(--color-border-mid);
  border-radius: 10px;
  background: var(--color-surface-2);
  padding: 10px;
  font-size: 12px;
  color: var(--color-text-muted);
  text-align: center;
}

#questionsBtn.active {
  background: var(--color-accent);
  color: var(--color-text-inverse);
}

#shareBtn.active {
  background: var(--color-accent);
  color: var(--color-text-inverse);
}

#questionsBtn.placing {
  box-shadow:
    0 0 0 3px rgb(var(--accent-rgb) / 0.25),
    0 8px 18px rgb(var(--accent-rgb) / 0.35);
}

.questions-tray {
  position: absolute;
  left: var(--island-cavity-left);
  bottom: var(--island-cavity-bottom);
  width: min(420px, calc(100vw - 24px));
  min-height: min(var(--island-cavity-width), calc(100vh - 120px));
  max-height: min(68vh, 460px);
  padding: 10px;
  border-radius: var(--control-radius-group);
  border: 1px solid var(--color-border-mid);
  background: var(--color-surface-1);
  box-shadow: var(--shadow-floating);
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: hidden;
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.questions-tray.is-open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.questions-tray-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--color-border-soft);
}

.questions-tray .recent-tray-title {
  margin: 0;
  padding: 0;
  font-size: 12px;
  font-weight: 700;
}

.questions-save-btn {
  width: auto;
  min-width: 0;
  height: 30px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 11px;
  flex: 0 0 auto;
  white-space: nowrap;
}

.questions-save-btn.is-armed {
  background: var(--color-accent);
  color: var(--color-text-inverse);
}

.share-package-status {
  min-height: 16px;
  font-size: 11px;
  line-height: 1.3;
  color: var(--color-text-muted);
  padding: 0 2px;
}

.questions-mode-hint {
  margin: 0;
  padding: 7px 8px;
  border-radius: 8px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-soft);
  font-size: 11px;
  line-height: 1.3;
  color: var(--color-text-muted);
}

.questions-quick-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 3px;
  align-items: stretch;
}

.questions-section-label {
  font-size: 11px;
  color: var(--color-text-muted);
  padding: 2px 2px 0;
}

.questions-section-label.imported-book-separator {
  font-size: 13px;
  font-weight: 600;
}

.questions-other-books {
  border: 1px solid var(--color-border-mid);
  border-radius: 10px;
  background: var(--color-surface-2);
  padding: 6px;
}

.questions-other-summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-secondary);
  list-style: none;
  user-select: none;
}

.questions-book-group {
  margin-top: 6px;
  border: 1px solid var(--color-border-mid);
  border-radius: 8px;
  background: var(--color-surface-1);
  padding: 6px;
}

.questions-book-summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
  list-style: none;
  user-select: none;
}

.questions-book-list {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.question-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-mid);
  border-radius: 10px;
  padding: 12px;
  border-left: 4px solid var(--marker-color, var(--color-accent));
  flex: 0 0 auto;
}

.question-card.shared-card {
  border-left-style: dashed;
}

.question-card-share-selected {
  box-shadow: 0 0 0 2px rgb(var(--accent-rgb) / 0.2);
}

.question-card-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}

.question-share-check {
  width: 16px;
  height: 16px;
  margin: 4px 6px 0 0;
  accent-color: var(--color-accent);
}

.question-open-btn {
  width: 100%;
  min-width: 0;
  height: auto;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 0;
  display: grid;
  gap: 6px;
  color: inherit;
  overflow: visible;
}

.question-open-btn:hover {
  background: transparent;
  border-color: transparent;
}

.question-card-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.question-color-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--marker-color, var(--color-accent));
  border: 1px solid rgb(255 255 255 / 0.85);
  box-shadow: 0 0 0 1px rgb(15 23 42 / 0.24);
  flex: 0 0 auto;
}

.question-card-title {
  font-size: 13px;
  font-family: var(--font-secondary);
  font-weight: 600;
  line-height: 1.3;
  white-space: normal;
  overflow-wrap: break-word;
}

.question-card-meta {
  display: grid;
  gap: 2px;
}

.question-card-page {
  margin-top: 0;
  font-size: 12px;
  line-height: 1.35;
  color: var(--color-text-muted);
  white-space: normal;
  overflow-wrap: break-word;
  word-break: normal;
}

.question-card-text {
  margin-top: 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--color-text-muted);
  display: block;
  white-space: normal;
  overflow-wrap: break-word;
  word-break: normal;
}

.question-delete-btn {
  width: 32px;
  min-width: 32px;
  height: 32px;
  border-radius: 8px;
  padding: 0;
  justify-self: end;
  align-self: start;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 32px;
}

.question-delete-btn .icon {
  width: 15px;
  height: 15px;
}

.questions-empty {
  border: 1px dashed var(--color-border-mid);
  border-radius: 10px;
  background: var(--color-surface-2);
  padding: 10px;
  font-size: 12px;
  color: var(--color-text-muted);
  text-align: center;
}

.question-composer {
  position: fixed;
  z-index: 45;
  width: min(320px, calc(100vw - 24px));
  padding: 10px;
  box-sizing: border-box;
  border-radius: 12px;
  border: 1px solid var(--color-border-mid);
  background: var(--color-surface-overlay);
  box-shadow: var(--shadow-floating);
}

.question-composer-meta {
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--color-text-muted);
}

.question-color-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.question-color-swatch {
  width: 24px;
  height: 24px;
  min-width: 24px;
  border-radius: 999px;
  border: 2px solid rgb(255 255 255 / 0.6);
  background: var(--marker-swatch, var(--color-accent));
  box-shadow: 0 0 0 1px rgb(15 23 42 / 0.25);
}

.question-color-swatch:hover,
.question-color-swatch:focus-visible {
  background: color-mix(in srgb, var(--marker-swatch, var(--color-accent)) 84%, black);
}

.question-color-swatch.active {
  box-shadow:
    0 0 0 2px var(--color-accent),
    0 0 0 4px rgb(var(--accent-rgb) / 0.2);
}

.question-composer textarea {
  width: 100%;
  min-height: 72px;
  max-height: 200px;
  resize: vertical;
  box-sizing: border-box;
  border-radius: 9px;
  border: 1px solid var(--color-border-mid);
  background: var(--color-surface-2);
  color: var(--color-text-main);
  padding: 8px;
  font: inherit;
  font-size: 13px;
}

.question-composer-actions {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.question-composer-save,
.question-composer-cancel {
  width: auto;
  min-width: 0;
  height: 30px;
  border-radius: 8px;
  padding: 0 10px;
  font-size: 12px;
}

@media (max-width: 900px) {
  .actions {
    left: 20px;
    bottom: 84px;
  }

  .recent-tray,
  .questions-tray {
    left: 0;
    width: min(360px, calc(100vw - 24px));
  }
}

button {
  cursor: pointer;
  border: 1px solid var(--color-border-mid);
  background: var(--color-surface-3);
  color: var(--color-text-main);
  width: var(--button-size);
  height: var(--button-size);
  padding: 0;
  border-radius: var(--control-radius-button);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-secondary);
  font-weight: 600;
  line-height: 1;
  text-align: center;
}

button:hover {
  background: var(--color-surface-4);
  border-color: var(--color-border-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

button:disabled:hover {
  background: var(--color-surface-3);
  border-color: var(--color-border-mid);
}

button.is-unavailable-action {
  cursor: not-allowed;
  opacity: 0.5;
}

button.is-unavailable-action:hover {
  background: var(--color-surface-3);
  border-color: var(--color-border-mid);
}

.missing-info-popup {
  position: fixed;
  inset: 0;
  background: var(--color-overlay-backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}

.missing-info-popup.is-open {
  opacity: 1;
  pointer-events: auto;
}

.missing-info-popup-card {
  width: min(460px, calc(100vw - 32px));
  background: var(--color-surface-1);
  border: 1px solid var(--color-border-strong);
  border-radius: 12px;
  box-shadow: var(--shadow-panel);
  padding: 16px;
  margin: 24px;
}

.missing-info-popup-title {
  margin: 0;
  font-size: 22px;
  font-family: var(--font-secondary);
  color: #c0392b;
}

.missing-info-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.missing-info-popup-close-icon {
  min-width: 38px;
  width: 38px;
  height: 38px;
}

.missing-info-popup-text {
  margin: 0 0 10px;
  color: var(--color-text-muted);
}

.missing-info-popup-note {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--color-text-muted);
  font-style: italic;
}

.missing-info-popup-chip {
  margin: 0 0 12px;
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--color-accent) 36%, var(--color-border-mid));
  background: color-mix(in srgb, var(--color-accent) 12%, var(--color-surface-2));
  color: var(--color-text-main);
  padding: 6px 12px;
  font-weight: 600;
}

.missing-info-popup-email {
  color: var(--color-accent-strong);
  font-weight: 600;
  text-decoration: none;
}

.missing-info-popup-email:hover,
.missing-info-popup-email:focus-visible {
  text-decoration: underline;
}

.missing-info-popup-contact-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
  position: relative;
}

.missing-info-popup-copy {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 10px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-mid);
}

.missing-info-popup-copy:hover {
  background: var(--color-surface-3);
}

.missing-info-popup-copy svg {
  width: 18px;
  height: 18px;
  display: block;
}

.missing-info-popup-copy.copied {
  border-color: var(--color-accent-strong);
}

.missing-info-popup-copy-feedback {
  position: absolute;
  right: -8px;
  top: -28px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--color-text-inverse);
  background: var(--color-accent-strong);
  border-radius: 999px;
  padding: 4px 8px;
  opacity: 0;
  transform: translateY(4px) scale(0.96);
  pointer-events: none;
}

.missing-info-popup-copy-feedback.is-visible {
  animation: copy-feedback-pop 1150ms ease forwards;
}

@keyframes copy-feedback-pop {
  0% {
    opacity: 0;
    transform: translateY(4px) scale(0.96);
  }
  15% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  72% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  100% {
    opacity: 0;
    transform: translateY(-6px) scale(0.98);
  }
}

#answerBtn.active {
  background: var(--color-accent);
  color: var(--color-text-inverse);
}

#dueDatesBtn.active {
  background: var(--color-accent);
  color: var(--color-text-inverse);
}

#whiteboardBtn.active {
  background: var(--color-accent);
  color: var(--color-text-inverse);
}

#geogebraBtn.active {
  background: var(--color-accent);
  color: var(--color-text-inverse);
}

.settings-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--color-overlay-backdrop);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
  z-index: 25;
  padding: 0; /* island defines its own margin */
}

.settings-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.settings-island {
  width: min(460px, calc(100vw - 32px));
  background: var(--color-surface-1);
  border: 1px solid var(--color-border-strong);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow-panel);
  margin: 24px;
}

.settings-island-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.settings-island-header h2 {
  margin: 0;
  font-size: 22px;
  font-family: var(--font-secondary);
}

.settings-island-header button {
  min-width: 38px;
}

.settings-group {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-contrast);
  border-radius: 10px;
  padding: 12px;
}

.settings-group + .settings-group {
  margin-top: 10px;
}

.settings-group h3 {
  margin: 0 0 8px;
  font-size: 14px;
  font-family: var(--font-secondary);
}

.settings-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 7px 0;
}

.settings-group input[type="range"] {
  width: 100%;
}

.settings-group select {
  width: 100%;
}

.settings-preset-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.settings-preset-color {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--color-border-mid);
  border-radius: 7px;
  background: var(--color-surface-1);
  cursor: pointer;
}

.settings-preset-color::-webkit-color-swatch-wrapper {
  padding: 2px;
}

.settings-preset-color::-webkit-color-swatch {
  border: 0;
  border-radius: 5px;
}

.settings-preset-color::-moz-color-swatch {
  border: 0;
  border-radius: 5px;
}

.settings-inline-action {
  margin-top: 10px;
  width: auto;
  min-width: 0;
  height: 30px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 12px;
}

.settings-footer-link {
  margin-top: 14px;
  text-align: center;
}

.settings-footer-link a {
  color: var(--color-text-muted);
  font-size: 14px;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.settings-footer-link a:hover {
  color: var(--color-text-main);
}

.settings-panel-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.settings-status {
  font-size: 12px;
  color: var(--color-text-muted);
  opacity: 0;
  transition: opacity 2600ms ease-out;
}

.settings-status.visible {
  opacity: 0.8;
}

.loading-indicator {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--color-surface-overlay);
  border: 1px solid var(--color-border-mid);
  border-radius: var(--control-radius-group);
  padding: 8px 14px;
  box-shadow: var(--shadow-loader);
  z-index: 40;
  opacity: 0;
  transition: opacity 180ms ease;
  pointer-events: none;
}

.loading-indicator.visible {
  opacity: 1;
}

.loading-spinner {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 2px solid var(--color-spinner-track);
  border-top-color: var(--color-accent-strong);
  animation: spin 900ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

body.invert-pdfs #viewer .book-page-layer > canvas:not(.annotation-canvas),
body.invert-pdfs #answersViewer .answer-page > canvas,
body.invert-pdfs #thumbnails canvas,
body.invert-pdfs .recent-thumb {
  filter: invert(1) hue-rotate(180deg) contrast(1.08) !important;
}

body.dark-mode.invert-pdfs {
  --color-bg-app: #000000;
  --color-surface-1: #000000;
  --color-surface-2: #050505;
  --color-surface-3: #111111;
  --color-surface-4: #1a1a1a;
  --color-surface-overlay: rgb(0 0 0 / 0.96);
  --color-border-soft: #2a2a2a;
  --color-border-mid: #333333;
  --color-border-strong: #333333;
  --color-border-contrast: #333333;
}

body.dark-mode.invert-pdfs .viewer-wrapper,
body.dark-mode.invert-pdfs .answers-wrapper,
body.dark-mode.invert-pdfs .sidebar,
body.dark-mode.invert-pdfs #viewer,
body.dark-mode.invert-pdfs #answersViewer,
body.dark-mode.invert-pdfs .pdf-page,
body.dark-mode.invert-pdfs .book-page-layer,
body.dark-mode.invert-pdfs .answer-page {
  background: #000000;
}

body.dark-mode.invert-pdfs #viewer .book-page-layer > canvas:not(.annotation-canvas),
body.dark-mode.invert-pdfs #answersViewer .answer-page > canvas,
body.dark-mode.invert-pdfs #thumbnails canvas,
body.dark-mode.invert-pdfs .recent-thumb {
  background: #000000;
  filter: invert(1) hue-rotate(180deg) contrast(1.08) !important;
}

body.dark-mode.invert-pdfs #dueDatesFrame,
body.dark-mode.invert-pdfs #geogebraFrame {
  background: #000000;
  filter: invert(1) hue-rotate(180deg) contrast(1.06);
}

/* Final overrides: keep marker cards readable and prevent button defaults
   from collapsing the text area into a narrow vertical column. */
.question-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  min-height: 0;
}

button.question-open-btn {
  flex: 1 1 auto;
  min-width: 0 !important;
  width: auto !important;
  max-width: none;
  height: auto !important;
  padding: 0 !important;
  display: block !important;
  text-align: left !important;
  line-height: 1.3;
}

button.question-open-btn .question-card-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

button.question-open-btn .question-card-title,
button.question-open-btn .question-card-page,
button.question-open-btn .question-card-text {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  writing-mode: horizontal-tb;
  text-orientation: mixed;
  white-space: normal;
  overflow-wrap: break-word;
  word-break: normal;
}

button.question-open-btn .question-card-page {
  margin-top: 2px;
}

button.question-open-btn .question-card-text {
  margin-top: 4px;
}

button.question-delete-btn {
  flex: 0 0 32px;
}

/* compact marker tray width */
.questions-tray {
  width: min(332px, calc(100vw - 24px));
}

@media (max-width: 900px) {
  .questions-tray {
    width: min(296px, calc(100vw - 24px));
  }
}

/* Align marker tray with the recent-books tray position. */
#questionsWrap .questions-tray {
  position: absolute;
  left: var(--island-cavity-left);
  bottom: var(--island-cavity-bottom);
  top: auto;
  z-index: 30;
}

#shareWrap .share-tray {
  position: fixed;
  left: calc(var(--sidebar-width) + 14px);
  top: 58px;
  width: min(392px, calc(100vw - 24px));
  max-height: min(76vh, 760px);
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--color-border-mid);
  background: var(--color-surface-overlay);
  box-shadow: 0 22px 40px rgb(2 6 23 / 0.26);
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
  z-index: 90;
}

.share-wrap {
  position: fixed;
  left: calc(var(--sidebar-width) + 14px);
  top: 14px;
  z-index: 92;
}

body.split-screen .share-wrap,
body.split-screen .share-package-clear-fab {
  display: none !important;
}

#shareBtn {
  width: 34px;
  min-width: 34px;
  height: 34px;
  border-radius: 8px;
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

#shareBtn .icon,
.share-tool-btn .icon {
  stroke-width: 1.6;
}

#shareBtn .icon {
  color: color-mix(in srgb, var(--color-text-main) 82%, black);
}

#shareBtn:hover {
  background: color-mix(in srgb, var(--color-surface-2) 92%, black 8%);
  border-color: var(--color-border-mid);
}

.share-tray-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--color-border-soft);
}

.share-tray-title-wrap {
  min-width: 0;
}

.share-tray-subtitle {
  margin-top: 3px;
  font-size: 11px;
  color: var(--color-text-muted);
  line-height: 1.3;
}

.share-close-btn {
  width: var(--button-size);
  min-width: var(--button-size);
  height: var(--button-size);
  border-radius: 8px;
}

.share-panel-section {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  gap: 8px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-mid);
  border-radius: 10px;
  padding: 9px;
}

.share-tool-btn {
  width: 100%;
  min-width: 0;
  height: 36px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 12px;
  font-family: var(--font-secondary);
}

.share-tool-btn.is-armed {
  background: var(--color-accent);
  color: var(--color-text-inverse);
}

.share-secondary-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.share-tray .questions-save-btn {
  width: 100%;
  min-width: 0;
  height: 32px;
  padding: 0 8px;
  font-size: 11px;
  border-radius: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
}

#shareTray button {
  min-width: 0;
}

#shareTray .questions-save-btn,
#shareTray .share-tool-btn {
  width: 100%;
}

#shareTray .share-close-btn,
#shareTray .share-copy-btn,
#shareTray .question-delete-btn {
  width: 34px;
  min-width: 34px;
  height: 34px;
}

#shareCreateLinkBtn {
  background: var(--color-surface-2);
  color: var(--color-text-main);
}

#shareCreateLinkBtn:disabled {
  opacity: 0.55;
}

.share-tray .share-package-status {
  padding: 4px 7px;
  border-radius: 8px;
  background: var(--color-surface-1);
  border: 1px solid var(--color-border-mid);
  min-height: 22px;
  display: flex;
  align-items: center;
  font-size: 10px;
  line-height: 1.3;
  color: var(--color-text-muted);
}

.share-list-section {
  flex: 0 1 auto;
  min-height: 0;
}

.share-list-title {
  font-size: 11px;
  color: var(--color-text-muted);
  padding: 0 2px;
}

.share-quick-list {
  flex: 1 1 auto;
  min-height: 120px;
  max-height: min(34vh, 280px);
  padding-right: 3px;
}

.share-tray .question-card-controls {
  align-items: center;
  gap: 10px;
}

.share-selection-card {
  display: flex !important;
  align-items: center;
  gap: 10px;
  padding: 10px;
}

.share-card-left-index {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-family: var(--font-secondary);
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  color: var(--color-text-inverse);
  background: color-mix(in srgb, var(--marker-color, var(--color-accent)) 88%, black);
  height: 34px;
  width: 44px;
  min-width: 44px;
  min-height: 34px;
}

.share-card-body {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.share-selection-card .question-open-btn {
  display: grid !important;
  align-content: center;
  justify-items: start;
  min-height: 34px;
  width: auto !important;
  min-width: 0 !important;
  flex: 0 0 auto;
  text-align: left;
  gap: 0;
}

.share-selection-card .question-card-title-row {
  width: 100%;
  justify-content: flex-start;
}

.share-selection-card .question-card-title {
  font-size: 13px;
  line-height: 1;
}

.share-selection-card .share-card-page-part {
  font-weight: 700;
}

.share-selection-card .share-card-sep-part {
  font-weight: 500;
}

.share-selection-card .share-card-book-part {
  font-weight: 500;
}

.share-selection-card .question-card-page {
  display: none;
}

.share-selection-card .question-card-controls {
  display: grid;
  grid-template-columns: repeat(2, 34px);
  gap: 8px;
  justify-content: start;
  align-items: center;
  align-content: center;
  min-height: 34px;
  margin-left: auto;
}

.share-selection-card .question-delete-btn {
  width: 34px;
  min-width: 34px;
  height: 34px;
}

.share-selection-card .question-delete-btn:only-child {
  grid-column: 2;
}

.share-selection-card .question-delete-btn .icon {
  width: 16px;
  height: 16px;
}

#shareSelectAllBtn,
#shareSelectNoneBtn {
  width: 100% !important;
  min-width: 0 !important;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 10px;
}

#shareSelectAllBtn .icon,
#shareSelectNoneBtn .icon {
  width: 15px;
  height: 15px;
}

.share-card-index {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 20px;
  border-radius: 999px;
  padding: 0 6px;
  font-size: 11px;
  font-family: var(--font-secondary);
  color: var(--color-text-inverse);
  background: color-mix(in srgb, var(--color-accent) 88%, black);
  line-height: 1;
  flex: 0 0 auto;
}

.share-zone-check {
  appearance: none;
  width: 34px;
  height: 34px;
  margin: 0;
  border-radius: 6px;
  border: 1px solid var(--color-border-mid);
  background: var(--color-surface-1);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.2);
  cursor: pointer;
  position: relative;
}

.share-zone-check:hover {
  border-color: var(--color-accent);
}

.share-zone-check:checked {
  background: var(--color-accent);
  border-color: var(--color-accent);
}

.share-zone-check:checked::after {
  content: "";
  position: absolute;
  left: 12px;
  top: 8px;
  width: 7px;
  height: 12px;
  border-right: 2.5px solid var(--color-text-inverse);
  border-bottom: 2.5px solid var(--color-text-inverse);
  transform: rotate(40deg);
}

.share-summary-selected {
  min-height: 22px;
  font-size: 11px;
  line-height: 1.3;
  color: var(--color-text-muted);
  padding: 0 2px;
  white-space: normal;
  overflow-wrap: break-word;
}

.share-summary-list {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 120px;
  gap: 8px;
  max-height: none;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 3px;
}

.share-page-zone {
  display: grid;
  place-items: center;
}

.share-zone-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 92%;
  height: 92%;
  font-family: var(--font-secondary);
  font-weight: 700;
  line-height: 1;
  color: rgb(255 255 255 / 0.88);
  text-shadow:
    0 2px 10px rgb(2 6 23 / 0.6),
    0 0 18px rgb(2 6 23 / 0.45);
  user-select: none;
  pointer-events: none;
  opacity: 0;
  transition: opacity 140ms ease;
  font-size: clamp(16px, calc(min(var(--zone-w, 0.12), var(--zone-h, 0.09)) * 520px), 140px);
}

body.share-tray-open .share-zone-number {
  opacity: 1;
}

.share-summary-section {
  flex: 1 1 auto;
  min-height: 0;
}

body.share-imported-only #shareToolSection,
body.share-imported-only #shareSummarySection,
body.share-imported-only #shareSecondaryActions {
  display: none !important;
}

.share-package-clear-fab {
  position: fixed;
  left: calc(var(--sidebar-width) + ((100vw - var(--sidebar-width)) / 2));
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 89;
  min-width: 150px;
  height: 34px;
  padding: 0 14px;
  border-radius: 9px;
  font-size: 12px;
  font-family: var(--font-secondary);
}

.share-package-clear-fab.is-armed {
  background: #ce3a3a;
  border-color: #ce3a3a;
  color: #fff;
}

.share-package-clear-fab:disabled {
  opacity: 0;
  pointer-events: none;
}

.share-link-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px 34px;
  gap: 8px;
  align-items: center;
}

.share-link-input {
  min-width: 0;
  width: 100%;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--color-border-mid);
  background: var(--color-surface-1);
  color: var(--color-text-muted);
  font-size: 11px;
  padding: 0 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  outline: none;
}

.share-copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  width: 34px;
  height: 34px;
  min-width: 34px;
  overflow: hidden;
}

.share-copy-btn .icon {
  width: 18px;
  height: 18px;
}

.share-link-row .missing-info-popup-copy-feedback {
  right: 44px;
  top: -30px;
}

.share-qr-popup-card {
  width: min(272px, calc(100vw - 32px));
}

.share-qr-popup-title {
  color: var(--color-text-main);
}

.share-qr-popup-note {
  margin: 0 0 12px;
  color: var(--color-text-muted);
}

.share-qr-popup-image-wrap {
  border: 1px solid var(--color-border-mid);
  border-radius: 10px;
  background: #fff;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 0 12px;
}

.share-qr-popup-image {
  width: min(230px, 100%);
  height: auto;
  display: block;
}

.share-qr-popup-url-row {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 8px;
  align-items: center;
}

.share-qr-btn {
  border-radius: 8px;
}

.share-qr-btn .icon {
  width: 18px;
  height: 18px;
}

.share-qr-btn .icon path {
  stroke: currentColor !important;
}

@media (max-width: 900px) {
  #questionsWrap .questions-tray {
    left: var(--island-cavity-left);
    bottom: var(--island-cavity-bottom);
    top: auto;
  }

  #shareWrap .share-tray {
    left: 12px;
    top: 12px;
    bottom: auto;
    position: fixed;
    width: min(94vw, 392px);
    max-height: min(84vh, 680px);
  }

  .share-wrap {
    left: 12px;
    top: 12px;
  }

  .share-package-clear-fab {
    left: 50%;
  }

  .share-secondary-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #clearSharePackageBtn {
    grid-column: 1 / -1;
  }
}
