/* Note pages: region inset from panel; notes placed absolutely inside */

:root {
  --note-responsive-font-scale: 1;
  --glass-blur-strength: 2px;
}

.philosopher-notes-content {
  position: relative;
  min-height: 100%;
  box-sizing: border-box;
  overflow: visible;
}

.notes-region {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: visible;
  border: none;
  pointer-events: none;
}

.notes-region > * {
  pointer-events: auto;
}

/* Single notes layer: one stacking context for all notes (left + right). Sibling to panels inside .app-layout. */
.notes-layer {
  position: absolute;
  inset: 0;
  z-index: 31;
  pointer-events: none;
  overflow: visible;
}

.notes-layer > * {
  pointer-events: auto;
}

/* Debug: philosopher zone bounding boxes (left and right). Visible only in dev mode. */
body[data-dev-mode="true"] #left-philosopher-content {
  outline: 2px dashed rgba(100, 180, 255, 0.7);
  outline-offset: 2px;
}

body[data-dev-mode="true"] #right-philosopher-content {
  outline: 2px dashed rgba(255, 180, 100, 0.7);
  outline-offset: 2px;
}

body[data-dev-mode="true"] #mobile-shared-notes-content {
  outline: 2px dashed rgba(150, 255, 150, 0.6);
  outline-offset: 2px;
}

/* Draggable: reserve touch for drag so page doesn't scroll when grabbing (mobile). */
.note-page {
  position: absolute;
  z-index: 1;
  flex-shrink: 0;
  border: none;
  outline: none;
  box-shadow: none;
  cursor: grab;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.margin-item {
  position: absolute;
  z-index: 0;
  flex-shrink: 0;
  border: none;
  outline: none;
  box-shadow: none;
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.margin-item__image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(4px 4px 5px rgba(0, 0, 0, 0.5));
  user-select: none;
  -webkit-user-drag: none;
}

/* For glass margin items (e.g. mglass.webp), cut a circular hole in the
 * image itself so the page behind shows through under the lens. The
 * position and radius are driven by CSS variables set from
 * transparent_x / transparent_y / transparent_radius.
 */
.margin-item--glass .margin-item__image {
  -webkit-mask-image: radial-gradient(
    circle at var(--glass-center-x, 50%) var(--glass-center-y, 50%),
    transparent 0,
    transparent var(--glass-hole-radius, 9px),
    black calc(var(--glass-hole-radius, 9px) + 1px)
  );
  mask-image: radial-gradient(
    circle at var(--glass-center-x, 50%) var(--glass-center-y, 50%),
    transparent 0,
    transparent var(--glass-hole-radius, 9px),
    black calc(var(--glass-hole-radius, 9px) + 1px)
  );
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
}
/* Circular glass lens overlay for special margin items (e.g. magnifying glass).
 * Positioned in the margin-item's bounding-box coordinate space using
 * transparent_x / transparent_y / transparent_radius from object-config.json.
 */
.margin-item--glass .margin-item__glass-lens {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  z-index: 2;
  /* Subtle glass fill; fall back if theme vars are unavailable. */
  /* background: rgba(255, 255, 255, 0.01); */
    /* Subtle but visible glass fill; if this alpha is too low, the
     * backdrop blur becomes almost imperceptible.
     */
    background: rgba(255, 255, 255, 0.1);
  /* Blur the backdrop (chat + philosophers) seen through the lens. */
  backdrop-filter: blur(var(--glass-blur-strength, 3px));
  -webkit-backdrop-filter: blur(var(--glass-blur-strength, 3px));
  /* Light inner rim and soft outer glow for a skeuomorphic feel. */
  box-shadow:
    inset 0 0 50px rgba(255, 255, 255, 0.35),
    0 0 50px rgba(0, 0, 0, 0.35);
}

.margin-item:hover .note-page__close {
  opacity: 1;
  pointer-events: auto;
}

.note-page__paper {
  position: relative;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-color: transparent;
  border: none;
  outline: none;
  box-shadow: none;

  /*
   * NOTE PAPER SHADOW (bottom-right, follows paper shape)
   * -----------------------------------------------
   * Uses filter: drop-shadow() so the shadow follows the opaque parts of the
   * paper image (PNG/WebP transparency). A box-shadow would cast a rectangular
   * shadow; drop-shadow uses the image alpha.
   *
   * To change the effect:
   *   - offset-x offset-y: position (e.g. 6px 6px = more to bottom-right)
   *   - blur-radius: softness (e.g. 12px = softer, 4px = harder)
   *   - color: e.g. rgba(0,0,0,0.25) for lighter, 0.5 for stronger
   * To disable: remove the filter line or set to "none".
   */
  filter: drop-shadow(5px 5px 6px rgba(0, 0, 0, 0.819));
}

.note-page:focus-visible {
  outline: none; /* no sharp box on selected note; paper keeps its drop-shadow */
}

.note-page__controls {
  position: absolute;
  top: 0.35rem;
  right: 0.4rem;
  z-index: 5;
}

.note-page__close {
  appearance: none;
  border: none;
  border-radius: 999px;
  width: 28px;
  height: 28px;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1;
  background: rgba(0, 0, 0, 0.55);
  color: #fefefe;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  transition: background 0.2s ease, color 0.2s ease, opacity 0.2s ease;
  opacity: 0;
  pointer-events: none;
}

.note-page:hover .note-page__close {
  opacity: 1;
  pointer-events: auto;
}

.note-page__close:hover {
  background: rgba(244, 192, 127, 0.8);
  color: #1f1204;
}

.note-page--dragging,
.margin-item.note-page--dragging {
  cursor: grabbing;
  /* Keep container transparent; rely on paper image's own shadow. */
  z-index: 100; /* above chat when dragged over */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Selected note: no extra box-shadow; paper keeps its drop-shadow via .note-page__paper */

/* Entrance: note/margin item appears like a dropped piece of paper (rotation preserved via --note-rotation). */
.note-page--entering,
.margin-item--entering {
  animation: note-enter 0.28s ease-out forwards;
}

@keyframes note-enter {
  from {
    opacity: 0;
    transform: translateY(-10px) rotate(var(--note-rotation, 0deg));
  }
  to {
    opacity: 1;
    transform: translateY(0) rotate(var(--note-rotation, 0deg));
  }
}

.note-page--destroying {
  pointer-events: none;
  animation: note-page-fade-out 0.45s ease-out forwards;
}

@keyframes note-page-fade-out {
  0% {
    opacity: 1;
    transform: scale(1) rotate(var(--note-rotation, 0deg));
  }
  100% {
    opacity: 0;
    transform: scale(0.97) rotate(var(--note-rotation, 0deg));
  }
}

/* Values from NoteFormatConfig applied via --note-* on .note-page__content */
.note-page__content {
  position: absolute;
  overflow: hidden;
  font-size: clamp(0.8rem, calc(var(--note-fontSize, 0.875rem) * var(--note-responsive-font-scale, 1)), 1.35rem);
  line-height: var(--note-lineHeight, 1.45);
  padding-top: var(--note-paddingTop, 0);
  padding-right: var(--note-paddingRight, 0);
  padding-bottom: var(--note-paddingBottom, 0);
  padding-left: var(--note-paddingLeft, 0);
  opacity: var(--note-opacity, 1);
  color: var(--note-color, #333);
  font-family: var(--note-fontFamily, inherit);
  box-sizing: border-box;
  background: transparent;
  border: none;
  outline: none;
  box-shadow: none;
}

/* Debug: allow label above text box to overflow (dev only) */
.note-page__content.note-page__content--debug-overflow {
  overflow: visible;
}

body:not([data-dev-mode="true"]) .note-page__content.note-page__content--debug-overflow {
  overflow: hidden;
}

.note-page__debug-text-box {
  overflow: visible;
}

/* Dev-only overlays: bounding box, text-region box, and padding box */
.note-page__debug-padding-box {
  position: absolute;
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-sizing: border-box;
  pointer-events: none;
  z-index: 4;
}

.note-page__debug-padding-box > span {
  position: absolute;
  top: -14px;
  left: 0;
  padding: 1px 4px;
  font-size: 10px;
  font-family: sans-serif;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  white-space: nowrap;
}

/* Dev-only bounding box + label for random margin objects */
.margin-item__debug-box {
  position: absolute;
  inset: 0;
  border: 1px solid rgba(0, 255, 255, 0.9);
  box-sizing: border-box;
  pointer-events: none;
  z-index: 4;
}

.margin-item__debug-box > .margin-item__debug-label {
  position: absolute;
  top: -14px;
  left: 0;
  padding: 1px 4px;
  font-size: 10px;
  font-family: sans-serif;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  white-space: nowrap;
}

/* Non-dev: hide note bounding box + label, text-character-region box, and padding box */
body:not([data-dev-mode="true"]) .note-page__debug-box,
body:not([data-dev-mode="true"]) .note-page__debug-text-box,
body:not([data-dev-mode="true"]) .note-page__debug-padding-box,
body:not([data-dev-mode="true"]) .margin-item__debug-box {
  display: none !important;
}

/* Left philosopher: use full width of note content (override panel’s fixed 205px) */
.left-philosopher .note-page__content .handwritten {
  margin-top: 0.25rem;
  width: 100%;
  max-width: none;
  box-sizing: border-box;
  background: transparent !important;
  background-image: none !important;
  box-shadow: none !important;
  padding: 0.25rem 0;
  color: inherit;
  font-size: inherit;
  transform: none;
}

.right-philosopher .note-page__content .container {
  margin-top: 0;
  padding-top: 0;
  background: transparent !important;
  box-shadow: none !important;
}

/* Each line reserves full height so new lines go below; written text doesn’t slide up */
.right-philosopher .note-page__content .line {
  position: relative;
  height: 3rem;
  min-height: 3rem;
  margin-bottom: 0;
  padding-bottom: calc(24px + 1.5em);
  flex-shrink: 0;
  box-sizing: border-box;
}

.right-philosopher .note-page__content .line span {
  position: absolute;
  top: 0;
  bottom: auto;
  left: 0.5rem;
  right: auto;
  color: inherit;
}

@media (max-width: 768px) {
  .notes-region {
    inset: 0;
  }

  .note-page__close {
    width: 32px;
    height: 32px;
  }
}
