:root {
  --desk-0: #121c22;
  --desk-1: #1d3038;
  --manila: #e2b33a;
  --manila-deep: #d4a028;
  --folder-w: min(400px, 80vw);
  --folder-h: calc(var(--folder-w) * 0.75);
  --open: 0;
  --font-ui: "Unbounded", "Segoe UI", sans-serif;
  --font-paper: "Literata", "Georgia", serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
}

body {
  min-height: 100dvh;
  min-height: 100svh;
  background: var(--desk-0);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.atmosphere__wash {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 90% 70% at 50% 62%, rgba(95, 138, 139, 0.16), transparent 62%),
    linear-gradient(165deg, #101a20 0%, var(--desk-1) 50%, #172a31 100%);
}

.atmosphere__glow {
  position: absolute;
  width: 48vmax;
  height: 48vmax;
  left: 50%;
  top: 60%;
  translate: -50% -50%;
  background: radial-gradient(circle, rgba(228, 179, 58, 0.1), transparent 65%);
  filter: blur(10px);
  opacity: calc(var(--open) * 0.65);
}

.atmosphere__grain {
  position: absolute;
  inset: 0;
  opacity: 0.12;
  mix-blend-mode: soft-light;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.55'/%3E%3C/svg%3E");
}

.stage {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 100dvh;
  min-height: 100svh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scene {
  position: relative;
  width: var(--folder-w);
  height: var(--folder-h);
  perspective: 1500px;
  perspective-origin: 50% 65%;
}

.folder {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  transform-style: preserve-3d;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  transform: translate3d(0, calc(var(--open) * -6px), 0);
}

.folder:focus-visible::after {
  content: "";
  position: absolute;
  inset: -12px;
  border: 2px solid rgba(239, 198, 90, 0.45);
  border-radius: 22px;
  pointer-events: none;
}

.folder__cast {
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: -12%;
  height: 24%;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.55), transparent 72%);
  filter: blur(16px);
  transform: translateZ(-80px) scaleX(calc(1 + var(--open) * 0.2));
  opacity: calc(0.72 + var(--open) * 0.18);
  pointer-events: none;
}

.folder__tab,
.folder__back,
.folder__papers,
.folder__front,
.folder__front-shadow {
  position: absolute;
  pointer-events: none;
}

/* Tab — CSS box, solid fill, sits on the closed face */
.folder__tab {
  z-index: 5;
  left: 8%;
  top: 8%;
  width: 30%;
  height: 14%;
}

.folder__tab-shape {
  position: absolute;
  inset: 0;
  background: var(--manila);
  border-radius: 10px 10px 0 0;
  /* Diagonal step into body on the right */
  clip-path: polygon(0 0, 78% 0, 100% 100%, 0 100%);
}

.folder__tab-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-ui);
  font-size: clamp(0.55rem, 1.9vw, 0.72rem);
  font-weight: 500;
  letter-spacing: 0.14em;
  color: rgba(70, 42, 8, 0.82);
  padding-right: 12%;
}

/* Back pocket — invisible when closed */
.folder__back {
  z-index: 1;
  left: 6.25%;
  right: 6.25%;
  top: 20.5%;
  bottom: 2.5%;
  background: var(--manila-deep);
  border-radius: 0 0 14px 14px;
  opacity: var(--open);
}

.folder__papers {
  z-index: 2;
  left: 10%;
  right: 10%;
  top: 24%;
  bottom: 16%;
  overflow: hidden;
  border-radius: 2px 6px 4px 4px;
  transform-style: preserve-3d;
  clip-path: inset(calc((1 - var(--open)) * 100%) 0 0 0);
  opacity: var(--open);
}

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 100%;
  border-radius: 3px 7px 5px 5px;
  transform-origin: 50% 100%;
  will-change: transform;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 12% 10% 10%;
}

.sheet--1 {
  z-index: 3;
  background: linear-gradient(180deg, #ffffff 0%, #fff8ec 55%, #f4ebe0 100%);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.9) inset,
    0 7px 14px rgba(0, 0, 0, 0.13),
    0 0 0 1px rgba(170, 145, 110, 0.22);
  transform:
    translate3d(0, calc(18% - var(--open) * 46%), 4px)
    rotate(calc(-0.25deg - var(--open) * 0.8deg));
  padding-top: calc(14% + var(--open) * 4%);
}

.sheet--2 {
  z-index: 2;
  background: linear-gradient(180deg, #f7f1e4 0%, #efe6d4 100%);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.5) inset,
    0 9px 16px rgba(0, 0, 0, 0.15),
    0 0 0 1px rgba(150, 130, 100, 0.24);
  transform:
    translate3d(calc(0.8% + var(--open) * 2.2%), calc(16% - var(--open) * 58%), 2px)
    rotate(calc(0.9deg + var(--open) * 2.5deg));
}

.sheet--3 {
  z-index: 1;
  background: linear-gradient(180deg, #eef2f6 0%, #e4e9ef 100%);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.45) inset,
    0 9px 16px rgba(0, 0, 0, 0.17),
    0 0 0 1px rgba(110, 125, 145, 0.28);
  transform:
    translate3d(calc(-0.8% - var(--open) * 1.8%), calc(14% - var(--open) * 68%), 1px)
    rotate(calc(-1deg - var(--open) * 2.8deg));
}

.sheet__heading {
  font-family: var(--font-paper);
  font-size: clamp(0.7rem, 2.2vw, 0.92rem);
  font-weight: 600;
  color: #3d3428;
  letter-spacing: 0.01em;
  line-height: 1.25;
  margin: 0 0 0.3rem;
  opacity: var(--open);
}

.sheet__line {
  display: block;
  height: 2px;
  width: 100%;
  border-radius: 2px;
  background: #cfc3ad;
  opacity: var(--open);
}

.sheet__line--short {
  width: 58%;
}

.folder__front-shadow {
  z-index: 3;
  left: 8%;
  right: 8%;
  top: 40%;
  bottom: -8%;
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 40%, rgba(0, 0, 0, 0.35), transparent 70%);
  filter: blur(12px);
  opacity: calc(var(--open) * 0.85);
  transform: translateZ(-20px);
  transform-style: preserve-3d;
}

.folder__front {
  z-index: 4;
  inset: 0;
  transform-origin: 50% 100%;
  transform: rotateX(calc(var(--open) * -62deg));
  transform-style: preserve-3d;
  will-change: transform;
  filter: none;
}

.folder__front-face {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  backface-visibility: hidden;
}

/*
  Solid CSS panel — hard top edge, no SVG AA fringe, no gradient fill.
  Top aligns with tab bottom (20.5% ≈ viewBox y=50/240).
*/
.folder__front-panel {
  position: absolute;
  left: 6.25%;
  right: 6.25%;
  top: 20.5%;
  bottom: 2.5%;
  background: var(--manila);
  border-radius: 0 0 14px 14px;
  box-shadow: none;
  border: 0;
  /* Explicit hard top — no highlight */
  background-image: none;
}

.folder__sticker {
  position: absolute;
  left: 50%;
  top: 52%;
  translate: -50% -50%;
  width: min(56%, 200px);
  padding: 0.75rem 0.85rem;
  border-radius: 4px;
  background: #f7f0e2;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.65) inset,
    0 2px 6px rgba(90, 55, 10, 0.18),
    0 0 0 1px rgba(150, 110, 40, 0.18);
  display: grid;
  gap: 0.2rem;
  text-align: center;
  transform: rotate(-1.4deg);
}

.folder__sticker-brand {
  font-family: var(--font-ui);
  font-size: clamp(0.8rem, 2.5vw, 1.1rem);
  font-weight: 700;
  color: #5a3a12;
  letter-spacing: -0.02em;
}

.folder__sticker-meta {
  font-family: var(--font-paper);
  font-size: clamp(0.62rem, 1.8vw, 0.76rem);
  color: rgba(90, 58, 18, 0.65);
}

@media (max-width: 520px) {
  :root {
    --folder-w: min(310px, 86vw);
  }

  .scene {
    perspective: 1150px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .atmosphere__glow {
    transition: none;
  }
}
