/* Tactile Paper Slip & Constant Note Card Frame:
   Outer .note-frame remains visually constant across the entire lifecycle:
   1. Roll flat sheet Right->Left into tight vertical cylinder
   2. Bring cylinder to middle & lay horizontally flat
   3. Wrap thin twine around center & tie into a small bow
   4. Drop into jar (or reverse smoothly when unwrapping!)
*/

.note-frame {
  position: relative;
  width: 100%;
  padding: 20px 22px;
  min-height: 238px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-top: 3px solid var(--crimson);
  background: linear-gradient(180deg, #fffdf8 0%, #fcf6ea 100%);
  overflow: visible;
}

.note-frame-body {
  position: relative;
  width: 100%;
  min-height: 194px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.note-state-box {
  min-height: 194px;
  display: grid;
  align-content: center;
  justify-items: center;
  text-align: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: rgba(255, 250, 240, 0.72);
  border: 1px dashed rgba(138, 121, 105, 0.28);
}

.note-state-icon {
  font-size: 2rem;
  line-height: 1;
}

.note-state-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.12rem;
  color: var(--ink-primary);
}

.note-state-title--closed {
  color: var(--crimson-dark);
}

.note-state-desc {
  margin: 0;
  font-size: 0.91rem;
  color: var(--ink-secondary);
  line-height: 1.5;
  max-width: 46ch;
}

.paper-desk {
  position: relative;
  width: 100%;
  perspective: 1200px;
}

.paper-roll-stage {
  position: relative;
  width: 100%;
  min-height: 194px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.paper-roll-wrap {
  position: relative;
  width: 100%;
  min-height: 194px;
}

.paper-flat-clip {
  position: relative;
  width: 100%;
  clip-path: inset(0 0 0 0);
}

.paper-sheet {
  position: relative;
  min-height: 194px;
  text-align: left;
  background: var(--slip-cream);
  border: 1px solid rgba(112, 86, 52, 0.24);
  border-radius: 14px;
  padding: 20px 22px 18px;
  box-shadow: var(--shadow-paper);
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 31px,
    rgba(166, 134, 92, 0.14) 32px
  );
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.paper-sheet::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 38px;
  width: 1px;
  background: rgba(192, 47, 40, 0.24);
  pointer-events: none;
}

.paper-sheet-inner {
  position: relative;
  padding-left: 26px;
  display: grid;
  gap: 12px;
}

.paper-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.paper-label {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
}

.hand-input {
  width: 100%;
  border: none;
  border-bottom: 1.5px dashed rgba(98, 85, 72, 0.35);
  background: transparent;
  padding: 4px 2px;
  font-family: var(--font-hand);
  font-size: 1.95rem;
  font-weight: 700;
  color: var(--ink-primary);
  line-height: 1.15;
}

.hand-input:focus {
  outline: none;
  border-bottom-color: var(--crimson);
}

.hand-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* 3D Vertical Paper Roll Spine sweeping across the flat sheet */
.paper-roll-spine {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(100% - 38px);
  width: 38px;
  border-radius: 18px;
  border: 1px solid rgba(132, 96, 48, 0.42);
  background: linear-gradient(
    90deg,
    #d8c29a 0%,
    #fffdf7 34%,
    #f3e4c7 72%,
    #cbb186 100%
  );
  box-shadow: -8px 4px 16px rgba(45, 31, 18, 0.2), inset 0 4px 6px rgba(255, 255, 255, 0.7);
  opacity: 0;
  pointer-events: none;
  z-index: 4;
}

/* Spiral paper roll caps at top & bottom of the vertical cylinder */
.paper-roll-spine::before,
.paper-roll-spine::after {
  content: '';
  position: absolute;
  left: 4px;
  right: 4px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid rgba(145, 110, 62, 0.45);
  background: radial-gradient(circle, #c8af86 25%, #fff9ed 60%, #dfd0b4 100%);
}

.paper-roll-spine::before { top: 2px; }
.paper-roll-spine::after { bottom: 2px; }

/* STEP 1A: Roll close smoothly RIGHT -> LEFT */
.paper-roll-wrap.is-rolling-rl .paper-flat-clip {
  animation: flatClipRollRL 0.54s cubic-bezier(0.42, 0, 0.58, 1) forwards;
}

.paper-roll-wrap.is-rolling-rl .paper-roll-spine {
  animation: spineSweepRL 0.54s cubic-bezier(0.42, 0, 0.58, 1) forwards;
}

@keyframes flatClipRollRL {
  0% {
    clip-path: inset(0 0% 0 0);
  }
  100% {
    clip-path: inset(0 calc(100% - 22px) 0 0);
  }
}

@keyframes spineSweepRL {
  0% {
    left: calc(100% - 22px);
    transform: scaleX(0.58);
    opacity: 0.4;
  }
  15% {
    opacity: 1;
  }
  100% {
    left: 0px;
    transform: scaleX(1);
    opacity: 1;
  }
}

/* STEP 1B (Reverse): Unroll smoothly LEFT -> RIGHT */
.paper-roll-wrap.is-unrolling-lr .paper-flat-clip {
  animation: flatClipUnrollLR 0.54s cubic-bezier(0.22, 0.85, 0.36, 1) forwards;
}

.paper-roll-wrap.is-unrolling-lr .paper-roll-spine {
  animation: spineSweepLR 0.54s cubic-bezier(0.22, 0.85, 0.36, 1) forwards;
}

@keyframes flatClipUnrollLR {
  0% {
    clip-path: inset(0 calc(100% - 22px) 0 0);
  }
  100% {
    clip-path: inset(0 0% 0 0);
  }
}

@keyframes spineSweepLR {
  0% {
    left: 0px;
    transform: scaleX(1);
    opacity: 1;
  }
  85% {
    opacity: 1;
  }
  100% {
    left: calc(100% - 20px);
    transform: scaleX(0.5);
    opacity: 0;
  }
}

/* STEP 2: Cylindrical Scroll centering & laying horizontally flat + Twine Bow */
.scroll-cylinder-wrap {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 176px;
  height: 40px;
  transform: translate(-50%, -50%) rotate(0deg);
  transform-origin: center center;
  z-index: 6;
}

.scroll-cylinder-body {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 999px;
  border: 1.5px solid rgba(132, 96, 48, 0.4);
  background: linear-gradient(180deg, #fffdf7 0%, #f4e4c7 52%, #d8bf95 100%);
  box-shadow: 0 12px 24px rgba(45, 31, 18, 0.16), inset 0 2px 4px rgba(255, 255, 255, 0.85);
}

/* Spiral paper end-caps on horizontal cylinder */
.scroll-cylinder-body::before,
.scroll-cylinder-body::after {
  content: '';
  position: absolute;
  top: 3px;
  bottom: 3px;
  width: 10px;
  border-radius: 50%;
  border: 1.5px solid rgba(145, 110, 62, 0.45);
  background: radial-gradient(circle, #c8af86 25%, #fff9ed 60%, #dfd0b4 100%);
}

.scroll-cylinder-body::before { left: 2px; }
.scroll-cylinder-body::after { right: 2px; }

/* Animate moving from Left Vertical -> Middle Horizontal Flat */
.scroll-cylinder-wrap.is-centering-flat {
  animation: scrollCenterLayFlat 0.44s cubic-bezier(0.25, 0.9, 0.3, 1) forwards;
}

@keyframes scrollCenterLayFlat {
  0% {
    transform: translate(calc(-50% + var(--left-offset, -160px)), -50%) rotate(90deg) scaleX(0.95);
  }
  100% {
    transform: translate(-50%, -50%) rotate(0deg) scaleX(1);
  }
}

/* Reverse: Middle Horizontal Flat -> Left Vertical before unrolling L->R */
.scroll-cylinder-wrap.is-standing-left {
  animation: scrollStandToLeft 0.42s cubic-bezier(0.4, 0, 0.25, 1) forwards;
}

@keyframes scrollStandToLeft {
  0% {
    transform: translate(-50%, -50%) rotate(0deg) scaleX(1);
  }
  100% {
    transform: translate(calc(-50% + var(--left-offset, -160px)), -50%) rotate(90deg) scaleX(0.95);
  }
}

/* Drop tied scroll down into the jar */
.scroll-cylinder-wrap.is-dropping-to-jar {
  animation: scrollDropOutToJar 0.46s cubic-bezier(0.45, 0, 0.85, 0.5) forwards;
}

@keyframes scrollDropOutToJar {
  0% {
    transform: translate(-50%, -50%) rotate(0deg) scale(1);
    opacity: 1;
  }
  25% {
    transform: translate(-50%, -62%) rotate(-4deg) scale(1.03);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, 145px) rotate(16deg) scale(0.42);
    opacity: 0;
  }
}

/* Twine & Small Bow SVG overlay */
.twine-bow-svg {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 176px;
  height: 76px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  overflow: visible;
}

.twine-wrap-path {
  fill: none;
  stroke: #8c5a32;
  stroke-width: 2.6;
  stroke-linecap: round;
  stroke-dasharray: 120;
  stroke-dashoffset: 0;
}

.twine-bow-group {
  transform-box: fill-box;
  transform-origin: center bottom;
}

.twine-bow-stroke {
  fill: none;
  stroke: #b52c24;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.twine-knot {
  fill: #b52c24;
}

/* Twine Hidden initial */
.scroll-cylinder-wrap.twine-hidden .twine-wrap-path {
  stroke-dashoffset: 120;
  opacity: 0;
}
.scroll-cylinder-wrap.twine-hidden .twine-bow-group {
  transform: scale(0);
  opacity: 0;
}

/* Animate Twine Wrapping + Tying Bow */
.scroll-cylinder-wrap.is-tying .twine-wrap-path {
  animation: twineWrapCenter 0.28s ease-out forwards;
}
.scroll-cylinder-wrap.is-tying .twine-bow-group {
  animation: bowTieIn 0.28s cubic-bezier(0.22, 1.3, 0.4, 1) 0.18s both;
}

@keyframes twineWrapCenter {
  0% {
    stroke-dashoffset: 120;
    opacity: 0.2;
  }
  100% {
    stroke-dashoffset: 0;
    opacity: 1;
  }
}

@keyframes bowTieIn {
  0% {
    transform: scale(0.1) rotate(-18deg);
    opacity: 0;
  }
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

/* Reverse: Untie Bow + Unwrap Twine */
.scroll-cylinder-wrap.is-untying .twine-bow-group {
  animation: bowUntieOut 0.24s ease-in forwards;
}
.scroll-cylinder-wrap.is-untying .twine-wrap-path {
  animation: twineUnwrapCenter 0.28s ease-in 0.14s forwards;
}

@keyframes bowUntieOut {
  0% {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
  100% {
    transform: scale(0.2) translateY(-10px);
    opacity: 0;
  }
}

@keyframes twineUnwrapCenter {
  0% {
    stroke-dashoffset: 0;
    opacity: 1;
  }
  100% {
    stroke-dashoffset: 120;
    opacity: 0;
  }
}

/* Emerged tied scroll rising inside the fixed-height stage */
.sealed-scroll-stage {
  position: relative;
  width: 100%;
  min-height: 194px;
  display: grid;
  align-items: center;
  justify-items: center;
  text-align: center;
}

.sealed-scroll-prompt {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 20px;
  width: 100%;
  min-height: 194px;
}

.sealed-scroll-btn {
  position: relative;
  width: 210px;
  height: 48px;
  padding: 0;
  border-radius: 999px;
  border: 1.5px solid rgba(132, 96, 48, 0.42);
  background: linear-gradient(180deg, #fffdf7 0%, #f4e4c7 52%, #d8bf95 100%);
  box-shadow: 0 14px 28px rgba(45, 31, 18, 0.16), inset 0 2px 4px rgba(255, 255, 255, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.sealed-scroll-btn.is-emerging {
  animation: scrollEmerge 0.72s cubic-bezier(0.2, 0.9, 0.3, 1.05);
}

@keyframes scrollEmerge {
  0% {
    opacity: 0;
    transform: translateY(105px) scale(0.55) rotate(-14deg);
  }
  70% {
    opacity: 1;
    transform: translateY(-6px) scale(1.04) rotate(2deg);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1) rotate(0deg);
  }
}

.sealed-scroll-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 18px 34px rgba(45, 31, 18, 0.2), inset 0 2px 4px rgba(255, 255, 255, 0.9);
}

.sealed-scroll-btn::before,
.sealed-scroll-btn::after {
  content: '';
  position: absolute;
  top: 4px;
  bottom: 4px;
  width: 11px;
  border-radius: 50%;
  border: 1.5px solid rgba(145, 110, 62, 0.45);
  background: radial-gradient(circle, #c8af86 25%, #fff9ed 60%, #dfd0b4 100%);
}
.sealed-scroll-btn::before { left: 3px; }
.sealed-scroll-btn::after { right: 3px; }

.sealed-scroll-hint {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink-secondary);
}

.reveal-target-name {
  margin: 4px 0;
  font-family: var(--font-hand);
  font-size: clamp(2rem, 4.4vw, 2.8rem);
  font-weight: 700;
  color: var(--crimson-dark);
  line-height: 1.08;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Jar Stage */
.jar-stage-card {
  position: relative;
  display: grid;
  place-items: center;
  padding: 26px 18px 20px;
  border-radius: var(--radius-lg);
  background: radial-gradient(circle at 50% 35%, rgba(255, 253, 248, 0.95), rgba(244, 232, 210, 0.78));
  border: 1px solid rgba(25, 84, 62, 0.16);
  border-bottom: 3px solid rgba(25, 84, 62, 0.45);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  min-height: 380px;
}

.jar-status-caption {
  margin: 12px 0 0;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--ink-secondary);
  text-align: center;
}

.jar-vessel {
  position: relative;
  width: 270px;
  height: 310px;
  transform-origin: 50% 72%;
}

/* Jar shakes vigorously to mix the notes inside */
.jar-vessel.is-mixing {
  animation: jarShakeMix 2.35s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes jarShakeMix {
  0%   { transform: translate(0, 0) rotate(0deg); }
  10%  { transform: translate(-8px, -10px) rotate(-9deg); }
  20%  { transform: translate(10px, -14px) rotate(10deg); }
  30%  { transform: translate(-11px, -8px) rotate(-11deg); }
  40%  { transform: translate(11px, -15px) rotate(9deg); }
  50%  { transform: translate(-9px, -10px) rotate(-10deg); }
  60%  { transform: translate(9px, -12px) rotate(8deg); }
  72%  { transform: translate(-6px, -6px) rotate(-6deg); }
  84%  { transform: translate(5px, -3px) rotate(4deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}

.jar-lid {
  transform-origin: 50% 42px;
  transition: transform 0.38s cubic-bezier(0.22, 1, 0.36, 1);
}

.jar-vessel.is-lid-open .jar-lid {
  transform: translateY(-22px) rotate(-9deg);
}

/* Rolled slip inside jar */
.jar-scroll {
  transform-box: fill-box;
  transform-origin: center center;
  transition: transform 0.4s ease;
}

.jar-scroll.is-dropping {
  animation: scrollDropInJar 0.65s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes scrollDropInJar {
  0% {
    opacity: 0;
    transform: translateY(-155px) scale(0.85) rotate(-18deg);
  }
  70% {
    opacity: 1;
    transform: translateY(6px) scale(1.02) rotate(4deg);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1) rotate(0deg);
  }
}

/* Notes swirl and tumble nicely inside the shaking jar */
.jar-vessel.is-mixing .jar-scroll {
  animation: noteMixOrbit var(--mix-dur, 0.95s) ease-in-out var(--mix-delay, 0s) infinite alternate;
}

@keyframes noteMixOrbit {
  0% {
    transform: translate(0px, 0px) rotate(0deg) scale(1);
  }
  33% {
    transform: translate(var(--mix-x1, 28px), var(--mix-y1, -78px)) rotate(var(--mix-r1, 58deg)) scale(0.95);
  }
  66% {
    transform: translate(var(--mix-x2, -30px), var(--mix-y2, -112px)) rotate(var(--mix-r2, -72deg)) scale(1.06);
  }
  100% {
    transform: translate(var(--mix-x3, 18px), var(--mix-y3, -44px)) rotate(var(--mix-r3, 34deg)) scale(0.98);
  }
}

@media (prefers-reduced-motion: reduce) {
  .paper-roll-wrap.is-rolling-rl .paper-flat-clip,
  .paper-roll-wrap.is-rolling-rl .paper-roll-spine,
  .paper-roll-wrap.is-unrolling-lr .paper-flat-clip,
  .paper-roll-wrap.is-unrolling-lr .paper-roll-spine,
  .scroll-cylinder-wrap.is-centering-flat,
  .scroll-cylinder-wrap.is-standing-left,
  .scroll-cylinder-wrap.is-dropping-to-jar,
  .scroll-cylinder-wrap.is-tying .twine-wrap-path,
  .scroll-cylinder-wrap.is-tying .twine-bow-group,
  .scroll-cylinder-wrap.is-untying .twine-bow-group,
  .scroll-cylinder-wrap.is-untying .twine-wrap-path,
  .jar-vessel.is-mixing,
  .jar-vessel.is-mixing .jar-scroll,
  .jar-scroll.is-dropping,
  .sealed-scroll-btn.is-emerging {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
