/* The dialog is a scrollable viewing window. Its inset leaves room for the
   silhouettes and shadows of the objects inside, even on a narrow screen. */
dialog.bay-file {
  --form-ink: #373126;
  --form-rule: #89806c;
  --stock: #f3eedf;
  --cast: #20190d50;
  --fold-size: 1.3rem;
  width: min(40.5rem, 100%);
  max-width: 100%;
  max-height: 100vh;
  max-height: 100dvh;
  margin: auto;
  padding: 1.4rem 1.25rem 2rem;
  border: 0;
  overflow: auto;
  overscroll-behavior: contain;
  background: transparent;
  color: var(--form-ink);
  font: 1rem/1.5 'Courier Prime', monospace;
  scrollbar-width: thin;
  scrollbar-color: #96897566 transparent;
}

.bay-file::backdrop { background: rgb(25 18 14 / .64); }

.bay-object { position: relative; transform-origin: 50% 32%; }

@media (prefers-reduced-motion: no-preference) {
  .bay-file[open] .bay-object { animation: bay-lift .22s ease-out; }
  @keyframes bay-lift {
    from { translate: 0 5px; rotate: -.4deg; }
    to { translate: 0; rotate: 0deg; }
  }
}

.bay-clipboard .bay-object {
  padding: 2.42rem .86rem 1.03rem;
  transform: rotate(-.6deg);
}

.bay-clipboard .bay-object::before {
  content: '';
  position: absolute;
  inset: 0;
  transform: perspective(95rem) rotateY(-2deg) rotateX(1deg);
  border: 1px solid #593f29;
  border-radius: .68rem .64rem .73rem .66rem;
  background:
    repeating-linear-gradient(127deg, #d6aa6809 0 1px, transparent 1px 5px),
    repeating-linear-gradient(49deg, #291a0d15 0 1px, transparent 1px 3px),
    linear-gradient(105deg, #91704e, #815f40 48%, #694b33);
  box-shadow: inset 0 0 0 1px #c5a27c, inset 0 -2px #5f4430,
    1px 2px #ab8864, 2px 3px #775438, 3px 5px #9b7959, 4px 7px #654830,
    7px 13px 13px #160e0966, 10px 22px 26px #120c0a40;
}

.bay-paper {
  position: relative;
  padding: 1.1rem clamp(1.25rem, 4vw, 2.1rem) 1.65rem;
  background:
    linear-gradient(156deg, #fffbee66, transparent 37%, #a08f6f0d 75%, transparent 85%),
    repeating-linear-gradient(28deg, #88755507 0 1px, transparent 1px 3px),
    var(--stock);
}
.bay-paper:focus { outline: none; }

.bay-clipboard .bay-paper {
  border: 1px solid #c9baa0;
  box-shadow: 1px 2px #d8ccb3, 2px 3px #a3977b, 3px 5px #ddd2be, 3px 8px 6px #35281b5e;
}

.bay-loose .bay-object {
  --punch-x: 1.02rem;
  margin-inline: clamp(.15rem, 1.5vw, 1.35rem);
  transform: rotate(.55deg);
}

.bay-loose .bay-paper {
  padding: 1.1rem clamp(1.25rem, 5vw, 2.35rem) 2.15rem clamp(2rem, 6vw, 2.85rem);
  isolation: isolate;
  background: none;
}
.bay-loose .bay-paper::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  border: 1px solid #c7bda5;
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - var(--fold-size)), calc(100% - var(--fold-size)) 100%, 0 100%);
  /* Two punched holes let the actual scene show through the filing margin. */
  mask-image: radial-gradient(circle at var(--punch-x) 28%, transparent 0 2.8px, black 3.4px),
              radial-gradient(circle at var(--punch-x) 72%, transparent 0 2.8px, black 3.4px);
  mask-composite: intersect;
  background:
    radial-gradient(circle at var(--punch-x) 28%, #938269 3.2px, #fffbed 4.2px, transparent 5.1px),
    radial-gradient(circle at var(--punch-x) 72%, #938269 3.2px, #fffbed 4.2px, transparent 5.1px),
    linear-gradient(178deg, transparent 48%, #a4917121 49.8%, #fffcf085 50.15%, transparent 51.2%),
    linear-gradient(92deg, #9b876412, transparent 13%, transparent 73%, #fff8e652),
    repeating-linear-gradient(26deg, transparent 0 2px, #8b754d08 2px 3px),
    var(--stock);
}

/* The turned tip exposes the reverse of the same sheet and casts a short shadow. */
.bay-loose .bay-paper::after {
  content: '';
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: var(--fold-size);
  height: var(--fold-size);
  border-radius: 2px 0 0 0;
  background: linear-gradient(135deg, #fffaf0, #d4c8ad 45%, #a59a83 51%, transparent 52%);
  box-shadow: -1px -1px 2px #65553a3b;
  clip-path: polygon(-8% -8%, 100% -8%, 100% 0, 0 100%, -8% 100%);
  pointer-events: none;
}

dialog.bay-carbon { --stock: #e6e9e2; --form-ink: #313c48; }
.bay-loose .bay-object::after {
  content: '';
  position: absolute;
  z-index: -1;
  inset: 2% .7rem 1px;
  border-radius: 0 0 40% 21%;
  box-shadow: 4px 10px 13px var(--cast);
  transform: perspective(58rem) rotateX(1.5deg) rotate(.3deg);
  pointer-events: none;
}
.bay-carbon .bay-object::before {
  content: '';
  position: absolute;
  inset: 3px -2px -4px 2px;
  transform: rotate(-.45deg);
  background: #b4c4cc;
  border: 1px solid #9ba7aa;
}

.bay-paper header {
  align-content: center;
  min-height: 2.65rem;
  border-bottom: 1px solid var(--form-rule);
}

.bay-file-id, .bay-file-series, .bay-paper h3, .bay-readings dt {
  font: 500 .69rem/1.35 'IBM Plex Mono', monospace;
  letter-spacing: .095em;
  text-transform: uppercase;
}

.bay-file-id, .bay-paper h3, .bay-readings dt { color: #585142; }
.bay-loose .bay-file-id, .bay-loose h3 { color: #774c3a; }
.bay-carbon .bay-file-id, .bay-carbon h3 { color: #425b70; }

.bay-file-close {
  float: right;
  position: sticky;
  top: .55rem;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  margin: -.2rem -.66rem -.12rem 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #5b5343;
  cursor: pointer;
}

.bay-file-close::before, .bay-file-close::after {
  content: '';
  grid-area: 1 / 1;
  width: 1rem;
  height: 2px;
  border-radius: 1px;
  background: currentColor;
  transform: rotate(45deg);
}

.bay-file-close::after { transform: rotate(-45deg); }
.bay-file-close:is(:hover, :focus-visible) { background: #e0d7c3; color: #342c20; }
.bay-file-close:focus-visible { outline: 2px solid #86714b; outline-offset: -5px; }
.bay-file-close:active { background: #cdbfa5; }

.bay-file-series {
  margin: 1.05rem 0 .2rem;
  color: #69604e;
  font: bold .76rem/1.3 'Courier Prime', monospace;
  letter-spacing: .10em;
}

.bay-paper h2 {
  margin: 0 0 1.15rem;
  font: 700 clamp(2rem, 5.4vw, 2.7rem)/1.05 'Source Serif 4', Georgia, serif;
  letter-spacing: -.035em;
}
.bay-paper section + section { margin-top: 1rem; }
.bay-paper h3 { margin: 0 0 .26rem; }
.bay-paper section p {
  --leading: 1.36rem;
  margin: 0;
  font: 400 .97rem/var(--leading) 'Courier Prime', monospace;
}
.bay-clipboard section p {
  background: repeating-linear-gradient(to bottom, transparent 0 calc(var(--leading) - 1px), #887f692a calc(var(--leading) - 1px) var(--leading));
}
.bay-clipboard .bay-clipboard-clip {
  position: absolute;
  z-index: 1;
  top: .55rem;
  left: 50%;
  width: clamp(7rem, 29%, 9.7rem);
  height: 3.02rem;
  transform: translateX(-50%);
  pointer-events: none;
  filter: drop-shadow(0 2px 1px #33271c80);
}

/* The domed rivets fasten the plate behind the paper. A folded jaw bears down on the sheet. */
.bay-clipboard-clip::before {
  content: '';
  position: absolute;
  inset: .29rem .3rem .32rem;
  border: 1px solid #575954;
  border-radius: .46rem .46rem .17rem .17rem;
  background:
    radial-gradient(circle at 9% 33%, #ecece3 0 1px, #b3b5ab 2px, #707570 4px, #444741 4.5px, transparent 5.3px),
    radial-gradient(circle at 91% 33%, #ecece3 0 1px, #b3b5ab 2px, #707570 4px, #444741 4.5px, transparent 5.3px),
    linear-gradient(172deg, #d5d5ca, #a3a69f 45%, #747973 85%);
  box-shadow: inset 0 1px #f1f0e5, inset 0 -2px #646961;
}

.bay-clipboard .bay-clip-lever {
  position: absolute;
  top: 0;
  width: 54%;
  height: 2.25rem;
  left: 23%;
  border: 1px solid #686b63;
  border-radius: 38% 38% 18% 18% / 51% 51% 20% 20%;
  background: linear-gradient(172deg, #eeeDE0 1%, #b4b6ac 19%, #8c918b 33%, #c9cbc1 58%, #797e76 80%);
  box-shadow: inset 0 1px #faf8ec, inset 0 -1px #565a53, 0 1px 2px #3e423a;
}

.bay-clip-lever::before {
  content: '';
  position: absolute;
  top: .33rem;
  left: 39%;
  width: 22%;
  height: .36rem;
  border-radius: 50%;
  background: #595a50;
  box-shadow: inset 0 1.5px 1.5px #332f29, 0 1px #e1e0d1;
}

.bay-clipboard .bay-clip-jaw {
  position: absolute;
  inset: auto 0 0;
  height: 1.13rem;
  border: 1px solid #4e534e;
  border-radius: .17rem .17rem .22rem .22rem;
  background: linear-gradient(#c5c7bc 0%, #f1f0e5 14%, #a4a9a1 25%, #81877f 62%, #4e554f 80%, #cacdc2 91%);
  box-shadow: 0 2px 0 #554f43, 0 4px 3px #3d352639;
}

.bay-clip-jaw::before {
  content: '';
  position: absolute;
  left: 12%;
  right: 12%;
  height: .31rem;
  top: -.25rem;
  border: 1px solid #686b63;
  border-radius: 3px;
  background: repeating-linear-gradient(92deg, #777d75 0 1px, #d7d8cc 1.5px 3px, #afb4aa 3px 4px);
}

.bay-clipboard .bay-readings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 0;
  margin: 0 0 1.12rem;
  border-top: 2px solid #514c3e;
  border-bottom: 1px solid var(--form-rule);
}

.bay-clipboard .bay-readings div {
  display: block;
  padding: .49rem .65rem .56rem;
}

.bay-clipboard .bay-readings div + div { border-left: 1px solid var(--form-rule); }

.bay-clipboard .bay-readings dd {
  margin: .18rem 0 0;
  color: #244e6a;
  font: italic 700 1.15rem/1.08 'Courier Prime', monospace;
  transform: rotate(-1.5deg);
  transform-origin: left;
}

@media (max-width: 480px) {
  dialog.bay-file { padding: .85rem .65rem 1.35rem; }
  .bay-clipboard .bay-object {
    padding: 2.28rem .48rem .78rem;
    transform: rotate(-.25deg);
  }
  .bay-clipboard .bay-paper { padding: 1rem .95rem 1.25rem; }
  .bay-loose .bay-object { --punch-x: .65rem; margin-inline: .12rem; }
  .bay-loose .bay-paper { padding: .8rem 1.05rem 1.55rem 1.55rem; }
  .bay-paper section p { --leading: 1.5rem; font-size: max(15px, 1rem); }
}
