:root {
  --ink: #f4f3ee;
  --ink-dim: rgba(244, 243, 238, .62);
  --ground: #080c0b;
  --glass: rgba(12, 20, 17, .58);
  --glass-line: rgba(244, 243, 238, .16);
  --accent: rgba(244, 243, 238, .92);
  --rail-gap: 10px;
  --edge: max(18px, env(safe-area-inset-left));
  --floor: max(20px, env(safe-area-inset-bottom));
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard",
    "Noto Sans KR", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

/* The HUD sets display on nearly everything, which would otherwise defeat the
   hidden attribute the app toggles. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

body.modal-open .feed { overflow: hidden; }

.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* ---------- feed ---------- */

.stage { position: fixed; inset: 0; }

.feed {
  height: 100dvh;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  outline: none;
}
.feed::-webkit-scrollbar { display: none; }

.slide {
  position: relative;
  height: 100dvh;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  overflow: hidden;
  background: var(--ground);
}

.slide-still,
.slide-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* The still holds the frame until the video has something to show, so a swipe
   never lands on a black rectangle. */
.slide-video {
  opacity: 0;
  transition: opacity .45s ease;
}
.slide.is-playing .slide-video-preview { opacity: 1; }
.slide.is-playing.is-full .slide-video-preview { opacity: 0; }
.slide.is-playing.is-full .slide-video-full { opacity: 1; }

/* Scrims only where the HUD actually sits. */
.slide::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(8, 12, 11, .5), rgba(8, 12, 11, 0) 22%),
    linear-gradient(0deg, rgba(8, 12, 11, .72), rgba(8, 12, 11, 0) 38%);
}

/* ---------- hud ---------- */

.hud {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 12px;
  padding: max(16px, env(safe-area-inset-top)) var(--edge) var(--floor);
  pointer-events: none;
}

.mark {
  margin: 0;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .34em;
  color: var(--ink-dim);
  mix-blend-mode: screen;
}

/* Sits in its own grid row so it can never land on top of the rails below. */
.tools {
  justify-self: end;
  align-self: end;
  display: grid;
  gap: 12px;
  pointer-events: auto;
}

.tool {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--glass-line);
  background: var(--glass);
  color: var(--ink);
  font-size: 1.05rem;
  cursor: pointer;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  transition: transform .18s ease, background .18s ease;
}
.tool:hover { transform: scale(1.06); }
.tool:active { transform: scale(.96); }
.tool[aria-pressed="true"] {
  background: rgba(244, 243, 238, .9);
  color: #0d1512;
}
.tool:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ---------- horizontal rails ---------- */

.rail {
  grid-column: 1;
  /* Children measure their offsetLeft against this box, which is what the
     scroll position is compared with. */
  position: relative;
  display: flex;
  gap: var(--rail-gap);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  pointer-events: auto;
}
.rail::-webkit-scrollbar { display: none; }

.rail-words { align-self: end; }

.word {
  flex: 0 0 min(30rem, calc(100% - 44px));
  scroll-snap-align: start;
  /* One phrase per swipe, the way one scene arrives per vertical swipe. */
  scroll-snap-stop: always;
  display: grid;
  align-content: center;
  min-height: 8.5rem;
  margin: 0;
  padding: 22px 24px;
  border-radius: 18px;
  border: 1px solid var(--glass-line);
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  font-size: 1.02rem;
  line-height: 1.7;
  text-wrap: pretty;
  white-space: pre-wrap;
}

.rail-sounds { align-self: end; }

.sound {
  flex: 0 0 auto;
  scroll-snap-align: center;
  scroll-snap-stop: always;
  padding: 13px 22px;
  border-radius: 999px;
  border: 1px solid var(--glass-line);
  background: var(--glass);
  color: var(--ink-dim);
  font-size: .92rem;
  white-space: nowrap;
  cursor: pointer;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.sound[aria-pressed="true"] {
  background: rgba(244, 243, 238, .9);
  border-color: transparent;
  color: #0d1512;
  font-weight: 600;
}
.sound[aria-disabled="true"] { opacity: .52; cursor: default; }
.sound:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ---------- breathing ---------- */

.breath {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 20px;
  pointer-events: none;
  text-align: center;
}

.breath-ring {
  width: 132px;
  height: 132px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid rgba(244, 243, 238, .4);
  background: rgba(12, 20, 17, .3);
  font-size: 1.6rem;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transform: scale(.82);
  transition: transform 3.6s ease-in-out;
}
.breath.inhale .breath-ring { transform: scale(1.08); }
.breath p { margin: 0; font-size: .95rem; color: var(--ink-dim); }

/* ---------- sheets ---------- */

.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  align-items: end;
  justify-items: center;
  background: rgba(5, 9, 8, .6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.sheet-overlay[hidden] { display: none; }

.sheet {
  width: min(560px, 100%);
  max-height: 88dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: grid;
  gap: 16px;
  padding: 22px var(--edge) calc(var(--floor) + 8px);
  border-radius: 26px 26px 0 0;
  border: 1px solid var(--glass-line);
  border-bottom: none;
  background: rgba(11, 18, 16, .94);
  animation: rise .28s ease-out;
}

@keyframes rise { from { transform: translateY(18px); opacity: 0; } }

.sheet header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.sheet h2 { margin: 0; font-size: 1.24rem; font-weight: 700; }

.close {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--glass-line);
  background: transparent;
  color: var(--ink);
  font-size: 1.1rem;
  cursor: pointer;
}

.sheet-lead, .hint, .disclaimer {
  margin: 0;
  font-size: .86rem;
  line-height: 1.65;
  color: var(--ink-dim);
}
.disclaimer { padding-top: 4px; font-size: .78rem; }

.sheet blockquote {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.8;
  text-wrap: pretty;
}

.sheet-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.sheet-meta small { color: var(--ink-dim); font-size: .78rem; }
.sheet-meta a { color: var(--ink-dim); font-size: .8rem; }

.sheet button:not(.close):not(.tool) {
  padding: 11px 16px;
  border-radius: 999px;
  border: 1px solid var(--glass-line);
  background: transparent;
  color: var(--ink);
  font-size: .88rem;
  cursor: pointer;
}
.sheet button[aria-pressed="true"] {
  background: rgba(244, 243, 238, .9);
  border-color: transparent;
  color: #0d1512;
  font-weight: 600;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
  display: grid;
  gap: 10px;
}
legend {
  padding: 0;
  font-size: .8rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
fieldset label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: .92rem;
}

input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.credits {
  border-top: 1px solid var(--glass-line);
  padding-top: 14px;
}
.credits > summary {
  cursor: pointer;
  font-size: .8rem;
  letter-spacing: .12em;
  color: var(--ink-dim);
}
.credits > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.credits > * + * { margin-top: 10px; }
.credits section + section { margin-top: 16px; }
.credits h3 { margin: 0 0 8px; font-size: .86rem; font-weight: 600; }

.credit-list {
  margin: 0 0 8px;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}
.credit-list li { font-size: .82rem; line-height: 1.55; }
.credit-list small { color: var(--ink-dim); font-size: .78rem; }
.credit-label { color: var(--ink-dim); margin-right: 6px; }
.credits a { color: var(--ink); }

@media (min-width: 760px) {
  .word { font-size: 1.08rem; }
}

@media (prefers-reduced-motion: reduce) {
  .slide-video, .breath-ring, .tool, .sheet { transition: none; animation: none; }
  .feed { scroll-behavior: auto; }
}
