:root {
  --bg: #f4ebdf;
  --ink: #1f1a17;
  --muted: #766b60;
  --paper: #fffaf0;
  --line: #d7c5af;
  --red: #bd4c43;
  --green: #2d6a5f;
  --gold: #e7b853;
  --blue: #486fb1;
  --shadow: 0 24px 76px rgba(49, 34, 20, 0.18);
  --cell-w: 192px;
  --cell-h: 208px;
  --atlas-w: 1536px;
  --atlas-h: 1872px;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 82% 8%, rgba(231, 184, 83, 0.26), transparent 24%),
    linear-gradient(180deg, #fffdf8 0%, var(--bg) 52%, #eaded1 100%);
}

button,
a {
  font: inherit;
}

button {
  cursor: pointer;
}

.story-topbar,
.story-page {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
}

.story-topbar {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) 150px;
  gap: 18px;
  align-items: center;
  padding: 24px 0 18px;
}

.back-link,
.caption-toggle,
.story-controls button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  text-decoration: none;
}

.back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
}

.caption-toggle {
  justify-self: end;
  padding: 0 14px;
}

.story-kicker,
.story-topbar h1 {
  margin: 0;
}

.story-kicker {
  color: var(--green);
  font-size: 12px;
  font-weight: 1000;
  letter-spacing: 0.12em;
  line-height: 1;
  text-transform: uppercase;
}

.story-topbar h1 {
  margin-top: 8px;
  font-size: clamp(30px, 5vw, 58px);
  line-height: 0.94;
  letter-spacing: 0;
}

.story-page {
  display: grid;
  grid-template-columns: minmax(320px, 540px) minmax(300px, 1fr);
  gap: 22px;
  align-items: start;
  padding-bottom: 54px;
}

.phone-frame {
  width: min(540px, 100%);
  padding: 12px;
  border: 1px solid rgba(31, 26, 23, 0.16);
  border-radius: 32px;
  background: #171514;
  box-shadow: var(--shadow);
}

.story-card {
  position: relative;
  aspect-ratio: 9 / 16;
  overflow: hidden;
  border-radius: 22px;
  background:
    linear-gradient(180deg, rgba(255, 250, 236, 0.18), rgba(255, 250, 236, 0) 34%, rgba(45, 106, 95, 0.13) 100%),
    url("assets/backgrounds/shirokuro-story-bg.png") center top / cover no-repeat,
    #f7ead1;
  isolation: isolate;
}

.story-card::before {
  position: absolute;
  z-index: 1;
  inset: 0;
  background:
    radial-gradient(circle at 50% 45%, transparent 38%, rgba(255, 250, 236, 0.2) 72%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0) 24%, rgba(31, 26, 23, 0.08));
  content: "";
  pointer-events: none;
}

.story-card::after {
  position: absolute;
  z-index: 2;
  inset: 18px;
  border: 2px solid rgba(31, 26, 23, 0.12);
  border-radius: 18px;
  content: "";
  pointer-events: none;
}

.actor {
  position: absolute;
  z-index: 4;
  display: grid;
  justify-items: center;
  gap: 7px;
  opacity: 0;
  transform: translate(-50%, 0) scale(1);
  transition:
    left 820ms cubic-bezier(0.2, 0.8, 0.2, 1),
    bottom 820ms cubic-bezier(0.2, 0.8, 0.2, 1),
    opacity 360ms ease;
}

.actor.is-visible {
  opacity: 1;
}

.actor.is-pop {
  animation: story-pop 620ms ease both;
}

.actor-louie {
  z-index: 5;
}

.actor-mirim {
  z-index: 6;
}

.actor-snowy {
  z-index: 5;
}

.actor > span {
  padding: 5px 9px;
  border: 1px solid rgba(31, 26, 23, 0.16);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink);
  font-size: 12px;
  font-weight: 1000;
  line-height: 1;
}

.sprite-frame {
  width: var(--cell-w);
  height: var(--cell-h);
  transform-origin: 50% 100%;
}

.sprite {
  position: relative;
  overflow: hidden;
  width: var(--cell-w);
  height: var(--cell-h);
}

.sprite img {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  width: var(--atlas-w);
  max-width: none;
  height: var(--atlas-h);
  image-rendering: pixelated;
  pointer-events: none;
  user-select: none;
}

.actor-louie .sprite-frame {
  transform: scale(0.7);
}

.actor-snowy .sprite-frame {
  transform: scale(0.44);
}

.actor-mirim .sprite-frame {
  transform: scale(1.08);
}

.floating-things span {
  position: absolute;
  z-index: 5;
  color: var(--red);
  font-size: 24px;
  font-weight: 1000;
  opacity: 0;
  text-shadow: 0 2px 0 #fffaf0;
}

.floating-things span:nth-child(1) {
  top: 35%;
  left: 18%;
  color: var(--green);
}

.floating-things span:nth-child(2) {
  top: 29%;
  left: 50%;
}

.floating-things span:nth-child(3) {
  top: 40%;
  right: 18%;
  color: var(--blue);
  font-size: 20px;
}

.floating-things span:nth-child(4) {
  top: 21%;
  right: 27%;
  color: var(--blue);
}

.floating-things span:nth-child(5) {
  top: 47%;
  left: 34%;
}

.story-card.is-sparkling .floating-things span {
  animation: sparkle-rise 1.45s ease-out both;
}

.story-card.is-sparkling .floating-things span:nth-child(2) {
  animation-delay: 120ms;
}

.story-card.is-sparkling .floating-things span:nth-child(3) {
  animation-delay: 220ms;
}

.story-card.is-sparkling .floating-things span:nth-child(4) {
  animation-delay: 320ms;
}

.story-card.is-sparkling .floating-things span:nth-child(5) {
  animation-delay: 420ms;
}

.subtitle-card {
  position: absolute;
  z-index: 8;
  right: 24px;
  bottom: 22px;
  left: 24px;
  min-height: 132px;
  padding: 14px 16px;
  border: 1px solid rgba(31, 26, 23, 0.22);
  border-radius: 14px;
  background: rgba(255, 253, 248, 0.92);
  box-shadow: 0 14px 34px rgba(31, 26, 23, 0.13);
  backdrop-filter: blur(10px);
}

.subtitle-card.is-hidden {
  display: none;
}

.scene-count,
.ko-line,
.en-line {
  margin: 0;
}

.scene-count {
  color: var(--green);
  font-size: 12px;
  font-weight: 1000;
  letter-spacing: 0.08em;
  line-height: 1;
  text-transform: uppercase;
}

.ko-line {
  margin-top: 7px;
  color: var(--ink);
  font-size: clamp(23px, 5.2vw, 34px);
  font-weight: 950;
  line-height: 1.14;
  word-break: keep-all;
}

.en-line {
  margin-top: 8px;
  color: #5f554c;
  font-size: clamp(14px, 2.7vw, 18px);
  font-weight: 850;
  line-height: 1.25;
}

.story-controls {
  display: grid;
  gap: 14px;
}

.control-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.story-controls button {
  padding: 0 13px;
}

.postable-link {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  text-decoration: none;
}

.story-controls .primary-action {
  border-color: #171514;
  background: #171514;
  color: #fffaf0;
}

.progress-dots {
  display: flex;
  gap: 8px;
}

.progress-dots button {
  width: 13px;
  min-width: 13px;
  height: 13px;
  min-height: 13px;
  padding: 0;
  border-radius: 50%;
  background: #d7c9bb;
}

.progress-dots button.is-active {
  background: var(--red);
}

.script-panel {
  display: grid;
  gap: 14px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.8);
  box-shadow: var(--shadow);
}

.script-panel ol {
  display: grid;
  gap: 12px;
  margin: 0;
  padding-left: 20px;
}

.script-panel li {
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.45;
}

.script-panel li strong {
  display: block;
  color: inherit;
  font-size: 15px;
}

.script-panel li span {
  display: block;
  margin-top: 2px;
}

.script-panel li.is-active {
  color: var(--ink);
  font-weight: 950;
}

@keyframes story-pop {
  0% {
    transform: translate(-50%, 0) scale(0.88);
  }
  58% {
    transform: translate(-50%, -15px) scale(1.04);
  }
  100% {
    transform: translate(-50%, 0) scale(1);
  }
}

@keyframes sparkle-rise {
  0% {
    transform: translateY(24px) scale(0.72);
    opacity: 0;
  }
  40% {
    opacity: 1;
  }
  100% {
    transform: translateY(-34px) scale(1.06);
    opacity: 0;
  }
}

body.capture-mode {
  min-width: 0;
  overflow: hidden;
  background: #171514;
}

body.capture-mode .story-topbar,
body.capture-mode .story-controls {
  display: none;
}

body.capture-mode .story-page {
  display: block;
  width: min(100vw, calc(100vh * 9 / 16));
  height: 100vh;
  padding: 0;
}

body.capture-mode .phone-frame {
  width: 100%;
  height: 100vh;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

body.capture-mode .story-card {
  width: 100%;
  height: 100vh;
  border-radius: 0;
}

body.capture-mode .actor-louie .sprite-frame,
body.capture-mode .actor-snowy .sprite-frame {
  transform: scale(0.92);
}

body.capture-mode .actor-mirim .sprite-frame {
  transform: scale(1.62);
}

body.capture-mode .actor > span {
  font-size: 15px;
}

@media (max-width: 980px) {
  .story-topbar,
  .story-page {
    width: min(100% - 24px, 1180px);
  }

  .story-topbar,
  .story-page {
    grid-template-columns: 1fr;
  }

  .caption-toggle {
    justify-self: start;
  }

  .phone-frame {
    justify-self: center;
  }
}

@media (max-width: 600px) {
  .story-topbar,
  .story-page {
    width: min(100% - 16px, 1180px);
  }

  .phone-frame {
    padding: 8px;
    border-radius: 24px;
  }

  .story-card {
    border-radius: 18px;
  }

  .actor-louie .sprite-frame {
    transform: scale(0.64);
  }

  .actor-snowy .sprite-frame {
    transform: scale(0.4);
  }

  .actor-mirim .sprite-frame {
    transform: scale(0.9);
  }

  .subtitle-card {
    right: 14px;
    bottom: 14px;
    left: 14px;
  }
}

body.capture-mode .actor-louie .sprite-frame {
  transform: scale(0.92);
}

body.capture-mode .actor-snowy .sprite-frame {
  transform: scale(0.56);
}

body.capture-mode .actor-mirim .sprite-frame {
  transform: scale(1.62);
}

body.capture-mode .actor-snowy > span {
  font-size: 13px;
}
