/* =========================================================
   NEXO INTERACTIVE FLIPBOOK — V6
   Desktop + mobile
   Mobile closed state stays compact.
   Mobile open state expands naturally so the complete
   notebook page and OCR workspace are visible.
   ========================================================= */

.workspace-page {
  position: relative;
  width: 100%;
  padding: 92px 4vw 112px;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  scroll-margin-top: 90px;
  overflow: hidden;
}

.workspace-wrap {
  width: min(1500px, 100%);
  margin: 0 auto;
}

.workspace-intro {
/*  max-width: 760px;*/
  margin: 0 0 46px;
}

.workspace-intro .hero-kicker {
  color: var(--blue);
  font: 500 11px 'DM Mono', monospace;
  letter-spacing: .2em;
  text-transform: uppercase;
}

.workspace-intro h2 {
  margin: 18px 0 20px;
  font-size: clamp(48px, 5.4vw, 82px);
  line-height: .93;
  letter-spacing: -.075em;
  color: var(--text);
}

.workspace-intro p {
/*  max-width: 680px;*/
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
  font-size: 14px;
}

.interactive-book-shell {
  position: relative;
  width: 100%;
}

.book-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin: 0 0 16px;
  padding: 0 4px;
}

.book-status {
  color: var(--muted);
  font: 600 9px 'DM Mono', monospace;
  letter-spacing: .12em;
}

.book-status i {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border-radius: 50%;
  background: #747b83;
  vertical-align: middle;
}

.book-close {
  opacity: 0;
  pointer-events: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: transparent;
  color: var(--muted);
  font: 500 9px 'DM Mono', monospace;
  letter-spacing: .06em;
  cursor: pointer;
}

.book-close.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.flipbook-scene {
  position: relative;
  width: min(1320px, 100%);
  height: 640px;
  margin: 0 auto;
  perspective: 2400px;
  isolation: isolate;
}

.book-shadow {
  position: absolute;
  left: 6%;
  right: 6%;
  bottom: 8px;
  height: 34px;
  z-index: -1;
  border-radius: 50%;
  background: rgba(0,0,0,.38);
  filter: blur(20px);
  transform: scaleX(.82);
}

.book-cover {
  position: absolute;
  z-index: 10;
  left: 50%;
  top: 0;
  width: 440px;
  height: 640px;
  padding: 0;
  border: 0;
  background: transparent;
  transform: translateX(-50%) rotateY(0deg);
  transform-origin: left center;
  transform-style: preserve-3d;
  backface-visibility: hidden;
  cursor: pointer;
  filter: drop-shadow(0 30px 34px rgba(0,0,0,.34));
  transition:
    transform 2.45s cubic-bezier(.18,.72,.16,1),
    opacity .20s linear 2.10s;
}

.book-cover img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.cover-click-badge {
  position: absolute;
  z-index: 6;
  left: 50%;
  bottom: 17%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 142px;
  justify-content: center;
  padding: 11px 16px;
  border: 1px solid rgba(112,168,255,.72);
  border-radius: 999px;
  background: rgba(7,10,14,.82);
  color: #75abff;
  font: 700 10px 'DM Mono', monospace;
  letter-spacing: .10em;
  white-space: nowrap;
  pointer-events: none;
  animation: bookCtaPulse 2.4s ease-in-out infinite;
}

.cover-click-badge .book-icon {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 1px solid rgba(117,171,255,.55);
  border-radius: 4px;
}

@keyframes bookCtaPulse {
  0%,100% {
    transform: translateX(-50%) translateY(0);
    opacity: .88;
  }
  50% {
    transform: translateX(-50%) translateY(-3px);
    opacity: 1;
  }
}

.flipbook-scene.is-open .book-cover {
  transform: translateX(0) rotateY(-178deg);
  pointer-events: none;
  opacity: 0;
}

.flipbook-scene.is-open .cover-click-badge {
  opacity: 0;
  animation: none;
}

.book-spread {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  border-radius: 26px;
  background: #dedbd2;
  box-shadow: 0 30px 70px rgba(0,0,0,.22);
  opacity: 0;
  transform: scale(.985);
  transition:
    opacity .90s ease .65s,
    transform 1.70s cubic-bezier(.2,.72,.16,1) .55s;
}

.flipbook-scene.is-open .book-spread {
  opacity: 1;
  transform: scale(1);
}

.book-page {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(70,91,111,.13) 0,
      rgba(70,91,111,.13) 1px,
      transparent 1px,
      transparent 28px
    ),
    #faf9f5;
  color: #20252a;
}

.book-page-left {
  padding: 32px 38px 34px 44px;
  border-radius: 22px 0 0 22px;
}

.book-page-left::after {
  content: '';
  position: absolute;
  z-index: 1;
  top: 0;
  bottom: 0;
  left: 72px;
  width: 1px;
  background: rgba(169,82,91,.16);
  pointer-events: none;
}

.book-page-right {
  padding: 32px 44px 30px 38px;
  border-radius: 0 22px 22px 0;
  background: linear-gradient(90deg, rgba(0,0,0,.045), transparent 10%), #11151a;
  color: #f1f4f7;
}

.book-spine {
  position: absolute;
  z-index: 8;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 18px;
  transform: translateX(-50%);
  background: linear-gradient(
    90deg,
    rgba(0,0,0,.22),
    rgba(255,255,255,.28) 48%,
    rgba(0,0,0,.22)
  );
  pointer-events: none;
}

.page-topline {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 17px;
  border-bottom: 1px solid rgba(55,65,75,.17);
  color: #77818b;
  font: 600 9px 'DM Mono', monospace;
  letter-spacing: .12em;
}

.book-page-right .page-topline {
  color: #a5afba;
  border-color: rgba(132,157,184,.18);
}

.page-topline small {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #8d98a3;
  font-size: 8px;
}

.page-topline small i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #70a8ff;
}

.writing-area {
  position: absolute;
  z-index: 2;
  inset: 0;
  background: transparent;
}

#writingCanvas,
[data-theme="dark"] #writingCanvas,
[data-theme="light"] #writingCanvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 0;
  background: transparent !important;
  touch-action: none;
  cursor: url('../img/nexo-pen.svg') 3 21, crosshair;
}

.paper-help {
  position: absolute;
  z-index: 4;
  top: 50%;
  left: 42px;
  right: 42px;
  transform: translateY(-50%);
  text-align: center;
  color: rgba(142,145,143,.58);
  font: italic 13px Georgia, serif;
  pointer-events: none;
}

.page-bottom,
.template-list {
  position: relative;
  z-index: 6;
}

.page-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 15px;
  color: #7e858b;
  font: 600 9px 'DM Mono', monospace;
}

.page-bottom button {
  border: 0;
  background: transparent;
  color: #3977d5;
  font: 600 9px 'DM Mono', monospace;
  cursor: pointer;
}

.template-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 11px;
}

.template-list button {
  border: 1px solid #dedfdd;
  background: rgba(238,238,235,.94);
  color: #62686d;
  padding: 8px;
  border-radius: 7px;
  font: 500 9px 'DM Mono', monospace;
  cursor: pointer;
}

.transcription-header {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-top: 30px;
}

.transcription-header label,
.ink-status label {
  display: block;
  margin-bottom: 8px;
  color: #6ea6ff;
  font: 600 9px 'DM Mono', monospace;
}

.transcription-header h3 {
  margin: 0;
  font: 500 clamp(26px,2.5vw,38px)/.95 Arial,sans-serif;
  letter-spacing: -.045em;
}

.live-pill {
  padding: 6px 9px;
  border: 1px solid rgba(112,168,255,.35);
  border-radius: 999px;
  color: #72a9ff;
  font: 600 8px 'DM Mono', monospace;
}

.ocr-preview {
  position: relative;
  z-index: 5;
  min-height: 190px;
  margin-top: 19px;
  padding: 23px;
  border: 1px solid rgba(112,168,255,.20);
  border-radius: 14px;
  background: #0c1015;
  color: #aeb8c3;
  font: italic 11px 'DM Mono', monospace;
  line-height: 1.7;
}

.ink-status {
  position: relative;
  z-index: 5;
  margin-top: 18px;
}

.ink-preview {
  min-height: 52px;
  padding: 12px 15px;
  border: 1px solid rgba(132,157,184,.16);
  border-radius: 10px;
  background: rgba(255,255,255,.025);
  color: #8f9ba7;
  font: italic 9px 'DM Mono', monospace;
}

.pipeline {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 78px;
  margin-top: 18px;
  padding: 15px 17px;
  border: 1px solid rgba(77,132,224,.30);
  border-radius: 13px;
  background: linear-gradient(
    90deg,
    rgba(101,8,32,.20),
    rgba(28,55,100,.18)
  );
}

.pipeline strong {
  display: block;
  color: #f5f7fa;
  font-size: 11px;
}

.pipeline small {
  display: block;
  max-width: 460px;
  margin-top: 6px;
  color: #9ca8b4;
  font-size: 9px;
  line-height: 1.5;
}

.pipeline .btn {
  flex: 0 0 auto;
  white-space: nowrap;
  background: #8b0628;
  border-color: #8b0628;
  color: #fff;
}

.page-security {
  position: relative;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-top: auto;
  padding-top: 17px;
  color: #8d98a3;
  font: 9px 'DM Mono', monospace;
}

/* User-requested instruction styling */
.book-instruction {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 14px;
  color: var(--muted);
  transition: opacity .3s ease, transform .3s ease;
}

.book-instruction.is-hidden {
  opacity: 0;
  transform: translateY(-5px);
  pointer-events: none;
}

.book-instruction span {
  color: var(--text);
  font: 500 12px Arial, sans-serif;
}

.book-instruction p {
  margin: 0;
  font: 10px 'DM Mono', monospace;
}

[data-theme="light"] .workspace-page {
  background: var(--accent);
  color: #fff;
}

[data-theme="light"] .workspace-intro h2 {
  color: #fff;
}

[data-theme="light"] .workspace-intro p {
  color: rgba(255,255,255,.84);
}

/* =========================================================
   MOBILE
   ========================================================= */

@media (max-width: 820px) {
  .workspace-page {
    padding: 68px 5vw 78px;
  }

  .workspace-intro {
    margin-bottom: 30px;
  }

  /* CLOSED BOOK: deliberately compact */
  .flipbook-scene {
    width: 100%;
    height: 500px;
    min-height: 500px;
  }

  /*
   * OPEN BOOK:
   * Do NOT use a fixed 900/1000px scene anymore.
   * The spread becomes part of normal document flow.
   * Its two pages stack naturally and the section expands.
   */
  .flipbook-scene.is-open {
    height: auto;
    min-height: 0;
    perspective: 1800px;
  }

  .book-cover {
    left: 50%;
    width: min(350px,82vw);
    height: min(500px,118vw);
  }

  .cover-click-badge {
    bottom: 14%;
    min-width: 132px;
    padding: 10px 13px;
    font-size: 9px;
  }

  .book-spread {
    position: absolute;
    inset: 0;
    display: block;
    overflow: hidden;
    border-radius: 18px;
  }

  /*
   * The spread itself becomes a normal-flow container only
   * after opening. This is what prevents the right page from
   * overlapping the left page.
   */
  .flipbook-scene.is-open .book-spread {
    position: relative;
    inset: auto;
    width: 100%;
    height: auto;
    min-height: 0;
    display: block;
    overflow: visible;
    transform: none;
  }

  .book-page-left,
  .book-page-right {
    position: relative;
    width: 100%;
    box-sizing: border-box;
    border-radius: 18px;
    overflow: hidden;
  }

  .flipbook-scene.is-open .book-page-left {
    height: 500px;
    min-height: 500px;
  }

  .flipbook-scene.is-open .book-page-right {
    height: 500px;
    min-height: 500px;
    margin-top: 18px;
  }

  .book-spine {
    display: none;
  }

  .book-page-left {
    padding: 24px 20px 26px;
  }

  .book-page-right {
    padding: 24px 20px 24px;
  }

  .book-page-left::after {
    left: 48px;
  }

  .pipeline {
    align-items: flex-start;
    flex-direction: column;
  }

  .pipeline .btn {
    width: 100%;
  }

  .book-instruction {
    margin-top: 14px;
  }
}

/* =========================================================
   SMALL MOBILE
   ========================================================= */

@media (max-width: 600px) {
  .workspace-page {
    padding: 58px 4vw 70px;
  }

  .workspace-intro h2 {
    font-size: 46px;
  }

  /* CLOSED BOOK */
  .flipbook-scene {
    height: 450px;
    min-height: 450px;
  }

  /* OPEN BOOK — normal flow */
  .flipbook-scene.is-open {
    height: auto;
    min-height: 0;
  }

  .book-cover {
    width: min(310px,82vw);
    height: min(450px,119vw);
  }

  .cover-click-badge {
    bottom: 13%;
    min-width: 126px;
    padding: 10px 12px;
    font-size: 8px;
  }

  .flipbook-scene.is-open .book-page-left,
  .flipbook-scene.is-open .book-page-right {
    height: 440px;
    min-height: 440px;
  }

  .flipbook-scene.is-open .book-page-right {
    margin-top: 14px;
  }

  .book-page-left {
    padding: 22px 16px;
  }

  .book-page-right {
    padding: 22px 16px;
  }

  .book-page-left::after {
    left: 40px;
  }

  .transcription-header {
    margin-top: 20px;
  }

  .transcription-header h3 {
    font-size: 25px;
  }

  .ocr-preview {
    min-height: 135px;
    padding: 18px;
  }

  .book-instruction {
    gap: 10px;
    text-align: center;
  }

  .book-instruction p {
    font-size: 9px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .book-cover,
  .book-spread {
    transition: none;
  }

  .cover-click-badge {
    animation: none;
  }
}
