/* =========================================================
   READER PEN WORKSPACE
   Compact, pressure-aware tablet writing below Mark.
   Ink stays responsive in memory and syncs to Supabase after
   idle, page changes, panel close, and Reader exit.
========================================================= */

html body #bvReaderPenLauncher[hidden] {
  display: none !important;
}

html body #bvSideLaunchers #bvReaderPenLauncher {
  order: 4 !important;
}

html body #bvReaderToolDock[data-active-tool="pen"]
  #bvReaderToolPanelPen:not([hidden]) {
  position: absolute !important;
  left: calc(100vw - 350px) !important;
  right: auto !important;
  top: 50% !important;
  bottom: auto !important;
  transform: translateY(-50%) !important;
  width: min(260px, calc(100vw - 96px)) !important;
  max-height: calc(100dvh - 88px) !important;
  overflow: auto !important;
  border-radius: 8px !important;
  z-index: 3 !important;
}

html body.bv-scroll-reader-active #bvReaderPenLauncher {
  display: none !important;
}

html body #bvReaderInkCanvas {
  position: absolute;
  inset: 0;
  display: block;
  z-index: 26;
  pointer-events: none;
  touch-action: pan-x pan-y;
  cursor: default;
  opacity: 1;
}

html body #bvReaderInkCanvas.is-active {
  pointer-events: auto;
  touch-action: none;
  cursor: crosshair;
}

html body #bvReaderInkCanvas.is-hidden {
  opacity: 0;
}

html body.bv-reader-pen-active #overlayCanvas,
html body.bv-reader-pen-active #ocrOverlayLayer {
  pointer-events: none !important;
}

.bv-reader-tool-panel-pen .bv-reader-tool-panel-content {
  display: grid;
  gap: 8px;
  padding: 9px;
}

.bv-reader-tool-panel-pen .bv-reader-dock-group {
  width: fit-content;
  max-width: 100%;
  margin: 0;
  justify-self: start;
}

.bv-reader-tool-panel-pen .bv-reader-dock-group-label {
  margin: 0 0 4px;
  font-size: 9px;
  letter-spacing: 0.11em;
}

.bv-reader-pen-primary-row,
.bv-reader-pen-colour-strip,
.bv-reader-pen-action-strip {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.bv-reader-pen-primary-row {
  justify-content: space-between;
}

.bv-reader-pen-icon-button {
  display: inline-flex;
  flex: 0 0 43px;
  align-items: center;
  justify-content: center;
  width: 43px;
  height: 43px;
  padding: 0;
  border: 2px solid var(--bv-ink, #171c2c);
  border-radius: 5px;
  background: var(--bv-paper, #fbfaf4);
  color: var(--bv-ink, #171c2c);
  box-shadow: 3px 4px 0 rgba(23, 28, 44, 0.22);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, transform 90ms ease, box-shadow 90ms ease;
}

.bv-reader-pen-icon-button svg,
.bv-reader-pen-custom-colour svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.bv-reader-pen-icon-button:hover,
.bv-reader-pen-icon-button.is-active {
  background: var(--bv-blue, #4465d8);
  color: #fff;
  transform: translateY(-1px);
}

.bv-reader-pen-icon-button:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 2px 0 rgba(23, 28, 44, 0.28);
}

.bv-reader-pen-icon-button:disabled {
  cursor: default;
  opacity: 0.35;
  transform: none;
}

.bv-reader-pen-size-stepper {
  display: grid;
  flex: 1 1 auto;
  grid-template-columns: 38px minmax(36px, 1fr) 38px;
  align-items: center;
  min-width: 118px;
  height: 43px;
  border: 2px solid var(--bv-ink, #171c2c);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.62);
  box-shadow: 3px 4px 0 rgba(23, 28, 44, 0.16);
}

.bv-reader-pen-size-button {
  width: 38px;
  height: 39px;
  min-height: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}

.bv-reader-pen-size-button:first-child {
  border-right: 1px solid rgba(23, 28, 44, 0.2);
}

.bv-reader-pen-size-button:last-child {
  border-left: 1px solid rgba(23, 28, 44, 0.2);
}

.bv-reader-pen-size-preview {
  display: grid;
  place-items: center;
  min-width: 36px;
  height: 100%;
}

.bv-reader-pen-size-preview::before {
  width: var(--bv-reader-pen-preview-size, 11px);
  height: var(--bv-reader-pen-preview-size, 11px);
  max-width: 19px;
  max-height: 19px;
  border-radius: 50%;
  background: var(--bv-ink, #171c2c);
  content: "";
  transition: width 120ms ease, height 120ms ease;
}

.bv-reader-pen-primary-row {
  display: grid !important;
  grid-template-columns: 40px 40px minmax(116px, 1fr);
  align-items: center;
  width: fit-content;
  max-width: 100%;
  gap: 7px;
}

.bv-reader-pen-primary-row > .bv-reader-pen-icon-button {
  width: 40px !important;
  min-width: 40px;
  height: 40px;
  flex: none;
}

.bv-reader-pen-primary-row > .bv-reader-pen-size-stepper {
  grid-column: auto;
  width: 116px;
  min-width: 116px;
  height: 40px;
  grid-template-columns: 36px minmax(32px, 1fr) 36px;
}

.bv-reader-pen-primary-row .bv-reader-pen-size-button {
  width: 36px;
  height: 36px;
}

.bv-reader-pen-colour-strip {
  display: grid !important;
  grid-template-columns: repeat(2, 38px);
  justify-content: start;
  width: fit-content;
  min-width: 0;
  gap: 7px;
  padding: 2px 1px 4px;
}

.bv-reader-pen-recent-colour,
.bv-reader-pen-custom-colour {
  position: relative;
  display: grid;
  place-items: center;
  width: 38px;
  min-width: 38px;
  height: 38px;
  padding: 0;
  overflow: hidden;
  border: 2px solid #fff;
  border-radius: 5px;
  outline: 2px solid var(--bv-ink, #171c2c);
  box-shadow: 2px 3px 0 rgba(23, 28, 44, 0.22);
  cursor: pointer;
  box-sizing: border-box;
  transition: transform 90ms ease, box-shadow 90ms ease;
}

.bv-reader-pen-recent-colour {
  background: var(--bv-pen-swatch, #171717);
}

.bv-reader-pen-recent-colour::after {
  color: #fff;
  font: 900 13px/1 sans-serif;
  text-shadow: 0 1px 2px #000;
  content: "✓";
  opacity: 0;
}

.bv-reader-pen-recent-colour.is-active::after {
  opacity: 1;
}

.bv-reader-pen-recent-colour.is-active {
  transform: translateY(-1px);
  outline-color: var(--bv-blue, #4465d8);
}

.bv-reader-pen-custom-colour {
  background: conic-gradient(#f24444, #f4d63d, #5fc55f, #42b9dc, #5252da, #c74ac8, #f24444);
  color: #fff;
}

.bv-reader-pen-recent-colour:hover,
.bv-reader-pen-custom-colour:hover {
  transform: translateY(-1px);
}

.bv-reader-pen-recent-colour:active,
.bv-reader-pen-custom-colour:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 rgba(23, 28, 44, 0.25);
}

.bv-reader-pen-custom-colour input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  opacity: 0;
}

.bv-reader-pen-custom-colour svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.55));
  pointer-events: none;
}

.bv-reader-pen-colour-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.bv-reader-pen-action-strip {
  display: grid !important;
  grid-template-columns: repeat(2, 38px);
  justify-content: start;
  width: fit-content;
  gap: 7px;
}

.bv-reader-pen-action-strip .bv-reader-pen-icon-button {
  width: 38px !important;
  min-width: 38px;
  height: 38px;
  flex: none;
}

.bv-reader-pen-danger:hover {
  background: #a2333f;
}

.bv-reader-pen-status {
  min-height: 0;
  padding: 5px 8px;
  border-left: 3px solid #2e97a3;
  border-radius: 2px;
  background: rgba(46, 151, 163, 0.08);
  color: var(--bv-text-muted, #667085);
  font-size: 10px;
  line-height: 1.25;
  white-space: normal;
}

@media (min-width: 1101px) {
  html body.bv-reader-pen-workspace-open #viewer .viewer-stack {
    width: min(1480px, calc(100% - 350px)) !important;
    margin-left: 0 !important;
    margin-right: 330px !important;
  }
}

@media (min-width: 701px) and (max-width: 1100px) {
  html body #bvReaderToolDock[data-active-tool="pen"]
    #bvReaderToolPanelPen:not([hidden]) {
    left: calc(100vw - 326px) !important;
    right: auto !important;
    width: min(248px, calc(100vw - 92px)) !important;
    max-height: calc(100dvh - 66px) !important;
  }

  .bv-reader-tool-panel-pen .bv-reader-tool-panel-content {
    gap: 6px;
    padding: 7px;
  }
}

@media (max-width: 700px) {
  html body #bvReaderToolDock[data-active-tool="pen"]
    #bvReaderToolPanelPen:not([hidden]) {
    left: 10px !important;
    right: auto !important;
    top: auto !important;
    bottom: 52px !important;
    transform: none !important;
    width: min(390px, calc(100vw - 20px)) !important;
    max-height: min(56dvh, 500px) !important;
    border-radius: 8px !important;
  }

  .bv-reader-pen-icon-button {
    width: 46px;
    height: 46px;
  }

  .bv-reader-pen-action-strip .bv-reader-pen-icon-button {
    height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bv-reader-pen-icon-button,
  .bv-reader-pen-size-preview::before {
    transition: none;
  }
}


/* C97: compact size control + deferred cloud-save workspace */
.bv-reader-pen-primary-row {
  position: relative;
  display: grid !important;
  grid-template-columns: repeat(2, 40px) !important;
  align-items: center;
  justify-content: start !important;
  width: fit-content !important;
  gap: 7px !important;
}

.bv-reader-pen-primary-row > .bv-reader-pen-icon-button {
  width: 40px !important;
  min-width: 40px !important;
  height: 40px !important;
}

.bv-reader-pen-size-toggle {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  align-items: center;
  gap: 5px;
  width: 87px;
  height: 34px;
  padding: 0 7px;
  border: 2px solid var(--bv-ink, #171c2c);
  border-radius: 5px;
  background: var(--bv-paper, #fbfaf4);
  color: var(--bv-ink, #171c2c);
  box-shadow: 3px 4px 0 rgba(23, 28, 44, 0.18);
  font: 700 9px/1 "Courier Prime", monospace;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, transform 90ms ease, box-shadow 90ms ease;
}

.bv-reader-pen-size-toggle:hover,
.bv-reader-pen-size-toggle[aria-expanded="true"] {
  background: var(--bv-blue, #4465d8);
  color: #fff;
  transform: translateY(-1px);
}

.bv-reader-pen-size-toggle:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 2px 0 rgba(23, 28, 44, 0.28);
}

.bv-reader-pen-size-toggle .bv-reader-pen-size-preview {
  display: grid;
  place-items: center;
  min-width: 20px;
  height: 28px;
}

.bv-reader-pen-size-toggle .bv-reader-pen-size-preview::before {
  background: currentColor;
}

.bv-reader-pen-size-label {
  overflow: hidden;
  text-overflow: clip;
  white-space: nowrap;
}

.bv-reader-pen-size-value {
  font-size: 8px;
  opacity: 0.78;
}

.bv-reader-pen-size-popover {
  grid-column: 1 / -1;
  width: 87px;
  padding: 7px 6px;
  border: 2px solid var(--bv-ink, #171c2c);
  border-radius: 5px;
  background: var(--bv-paper, #fbfaf4);
  box-shadow: 3px 4px 0 rgba(23, 28, 44, 0.18);
  box-sizing: border-box;
}

.bv-reader-pen-size-popover[hidden] {
  display: none !important;
}

.bv-reader-pen-size-range {
  display: block;
  width: 71px;
  margin: 0;
  accent-color: var(--bv-blue, #4465d8);
  touch-action: pan-x;
}

.bv-reader-pen-colour-strip,
.bv-reader-pen-action-strip {
  width: 87px !important;
  box-sizing: border-box;
}

.bv-reader-pen-status {
  max-width: 142px;
}


/* C98: edge-anchored compact pen panel */
html body #bvReaderToolDock[data-active-tool="pen"]
  #bvReaderToolPanelPen:not([hidden]) {
  left: calc(100vw - 230px) !important;
  right: auto !important;
  width: 136px !important;
  max-width: calc(100vw - 96px) !important;
}

.bv-reader-tool-panel-pen .bv-reader-tool-panel-content {
  justify-items: end !important;
  padding: 7px !important;
}

.bv-reader-tool-panel-pen .bv-reader-dock-group {
  width: 105px !important;
  min-width: 0 !important;
  max-width: 105px !important;
  justify-self: end !important;
  box-sizing: border-box !important;
}

.bv-reader-tool-panel-pen .bv-reader-dock-group-body {
  margin-inline: 0 !important;
}

.bv-reader-tool-panel-pen .bv-reader-pen-primary-row,
.bv-reader-tool-panel-pen .bv-reader-pen-colour-strip,
.bv-reader-tool-panel-pen .bv-reader-pen-action-strip {
  justify-self: end !important;
}

.bv-reader-tool-panel-pen .bv-reader-pen-status {
  width: 105px !important;
  max-width: 105px !important;
  justify-self: end !important;
  box-sizing: border-box !important;
}

@media (min-width: 701px) and (max-width: 1100px) {
  html body #bvReaderToolDock[data-active-tool="pen"]
    #bvReaderToolPanelPen:not([hidden]) {
    left: calc(100vw - 222px) !important;
    right: auto !important;
    width: 136px !important;
    max-width: calc(100vw - 88px) !important;
  }
}

@media (max-width: 700px) {
  html body #bvReaderToolDock[data-active-tool="pen"]
    #bvReaderToolPanelPen:not([hidden]) {
    left: calc(100vw - 156px) !important;
    right: auto !important;
    width: 136px !important;
    max-width: calc(100vw - 20px) !important;
  }
}

@media (pointer: coarse) {
  .bv-reader-pen-primary-row {
    grid-template-columns: repeat(2, 42px) !important;
  }

  .bv-reader-pen-primary-row > .bv-reader-pen-icon-button {
    width: 42px !important;
    min-width: 42px !important;
    height: 42px !important;
  }

  .bv-reader-pen-size-toggle,
  .bv-reader-pen-size-popover,
  .bv-reader-pen-colour-strip,
  .bv-reader-pen-action-strip {
    width: 91px !important;
  }

  .bv-reader-pen-size-range {
    width: 75px !important;
  }

  .bv-reader-tool-panel-pen .bv-reader-dock-group,
  .bv-reader-tool-panel-pen .bv-reader-pen-status {
    width: 109px !important;
    max-width: 109px !important;
  }

  html body #bvReaderToolDock[data-active-tool="pen"]
    #bvReaderToolPanelPen:not([hidden]) {
    width: 140px !important;
  }
}
