.overlay {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: clamp(10px, 3vw, 36px);
}
.overlay[hidden] { display: none; }
.overlay__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 9, 6, .74);
  opacity: 0;
  transition: opacity .4s ease;
}
.overlay.is-open .overlay__backdrop { opacity: 1; }

.sheet {
  position: relative;
  width: min(1000px, 100%);
  height: min(88vh, 920px);
  height: min(88dvh, 920px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .75);
  transform-origin: center;
  transition: transform .55s cubic-bezier(.2, .9, .25, 1), opacity .35s ease;
}
.sheet__header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px 12px 18px;
  border-bottom: 1px solid #e3d8c4;
  background: #f4ecdd;
}
.sheet__number {
  flex: none;
  display: grid;
  place-items: center;
  width: 54px;
  height: 34px;
  padding-left: 9px;
  color: #3a2a1d;
  background: #fbf5e9;
  clip-path: polygon(20% 0, 100% 0, 100% 100%, 20% 100%, 0 50%);
  font-family: var(--serif);
  font-size: 1.25rem;
  font-weight: 700;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .3));
}
.sheet__number-ribbon {
  flex: none;
  width: 6px;
  align-self: stretch;
  margin: -12px 0;
  background: var(--ribbon-color, var(--berry));
}
.sheet__text { flex: 1; min-width: 0; }
.sheet__date { margin: 0; font-size: .78rem; color: var(--ink-light); }
.sheet__title {
  margin: 1px 0 0;
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.15rem, 2.2vw, 1.5rem);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sheet__author { margin: 1px 0 0; font-size: .86rem; color: var(--fir); }
.sheet__author:empty { display: none; }
.sheet__nav { display: flex; gap: 6px; flex: none; }
.round-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid #d8ccb6;
  border-radius: 50%;
  background: #fbf5e9;
  color: var(--ink);
  cursor: pointer;
}
.round-button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.round-button:hover:not(:disabled) { border-color: #a89474; background: #fff; }
.round-button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.round-button:disabled { opacity: .35; cursor: default; }
.round-button__shrink, .round-button[aria-pressed="true"] .round-button__grow { display: none; }
.round-button[aria-pressed="true"] .round-button__shrink { display: block; }
.overlay.is-large { padding: clamp(6px, 1vw, 14px); }
.overlay.is-large .sheet { width: 100%; height: 100%; border-radius: 8px; }

.sheet__content { position: relative; flex: 1; min-height: 0; background: var(--paper); }
.sheet__frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  opacity: 0;
  transition: opacity .4s ease;
}
.sheet__frame.is-visible { opacity: 1; }
.sheet__loading, .sheet__empty {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  align-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  color: var(--ink-light);
}
.sheet.is-loading .sheet__loading { display: grid; }
.sheet.is-empty .sheet__empty { display: grid; }
.sheet__loading p { margin: 0; font-family: var(--serif); font-size: 1.05rem; }
.sheet__loading span {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid #e3d8c4;
  border-top-color: var(--berry);
  animation: loading-spin 1s linear infinite;
}
.sheet__empty h3 { margin: 0; font-family: var(--serif); font-weight: 600; font-size: 1.5rem; color: var(--ink); }
.sheet__empty p { margin: 0; max-width: 36ch; line-height: 1.5; }
@keyframes loading-spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  .overlay { padding: 0; }
  .sheet { width: 100%; height: 100%; border-radius: 0; }
  .sheet__header { gap: 10px; padding: max(10px, env(safe-area-inset-top)) 10px 10px 12px; }
  .sheet__number { width: 46px; height: 30px; font-size: 1.05rem; }
  .round-button { width: 34px; height: 34px; }
  #sheet-size { display: none; }
  .overlay.is-large { padding: 0; }
  .overlay.is-large .sheet { border-radius: 0; }
}
