/* ============================================================
   ReadsMe Mobile — Shell Layout
   Mobile IS the base. No @media (min-width) queries.
   Desktop: body.desktop-frame wraps content in .phone-shell.

   IMPORTANT — Ensure index.html viewport meta is:
     <meta name="viewport" content="width=device-width,
       initial-scale=1, viewport-fit=cover,
       interactive-widget=resizes-content">
   ============================================================ */

/* ============================================================
   RESET & BASE
   ============================================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
  /* Prevent text size inflation on orientation change (iOS) */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* Smooth font rendering */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: var(--text-base);
}

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  color: var(--text-primary);
  background-color: var(--surface-primary);
  /* Prevent pull-to-refresh interfering with swipe sheet gestures */
  overscroll-behavior-y: none;
}

/* ============================================================
   DESKTOP FRAME
   Only active when body has class "desktop-frame".
   Renders the app inside a centered phone silhouette.
   ============================================================ */
body.desktop-frame {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  background-color: #1a1a1a;
}

.phone-shell {
  /* Hidden by default — only relevant when desktop-frame is active */
  display: none;
}

body.desktop-frame .phone-shell {
  display: block;
  position: relative;
  width: 390px;
  height: 844px;
  max-height: 100dvh;
  overflow: hidden;
  border-radius: 44px;
  /* Device chrome shadow: depth layer + hairline highlight ring */
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.35),
    0 0 0 1px rgba(255, 255, 255, 0.08);
  /* Scope fixed children inside the shell */
  isolation: isolate;
}

/* ============================================================
   BOOK SURFACE
   The full-screen reading/listening canvas.
   All content renders inside this layer.
   ============================================================ */
.book-surface {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: var(--z-surface);
  background-color: var(--surface-primary);
}

body.desktop-frame .book-surface {
  position: absolute;
  inset: 0;
}

/* ============================================================
   PERSISTENT CONTROLS
   The two-button bar anchored to the bottom of the screen.
   pointer-events: none on the container so taps pass through
   to the reading surface; children restore pointer-events.
   ============================================================ */
.persistent-controls {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding-bottom: calc(var(--space-4) + var(--safe-bottom));
  padding-inline: var(--space-6);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-2);
  pointer-events: none;
  z-index: var(--z-bottom);
  /* Solid page-colour strip behind the pills, fading out above them, so book text never
     shows between or under the buttons (UX-AUDIT P2). Pagination already repeats the
     covered strip on the next page (navigation.js _pageOverlap), so no line is lost. */
  padding-top: var(--space-5);
  background: linear-gradient(to top,
    var(--bg-color) 0,
    var(--bg-color) calc(100% - var(--space-5)),
    transparent 100%);
}

body.desktop-frame .persistent-controls {
  position: absolute;
}

/* Restore pointer-events for interactive children */
.persistent-controls > * {
  pointer-events: auto;
}

/* ============================================================
   PERSISTENT BUTTONS — shared base
   ============================================================ */
.btn-ask,
.btn-you {
  /* Touch target guarantee */
  min-width: var(--touch-min);
  min-height: var(--touch-min);
  flex: 1 1 0;

  /* Pill shape */
  border-radius: var(--radius-pill);
  padding: 0 var(--space-3);

  /* Layout */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);

  /* Typography */
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  letter-spacing: 0.01em;
  white-space: nowrap;

  /* Interaction */
  cursor: pointer;
  border: 1px solid transparent;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  touch-action: manipulation;
  transition:
    transform var(--transition-fast),
    opacity var(--transition-fast),
    box-shadow var(--transition-fast);
}

.btn-ask:active,
.btn-you:active {
  transform: scale(0.95);
}

/* ============================================================
   BTN-ASK (Ask) and BTN-YOU (Menu): quiet pills
   Page colour with a strong edge, so they read as buttons without
   pulling the eye from Feedback, the filled pill (author-feedback.css).
   ============================================================ */
.btn-ask,
.btn-you {
  background: var(--btn-quiet-bg);
  color: var(--btn-quiet-text);
  border-color: var(--btn-quiet-border);
}

/* ============================================================
   BOTTOM SHEET
   Base class for all sheets (chat, profile, settings, etc.)
   JS adds .peek / .half / .full to animate open states.
   ============================================================ */
.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
  background: var(--surface-raised);
  /* Start off-screen */
  transform: translateY(100%);
  transition: transform var(--transition-normal);
  /* Safe area padding so content clears home indicator */
  padding-bottom: var(--safe-bottom);
  z-index: var(--z-sheet);
  /* Prevent sheet scroll from propagating to book surface */
  overscroll-behavior: contain;
}

body.desktop-frame .bottom-sheet {
  position: absolute;
}

/* --- Peek: handle + one line of preview --- */
.bottom-sheet.peek {
  transform: translateY(calc(100% - 72px));
}

/* --- Half: roughly half the screen height --- */
.bottom-sheet.half {
  transform: translateY(50%);
}

/* Full sheets keep the handle visible and reserve its height above the content.
   A full sheet reaches the top of the screen, so the top safe area keeps the handle below the notch. */
.bottom-sheet.full {
  display: flex;
  flex-direction: column;
  transform: translateY(0);
  border-radius: 0;
  padding-top: var(--safe-top, 0px);
}

.bottom-sheet.full > .you-sheet-inner,
.bottom-sheet.full > .chat-sheet-inner,
.bottom-sheet.full > .ask-sheet-inner {
  flex: 1;
  min-height: 0;
}

/* ============================================================
   SHEET HANDLE
   The drag indicator pill at the top of every sheet.
   ============================================================ */
.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--edge-strong);
  border-radius: var(--radius-sm);
  margin: var(--space-3) auto 0;
  /* Allow drag events to pass through to the sheet */
  touch-action: none;
  flex-shrink: 0;
  position: relative; /* needed for ::after hit-area expansion */
}

/* Expand touch target to ~44×56px without changing visual appearance */
.sheet-handle::after {
  content: '';
  position: absolute;
  top: -20px;    /* expand 20px above */
  bottom: -20px; /* expand 20px below */
  left: -10px;   /* expand 10px each side */
  right: -10px;
}

/* ============================================================
   SHEET BACKDROP
   Scrim that appears behind open sheets.
   JS adds .visible when a sheet reaches .half or .full.
   ============================================================ */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: var(--surface-overlay);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
  z-index: calc(var(--z-sheet) - 1);
}

body.desktop-frame .sheet-backdrop {
  position: absolute;
}

.sheet-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ============================================================
   ONBOARDING STATE
   Hide the persistent bottom controls while green-room is active.
   body.onboarding-active is added by controls.js C7/C9.
   ============================================================ */
body.onboarding-active .persistent-controls {
  display: none;
  pointer-events: none;
}
