:root {
  color-scheme: light;
  --bg: #f6efe3;
  --surface: #fffdfa;
  --surface-soft: #edf6f2;
  --paper: #fff7e8;
  --paper-deep: #f1dfbd;
  --ink: #1d2928;
  --book-ink: #3b2c20;
  --muted: #64706d;
  --line: #ddd4c5;
  --line-strong: #c5b8a5;
  --accent: #25776f;
  --accent-dark: #1b5f59;
  --coral: #b95d45;
  --gold: #b9852c;
  --violet: #6a5fc3;
  --shadow: 0 22px 58px rgba(54, 43, 29, 0.14);
  --shadow-soft: 0 12px 30px rgba(54, 43, 29, 0.08);
  --ui-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif;
  --book-title-font: "Songti SC", "STSong", "Noto Serif SC", serif;
  --book-body-font: "Kaiti SC", "STKaiti", "LXGW WenKai", "Noto Serif SC", serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    repeating-linear-gradient(0deg, rgba(88, 68, 38, 0.035) 0 1px, transparent 1px 7px),
    linear-gradient(135deg, rgba(237, 246, 242, 0.88), rgba(255, 247, 232, 0.72) 46%, rgba(239, 246, 241, 0.95)),
    var(--bg);
  color: var(--ink);
  font-family: var(--ui-font);
  letter-spacing: 0;
}

body.image-expanded {
  overflow: hidden;
}

body.control-panel-open {
  position: fixed;
  right: 0;
  left: 0;
  overflow: hidden;
}

button,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-weight: 760;
  transition: border-color 160ms ease, box-shadow 160ms ease, color 160ms ease, transform 160ms ease, background 160ms ease;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
  box-shadow: 0 8px 20px rgba(15, 118, 110, 0.14);
  color: var(--accent);
  transform: translateY(-1px);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

textarea:disabled {
  cursor: not-allowed;
  background: #f4f1ea;
  color: var(--muted);
  opacity: 0.72;
}

button:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.24);
  outline-offset: 3px;
}

textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 12px;
  background: #fffdf8;
  color: var(--ink);
  line-height: 1.62;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #fffdf8;
  color: var(--ink);
  font-weight: 700;
}

textarea:focus {
  border-color: var(--accent);
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.08);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(32px, 5vw, 58px);
  line-height: 1.02;
  max-width: 760px;
}

h2 {
  font-size: 20px;
  line-height: 1.2;
}

h3 {
  font-size: 17px;
  line-height: 1.28;
}

.shell {
  width: min(1220px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 32px;
}

.topbar,
.section-heading,
.reading-header,
.branch-actions,
.custom-toolbar,
.sort-tabs {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  margin: 0 -8px 18px;
  padding: 10px 8px;
  background: rgba(245, 248, 247, 0.82);
  backdrop-filter: blur(14px);
}

.topbar-right,
.auth-controls,
.credit-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0;
  color: var(--ink);
  text-decoration: none;
}

.brand-logo {
  display: block;
  width: 256px;
  height: auto;
}

.status {
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 80;
  min-height: 26px;
  max-width: min(calc(100vw - 32px), 520px);
  overflow: hidden;
  border: 1px solid rgba(15, 118, 110, 0.2);
  border-radius: 999px;
  padding: 8px 14px;
  background: rgba(29, 41, 40, 0.92);
  box-shadow: var(--shadow-soft);
  color: #ffffff;
  font-size: 13px;
  font-weight: 760;
  pointer-events: none;
  text-align: center;
  text-overflow: ellipsis;
  transform: translateX(-50%);
  white-space: nowrap;
  animation: tipIn 160ms ease;
}

.status.error {
  border-color: rgba(194, 87, 61, 0.34);
  background: rgba(167, 66, 43, 0.94);
  color: #ffffff;
}

@keyframes tipIn {
  from {
    opacity: 0;
    transform: translate(-50%, -8px);
  }

  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

.auth-controls button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.auth-controls .topbar-icon-button {
  display: grid;
  width: 40px;
  min-width: 40px;
  min-height: 40px;
  border: 0;
  background: transparent;
  box-shadow: none;
  place-items: center;
  padding: 0;
}

.auth-controls .topbar-icon-button:hover:not(:disabled) {
  background: transparent;
  box-shadow: none;
}

.topbar-icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.credit-badge {
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
  white-space: nowrap;
}

.mobile-credit-badge {
  display: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  white-space: nowrap;
}

.home-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 22px;
  align-items: end;
  min-height: 168px;
  padding: 28px 0 24px;
}

.home-hero h1 {
  margin-top: 8px;
}

.story-filters {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  max-width: 520px;
}

.story-filters button {
  min-height: 38px;
  border-radius: 999px;
  padding: 0 14px;
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
}

.story-filters button.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.section-heading {
  margin: 0 0 14px;
}

.section-heading.compact {
  margin-top: 34px;
}

#myBranchesSection {
  scroll-margin-top: 76px;
}

.my-branches-anchor {
  display: none;
}

.my-branches-anchor::after {
  content: "↓";
  font-size: 12px;
}

.section-heading p,
.node-text,
.branch-text {
  color: var(--muted);
  line-height: 1.7;
}

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

.story-card,
.branch-item,
.story-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.story-card {
  display: grid;
  overflow: hidden;
  min-height: 430px;
  transition: border-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.story-card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
  transform: translateY(-3px);
}

.story-cover,
.branch-thumb {
  position: relative;
  overflow: hidden;
  background: var(--surface-soft);
}

.story-cover {
  min-height: 228px;
}

.story-cover img,
.branch-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.story-cover.has-image::after {
  position: absolute;
  inset: auto 0 0;
  height: 48%;
  background: linear-gradient(180deg, transparent, rgba(7, 19, 22, 0.72));
  content: "";
}

.story-card-body {
  display: grid;
  gap: 12px;
  align-content: start;
  padding: 16px;
}

.story-card h2 {
  font-size: 21px;
}

html[lang="en"] .story-summary {
  display: -webkit-box;
  height: 6.8em;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  line-clamp: 4;
}

.story-card button {
  margin-top: 2px;
}

.story-create-opening-button {
  grid-column: 1 / -1;
  justify-self: center;
  min-width: min(100%, 220px);
  padding: 0 18px;
}

.story-stats,
.branch-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.story-stats span,
.branch-stats span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  background: #fbfdfc;
}

.branch-stats .is-ending {
  border-color: rgba(15, 118, 110, 0.32);
  color: #0f766e;
  background: rgba(204, 251, 241, 0.68);
}

.branch-stats .is-open {
  border-color: rgba(107, 114, 128, 0.28);
  color: #4b5563;
  background: rgba(249, 250, 251, 0.86);
}

.branch-stats .is-public {
  border-color: rgba(22, 101, 52, 0.28);
  color: #166534;
  background: rgba(220, 252, 231, 0.78);
}

.branch-stats .is-private {
  border-color: rgba(180, 83, 9, 0.3);
  color: #92400e;
  background: rgba(254, 243, 199, 0.78);
}

.cover-placeholder {
  display: grid;
  height: 100%;
  min-height: 228px;
  place-items: end start;
  padding: 16px;
  color: #ffffff;
  background:
    linear-gradient(140deg, rgba(15, 118, 110, 0.86), rgba(105, 87, 200, 0.78)),
    var(--surface-soft);
  font-weight: 800;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.tag,
.eyebrow,
.panel-label,
.custom-count {
  color: var(--muted);
  font-size: 13px;
}

.tag {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  background: #fbfdfc;
  font-weight: 720;
}

.eyebrow,
.panel-label {
  font-weight: 800;
  text-transform: uppercase;
}

.panel-label {
  margin-bottom: -4px;
}

.branch-list {
  display: grid;
  gap: 10px;
}

.branch-item {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr) 148px;
  gap: 14px;
  align-items: center;
  padding: 10px;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.branch-item:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-soft);
  transform: translateY(-1px);
}

.branch-thumb {
  aspect-ratio: 1;
  border-radius: 7px;
}

.branch-thumb.placeholder {
  display: grid;
  place-items: center;
  color: var(--accent);
  font-weight: 850;
}

.branch-item h3 {
  margin: 4px 0 6px;
}

.branch-item .branch-text {
  display: -webkit-box;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.branch-title {
  margin-bottom: 5px;
  color: var(--book-ink);
  font-size: 14px;
  font-weight: 780;
}

.branch-stats {
  margin-top: 8px;
}

.branch-empty {
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  padding: 18px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.68);
}

.public-load-more {
  display: block;
  width: min(100%, 260px);
  margin: 14px auto 0;
}

.node-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 420px);
  gap: 22px;
  align-items: start;
}

.storybook-page {
  position: relative;
  display: grid;
  gap: 16px;
  overflow: hidden;
  border: 1px solid rgba(197, 184, 165, 0.78);
  border-radius: 8px;
  padding: 20px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.68), rgba(255, 247, 232, 0.68)),
    repeating-linear-gradient(90deg, rgba(88, 68, 38, 0.035) 0 1px, transparent 1px 10px),
    var(--paper);
  box-shadow: var(--shadow);
}

.storybook-page::after {
  position: absolute;
  inset: 10px;
  /* border: 1px solid rgba(185, 133, 44, 0.16); */
  /* border-radius: 6px; */
  content: "";
  pointer-events: none;
}

.storybook-page > * {
  position: relative;
  z-index: 1;
}

.visual-panel {
  overflow: hidden;
  border: 1px solid rgba(98, 75, 42, 0.2);
  border-radius: 8px;
  /* padding: 10px; */
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.92), rgba(242, 223, 189, 0.46)),
    var(--paper-deep);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.64);
}

.visual-panel.is-expanded {
  position: fixed;
  inset: 0;
  z-index: 50;
  border: 0;
  border-radius: 0;
  /* padding: min(5vw, 44px); */
  background: rgba(16, 24, 27, 0.92);
  box-shadow: none;
}

.image-box {
  display: grid;
  aspect-ratio: 4 / 3;
  min-height: 0;
  overflow: hidden;
  place-items: center;
  border-radius: 6px;
  background:
    linear-gradient(145deg, rgba(37, 119, 111, 0.16), rgba(185, 133, 44, 0.14)),
    #e8eee9;
}

.image-box.has-image {
  cursor: zoom-in;
}

.image-box.is-expanded {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  border-radius: 0;
  background: transparent;
  cursor: zoom-out;
}

.image-box img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-box.is-expanded img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.image-expand-close {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 52;
  display: grid;
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  place-items: center;
  border: 0;
  border-radius: 999px;
  padding: 0;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
  color: var(--ink);
}

.image-expand-close:hover:not(:disabled) {
  background: #ffffff;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.2);
  transform: none;
}

.image-expand-close svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.image-placeholder {
  width: min(560px, 82%);
  color: #526066;
  line-height: 1.7;
  text-align: center;
  white-space: pre-wrap;
}

.image-state {
  display: grid;
  width: min(520px, 82%);
  justify-items: center;
  gap: 12px;
  color: #526066;
  line-height: 1.7;
  text-align: center;
}

.image-state.error {
  color: #8f3d28;
}

.image-state-title {
  color: var(--ink);
  font-size: 18px;
  font-weight: 820;
}

.image-state-text {
  white-space: pre-wrap;
}

.image-state button {
  min-width: 128px;
  padding: 0 18px;
}

.image-spinner {
  width: 42px;
  height: 42px;
  border: 4px solid rgba(15, 118, 110, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: imageSpin 900ms linear infinite;
}

@keyframes imageSpin {
  to {
    transform: rotate(360deg);
  }
}

.story-panel {
  position: sticky;
  top: 76px;
  display: grid;
  gap: 16px;
  max-height: calc(100vh - 92px);
  overflow-y: auto;
  padding: 18px;
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.96), rgba(244, 249, 246, 0.98)),
    var(--surface);
}

.story-panel-body {
  display: grid;
  gap: 16px;
}

.control-panel-close {
  display: none;
  width: 40px;
  min-width: 40px;
  min-height: 40px;
  place-items: center;
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 0;
}

.control-panel-close:hover:not(:disabled) {
  background: transparent;
  box-shadow: none;
  transform: none;
}

.control-panel-close svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

#controlPanelToggle {
  display: none;
}

.story-copy {
  display: grid;
  gap: 12px;
  padding: 2px 8px 4px;
}

.reading-header {
  min-width: 0;
  align-items: flex-end;
}

.reading-tools {
  display: grid;
  flex: 0 1 auto;
  justify-items: end;
  min-width: 0;
  gap: 6px;
}

.branch-actions {
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.reading-title-block {
  display: grid;
  flex: 1 1 auto;
  min-width: 0;
  gap: 8px;
}

.reading-title-block h1 {
  max-width: none;
  color: var(--book-ink);
  font-family: var(--book-title-font);
  font-size: clamp(32px, 3.2vw, 44px);
  font-weight: 760;
  line-height: 1.16;
}

html[lang="en"] .reading-title-block h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(31px, 3vw, 42px);
}

.reading-meta {
  max-width: 420px;
  min-width: 0;
  text-align: right;
}

.reading-header button,
.story-filters button,
.sort-tabs button {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 14px;
  font-size: 14px;
}

.branch-actions .icon-button {
  display: grid;
  width: 40px;
  min-width: 40px;
  height: 40px;
  min-height: 40px;
  border: 0;
  background: transparent;
  box-shadow: none;
  place-items: center;
  padding: 0;
}

.branch-actions .icon-button:hover:not(:disabled) {
  background: transparent;
  box-shadow: none;
}

.branch-actions .icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.branch-actions .icon-button svg.octicon {
  width: 20px;
  height: 20px;
  fill: currentColor;
  stroke: none;
}

#branchDeleteButton svg {
  width: 20px;
  height: 20px;
}

.sort-tabs {
  justify-content: flex-end;
  gap: 8px;
}

.sort-tabs button.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.node-text {
  color: var(--book-ink);
  font-family: var(--book-body-font);
  font-size: clamp(21px, 2.2vw, 26px);
  line-height: 1.82;
  min-height: 8.2em;
}

html[lang="en"] .node-text {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(18px, 1.7vw, 22px);
  line-height: 1.74;
}

.ending-box {
  border-left: 4px solid var(--coral);
  border-radius: 0 8px 8px 0;
  padding: 10px 12px;
  background: #fff3ef;
  color: #8f3d28;
  font-weight: 780;
}

.image-tool-panel,
.decision-area {
  display: grid;
  gap: 12px;
}

.image-tool-panel {
  border-top: 1px solid rgba(15, 118, 110, 0.16);
  padding-top: 14px;
}

.image-tool-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.image-tool-controls {
  display: grid;
  gap: 10px;
}

.image-mode-group,
.image-tool-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.image-mode-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.image-mode-option {
  display: flex;
  align-items: center;
  min-height: 38px;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  background: #fffdf8;
  color: var(--ink);
  font-size: 13px;
  font-weight: 780;
  cursor: pointer;
}

.image-mode-option:has(input:checked) {
  border-color: rgba(37, 119, 111, 0.52);
  background: rgba(237, 246, 242, 0.98);
  color: var(--accent);
}

.image-mode-option:has(input:disabled) {
  cursor: not-allowed;
  opacity: 0.58;
}

.image-mode-option input {
  accent-color: var(--accent);
}

.image-mode-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.image-version-label {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
}

.image-version-label select {
  display: block;
  height: 38px;
  min-height: 38px;
  width: 100%;
}

.image-tool-actions button {
  flex: 0 0 auto;
  height: 38px;
  min-height: 38px;
  padding: 0 13px;
  white-space: nowrap;
}

.image-tool-actions .image-version-label[hidden] + button {
  flex: 1 1 auto;
}

.image-tool-actions button.is-loading {
  border-color: var(--accent);
  color: var(--accent);
}

.next-step-gate {
  display: grid;
  gap: 10px;
}

.next-step-gate button {
  width: 100%;
}

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

.next-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.next-heading-title {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}

.next-heading-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.next-heading button {
  min-height: 34px;
  padding: 0 11px;
  font-size: 13px;
}

.next-heading .icon-button {
  display: grid;
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  place-items: center;
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 0;
  font-size: 19px;
  line-height: 1;
}

.next-heading .icon-button:hover:not(:disabled) {
  background: transparent;
  box-shadow: none;
  transform: none;
}

.choice-button {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 11px;
  align-items: center;
  min-height: 64px;
  padding: 11px 12px;
  text-align: left;
}

.choice-button:hover:not(:disabled) .choice-label {
  background: var(--accent);
  color: #ffffff;
}

.choice-button.is-route-selected {
  border-color: rgba(105, 87, 200, 0.42);
  background: #f8f6ff;
}

.choice-button.is-route-selected .choice-label {
  border-color: var(--violet);
  background: var(--violet);
  color: #ffffff;
}

.choice-label {
  display: grid;
  min-width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid rgba(15, 118, 110, 0.28);
  border-radius: 999px;
  padding: 0 8px;
  color: var(--accent);
  font-weight: 850;
  transition: background 160ms ease, color 160ms ease;
}

.choice-text {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.choice-main {
  overflow-wrap: anywhere;
}

.choice-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.choice-ending,
.choice-cached,
.choice-selected {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 1px 7px;
}

.choice-selected {
  background: #ebe7ff;
  color: var(--violet);
}

.choice-ending {
  background: #fff3ef;
  color: var(--coral);
}

.choice-cached {
  background: #f7f0db;
  color: #8a6115;
}

.custom-box {
  display: grid;
  gap: 6px;
  /* border: 1px solid rgba(15, 118, 110, 0.2); */
  border-radius: 8px;
  /* padding: 12px; */
  background:
    linear-gradient(180deg, rgba(240, 246, 243, 0.8), rgba(255, 255, 255, 0.92)),
    var(--surface);
}

.custom-box textarea {
  min-height: 60px;
}

.custom-toolbar {
  min-height: 28px;
  flex-wrap: wrap;
  gap: 10px;
}

.ending-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 760;
}

.ending-toggle.is-disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.ending-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.custom-count {
  margin-left: auto;
  white-space: nowrap;
}

.custom-toolbar #customNextButton {
  flex: 0 0 auto;
  /* min-width: 132px; */
  padding: 0 16px;
}

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.primary:hover:not(:disabled) {
  background: var(--accent-dark);
  color: #ffffff;
}

.confirm-dialog,
.login-dialog,
.settings-dialog {
  width: min(440px, calc(100% - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.confirm-dialog::backdrop,
.login-dialog::backdrop,
.settings-dialog::backdrop {
  background: rgba(21, 32, 35, 0.38);
  backdrop-filter: blur(3px);
}

.confirm-dialog form,
.login-dialog form,
.settings-dialog form {
  display: grid;
  gap: 0;
}

.login-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding: 18px 18px 14px;
}

.login-body {
  display: grid;
  gap: 10px;
  padding: 16px 18px 18px;
}

.dialog-icon-button {
  display: grid;
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  place-items: center;
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 0;
}

.dialog-icon-button:hover:not(:disabled) {
  background: transparent;
  box-shadow: none;
}

.dialog-icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.login-method-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 46px;
}

.login-provider-icon {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
}

.login-divider {
  height: 1px;
  margin-top: 4px;
  background: var(--line);
}

.login-more-hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
}

.login-dialog-hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  text-align: center;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  padding: 18px 18px 14px;
}

.settings-icon-button {
  display: grid;
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  place-items: center;
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 0;
}

.settings-icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.settings-body {
  display: grid;
  gap: 14px;
  padding: 16px 18px 18px;
}

.settings-summary {
  display: grid;
  gap: 0;
  overflow: hidden;
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: 8px;
  background: var(--surface-soft);
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 46px;
  border-bottom: 1px solid rgba(15, 118, 110, 0.14);
  padding: 0 14px;
  color: var(--muted);
  font-size: 14px;
}

.settings-row:last-child {
  border-bottom: 0;
}

.settings-row strong {
  color: var(--ink);
  font-size: 16px;
  white-space: nowrap;
}

.settings-user-name {
  display: block;
  max-width: min(56vw, 240px);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.settings-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}

.settings-actions button {
  min-height: 42px;
  padding: 0 16px;
}

.settings-prompt {
  border: 1px solid rgba(185, 133, 44, 0.32);
  border-radius: 8px;
  padding: 12px 14px;
  background: rgba(185, 133, 44, 0.1);
  color: var(--book-ink);
  font-size: 14px;
  line-height: 1.55;
}

.confirm-body {
  display: grid;
  gap: 10px;
  padding: 18px;
}

.confirm-title {
  font-size: 20px;
  font-weight: 850;
}

.confirm-text {
  color: var(--muted);
  line-height: 1.65;
}

.confirm-choice {
  max-height: none;
  overflow-y: visible;
  border: 1px solid rgba(15, 118, 110, 0.2);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface-soft);
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.publishing-name-options {
  display: grid;
  gap: 8px;
}

.publishing-option-groups {
  display: grid;
  gap: 14px;
}

.publishing-option-label {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.publishing-cover-select {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(15, 118, 110, 0.24);
  border-radius: 8px;
  padding: 0 10px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

.publishing-cover-select:focus {
  outline: 2px solid rgba(15, 118, 110, 0.24);
  outline-offset: 2px;
}

.publishing-name-option {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 14px;
}

.confirm-prompt-input {
  width: 100%;
  min-height: 132px;
  resize: vertical;
  border: 1px solid rgba(15, 118, 110, 0.28);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface-soft);
  color: var(--ink);
  font: inherit;
  line-height: 1.7;
}

.confirm-prompt-input:focus {
  outline: 2px solid rgba(15, 118, 110, 0.24);
  outline-offset: 2px;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding: 12px 18px 16px;
}

.confirm-actions button {
  min-width: 96px;
  padding: 0 16px;
}

.page-nav-row {
  display: flex;
  justify-self: end;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  max-width: 100%;
}

.page-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  max-width: 100%;
  border: 1px solid rgba(98, 75, 42, 0.18);
  border-radius: 8px;
  padding: 6px;
  background: rgba(255, 253, 248, 0.88);
  box-shadow: var(--shadow-soft);
}

.page-nav-button {
  display: grid;
  width: 36px;
  min-width: 36px;
  height: 36px;
  min-height: 36px;
  place-items: center;
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 0;
}

.page-nav-button:hover:not(:disabled) {
  background: transparent;
  box-shadow: none;
}

.page-nav-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.page-indicator {
  min-width: 96px;
  color: var(--book-ink);
  font-size: 14px;
  font-weight: 820;
  text-align: center;
  white-space: nowrap;
}

.side-fork-button {
  width: 100%;
}

.branch-readonly-hint {
  border-top: 1px solid rgba(15, 118, 110, 0.16);
  padding-top: 2px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.is-busy .choice-button,
.is-busy #customNextButton {
  position: relative;
  overflow: hidden;
}

.is-busy .choice-button::after,
.is-busy #customNextButton::after {
  position: absolute;
  inset: auto 12px 8px;
  height: 2px;
  overflow: hidden;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 220% 100%;
  content: "";
  animation: loadingBar 900ms linear infinite;
}

@keyframes loadingBar {
  from {
    background-position: 120% 0;
  }

  to {
    background-position: -120% 0;
  }
}

@media (max-width: 960px) {
  .home-hero,
  .story-grid,
  .node-layout {
    grid-template-columns: 1fr;
  }

  .story-filters {
    width: min(100%, 420px);
  }

  .storybook-page {
    touch-action: pan-y pinch-zoom;
  }

  .topbar {
    transition: opacity 160ms ease, transform 180ms ease;
    will-change: transform;
  }

  body.mobile-topbar-hidden .topbar {
    opacity: 0;
    pointer-events: none;
    transform: translateY(calc(-100% - 12px));
  }

  .story-panel {
    position: fixed;
    top: auto;
    right: 16px;
    bottom: 0;
    left: 16px;
    z-index: 45;
    display: none;
    max-height: min(72vh, 560px);
    overflow-y: auto;
    padding: 14px;
    border-color: rgba(37, 119, 111, 0.24);
    box-shadow: 0 18px 46px rgba(54, 43, 29, 0.2);
  }

  .story-panel.is-open {
    display: grid;
  }

  .story-panel-body {
    max-height: none;
    overflow: visible;
    padding: 0;
  }

  .control-panel-close {
    display: grid;
  }

  #controlPanelToggle {
    display: inline-grid;
    flex: 0 0 auto;
    width: 48px;
    min-width: 48px;
    height: 48px;
    min-height: 48px;
    place-items: center;
    border: 0;
    border-radius: 14px;
    background: var(--accent);
    box-shadow: 0 10px 20px rgba(15, 118, 110, 0.26);
    padding: 0;
    color: #ffffff;
    line-height: 0;
  }

  #controlPanelToggle:hover:not(:disabled) {
    background: var(--accent-dark);
    box-shadow: 0 12px 22px rgba(15, 118, 110, 0.3);
    color: #ffffff;
    transform: translateY(-1px);
  }

  #controlPanelToggle.is-active {
    background: var(--accent-dark);
    box-shadow: 0 8px 18px rgba(15, 118, 110, 0.24);
    color: #ffffff;
    transform: none;
  }

  #controlPanelToggle svg {
    display: block;
    width: 42px;
    height: 42px;
  }

  body.image-expanded .story-panel {
    display: none;
  }

  .image-box {
    aspect-ratio: 4 / 3;
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(100% - 24px, 1220px);
    padding-bottom: 22px;
  }

  .topbar,
  .section-heading,
  .reading-header,
  .branch-item {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-right {
    align-items: flex-start;
    flex-direction: column;
  }

  .credit-controls,
  .auth-controls {
    width: 100%;
    justify-content: space-between;
  }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 4px 8px;
    margin: 0 -4px 12px;
    padding: 6px 4px;
  }

  .topbar-right,
  .auth-controls {
    display: contents;
  }

  .brand {
    min-width: 0;
  }

  .brand-logo {
    width: 136px;
  }

  .credit-controls {
    display: none;
  }

  .auth-controls button {
    min-height: 44px;
  }

  .auth-controls .topbar-icon-button {
    width: 44px;
    min-width: 44px;
    min-height: 44px;
  }

  .credit-badge {
    font-size: 12px;
  }

  .mobile-credit-badge {
    display: inline;
  }

  #loginButton,
  #settingsButton {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
  }

  .home-hero {
    min-height: 0;
    padding-top: 14px;
  }

  .home-hero h1 {
    font-size: 30px;
  }

  .my-branches-anchor {
    display: flex;
    align-items: center;
    gap: 7px;
    justify-content: center;
    width: fit-content;
    min-height: 44px;
    margin: -4px 0 14px auto;
    border-radius: 999px;
    padding: 0 13px;
    background: rgba(37, 119, 111, 0.11);
    color: var(--accent-dark);
    font-size: 14px;
    font-weight: 800;
    text-decoration: none;
  }

  .story-filters {
    min-width: 0;
    justify-content: flex-start;
  }

  .story-filters button,
  .sort-tabs button,
  .branch-actions .icon-button {
    min-height: 44px;
  }

  .branch-actions .icon-button {
    width: 44px;
    min-width: 44px;
    height: 44px;
  }

  .story-card {
    min-height: 0;
  }

  .story-card .story-summary,
  html[lang="en"] .story-card .story-summary {
    display: block;
    height: auto;
    overflow: visible;
    -webkit-line-clamp: unset;
    line-clamp: unset;
  }

  .branch-item {
    display: flex;
  }

  .branch-thumb {
    width: 100%;
    aspect-ratio: 16 / 9;
  }

  .storybook-page {
    padding: 10px;
  }

  .story-copy {
    padding-inline: 2px;
  }

  .reading-title-block h1 {
    font-size: 26px;
  }

  .reading-header button {
    align-self: flex-start;
  }

  .branch-actions,
  .sort-tabs {
    justify-content: flex-end;
    width: 100%;
  }

  .reading-tools {
    justify-items: start;
    width: 100%;
  }

  .reading-meta {
    max-width: 100%;
    text-align: left;
  }

  .page-nav-row {
    justify-self: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
  }

  .page-nav {
    gap: 4px;
    justify-content: center;
    flex: 1 1 auto;
    min-width: 0;
    padding: 1px;
  }

  .page-nav-button {
    flex: 0 0 40px;
    width: 40px;
    min-width: 40px;
    height: 44px;
    min-height: 44px;
  }

  .page-indicator {
    /* flex: 1 1 72px; */
    min-width: 36px;
    font-size: 13px;
  }

  .image-box {
    aspect-ratio: 1;
  }

  .confirm-actions {
    flex-direction: column-reverse;
  }

  .confirm-actions button {
    width: 100%;
  }

  /* .custom-toolbar #customNextButton {
    flex: 1 1 148px;
  } */
}
