:root {
  --ink: #f6f2ec;
  --ink-soft: rgba(246, 242, 236, 0.62);
  --panel: #f6f2ec;
  --glass: rgba(251, 248, 244, 0.5);
  --glass-edge: rgba(255, 255, 255, 0.5);
  --glass-blur: blur(44px) saturate(165%);
  --panel-ink: #1b1917;
  --panel-ink-soft: #5d564e;
  --fade: 600ms;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Times New Roman", Georgia, serif;
  --sans: "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #0b0a09;
  color: var(--ink);
  font-family: var(--sans);
  overscroll-behavior: none;
}

/* ---------- stage ---------- */

#stage {
  position: fixed;
  inset: 0;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  background: #0b0a09;
  cursor: pointer;
}

.clip {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity var(--fade) var(--ease);
  z-index: 0;
  pointer-events: none;
  will-change: opacity;
}

.clip.is-active { opacity: 1; }

#scrim {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(0,0,0,0) 40%, rgba(0,0,0,0.34) 100%),
    linear-gradient(to top, rgba(0,0,0,0.42) 0%, rgba(0,0,0,0) 38%);
}

/* ---------- arrows ---------- */

#prev, #next {
  position: fixed;
  top: 50%;
  z-index: 2;
  width: 56px;
  height: 56px;
  margin-top: -28px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 50%;
  background: rgba(10, 9, 8, 0.42);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff;
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.32);
  cursor: pointer;
  transition: background 220ms var(--ease), border-color 220ms var(--ease),
              color 220ms var(--ease), transform 220ms var(--ease);
}

#prev { left: clamp(14px, 3vw, 40px); }
#next { right: clamp(14px, 3vw, 40px); }

#prev:hover, #next:hover {
  background: var(--ink);
  border-color: var(--ink);
  color: #14110f;
}

#prev:active, #next:active { transform: scale(0.94); }

#prev:focus-visible, #next:focus-visible, #modal-close:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

#prev svg, #next svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- modal ---------- */

#modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: none;
  padding: clamp(16px, 4vw, 48px);
  background: rgba(8, 7, 6, 0.3);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  overflow-y: auto;
}

#modal.is-open { display: flex; align-items: center; justify-content: center; }

#modal-panel {
  position: relative;
  width: 100%;
  max-width: 720px;
  max-height: 85vh;
  overflow-y: auto;
  padding: clamp(28px, 5vw, 64px) clamp(22px, 5vw, 60px);
  background: var(--glass);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-edge);
  color: var(--panel-ink);
  box-shadow:
    0 30px 90px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  animation: rise 420ms var(--ease) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: none; }
}

#modal-close {
  position: absolute;
  top: clamp(10px, 2vw, 18px);
  right: clamp(10px, 2vw, 18px);
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--panel-ink-soft);
  cursor: pointer;
  transition: background 200ms var(--ease), color 200ms var(--ease);
}

#modal-close:hover { background: rgba(27, 25, 23, 0.09); color: var(--panel-ink); }

#modal-close svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
}

#modal-title {
  margin: 0 0 10px;
  font-family: var(--sans);
  font-size: clamp(15px, 2.1vw, 19px);
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  max-width: 88%;
}

#modal-author {
  margin: 0 0 clamp(22px, 4vw, 36px);
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--panel-ink-soft);
}

#modal-body {
  font-family: var(--serif);
  font-size: clamp(15px, 1.9vw, 17.5px);
  line-height: 1.72;
  color: #26221e;
  hyphens: auto;
  -webkit-hyphens: auto;
}

#modal-body p {
  margin: 0 0 1.15em;
  white-space: pre-line;
}

#modal-body p:last-child { margin-bottom: 0; }

#modal-body ul {
  margin: 0 0 1.15em;
  padding-left: 1.2em;
}

#modal-body li { margin-bottom: 0.4em; }

/* ---------- small screens ---------- */

@media (max-width: 640px) {
  #prev, #next { width: 46px; height: 46px; margin-top: -23px; }
  #prev svg, #next svg { width: 18px; height: 18px; }
  /* Inset the sheet so the clip stays visible around the glass. */
  #modal { padding: 14px; }
  #modal-panel {
    max-height: calc(100dvh - 28px);
    max-width: none;
    border-radius: 3px;
    padding-top: clamp(56px, 12vw, 72px);
    padding-bottom: calc(clamp(32px, 8vw, 44px) + env(safe-area-inset-bottom));
  }
  /* Sticky so it stays reachable while a long text scrolls under it. */
  #modal-close {
    position: sticky;
    top: 10px;
    margin-left: auto;
    margin-bottom: -44px;
    z-index: 3;
    background: rgba(250, 247, 242, 0.82);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-edge);
  }
  #modal-close:hover { background: rgba(250, 247, 242, 0.95); }
}

@media (prefers-reduced-motion: reduce) {
  .clip { transition-duration: 1ms; }
  #modal-panel { animation: none; }
}
