:root {
  --bwd-ink: #241b16;
  --bwd-muted-ink: #514137;
  --bwd-paper-shadow: 0 20px 54px rgba(0, 0, 0, 0.48);
  --bwd-ease: cubic-bezier(0.22, 0.72, 0.24, 1);
}

body.bwd-document-open {
  overflow: hidden;
  overscroll-behavior: none;
}

.bwd-document-overlay {
  position: fixed;
  z-index: 10040;
  inset: 0;
  display: grid;
  place-items: center;
  box-sizing: border-box;
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  overflow: hidden;
  background: rgba(7, 5, 4, 0);
  opacity: 0;
  transition:
    opacity 160ms var(--bwd-ease),
    background-color 160ms var(--bwd-ease);
}

.bwd-document-overlay.is-open {
  background: rgba(7, 5, 4, 0.84);
  opacity: 1;
}

.bwd-document-overlay.is-closing {
  pointer-events: none;
}

.bwd-document-viewport {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

.bwd-document-surface {
  position: relative;
  isolation: isolate;
  flex: none;
  overflow: hidden;
  color: var(--bwd-ink);
  box-shadow: var(--bwd-paper-shadow);
  opacity: 0;
  transform: translateY(10px) scale(0.965) rotate(-0.3deg);
  transform-origin: 50% 50%;
  transition:
    opacity 220ms var(--bwd-ease),
    transform 220ms var(--bwd-ease);
}

.is-open .bwd-document-surface {
  opacity: 1;
  transform: translateY(0) scale(1) rotate(0);
}

.is-closing .bwd-document-surface {
  opacity: 0;
  transform: translateY(7px) scale(0.975) rotate(-0.2deg);
}

.bwd-document-background {
  position: absolute;
  z-index: -1;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.bwd-document-copy {
  position: absolute;
  box-sizing: border-box;
  color: var(--bwd-ink);
  font-family: Georgia, "Times New Roman", "Noto Serif KR", serif;
  text-wrap: pretty;
}

.bwd-document-paragraph {
  margin: 0;
}

.bwd-document-line {
  display: block;
}

.bwd-document-invitation {
  width: min(76dvh, 680px, calc(100vw - 32px));
  aspect-ratio: 1;
}

.bwd-invitation-copy {
  inset: 15.5% 18% 13% 17%;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.bwd-document-recipient {
  min-width: 0;
  margin: 0 0 clamp(12px, 2.1cqw, 22px);
  overflow-wrap: anywhere;
  font-size: clamp(0.92rem, 2.5cqw, 1.2rem);
  font-weight: 600;
  letter-spacing: 0.025em;
}

.bwd-invitation-body {
  display: grid;
  align-content: start;
  gap: clamp(8px, 1.5cqw, 16px);
  min-height: 0;
  font-size: clamp(0.72rem, 1.8cqw, 0.98rem);
  line-height: 1.52;
}

.bwd-document-signature-image {
  justify-self: end;
  width: min(47%, 250px);
  height: auto;
  margin: 2% 1% 0 0;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.bwd-document-symptom-memo,
.bwd-document-medical-handbook {
  width: min(88vw, 1040px);
  aspect-ratio: 3 / 2;
}

.bwd-symptom-copy {
  inset: 13% 35.5% 11% 35.5%;
  display: grid;
  align-content: start;
  gap: clamp(5px, 0.7cqw, 10px);
  transform: rotate(-0.2deg);
  font-size: clamp(0.55rem, 0.92cqw, 0.82rem);
  line-height: 1.34;
}

.bwd-memo-entry {
  display: grid;
  gap: 1px;
}

.bwd-memo-date {
  margin: 0;
  font: 700 0.96em/1.2 Georgia, "Times New Roman", "Noto Serif KR", serif;
  letter-spacing: 0.02em;
}

.bwd-memo-entry:nth-child(2n) {
  padding-left: 2%;
}

.bwd-medical-copy {
  inset: 15% 9.5% 14% 55%;
  display: grid;
  align-content: start;
  gap: clamp(8px, 1cqw, 16px);
  font-size: clamp(0.6rem, 1.02cqw, 0.9rem);
  line-height: 1.52;
}

.bwd-medical-title {
  margin: 0;
  padding-bottom: 0.42em;
  border-bottom: 1px solid rgba(54, 40, 31, 0.55);
  font: 700 1.16em/1.35 Georgia, "Times New Roman", "Noto Serif KR", serif;
  letter-spacing: -0.015em;
}

.bwd-medical-body {
  display: grid;
  gap: clamp(7px, 0.9cqw, 14px);
}

.bwd-medical-margin-note {
  justify-self: end;
  margin: 0.15em 2% 0 0;
  padding-bottom: 0.16em;
  border-bottom: 1px solid rgba(70, 51, 39, 0.55);
  color: var(--bwd-muted-ink);
  font-size: 0.92em;
  font-style: italic;
  transform: rotate(-1.2deg);
}

.bwd-document-close {
  position: fixed;
  z-index: 3;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  min-width: 58px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid rgba(211, 187, 151, 0.72);
  border-radius: 2px;
  background: rgba(19, 14, 12, 0.92);
  color: #f0e7dc;
  font: 600 0.88rem/1 Pretendard, system-ui, sans-serif;
  cursor: pointer;
}

.bwd-document-close:hover,
.bwd-document-close:focus-visible {
  border-color: #d8b77f;
  outline: 2px solid rgba(216, 183, 127, 0.48);
  outline-offset: 2px;
}

[data-blackwood-inline-document] {
  display: grid;
  place-items: center;
  width: 100%;
  min-width: 0;
}

[data-blackwood-inline-document] .bwd-document-surface {
  opacity: 1;
  transform: none;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.38);
}

[data-blackwood-inline-document] .bwd-document-invitation {
  width: min(100%, 680px);
}

.bwe-document-detail-trigger {
  min-height: 44px;
}

.bwe-notebook-document-action {
  margin: 18px 0 4px;
}

.bwe-notebook-document-action button {
  width: 100%;
  min-height: 44px;
}

@media (max-width: 700px) and (orientation: portrait) {
  .bwd-document-overlay {
    padding-inline:
      max(8px, env(safe-area-inset-left))
      max(8px, env(safe-area-inset-right));
  }

  .bwd-document-invitation {
    width: min(calc(100vw - 16px), 620px);
  }

  .bwd-invitation-copy {
    inset: 14.8% 15.5% 12% 15%;
  }

  .bwd-document-recipient {
    font-size: clamp(0.86rem, 4.1vw, 1rem);
  }

  .bwd-invitation-body {
    gap: clamp(5px, 1.9vw, 10px);
    font-size: clamp(0.67rem, 2.85vw, 0.84rem);
    line-height: 1.43;
  }

  .bwd-document-signature-image {
    width: 45%;
    margin-top: 0;
  }

  .bwd-document-symptom-memo,
  .bwd-document-medical-handbook {
    width: min(calc(100vw - 16px), 430px);
    height: min(76dvh, 650px);
    aspect-ratio: auto;
  }

  .bwd-document-symptom-memo .bwd-document-background,
  .bwd-document-medical-handbook .bwd-document-background {
    left: 50%;
    width: auto;
    max-width: none;
    object-fit: contain;
    transform: translateX(-50%);
  }

  .bwd-document-symptom-memo .bwd-document-background {
    height: 100%;
  }

  .bwd-symptom-copy {
    inset: 18% 18% 9%;
    gap: clamp(7px, 1.2dvh, 11px);
    font-size: clamp(0.68rem, 2.9vw, 0.82rem);
    line-height: 1.38;
  }

  .bwd-document-medical-handbook .bwd-document-background {
    left: 0;
    height: 100%;
  }

  .bwd-medical-copy {
    inset: 10% 8% 9%;
    gap: clamp(10px, 1.5dvh, 15px);
    font-size: clamp(0.75rem, 3.25vw, 0.9rem);
    line-height: 1.48;
  }
}

@media (max-width: 700px) and (orientation: landscape), (max-height: 420px) {
  .bwd-document-overlay {
    place-items: start center;
    padding-block:
      max(8px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-bottom));
  }

  .bwd-document-viewport {
    place-items: start center;
    padding-top: 2px;
  }

  .bwd-document-invitation {
    width: min(340px, calc(100vw - 104px));
    min-width: 300px;
  }

  .bwd-invitation-body {
    gap: 5px;
    font-size: 0.66rem;
    line-height: 1.38;
  }

  .bwd-document-recipient {
    margin-bottom: 7px;
    font-size: 0.78rem;
  }

  .bwd-document-signature-image {
    width: 42%;
  }

  .bwd-document-symptom-memo,
  .bwd-document-medical-handbook {
    width: min(520px, calc(100vw - 76px));
  }

  .bwd-document-close {
    top: max(8px, env(safe-area-inset-top));
    right: max(8px, env(safe-area-inset-right));
  }
}

@media (prefers-reduced-motion: reduce) {
  .bwd-document-overlay,
  .bwd-document-surface {
    transition-duration: 1ms;
  }

  .bwd-document-surface,
  .is-closing .bwd-document-surface {
    transform: none;
  }
}
