/* ------------------------------------------------------------------
   Kedge Line — cartouche
   The destination panel. Reads as a chart cartouche, not a UI card.
   ------------------------------------------------------------------ */

.cartouche {
  position: fixed;
  z-index: 40;
  right: clamp(14px, 3vw, 64px);
  top: 50%;
  width: min(470px, 40vw);
  max-height: min(78vh, 660px);
  transform: translateY(-50%);
  padding: clamp(24px, 2.4vw, 34px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(120% 100% at 10% 0%, #f6ecd6 0%, transparent 60%),
    linear-gradient(175deg, #efe2c6, #e2d0ab 70%, #d8c49c);
  border: 1.5px solid rgba(43, 35, 24, 0.8);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.5) inset,
    0 24px 60px -26px rgba(38, 28, 14, 0.62),
    0 3px 12px rgba(38, 28, 14, 0.2);
  color: var(--ink);
  cursor: default;
  animation: cartouche-in 420ms var(--ease) both;
}

.cartouche::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 0.75px solid rgba(43, 35, 24, 0.45);
  pointer-events: none;
}

.cartouche[hidden] {
  display: none;
}

@keyframes cartouche-in {
  from {
    opacity: 0;
    transform: translateY(calc(-50% + 10px));
  }
  to {
    opacity: 1;
    transform: translateY(-50%);
  }
}

.cartouche-kicker {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  font-family: var(--display-sc);
  font-size: 12px;
  letter-spacing: 0.2em;
  color: var(--oxblood);
}

.cartouche-kicker span {
  white-space: nowrap;
}

.cartouche-kicker span:last-child {
  color: var(--ink-faint);
}

.cartouche-title {
  margin: 10px 0 0;
  font-family: var(--display);
  font-size: clamp(34px, 3.4vw, 46px);
  font-weight: 400;
  line-height: 1.02;
  letter-spacing: 0.004em;
}

.cartouche-ornament {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 14px 0 14px;
  color: var(--ink);
}

.cartouche-ornament span {
  flex: 1;
  height: 1px;
  background: rgba(43, 35, 24, 0.4);
}

.cartouche-body {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 6px;
  margin-right: -6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(43, 35, 24, 0.35) transparent;
}

.cartouche:focus {
  outline: none;
}

.cartouche-body p {
  margin: 0 0 0.85em;
  font-family: var(--display);
  font-size: clamp(15.5px, 1.18vw, 17px);
  line-height: 1.52;
}

.cartouche-body p:last-child {
  margin-bottom: 0;
}

.cartouche-body .term {
  font-style: italic;
}

.cartouche-body .lede {
  font-size: clamp(16px, 1.25vw, 18px);
}

.cartouche-body .tag {
  font-family: var(--display-sc);
  font-size: 0.94em;
  letter-spacing: 0.1em;
  color: var(--oxblood);
}

.cartouche-body .aside {
  font-size: 0.92em;
  color: var(--ink-soft);
}

.cartouche-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
  padding-top: 15px;
  border-top: 1px solid rgba(43, 35, 24, 0.3);
}

.button {
  flex: 0 0 auto;
  padding: 11px 20px 10px;
  border: 1px solid #362518;
  background: #4a3423;
  color: #f2e7d0;
  font-family: var(--display-sc);
  font-size: 16px;
  letter-spacing: 0.12em;
  cursor: pointer;
  transition: background 160ms var(--ease), transform 160ms var(--ease);
}

.button:hover {
  background: #5a4029;
}

.button:active {
  transform: translateY(1px);
}

.button--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--ink-faint);
  padding: 11px 4px 10px;
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-thickness: 1px;
  text-decoration-color: rgba(43, 35, 24, 0.35);
}

.button--ghost:hover {
  background: transparent;
  color: var(--ink);
}

.button[disabled] {
  background: transparent;
  border-color: rgba(43, 35, 24, 0.35);
  color: var(--ink-faint);
  cursor: default;
}

.cartouche-hint {
  margin: 0;
  font-family: var(--display);
  font-style: italic;
  font-size: 13px;
  color: var(--ink-faint);
  text-align: right;
}

.cartouche-rule {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 14px;
  background: repeating-linear-gradient(
    90deg,
    rgba(43, 35, 24, 0.16) 0 1px,
    transparent 1px 9px
  );
  opacity: 0.5;
  pointer-events: none;
}

/* --- small screens: bottom sheet --------------------------------- */

@media (max-aspect-ratio: 4/5) {
  .cartouche {
    left: 50%;
    right: auto;
    top: auto;
    bottom: max(10px, env(safe-area-inset-bottom));
    width: min(560px, calc(100% - 20px));
    max-height: 62svh;
    transform: translateX(-50%);
    padding: 22px 22px 20px;
    animation-name: cartouche-up;
  }

  @keyframes cartouche-up {
    from {
      opacity: 0;
      transform: translate(-50%, 14px);
    }
    to {
      opacity: 1;
      transform: translate(-50%, 0);
    }
  }

  .cartouche-actions {
    position: sticky;
    bottom: 0;
    background: linear-gradient(to top, #ddcba6 70%, rgba(221, 203, 166, 0));
    margin: 12px -4px -6px;
    padding: 14px 4px 6px;
    border-top: 1px solid rgba(43, 35, 24, 0.22);
  }
}

/* short screens keep a side panel, but with less air */
@media (max-height: 560px) {
  .cartouche {
    max-height: 92svh;
    padding: 15px 20px 13px;
  }

  .cartouche-kicker {
    font-size: 9.5px;
    letter-spacing: 0.12em;
    gap: 8px;
  }

  .cartouche-title {
    margin-top: 4px;
    font-size: 28px;
  }

  .cartouche-ornament {
    margin: 7px 0;
  }

  .cartouche-body p {
    margin-bottom: 0.6em;
    font-size: 14px;
    line-height: 1.42;
  }

  .cartouche-body .lede {
    font-size: 14.5px;
  }

  .cartouche-actions {
    margin-top: 10px;
    padding-top: 9px;
  }

  .button {
    padding: 9px 16px 8px;
    font-size: 15px;
  }

  .cartouche-hint {
    font-size: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cartouche {
    animation: none;
  }

  .button {
    transition: none;
  }
}

/* Sheet on a desk: the cartouche sits inside the trimmed edge. */
body[data-sheet="desk"] .cartouche {
  right: calc(var(--sheet-inset) + clamp(10px, 1.8vw, 34px));
  max-height: min(72vh, 620px);
}
