:root {
  color-scheme: dark;
  --ink: #f4eee4;
  --muted: #b7aa99;
  --dim: #756b60;
  --black: #050403;
  --panel: rgba(18, 14, 12, 0.82);
  --panel-strong: rgba(27, 20, 18, 0.94);
  --line: rgba(244, 238, 228, 0.14);
  --blood: #b41624;
  --blood-hot: #e43c43;
  --ember: #d7a45d;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.52);
  --radius: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100svh;
  background:
    radial-gradient(circle at 16% 8%, rgba(180, 22, 36, 0.2), transparent 28rem),
    linear-gradient(135deg, #050403 0%, #130d0b 44%, #090706 100%);
  color: var(--ink);
  font-family:
    ui-serif,
    "Apple SD Gothic Neo",
    "Malgun Gothic",
    "Noto Serif KR",
    Georgia,
    serif;
  overflow-x: hidden;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  content: "";
  background:
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.012) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: radial-gradient(circle at center, #000, transparent 78%);
}

[hidden] {
  display: none !important;
}

button {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  color: inherit;
  font: inherit;
  background: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: 2px solid var(--blood-hot);
  outline-offset: 3px;
}

img,
video {
  display: block;
  max-width: 100%;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: calc(54px + var(--safe-top));
  padding: var(--safe-top) max(14px, var(--safe-right)) 0 max(14px, var(--safe-left));
  border-bottom: 1px solid rgba(244, 238, 228, 0.1);
  background: rgba(5, 4, 3, 0.84);
  backdrop-filter: blur(16px);
}

.brand,
.header-actions button,
.reader-bar button,
.dialog-actions button,
.ending-panel button,
.rotate-hint button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
}

.brand {
  min-width: 0;
  padding: 0 8px;
}

.brand-mark {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid rgba(228, 60, 67, 0.56);
  border-radius: 50%;
  color: var(--blood-hot);
  font-size: 12px;
  box-shadow: 0 0 18px rgba(180, 22, 36, 0.4);
}

.wordmark {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wordmark small {
  overflow: hidden;
  color: var(--dim);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.08em;
  line-height: 1;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-actions button,
.reader-bar button,
.dialog-actions button,
.ending-panel button,
.rotate-hint button {
  padding: 0 12px;
  border: 1px solid rgba(244, 238, 228, 0.14);
  background: rgba(244, 238, 228, 0.06);
}

.header-actions button:hover,
.reader-bar button:hover,
.dialog-actions button:hover,
.ending-panel button:hover,
.rotate-hint button:hover,
.choice:hover,
.media-thumb:hover,
.clip-choice:hover {
  border-color: rgba(228, 60, 67, 0.58);
  background: rgba(180, 22, 36, 0.16);
}

main#app {
  min-height: calc(100svh - 54px - var(--safe-top));
  padding: 14px max(16px, var(--safe-right)) max(16px, var(--safe-bottom)) max(16px, var(--safe-left));
}

.library {
  display: grid;
  width: min(1180px, 100%);
  min-height: calc(100svh - 84px - var(--safe-top) - var(--safe-bottom));
  margin: 0 auto;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
}

.library-heading {
  max-width: 760px;
}

.eyebrow,
.card-index,
.card-meta,
.save-indicator,
.media-caption,
.choices-title,
.library-footer,
.reader-footer,
.settings-row,
.help-copy {
  color: var(--muted);
  font-family:
    ui-sans-serif,
    "Apple SD Gothic Neo",
    "Malgun Gothic",
    system-ui,
    sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.library-heading h1,
.text-pane h1 {
  margin: 4px 0 0;
  color: var(--ink);
  font-size: clamp(28px, 5.2vw, 62px);
  line-height: 0.95;
  letter-spacing: 0;
}

.library-heading p {
  max-width: 640px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: clamp(14px, 1.7vw, 18px);
  line-height: 1.55;
}

.shelf {
  display: grid;
  min-height: 0;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: minmax(180px, 1fr);
  gap: 10px;
}

.story-card {
  position: relative;
  isolation: isolate;
  display: grid;
  overflow: hidden;
  min-height: 0;
  border: 1px solid rgba(244, 238, 228, 0.12);
  background: #111;
  box-shadow: var(--shadow);
  text-align: left;
}

.story-card img {
  position: absolute;
  inset: 0;
  z-index: -2;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.82) contrast(1.06) brightness(0.78);
  transform: scale(1.01);
}

.card-shade {
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(180deg, rgba(5, 4, 3, 0.04), rgba(5, 4, 3, 0.78) 58%, rgba(5, 4, 3, 0.96)),
    linear-gradient(90deg, rgba(5, 4, 3, 0.68), rgba(5, 4, 3, 0.16));
}

.card-content {
  align-self: end;
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 14px;
}

.card-content h2 {
  margin: 4px 0 0;
  color: var(--ink);
  font-size: clamp(18px, 2.6vw, 30px);
  line-height: 1;
  letter-spacing: 0;
}

.card-content > p {
  display: -webkit-box;
  overflow: hidden;
  margin: 7px 0 0;
  color: rgba(244, 238, 228, 0.82);
  font-size: clamp(12px, 1.35vw, 15px);
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.card-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: rgba(244, 238, 228, 0.72);
  font-family:
    ui-sans-serif,
    "Apple SD Gothic Neo",
    "Malgun Gothic",
    system-ui,
    sans-serif;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
}

.card-bottom > span:first-child {
  min-width: 0;
}

.card-action {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid rgba(228, 60, 67, 0.54);
  border-radius: 999px;
  color: #fff8ef;
  background: rgba(180, 22, 36, 0.34);
  font-family:
    ui-sans-serif,
    "Apple SD Gothic Neo",
    "Malgun Gothic",
    system-ui,
    sans-serif;
  font-size: 12px;
  font-weight: 800;
}

.library-footer,
.reader-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 28px;
  gap: 12px;
  opacity: 0.82;
}

.reader {
  display: grid;
  width: min(1260px, 100%);
  height: calc(100svh - 84px - var(--safe-top) - var(--safe-bottom));
  min-height: 0;
  margin: 0 auto;
  grid-template-rows: minmax(0, 1fr) 28px;
  gap: 8px;
}

.reader-bar {
  display: grid;
  min-height: 0;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
}

.reader-bar button {
  min-height: 44px;
  padding: 0 10px;
}

.scene-label {
  overflow: hidden;
  color: var(--muted);
  font-family:
    ui-sans-serif,
    "Apple SD Gothic Neo",
    "Malgun Gothic",
    system-ui,
    sans-serif;
  font-size: 12px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.save-indicator {
  justify-self: end;
}

.reader-grid {
  display: grid;
  min-height: 0;
  grid-template-columns: minmax(0, var(--video-share, 55fr)) minmax(280px, var(--text-share, 45fr));
  gap: 10px;
}

.media-pane,
.text-pane {
  min-height: 0;
  border: 1px solid rgba(244, 238, 228, 0.12);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.media-pane {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 7px;
  padding: 8px;
}

.screen {
  position: relative;
  display: grid;
  overflow: hidden;
  min-height: 0;
  place-items: center;
  border: 1px solid rgba(244, 238, 228, 0.11);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(244, 238, 228, 0.06), transparent),
    #030303;
}

.screen img,
.screen video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
}

.screen video {
  background: #000;
}

.play-overlay {
  position: absolute;
  inset: auto auto 14px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 1px solid rgba(255, 248, 239, 0.2);
  border-radius: 999px;
  background: rgba(180, 22, 36, 0.92);
  backdrop-filter: blur(12px);
  font-family:
    ui-sans-serif,
    "Apple SD Gothic Neo",
    "Malgun Gothic",
    system-ui,
    sans-serif;
  font-size: 13px;
  font-weight: 800;
}

.play-icon {
  padding-left: 2px;
  font-size: 18px;
  line-height: 1;
  color: #fff;
}

.media-caption {
  overflow: hidden;
  min-height: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.media-strip {
  display: flex;
  min-height: 44px;
  gap: 7px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.media-thumb,
.clip-choice {
  flex: 0 0 auto;
  min-width: 74px;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid rgba(244, 238, 228, 0.12);
  background: rgba(244, 238, 228, 0.05);
  color: rgba(244, 238, 228, 0.84);
  font-family:
    ui-sans-serif,
    "Apple SD Gothic Neo",
    "Malgun Gothic",
    system-ui,
    sans-serif;
  font-size: 12px;
  font-weight: 800;
}

.media-thumb {
  position: relative;
  overflow: hidden;
  width: 74px;
  padding: 0;
}

.media-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.74;
}

.media-thumb span {
  position: absolute;
  right: 6px;
  bottom: 5px;
  display: grid;
  width: 20px;
  height: 20px;
  place-items: center;
  border-radius: 50%;
  background: rgba(5, 4, 3, 0.78);
  color: var(--ink);
}

.media-thumb[aria-current="true"],
.media-thumb[aria-pressed="true"],
.clip-choice[aria-current="true"],
.clip-choice[aria-pressed="true"],
.choice[aria-current="true"] {
  border-color: rgba(228, 60, 67, 0.84);
  background: rgba(180, 22, 36, 0.24);
  color: #fff;
}

.text-pane {
  overflow: auto;
  padding: clamp(14px, 2.2vw, 26px);
  background:
    linear-gradient(180deg, rgba(180, 22, 36, 0.08), transparent 34%),
    var(--panel-strong);
  scrollbar-color: rgba(228, 60, 67, 0.52) rgba(244, 238, 228, 0.08);
}

.text-pane h1 {
  margin-bottom: 14px;
  font-size: clamp(24px, 3.7vw, 46px);
  line-height: 1.02;
}

.prose,
.transition,
.ending-panel {
  color: rgba(244, 238, 228, 0.9);
  font-size: clamp(15px, 1.65vw, 19px);
  line-height: 1.75;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.prose p,
.transition p,
.ending-panel p {
  margin: 0 0 13px;
}

.transition {
  margin: 14px 0;
  padding: 12px 13px;
  border-left: 2px solid var(--blood-hot);
  background: rgba(244, 238, 228, 0.05);
}

.story-intro {
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid rgba(244, 238, 228, 0.1);
  border-radius: var(--radius);
  background: rgba(244, 238, 228, 0.045);
}

.story-intro summary,
.rules-button {
  min-height: 44px;
  color: var(--ember);
  cursor: pointer;
  font-family:
    ui-sans-serif,
    "Apple SD Gothic Neo",
    "Malgun Gothic",
    system-ui,
    sans-serif;
  font-weight: 800;
}

.rules-button {
  margin: 4px 0 14px;
  padding: 0 12px;
  border: 1px solid rgba(215, 164, 93, 0.3);
  background: rgba(215, 164, 93, 0.08);
}

.choices-title {
  margin: 18px 0 9px;
  color: var(--ember);
}

.choices {
  display: grid;
  gap: 8px;
}

.choice {
  display: grid;
  min-height: 52px;
  padding: 8px 10px;
  border: 1px solid rgba(244, 238, 228, 0.14);
  background: transparent;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  text-align: left;
}

.choice-label {
  min-width: 0;
  font-size: clamp(14px, 1.5vw, 17px);
  line-height: 1.38;
}

.ending-panel {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid rgba(215, 164, 93, 0.32);
  border-radius: var(--radius);
  background: rgba(215, 164, 93, 0.08);
}

.ending-panel button {
  margin-top: 8px;
  margin-right: 8px;
  min-height: 44px;
}

.ending-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.ending-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  gap: 12px;
  padding: 9px 10px;
  border: 1px solid rgba(244, 238, 228, 0.12);
  border-radius: var(--radius);
  background: rgba(244, 238, 228, 0.045);
}

.ending-item.discovered {
  border-color: rgba(215, 164, 93, 0.46);
  color: #fff7e8;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(244, 238, 228, 0.09);
}

.help-copy {
  margin-top: 10px;
  letter-spacing: 0;
  text-transform: none;
}

dialog {
  width: min(520px, calc(100vw - 28px));
  max-height: min(720px, calc(100svh - 28px));
  padding: 0;
  border: 1px solid rgba(244, 238, 228, 0.16);
  border-radius: var(--radius);
  color: var(--ink);
  background: #130e0c;
  box-shadow: 0 28px 100px rgba(0, 0, 0, 0.78);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.68);
  backdrop-filter: blur(5px);
}

.dialog-header,
.dialog-body,
.dialog-actions {
  padding: 14px;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(244, 238, 228, 0.1);
}

.dialog-header h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.dialog-body {
  overflow: auto;
  max-height: min(58svh, 460px);
}

.transition-screen {
  display: grid;
  place-content: center;
  justify-items: start;
  min-height: min(66svh, 540px);
  max-width: 680px;
  margin: 0 auto;
  padding: clamp(28px, 7vw, 74px);
}

.transition-copy {
  margin: 4px 0 28px;
  font-size: clamp(20px, 2.4vw, 30px);
  line-height: 1.7;
}

.transition-copy p {
  margin: 0 0 16px;
}

.transition-screen button {
  min-width: 150px;
  padding: 13px 18px;
}

.guide-warning,
.guide-verdict { margin: 0 0 14px; padding: 10px 12px; border: 1px solid rgba(215, 164, 93, 0.36); border-radius: 10px; color: #f0d6a2; background: rgba(215, 164, 93, 0.08); font-size: 13px; line-height: 1.5; }
.guide-list { display: grid; gap: 9px; }
.guide-card, .guide-back { width: 100%; text-align: left; }
.guide-card { display: grid; gap: 4px; padding: 13px; border: 1px solid rgba(244, 238, 228, 0.14); border-radius: 10px; color: var(--ink); background: rgba(255, 255, 255, 0.035); }
.guide-card:hover { border-color: rgba(215, 164, 93, 0.56); background: rgba(215, 164, 93, 0.1); }
.guide-card-meta, .guide-card small { color: var(--muted); font-size: 12px; line-height: 1.4; }
.guide-card strong { font-size: 16px; }
.guide-back { margin-bottom: 12px; color: #f0d6a2; background: transparent; }
.guide-section { margin: 0 0 22px; }
.guide-section h3, .guide-section h4 { margin: 0 0 8px; }
.guide-section p, .guide-section li { color: var(--muted); line-height: 1.62; }
.guide-section ul { margin: 0; padding-left: 20px; }
.guide-endings { display: grid; gap: 8px; }
.guide-endings article { padding: 10px 12px; border-left: 2px solid rgba(215, 164, 93, 0.55); background: rgba(255, 255, 255, 0.035); }
.guide-endings p { margin: 0; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid rgba(244, 238, 228, 0.1);
}

.rotate-hint {
  display: none;
  margin: 0 0 10px;
  padding: 12px;
  border: 1px solid rgba(215, 164, 93, 0.3);
  border-radius: var(--radius);
  background: rgba(215, 164, 93, 0.08);
}

.rotate-hint .icon,
.rotate-hint h2,
.rotate-hint p {
  margin: 0 0 7px;
}

.rotate-hint h2 {
  font-size: 17px;
  line-height: 1.25;
}

.rotate-hint p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

body.large-text .prose,
body.large-text .transition,
body.large-text .ending-panel {
  font-size: clamp(17px, 2vw, 22px);
  line-height: 1.78;
}

.toast {
  position: fixed;
  right: max(14px, var(--safe-right));
  bottom: max(14px, var(--safe-bottom));
  z-index: 40;
  max-width: min(360px, calc(100vw - 28px));
  padding: 11px 13px;
  border: 1px solid rgba(244, 238, 228, 0.14);
  border-radius: var(--radius);
  color: var(--ink);
  background: rgba(16, 11, 10, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  font-family:
    ui-sans-serif,
    "Apple SD Gothic Neo",
    "Malgun Gothic",
    system-ui,
    sans-serif;
  font-size: 13px;
}

@media (orientation: landscape) and (max-height: 520px) {
  body.reading {
    overflow: hidden;
  }

  .app-header {
    min-height: calc(44px + var(--safe-top));
    padding-left: calc(var(--safe-left) + 26px);
    padding-right: calc(var(--safe-right) + 26px);
    border-bottom: 0;
    box-shadow: inset 0 -1px 0 rgba(244, 238, 228, 0.1);
  }

  .wordmark {
    font-size: 13px;
  }

  .header-actions button {
    min-height: 44px;
    padding: 0 9px;
    font-size: 12px;
  }

  main#app {
    height: calc(100svh - 44px - var(--safe-top));
    min-height: 0;
    padding-top: 6px;
    padding-bottom: max(6px, var(--safe-bottom));
  }

  body:not(.reading) main#app {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
  }

  body.reading main#app {
    overflow: hidden;
    padding-left: 6px;
    padding-right: 6px;
  }

  .reader .play-overlay {
    left: max(14px, calc(var(--safe-left) - 6px));
  }

  .reader .media-caption,
  .reader .media-strip {
    padding-left: max(0px, calc(var(--safe-left) - 12px));
  }

  .reader .text-pane {
    padding-right: max(12px, calc(var(--safe-right) - 6px));
  }

  .reader-footer {
    padding-left: max(8px, calc(var(--safe-left) - 6px));
    padding-right: max(8px, calc(var(--safe-right) - 6px));
  }

  .library {
    min-height: calc(100svh - 60px - var(--safe-top) - var(--safe-bottom));
    gap: 8px;
  }

  .library-heading h1 {
    font-size: clamp(24px, 4.8vw, 40px);
  }

  .library-heading p {
    display: -webkit-box;
    overflow: hidden;
    margin-top: 6px;
    font-size: 13px;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .shelf {
    gap: 8px;
  }

  .card-content {
    padding: 10px;
    gap: 5px;
  }

  .card-content h2 {
    font-size: clamp(17px, 2.7vw, 24px);
  }

  .card-content > p {
    font-size: 12px;
    line-height: 1.35;
    -webkit-line-clamp: 2;
  }

  .card-action {
    min-height: 28px;
    font-size: 11px;
  }

  .library-footer,
  .reader-footer {
    min-height: 22px;
    font-size: 10px;
  }

  .reader {
    height: 100%;
    grid-template-rows: minmax(0, 1fr) 22px;
    gap: 6px;
  }

  .reader-bar {
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    gap: 7px;
  }

  .reader-bar button {
    min-height: 44px;
  }

  .reader-grid {
    grid-template-columns: minmax(0, var(--video-share, 55fr)) minmax(252px, var(--text-share, 45fr));
    gap: 8px;
  }

  .media-pane {
    grid-template-rows: minmax(0, 1fr) 14px 44px;
    gap: 5px;
    padding: 6px;
  }

  .text-pane {
    padding: 12px;
  }

  .text-pane h1 {
    margin-bottom: 8px;
    font-size: clamp(22px, 3.5vw, 34px);
  }

  .prose,
  .transition,
  .ending-panel {
    font-size: clamp(14px, 1.7vw, 16px);
    line-height: 1.58;
  }

  .prose p,
  .transition p,
  .ending-panel p {
    margin-bottom: 9px;
  }

  .transition,
  .ending-panel {
    padding: 9px 10px;
  }

  .choices-title {
    margin: 12px 0 7px;
  }

  .choice {
    min-height: 46px;
    padding: 6px 9px;
  }
}

@media (orientation: portrait), (max-width: 720px) and (min-height: 520px) {
  main#app {
    padding-top: 12px;
  }

  .rotate-hint:not([hidden]) {
    display: block;
  }

  .library {
    min-height: auto;
    grid-template-rows: auto auto auto;
  }

  .shelf {
    grid-template-columns: 1fr;
  }

  .story-card {
    min-height: 210px;
  }

  .reader {
    height: auto;
    min-height: calc(100svh - 78px - var(--safe-top) - var(--safe-bottom));
    grid-template-rows: auto auto;
  }

  .reader-bar {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .save-indicator {
    grid-column: 1 / -1;
    justify-self: start;
  }

  .reader-grid {
    grid-template-columns: 1fr;
  }

  .media-pane {
    min-height: min(var(--portrait-video-height, 64svh), 430px);
  }

  .screen {
    aspect-ratio: 16 / 9;
  }

  .text-pane {
    overflow: visible;
  }
}

@media (min-width: 900px) and (min-height: 620px) {
  main#app {
    padding-top: 20px;
  }

  .library {
    gap: 18px;
  }

  .shelf {
    gap: 16px;
  }

  .reader {
    gap: 12px;
    height: calc(100svh - 90px - var(--safe-top) - var(--safe-bottom));
  }

  .reader-grid {
    gap: 14px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .story-card,
  .choice,
  .media-thumb,
  .clip-choice,
  .header-actions button,
  .reader-bar button,
  .dialog-actions button,
  .ending-panel button,
  .rotate-hint button {
    transition:
      transform 160ms ease,
      border-color 160ms ease,
      background-color 160ms ease,
      filter 160ms ease;
  }

  .story-card:hover {
    transform: translateY(-2px);
  }

  .story-card:hover img {
    filter: saturate(0.9) contrast(1.12) brightness(0.9);
  }

  .choice:hover,
  .media-thumb:hover,
  .clip-choice:hover,
  .header-actions button:hover,
  .reader-bar button:hover,
  .dialog-actions button:hover,
  .ending-panel button:hover,
  .rotate-hint button:hover {
    transform: translateY(-1px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* Keep all five tools visible in the single header row. */
.header-actions {
  gap: 6px;
  flex-shrink: 0;
}

.header-actions button {
  width: 44px;
  padding: 0;
  background: transparent;
}

.header-actions svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.header-actions button:disabled {
  opacity: 0.3;
  cursor: default;
  transform: none;
  background: transparent;
  border-color: var(--line);
}

.choice:active,
.choice:focus-visible,
.header-actions button:enabled:active {
  color: #fff;
  border-color: var(--blood-hot);
  background: rgba(180, 22, 36, 0.2);
}

/* Give single-clip scenes the height previously reserved for empty thumbnails. */
.media-pane:has(.media-strip:empty),
.media-pane:has(video:not([hidden])) {
  grid-template-rows: minmax(0, 1fr) auto;
}

.media-strip:empty,
.media-pane:has(video:not([hidden])) .media-strip {
  display: none;
}

/* Reader preferences apply immediately without restarting the story. */
.prose, .transition, .ending-panel, .choice-label {
  font-size: var(--reader-font-size, 16px);
  line-height: var(--reader-line-height, 1.65);
}

.text-pane h1 {
  font-size: calc(var(--reader-font-size, 16px) * 1.75);
}

.layout-settings {
  display: grid;
  gap: 12px;
}

.layout-settings fieldset {
  margin: 0;
  padding: 0;
  min-width: 0;
  border: 0;
}

.layout-settings legend {
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 700;
}

.setting-segments {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.language-segments {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

@media (max-width: 640px) {
  .language-segments {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.setting-segments button {
  min-height: 44px;
  border: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
}

.setting-segments button[aria-pressed="true"] {
  border-color: var(--blood-hot);
  background: rgba(180, 22, 36, 0.25);
  color: #fff;
}

.dialog-body:has(.layout-settings) {
  max-height: min(580px, calc(100svh - 120px));
}
