/* ============================================
   Feedback widget — floating chat button + modal
   (front-end only; posts JSON to /contact)
   Paper theme: reuses the shared palette in style.css
   ============================================ */

/* ---------- floating chat button (bottom right) ---------- */
.feedback-fab {
  position: fixed;
  right: 28px;
  bottom: 28px;
  z-index: 95; /* above page content + beta ribbon (90), below navbar (100) */
  width: 58px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(58, 47, 26, 0.35);
  border-radius: 50%;
  background: var(--ink);
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(58, 47, 26, 0.28);
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.feedback-fab i {
  font-size: 1.5rem;
  color: var(--paper-card);
}

/* ---------- hover / focus tooltip (sits to the left of the button) ---------- */
.feedback-fab::after {
  content: "Share feedback";
  position: absolute;
  right: calc(100% + 12px);
  top: 50%;
  padding: 7px 12px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--paper-card);
  font-family: "Outfit", sans-serif;
  font-size: 0.8rem;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
  box-shadow: 0 6px 16px rgba(58, 47, 26, 0.22);
  opacity: 0;
  transform: translateY(-50%) translateX(4px);
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
}

/* little arrow pointing at the button */
.feedback-fab::before {
  content: "";
  position: absolute;
  right: calc(100% + 5px);
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--ink);
  opacity: 0;
  transform: translateY(-50%) rotate(45deg);
  transition: opacity 0.18s ease;
  pointer-events: none;
}

.feedback-fab:hover::after,
.feedback-fab:focus-visible::after {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

.feedback-fab:hover::before,
.feedback-fab:focus-visible::before {
  opacity: 1;
}

/* no hover on touch: the tap opens the form, so a stuck tooltip is noise */
@media (hover: none) {
  .feedback-fab::after,
  .feedback-fab::before {
    display: none;
  }
}

.feedback-fab:hover {
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 16px 32px rgba(58, 47, 26, 0.36);
  filter: none;
}

.feedback-fab:active {
  transform: translateY(-1px) scale(0.99);
}

.feedback-fab:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: 3px;
}

/* ---------- modal shell ---------- */
.feedback-modal {
  position: fixed;
  inset: 0;
  z-index: 300; /* clears sidebar (200) / overlays (150) / profile dropdown (100) */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.feedback-modal[hidden] {
  display: none;
}

.feedback-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(40, 32, 16, 0.45);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  animation: feedback-fade 0.18s ease;
}

.feedback-card {
  position: relative;
  width: 100%;
  max-width: 440px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 30px 30px 26px;
  background: var(--paper-card);
  border: 1px solid var(--paper-line);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(40, 32, 16, 0.35);
  animation: feedback-rise 0.22s ease;
}

@keyframes feedback-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes feedback-rise {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.feedback-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.feedback-close i {
  font-size: 1.15rem;
  color: inherit;
}

.feedback-close:hover {
  background: var(--paper-border);
  color: var(--ink);
}

.feedback-close:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

/* ---------- heading ---------- */
.feedback-title {
  margin: 0;
  font-family: "Caveat", cursive;
  font-size: 2rem;
  font-weight: 600;
  line-height: 1.15;
  color: var(--ink);
}

.feedback-sub {
  margin: 6px 0 20px;
  font-family: "Outfit", sans-serif;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--ink-muted);
}

/* context chip — "Physics › Forces", filled in by script_feedback.js */
.feedback-context {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: -8px 0 16px;
  padding: 6px 10px;
  font-family: "Outfit", sans-serif;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--ink-muted);
  background: #f3edd9;
  border: 1px solid var(--paper-line);
  border-radius: 8px;
}

.feedback-context[hidden] {
  display: none;
}

.feedback-context i {
  font-size: 0.95rem;
  color: var(--amber-soft);
}

/* ---------- fields ---------- */
.feedback-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  height: auto;
  align-items: stretch;
}

.feedback-input,
.feedback-textarea {
  width: 100%;
  padding: 12px 14px;
  font-family: "Outfit", sans-serif;
  font-size: 0.95rem;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--paper-border);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.feedback-input::placeholder,
.feedback-textarea::placeholder {
  color: #a49a7f;
}

.feedback-input:focus,
.feedback-textarea:focus {
  border-color: var(--paper-accent);
  box-shadow: 0 0 0 3px rgba(201, 185, 146, 0.35);
}

.feedback-textarea {
  resize: vertical;
  min-height: 110px;
  line-height: 1.5;
}

/* honeypot — visually hidden, never focusable by users */
.feedback-honeypot {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
}

.feedback-form .feedback-submit {
  margin-top: 4px;
  width: 100%;
  height: 48px;
  font-family: "Outfit", sans-serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--paper-accent);
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.feedback-form .feedback-submit:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.15);
}

.feedback-form .feedback-submit:disabled {
  cursor: default;
  opacity: 0.65;
}

.feedback-status {
  min-height: 1.1rem;
  margin: 0;
  font-family: "Outfit", sans-serif;
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--ink-muted);
}

.feedback-status.is-ok {
  color: #4b7a3a;
}

.feedback-status.is-error {
  color: #b23b1f;
}

/* scroll lock while the modal is up */
body.feedback-open {
  overflow: hidden;
}

/* ---------- small screens: bottom sheet ---------- */
@media (max-width: 600px) {
  .feedback-fab {
    right: 18px;
    bottom: 18px;
    width: 54px;
    height: 54px;
  }

  .feedback-fab i {
    font-size: 1.4rem;
  }

  .feedback-modal {
    padding: 0;
    align-items: flex-end;
  }

  .feedback-card {
    max-width: 100%;
    max-height: 88vh;
    padding: 26px 22px calc(22px + env(safe-area-inset-bottom));
    border-radius: 18px 18px 0 0;
    animation: feedback-sheet 0.24s ease;
  }

  @keyframes feedback-sheet {
    from { opacity: 0; transform: translateY(28px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  .feedback-title {
    font-size: 1.75rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .feedback-fab,
  .feedback-card,
  .feedback-backdrop {
    transition: none;
    animation: none;
  }

  .feedback-fab::after,
  .feedback-fab::before {
    transition: none;
  }

  .feedback-fab:hover,
  .feedback-form .feedback-submit:hover:not(:disabled) {
    transform: none;
  }
}

/* ============================================
   Notes page adjustments
   (fixed bottom nav on mobile, PDF split-screen
   on the right, page scrolls inside .notes-panel)
   ============================================ */

/* above the citation panel (300) and the guest gate (capped at 1 by
   .notes-panel's stacking context) */
body.notes-page .feedback-modal {
  z-index: 400;
}

/* the page scrolls inside the notes pane, not on <body> */
body.notes-page.feedback-open .notes-panel,
body.notes-page.feedback-open .sidebar,
body.notes-page.feedback-open .chapters-list {
  overflow: hidden;
}

/* reserve room at the bottom of the pane so the button never lands on the
   prev/next topic cards (or the last block of notes on a final topic) */
body.notes-page .notes-panel {
  padding-bottom: 108px;
}

/* same idea on the subjects wall: keep the last row of cards clear of it */
body.subjects-page .subjects-container {
  padding-bottom: 108px;
}

/* mobile: lift the button clear of the bottom nav (~64px tall) */
@media (max-width: 768px) {
  body.notes-page .feedback-fab {
    right: 14px;
    bottom: calc(76px + env(safe-area-inset-bottom));
    width: 52px;
    height: 52px;
  }

  body.notes-page .feedback-fab i {
    font-size: 1.35rem;
  }

  /* button is lifted higher here, so the pane needs more clearance */
  body.notes-page .notes-panel {
    padding-bottom: 148px;
  }
}

@media (max-width: 600px) {
  body.subjects-page .subjects-container {
    padding-bottom: 96px;
  }
}

/* reading a paper in split-screen: the PDF takes the right half, so tuck the
   button away instead of parking it on top of the viewer */
body.notes-page.split-screen .feedback-fab {
  opacity: 0;
  transform: translateY(6px) scale(0.92);
  pointer-events: none;
}

/* ============================================
   Papers page (subject paper list) adjustments
   Slower chrome: left tab rail, mobile bottom
   nav, filter dropdown, guest paper promo
   ============================================ */

/* above the guest paper promo (400), the guidance toast (300) and the
   filter dropdown (120) */
body.papers-page .feedback-modal {
  z-index: 500;
}

/* the mobile bottom nav is z 95 — stay above it */
body.papers-page .feedback-fab {
  z-index: 96;
}

/* reserve room so the button never covers the last paper card */
body.papers-page .papers-main {
  padding-bottom: 108px;
}

@media (max-width: 768px) {
  body.papers-page .feedback-fab {
    right: 14px;
    bottom: calc(76px + env(safe-area-inset-bottom));
    width: 52px;
    height: 52px;
  }

  body.papers-page .feedback-fab i {
    font-size: 1.35rem;
  }

  body.papers-page .papers-main {
    padding-bottom: 150px;
  }
}

