@font-face {
  font-family: 'Iansui';
  src: url('/fonts/iansui/Iansui-Regular.woff2') format('woff2');
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: 'GenWanMin TW';
  src: url('/fonts/genwan-min/GenWanMin2TW-Regular.woff2') format('woff2');
  font-style: normal;
  font-weight: 400;
  /* 中文正文字檔較大：先顯示系統宋體，下載及快取完成後再切換為源雲明體。 */
  font-display: swap;
}

@font-face {
  font-family: 'Source Serif 4';
  src: url('/fonts/source-serif-4/SourceSerif4-Regular.woff2') format('woff2');
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  --bg: #faf7f2;
  --card: #ffffff;
  --ink: #2b2620;
  --muted: #5f574d;
  --line: #e8e1d6;
  --primary: #b5543a;
  --primary-ink: #fff;
  --mine: #f3e8d9;
  --theirs: #ffffff;
  --radius: 14px;
  /* 未知語系先維持原本的系統字體，避免未來新增 locale 時意外套錯字形。 */
  --font-brand: 'Noto Serif TC', 'Songti TC', 'PMingLiU', serif;
  --font-story: 'Noto Serif TC', 'Songti TC', 'PMingLiU', serif;
  --font-ui: 'PingFang TC', 'Noto Sans TC', 'Microsoft JhengHei', system-ui, sans-serif;
}

:lang(zh-Hant) {
  --font-brand: 'Iansui', 'Noto Serif TC', 'Songti TC', 'PMingLiU', serif;
  --font-story: 'GenWanMin TW', 'Noto Serif TC', 'Songti TC', 'PMingLiU', serif;
  --font-ui: 'PingFang TC', 'Noto Sans TC', 'Microsoft JhengHei', system-ui, sans-serif;
}

:lang(en) {
  --font-brand: 'Iansui', 'Segoe Print', 'Bradley Hand', cursive;
  --font-story: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --font-ui: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

/* 底色掛在 html（畫布本身），不倚賴 body→canvas 傳遞：
   短頁、捲動超出、overscroll 都不會露出白底 */
html { background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.7;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  color: var(--ink);
  font-family: var(--font-brand);
  font-size: 1.05rem;
  font-synthesis: none;
  font-weight: 400;
  text-decoration: none;
}
.topbar-user { display: flex; align-items: center; gap: 8px; }
.user-name { color: var(--muted); font-size: 0.9rem; }
.topbar-user form { margin: 0; }
.topbar-settings {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  color: var(--muted);
}
.topbar-settings:hover { background: rgba(181, 84, 58, 0.08); color: var(--primary); }
/* 語言切換：地球圖示 + 原生 select（app.js 監聽 change 導向 /lang/<code>） */
.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: var(--muted);
  border-radius: 999px;
  padding: 2px 4px 2px 6px;
}
.lang-switch:hover { color: var(--primary); }
.lang-switch-icon { display: inline-grid; place-items: center; }
.lang-switch-icon svg {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.lang-select {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.82rem;
  padding: 2px 2px;
  cursor: pointer;
  max-width: 8.5em;
}
.lang-select:focus-visible { outline: 2px solid var(--primary); border-radius: 6px; }
.topbar-settings svg {
  width: 19px;
  height: 19px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.container { max-width: 640px; margin: 0 auto; padding: 20px 16px 64px; }
/* 後台等資料密集頁面：寬螢幕用更寬版面，讓表格一次看完不用橫向捲動 */
.container-wide { max-width: 1080px; }

h1 { font-size: 1.4rem; margin: 0 0 12px; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.85rem; }
.error { color: #b02a2a; background: #fdeaea; padding: 10px 14px; border-radius: 10px; }
.notice { background: #fff7e0; padding: 10px 14px; border-radius: 10px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px 20px;
}
.center-card { text-align: center; margin-top: 8vh; }

.login-page { padding-top: 16px; }
.login-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  min-height: 500px;
  padding: 22px 0 30px;
}
.login-copy {
  order: 2;
  max-width: 520px;
  text-align: center;
}
.login-copy h1 {
  font-family: var(--font-brand);
  font-size: 2.25rem;
  line-height: 1.15;
  margin-bottom: 14px;
}
.login-lede {
  max-width: 30em;
  color: var(--muted);
  font-size: 1.05rem;
  margin: 0 auto;
}
.login-book {
  order: 1;
  position: relative;
  width: min(300px, 76vw);
  height: 340px;
  perspective: 900px;
}
.login-book::before {
  content: '';
  position: absolute;
  left: 28px;
  right: 14px;
  bottom: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(43, 38, 32, 0.12);
  transition: transform 180ms ease, opacity 180ms ease;
}
.book-cover {
  position: absolute;
  inset: 8px 16px 34px 10px;
  display: flex;
  flex-direction: column;
  padding: 24px 22px;
  border: 1px solid var(--ink);
  border-radius: 6px 12px 12px 6px;
  background:
    linear-gradient(90deg, rgba(43, 38, 32, 0.12), transparent 12px),
    #fffdf8;
  box-shadow: 10px 10px 0 var(--line);
  transform: rotate(-2deg);
  color: var(--ink);
  text-decoration: none;
  transition: transform 180ms ease, box-shadow 180ms ease;
}
.book-cover-link {
  cursor: pointer;
}
.book-cover-link:hover {
  transform: rotate(-2deg) translateY(-10px) rotateY(-7deg);
  box-shadow: 18px 20px 0 var(--line);
}
.login-book:has(.book-cover-link:hover)::before {
  transform: translateY(8px) scale(0.88);
  opacity: 0.7;
}
.book-cover-link:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 6px;
}
.book-label {
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
}
.book-title {
  margin-top: 66px;
  font-family: var(--font-brand);
  font-size: 2rem;
}
.book-line,
.book-line.short {
  height: 1px;
  background: var(--line);
  margin-top: 16px;
}
.book-line.short { width: 68%; }
.book-action {
  margin-top: 18px;
  align-self: flex-start;
  padding: 6px 12px;
  border: 1px solid var(--primary);
  border-radius: 999px;
  color: var(--primary);
  font-family: var(--font-brand);
  font-size: 0.85rem;
}
.book-login-note {
  margin-top: 8px;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 0.75rem;
}
.book-route {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.book-route span {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  border: 1px solid var(--primary);
  background: var(--card);
}
.book-route span:first-child { background: var(--primary); }
.login-journey {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: 640px;
  margin: 0 auto 24px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.login-journey div {
  display: grid;
  grid-template-columns: 34px 1fr;
  column-gap: 10px;
  align-items: start;
  padding-top: 12px;
}
.journey-icon {
  grid-row: span 2;
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fffdf8;
  color: var(--primary);
  font-family: var(--font-ui);
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1;
}
.journey-icon svg {
  display: block;
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.login-journey strong {
  display: block;
  font-size: 0.95rem;
}
.journey-copy {
  display: block;
  color: var(--muted);
  font-size: 0.88rem;
}

/* 字體角色：手寫字只負責短標題／儀式文字，長文與操作維持各自的閱讀角色。 */
.login-copy h1,
.login-copy .eyebrow,
.book-title,
.book-action,
.desk-books .story-title,
.book-spine,
.story-head h1,
.completion-book h1,
.story-card-frame h1,
.secret-keepsake h2,
.book-letters h2,
.finished-book-next h2,
.sequel-next,
.ms-epigraph:not(.ms-recap) {
  font-family: var(--font-brand);
  font-synthesis: none;
}

.manuscript,
.ms-compose textarea,
.ms-recap-text,
.story-card-body,
.saved-line blockquote,
.report-content,
.blind-card-back {
  font-family: var(--font-story);
  font-synthesis: none;
}

button,
input,
select,
.notice,
.hint,
.story-meta,
.ms-meta,
.ms-comments,
.ms-compose-hint,
.ms-ending-notice,
.book-login-note,
.journey-copy,
.tag {
  font-family: var(--font-ui);
}

.section { margin-bottom: 28px; }
.dashboard-shell[data-tabs-ready="true"] .dashboard-panel[hidden] { display: none; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.section-head h2 { margin: 0; }
.eyebrow {
  margin: 0 0 2px;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}
.login-copy .eyebrow { font-family: var(--font-brand); }

.how-to-play {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  margin: 18px 0 28px;
}
.how-to-play-compact { margin-top: 0; }
.how-to-play-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.how-to-play-head h2 { margin: 0; }
.desk-empty {
  display: grid;
  gap: 10px;
  padding: 24px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.44)),
    repeating-linear-gradient(180deg, transparent 0 31px, rgba(181, 84, 58, 0.12) 32px);
}
.desk-empty h3 {
  max-width: 18em;
  margin: 0;
  font-family: var(--font-brand);
  font-size: 1.35rem;
  line-height: 1.55;
}
.desk-empty p { margin: 0; }
.desk-empty .btn {
  justify-self: start;
  margin-top: 6px;
}
.rules-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: rules;
}
.rules-list li {
  display: grid;
  grid-template-columns: 28px 1fr;
  column-gap: 10px;
  row-gap: 1px;
  counter-increment: rules;
}
.rules-list li::before {
  content: counter(rules);
  grid-row: span 2;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fff7e0;
  color: var(--primary);
  display: grid;
  place-items: center;
  font-size: 0.82rem;
  font-weight: 700;
}
.rules-list strong {
  line-height: 1.35;
}
.rules-list span {
  color: var(--muted);
  font-size: 0.9rem;
}

/* 首次使用引導：空書桌的步驟＋動作、登入頁與新故事頁的輔助文案 */
.desk-empty-steps { margin: 4px 0 2px; }
.desk-empty-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  margin-top: 6px;
}
.login-demo-link {
  margin: 14px 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}
.login-demo-link a { color: var(--primary); text-decoration: none; }
.login-demo-link a:hover { text-decoration: underline; }
.new-story-lede { margin: -4px 0 18px; }

.btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-lg { padding: 12px 24px; font-size: 1.05rem; }
.btn-sm { padding: 4px 12px; font-size: 0.85rem; }
.btn-ghost { background: transparent; }
.btn-ai { border-color: #7c5cd6; color: #7c5cd6; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.btn[data-copied]::after { content: ' ✓ 已複製'; color: #2e7d32; }
.icon-btn {
  position: relative;
  width: 40px;
  height: 40px;
  padding: 0;
}
.icon-btn svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn[data-copied]::after {
  content: '已複製';
  position: absolute;
  transform: translateY(34px);
  color: #2e7d32;
  font-size: 0.75rem;
  white-space: nowrap;
}
.head-card-actions {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 12px; /* 與「已完結」pill 拉開間隔 */
  vertical-align: middle;
}
/* 有悄悄話導覽鈕時：它成為圖示群第一顆，改由它跟 pill 拉開；後面的卡片工具收回為群內間距 */
.ms-secret-nav { margin-left: 12px; }
.ms-secret-nav + .head-card-actions { margin-left: 6px; }
.btn.icon-btn-inline {
  width: 22px;
  height: 22px;
  min-height: 22px;
  border-radius: 999px;
}
.icon-btn-inline svg {
  width: 12px;
  height: 12px;
}
.icon-btn-inline[data-copied]::after {
  transform: translateY(22px);
  left: 50%;
  translate: -50% 0;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fffdf8;
}

.confirm-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: rgba(43, 38, 32, 0.24);
}
.confirm-card {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffdf8;
  box-shadow: 0 18px 60px rgba(43, 38, 32, 0.18);
  padding: 24px 22px 20px;
}
.confirm-kicker {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}
.confirm-card h2 {
  margin: 0 0 10px;
  font-family: var(--font-brand);
  font-size: 1.2rem;
}
.confirm-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}
.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.story-item {
  display: block;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  text-decoration: none;
  color: var(--ink);
}
.story-item-hot { border-color: var(--primary); background: var(--mine); }
.story-item-ended { opacity: 0.7; }
.story-title { font-weight: 600; }
.story-meta { color: var(--muted); font-size: 0.85rem; }

.desk-books {
  display: grid;
  grid-template-columns: repeat(auto-fill, 176px);
  gap: 24px 22px;
  align-items: end;
  justify-content: start;
  padding: 10px 2px 22px;
  perspective: 900px;
}
.desk-books .story-item {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 220px;
  margin: 0;
  padding: 20px 16px 18px 22px;
  border: 1px solid rgba(43, 38, 32, 0.42);
  border-radius: 6px 10px 10px 6px;
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--cover-accent, #2b2620) 22%, transparent), transparent 13px),
    var(--cover-bg, #fffdf8);
  box-shadow: 8px 10px 0 var(--line);
  color: var(--cover-ink, var(--ink));
  transform: rotate(-1.4deg);
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
  overflow: hidden;
}
.desk-books .story-item:nth-child(2n) { transform: rotate(1.2deg); }
.desk-books .story-item:nth-child(3n) { transform: rotate(-0.4deg); }
.desk-books .story-item::after {
  content: '';
  position: absolute;
  left: 18px;
  right: 10px;
  bottom: -18px;
  height: 16px;
  border-radius: 50%;
  background: rgba(43, 38, 32, 0.10);
  z-index: -1;
  transition: transform 180ms ease, opacity 180ms ease;
}
.desk-books .story-item:hover,
.desk-books .story-item:focus-visible {
  border-color: var(--primary);
  box-shadow: 14px 18px 0 var(--line);
  transform: translateY(-12px) rotate(-1.4deg) rotateY(-5deg);
}
.desk-books .story-item:nth-child(2n):hover,
.desk-books .story-item:nth-child(2n):focus-visible {
  transform: translateY(-12px) rotate(1.2deg) rotateY(5deg);
}
.desk-books .story-item:nth-child(3n):hover,
.desk-books .story-item:nth-child(3n):focus-visible {
  transform: translateY(-12px) rotate(-0.4deg) rotateY(-4deg);
}
.desk-books .story-item:hover::after,
.desk-books .story-item:focus-visible::after {
  opacity: 0.68;
  transform: translateY(10px) scale(0.88);
}
.desk-books .story-item-hot {
  border-color: var(--cover-accent, var(--primary));
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--cover-accent, var(--primary)) 28%, transparent), transparent 13px),
    var(--cover-bg, #fff7ef);
}
.desk-books .story-item::before {
  content: '';
  position: absolute;
  inset: 12px 12px 12px 20px;
  pointer-events: none;
  opacity: 0.72;
}
.desk-books .cover-pattern-0::before {
  border: 1px solid var(--cover-soft, rgba(43, 38, 32, 0.12));
}
.desk-books .cover-pattern-1::before {
  background: repeating-linear-gradient(
    135deg,
    transparent 0 16px,
    var(--cover-soft, rgba(43, 38, 32, 0.12)) 17px 18px
  );
}
.desk-books .cover-pattern-2::before {
  background:
    radial-gradient(circle at 76% 24%, var(--cover-soft, rgba(43, 38, 32, 0.12)) 0 20px, transparent 21px),
    radial-gradient(circle at 28% 72%, var(--cover-soft, rgba(43, 38, 32, 0.12)) 0 12px, transparent 13px);
}
.desk-books .cover-pattern-3::before {
  background:
    linear-gradient(var(--cover-soft, rgba(43, 38, 32, 0.12)) 0 0) 68% 20% / 42px 1px no-repeat,
    linear-gradient(var(--cover-soft, rgba(43, 38, 32, 0.12)) 0 0) 70% 27% / 28px 1px no-repeat,
    linear-gradient(var(--cover-soft, rgba(43, 38, 32, 0.12)) 0 0) 72% 34% / 36px 1px no-repeat;
}
.desk-books .cover-pattern-4::before {
  border: 1px solid var(--cover-soft, rgba(43, 38, 32, 0.12));
  border-radius: 999px;
  width: 58px;
  height: 58px;
  inset: auto 18px 22px auto;
}
.desk-books .cover-pattern-5::before {
  background:
    linear-gradient(90deg, transparent 0 48%, var(--cover-soft, rgba(43, 38, 32, 0.12)) 49% 51%, transparent 52%),
    linear-gradient(0deg, transparent 0 48%, var(--cover-soft, rgba(43, 38, 32, 0.12)) 49% 51%, transparent 52%);
  background-size: 42px 42px;
}
.desk-books .cover-mark {
  position: absolute;
  right: 16px;
  bottom: 18px;
  width: 26px;
  height: 26px;
  border: 1px solid color-mix(in srgb, var(--cover-accent, var(--primary)) 46%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--cover-bg, #fffdf8) 78%, white);
}
.desk-books .cover-mark::before {
  content: '';
  position: absolute;
  inset: 7px;
  border: 1px solid var(--cover-accent, var(--primary));
  border-radius: 3px;
  transform: rotate(-12deg);
}
.desk-books .story-title {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  font-family: var(--font-brand);
  font-size: 1.02rem;
  line-height: 1.45;
}
.desk-books .story-meta {
  position: relative;
  margin-top: 22px;
  color: var(--muted);
  font-size: 0.82rem;
}
.desk-books .tag {
  font-family: var(--font-ui);
  font-size: 0.7rem;
}

.tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 1px 10px;
  border-radius: 999px;
  vertical-align: middle;
}
.tag-turn { background: var(--primary); color: #fff; }
.tag-wait { background: #efe9df; color: var(--muted); }
.tag-ended { background: #e3e3e3; color: #666; }

.form label { display: block; margin-bottom: 16px; font-weight: 600; font-size: 0.95rem; }
.form input, .form textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  background: #fffdf9;
}
.form textarea { resize: vertical; }
.form input:focus, .form textarea:focus { outline: 2px solid var(--primary); border-color: transparent; }
.char-over { color: #b02a2a !important; font-weight: 700; }
.char-error { color: #b02a2a; font-weight: 700; }

.story-head { margin-bottom: 16px; }
.story-head h1 { margin-bottom: 4px; }

/* Admin-only legacy turn preview. Player story pages use .manuscript / .ms-* instead. */
.turns { margin: 20px 0; }
.turn {
  max-width: 88%;
  margin-bottom: 14px;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--theirs);
}
.turn-mine { margin-left: auto; background: var(--mine); }
.turn-meta { display: flex; gap: 10px; font-size: 0.85rem; color: var(--muted); margin-bottom: 2px; }
.turn-author { font-weight: 600; }
.turn-content { white-space: pre-wrap; word-break: break-word; }

.turn-form { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.waiting-note { text-align: center; }

.invite-box {
  background: var(--card);
  border: 1px dashed var(--primary);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 14px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.invite-box code {
  word-break: break-all;
  font-size: 0.82rem;
  background: var(--bg);
  padding: 6px 8px;
  border-radius: 8px;
}

.end-propose { text-align: center; margin: 20px 0; }

.tools { border-top: 1px solid var(--line); padding-top: 20px; margin-top: 28px; }

.form select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  background: #fffdf9;
}

.card-picker {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
}
.card-picker-title { font-weight: 600; font-size: 0.95rem; }
.opening-card {
  background: #fff7e0;
  border-radius: 10px;
  padding: 12px 14px;
  margin: 10px 0;
  font-style: italic;
}
.story-opening {
  text-align: left;
  font-style: normal;
  border: 1px dashed #e0c060;
  margin: 0 0 14px;
}

/* 續寫入口（/new?sequel_to=…）：鎖定欄位（夥伴/關係自上一卷繼承，不可改） */
.locked-field { margin-bottom: 16px; font-size: 0.95rem; }
.locked-label { font-weight: 600; }
.locked-value {
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: #f7f3ea;
  color: var(--muted);
}
/* 前情提要屬於故事內容：襯線（字體即邊界，見 docs/DESIGN-DIRECTION.md） */
.form textarea.recap-input {
  font-family: var(--font-story);
  font-size: 16px;
  line-height: 1.9;
}
.back-to-prev { margin-top: 14px; font-size: 0.9rem; }
.back-to-prev a { color: var(--muted); text-decoration: none; }
.back-to-prev a:hover { color: var(--primary); }

.report-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.report-mine { border-color: var(--primary); }
.report-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.report-card h3 { margin: 0 0 8px; font-size: 1rem; }
.report-card-head h3 {
  min-width: 0;
  margin-bottom: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.report-content { white-space: pre-wrap; word-break: break-word; }
.selfserve summary { cursor: pointer; }
.book-letters .report-card { text-align: left; }
.report-owner {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}
.report-card-collapsible .report-content {
  line-height: 1.8;
}
.report-content-collapsed {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}
.report-expand {
  display: block;
  margin: 12px 0 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--primary);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
}
.report-expand::after { content: ' ↓'; }
.report-expand[aria-expanded='true']::after { content: ' ↑'; }
.report-expand:hover { text-decoration: underline; }
.report-expand:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
  border-radius: 2px;
}
.report-content-full {
  padding-top: 4px;
  white-space: pre-wrap;
}

/* 完結後：手稿裝訂成書，並在書末依序放入彩蛋、兩封洞察信與續卷入口。 */
.finished-book-cover {
  position: relative;
  display: block;
  padding: 28px 54px 26px 24px;
  border: 1px solid var(--ink);
  border-radius: 5px 12px 12px 5px;
  background:
    linear-gradient(90deg, rgba(43, 38, 32, 0.1), transparent 14px),
    #fffdf8;
  box-shadow: 7px 7px 0 var(--line);
}
.finished-book-cover .tools-fold { position: absolute; top: 18px; right: 18px; }
.finished-book-cover .story-head-main { text-align: center; }
.finished-book-cover h1 {
  margin: 20px 0 8px;
  font-family: var(--font-brand);
  font-size: 1.65rem;
}
.finished-book-cover .story-meta { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; }
.finished-book-label,
.book-end-kicker,
.completion-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.16em;
}
.book-end-divider {
  display: grid;
  place-items: center;
  gap: 2px;
  margin: 38px 0;
  color: var(--primary);
}
.book-end-divider span { font-family: serif; font-size: 1.3rem; }
.book-end-divider small { color: var(--muted); font-size: 0.75rem; letter-spacing: 0.16em; }
.secret-keepsake,
.book-letters,
.finished-book-next {
  margin: 28px 0;
  padding: 24px 20px;
  border-top: 1px solid var(--line);
  text-align: center;
}
.secret-keepsake {
  border: 1px dashed rgba(181, 84, 58, 0.45);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.72);
}
.secret-keepsake h2,
.book-letters h2,
.finished-book-next h2 { margin-top: 7px; }
.letter-placeholders {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin: 22px auto;
}
.letter-placeholders span {
  position: relative;
  display: grid;
  place-items: center;
  width: 116px;
  height: 76px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #fffdf8;
  box-shadow: 3px 3px 0 var(--line);
}
.letter-placeholders span::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(30deg, transparent 49%, var(--line) 50%, transparent 51%);
  opacity: 0.55;
}
.letter-placeholders i {
  z-index: 1;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--primary);
  font-family: serif;
  font-style: normal;
}
.letter-placeholders small { position: absolute; bottom: -24px; color: var(--muted); }
.book-letters-waiting .letters-status { max-width: 32em; margin: 34px auto 16px; }
.letters-arrived { margin-top: 24px; }
.has-arrived .letter-placeholders span {
  border-color: rgba(181, 84, 58, 0.55);
  animation: letter-arrived 450ms ease-out both;
}

/* 盲測拆信：兩張直式卡左右並排，點擊後同一張翻面，不另外長出內容卡。 */
.blind-envelope-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 24px 0 18px;
  perspective: 1200px;
}
.blind-envelope {
  position: relative;
  min-width: 0;
}
.blind-envelope-seal {
  display: block;
  width: 100%;
  min-height: 310px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  perspective: 900px;
}
.blind-card-inner {
  position: relative;
  display: block;
  width: 100%;
  min-height: 310px;
  transform-style: preserve-3d;
  transition: transform 420ms cubic-bezier(.2,.72,.2,1);
}
.blind-envelope-seal:hover .blind-card-inner {
  transform: translateY(-4px) rotateY(-2deg);
}
.blind-envelope-seal:focus-visible {
  outline: none;
}
.blind-envelope-seal:focus-visible .blind-card-face {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
}
.blind-card-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  box-shadow: 5px 6px 0 var(--line);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.blind-card-front {
  background:
    linear-gradient(180deg, rgba(181, 84, 58, 0.045), transparent 42%),
    #fffdf8;
}
.blind-card-back {
  align-items: flex-start;
  justify-content: flex-start;
  overflow-y: auto;
  transform: rotateY(180deg);
  font-family: var(--font-story);
  font-size: 0.95rem;
  line-height: 1.9;
  text-align: left;
}
.blind-card-back .report-content { margin: auto 0; }
.blind-card-back small {
  align-self: center;
  margin-top: auto;
  color: var(--muted);
  font-family: var(--font-ui);
}
.blind-card-choice {
  min-width: 86px;
  padding: 5px 12px;
  border: 1px solid transparent;
  border-radius: 999px;
  text-align: center;
  transition: color 160ms ease, border-color 160ms ease, background 160ms ease;
}
.blind-letters.is-ready-to-guess .blind-card-choice {
  border-color: var(--primary);
  background: rgba(181, 84, 58, 0.07);
  color: var(--primary);
  font-weight: 600;
}
.blind-envelope.is-revealed-owner .blind-card-choice {
  border-color: transparent;
  background: transparent;
  color: var(--ink);
  font-weight: 700;
}
.blind-envelope.is-revealed-owner .blind-envelope-seal {
  cursor: default;
}
.blind-envelope.is-mine .blind-card-back {
  border-color: #d9b85f;
  background: #fff7d9;
  box-shadow: 5px 6px 0 rgba(217, 184, 95, 0.2);
}
.blind-card-overline {
  color: var(--muted);
  font-size: 0.62rem;
  letter-spacing: 0.13em;
}
.blind-envelope-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin: 42px 0 14px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  box-shadow: 0 0 0 5px rgba(181, 84, 58, 0.09);
  font-family: var(--font-brand);
  font-size: 1.25rem;
}
.blind-card-front strong {
  font-family: var(--font-brand);
  font-size: 1.05rem;
}
.blind-card-front small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.75rem;
}
.blind-card-flourish {
  margin-top: auto;
  color: rgba(181, 84, 58, 0.55);
  font-family: serif;
}
.blind-envelope.is-open .blind-card-inner,
.blind-envelope.is-open .blind-envelope-seal:hover .blind-card-inner {
  transform: rotateY(180deg);
}
.blind-read-progress { color: var(--muted); font-size: 0.85rem; }
.blind-reveal {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
  scroll-margin-top: 110px;
}
.blind-reveal-result {
  margin-bottom: 14px;
  padding: 14px;
  border-radius: 10px;
  background: #fff7e0;
}
.blind-reveal-result h3,
.blind-reveal-result p { margin: 0; }
.blind-reveal-result h3 { font-size: 1.15rem; }
.blind-show-reports { margin: 16px 0 6px; }
[data-full-reports] { scroll-margin-top: 110px; }
.blind-reveal-labels {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin: 16px 0;
  color: var(--primary);
  font-size: 0.85rem;
}
.blind-reveal .report-card { text-align: left; }
@keyframes letter-arrived {
  from { transform: translateY(-8px); opacity: 0.35; }
  to { transform: translateY(0); opacity: 1; }
}
.finished-book-next { padding-bottom: 8px; }
.finished-book-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 18px 0 12px; }
.finished-book-shelf { color: var(--muted); font-size: 0.85rem; }

.completion-open { overflow: hidden; }
.completion-stage {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(250, 247, 242, 0.96);
  animation: completion-enter 480ms ease-out both;
}
.completion-stage.is-leaving { animation: completion-leave 340ms ease-in both; }
.completion-book {
  width: min(410px, 100%);
  padding: 38px 28px 30px;
  border: 1px solid var(--ink);
  border-radius: 6px 14px 14px 6px;
  background:
    linear-gradient(90deg, rgba(43, 38, 32, 0.12), transparent 16px),
    #fffdf8;
  box-shadow: 10px 10px 0 var(--line);
  text-align: center;
}
.completion-book h1 {
  margin: 8px 0 14px;
  font-family: var(--font-brand);
  font-size: 1.65rem;
}
.completion-flourish { margin-top: 26px; color: var(--primary); }
.completion-meta, .completion-date { margin: 0; color: var(--muted); }
.completion-date { font-size: 0.8rem; }
.completion-book .btn { margin-top: 28px; }
.completion-note { margin: 16px 0 0; color: var(--muted); font-size: 0.8rem; }
@keyframes completion-enter {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes completion-leave {
  from { opacity: 1; }
  to { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .completion-stage,
  .completion-stage.is-leaving,
  .has-arrived .letter-placeholders span { animation: none; }
  .blind-card-inner { transition: none; }
}
@media (max-width: 600px) {
  .blind-envelope-list {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .blind-envelope-seal,
  .blind-card-inner { min-height: 190px; }
  .blind-card-face { padding: 18px 20px; }
  .blind-card-front {
    display: grid;
    grid-template-columns: 54px 1fr;
    grid-template-rows: auto auto auto;
    column-gap: 16px;
    align-content: center;
    justify-items: start;
    text-align: left;
  }
  .blind-card-front .blind-card-overline,
  .blind-card-front .blind-card-flourish { grid-column: 1 / -1; }
  .blind-envelope-mark {
    grid-row: 2 / span 2;
    width: 48px;
    height: 48px;
    margin: 10px 0 0;
  }
  .blind-card-front strong { align-self: end; }
  .blind-card-front small { align-self: start; }
  .blind-card-front .blind-card-flourish { display: none; }
  .blind-card-back { font-size: 0.9rem; line-height: 1.75; }
  .blind-card-back .report-content { margin: 12px 0; }
}

.story-card-page { max-width: 560px; margin: 24px auto; }
.story-card-frame {
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: 4px;
  padding: 32px 28px;
  box-shadow: 6px 6px 0 var(--line);
}
.story-card-label { text-align: center; color: var(--muted); font-size: 0.8rem; letter-spacing: 2px; }
.story-card-frame h1 { text-align: center; margin: 10px 0 20px; font-family: var(--font-brand); }
.story-card-body {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--font-story);
  font-size: 17px;
  line-height: 2.1;
  text-indent: 2em;
}
.story-card-sign { text-align: right; color: var(--muted); font-size: 0.85rem; margin-top: 20px; }
/* Free 方案故事卡浮水印：淡色、不擋閱讀，右下角品牌導流 */
.story-card-frame.has-watermark { position: relative; overflow: hidden; }
.story-card-watermark {
  position: absolute;
  right: 12px;
  bottom: 10px;
  font-size: 0.72rem;
  letter-spacing: 1px;
  color: var(--muted);
  opacity: 0.4;
  pointer-events: none;
  user-select: none;
}

.admin-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.admin-head h1 { margin-bottom: 12px; }
.admin-note { margin-top: 14px; font-size: 0.8rem; line-height: 1.6; }
.user-name { font-weight: 600; }
.user-email { color: var(--muted); font-size: 0.78rem; word-break: break-all; }
.user-actions { display: flex; flex-wrap: wrap; gap: 6px; }
tr.user-disabled td { opacity: 0.55; }
.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  white-space: nowrap;
}
.badge + .badge { margin-left: 4px; }
.badge-super { color: #8a5a1a; border-color: #d9b483; background: #f6ebda; }
.badge-admin { color: #2c6b4f; border-color: #a9d3bf; background: #e4f2ea; }
.badge-off { color: #b23b2e; border-color: #e0b0aa; background: #f7e4e1; }
/* 方案 badge（Freemium）：free 中性、plus/insight 漸強 */
.badge-tier { vertical-align: middle; }
.badge-tier.tier-free { color: var(--muted); border-color: var(--line); background: transparent; }
.badge-tier.tier-plus { color: #2c5a8a; border-color: #a9c3d9; background: #e4edf5; }
.badge-tier.tier-insight { color: #6a3a8a; border-color: #c9a9d9; background: #efe4f5; }
.badge-link { text-decoration: none; cursor: pointer; }
.badge-link:hover { border-color: var(--ink); }
/* 後台方案指派表單 */
.tier-form { display: inline-flex; gap: 6px; align-items: center; }
.tier-select { font-size: 0.8rem; padding: 2px 6px; border: 1px solid var(--line); border-radius: 4px; background: var(--card); color: var(--ink); }
/* 方案頁：Recur 訂閱結帳（金流未設定時退回假門表單，樣式共用） */
.upgrade-page { max-width: 900px; margin: 0 auto; }
.upgrade-inline { text-decoration: none; }
.upgrade-inline:hover { text-decoration: underline; }
.upgrade-thanks { margin: 16px 0; }
.upgrade-foot { margin-top: 18px; }
.pricing-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-top: 20px; }
.pricing-card { border: 1px solid var(--line); border-radius: 8px; padding: 20px; background: var(--card); display: flex; flex-direction: column; }
.pricing-card.is-current { border-color: var(--ink); box-shadow: 3px 3px 0 var(--line); }
.pricing-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pricing-current { font-size: 0.72rem; color: var(--muted); }
.pricing-price { font-size: 1.5rem; font-weight: 700; margin: 12px 0 2px; }
.pricing-tagline { font-size: 0.85rem; }
.pricing-bullets { list-style: none; padding: 0; margin: 14px 0; display: flex; flex-direction: column; gap: 8px; font-size: 0.9rem; }
.pricing-bullets li { padding-left: 18px; position: relative; }
.pricing-bullets li::before { content: '✓'; position: absolute; left: 0; color: var(--muted); }
.pricing-cta { width: 100%; margin-top: auto; }
.pricing-cta-note { margin-top: auto; font-size: 0.82rem; text-align: center; padding-top: 6px; }
/* Play 付款政策：TWA 內不得出現導向站外金流的入口（見 src/views.tsx 的 TWA_DETECT）。
   寫成「非此環境就隱藏」而不是「預設隱藏再放行」：放行版要用 display 值把元素顯示回來，
   會蓋掉 .btn 等既有的 display（flex/inline-flex），元素顯示了但排版壞掉。
   這樣寫則是該顯示時完全不介入、維持原樣式；該隱藏時用 !important 確保蓋得過 .btn。
   html 還沒有 data-twa（JS 停用或偵測拋錯）時 :not() 成立 → 付費入口維持隱藏，失敗方向安全。 */
html:not([data-twa='0']) [data-web-only] { display: none !important; }
html:not([data-twa='1']) [data-twa-only] { display: none !important; }

.pricing-trial { font-size: 0.8rem; color: var(--muted); margin-top: 6px; }
.checkout-error { margin: 16px 0; background: #fdecea; }
.upgrade-portal { margin-top: 20px; }
.checkout-success { text-align: center; padding-top: 24px; }
.btn-danger { color: #c0392b; }
.admin-stats { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 20px; }
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 16px;
  min-width: 100px;
  text-align: center;
}
.stat-num { font-size: 1.4rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.75rem; }
.table-wrap { overflow-x: auto; }
.admin-table { border-collapse: collapse; font-size: 0.85rem; width: 100%; }
.admin-table th, .admin-table td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
  background: var(--card);
  vertical-align: top;
}
/* 短欄位不換行、寬文字欄位允許換行，桌機才不會被迫橫向捲動 */
.admin-table th { white-space: nowrap; }
.cell-clip { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 手機：把每一列表格轉成一張卡片，欄位標題移到左側，免橫向捲動 */
@media (max-width: 700px) {
  .admin-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }
  .admin-table,
  .admin-table tbody,
  .admin-table tr,
  .admin-table td {
    display: block;
    width: 100%;
  }
  .admin-table tr {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 12px;
  }
  .admin-table td {
    border: none;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
    padding: 8px 12px;
    white-space: normal;
  }
  .admin-table td:last-child { border-bottom: none; }
  .admin-table td::before {
    content: attr(data-label);
    flex: 0 0 auto;
    font-weight: 600;
    color: var(--muted);
  }
  .admin-table td.cell-clip {
    max-width: none;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }
}

@media (max-width: 520px) {
  .login-page { padding-top: 0; }
  .login-hero {
    gap: 16px;
    min-height: 0;
    padding: 8px 0 22px;
  }
  .login-copy h1 { font-size: 1.95rem; }
  .login-lede { font-size: 1rem; }
  .login-book {
    width: min(250px, 78vw);
    height: 320px;
  }
  .book-cover {
    inset: 8px 14px 30px 8px;
    padding: 22px 20px;
  }
  .book-title { margin-top: 36px; font-size: 1.75rem; }
  .book-line,
  .book-line.short { margin-top: 12px; }
  .book-action { margin-top: auto; }
  .book-login-note { margin-top: 6px; }
  .book-route { margin-top: 8px; }
  .book-cover-link:hover {
    transform: rotate(-2deg) translateY(-6px) rotateY(-5deg);
    box-shadow: 14px 15px 0 var(--line);
  }
  .login-journey { grid-template-columns: 1fr; gap: 4px; }
  .how-to-play-head {
    display: block;
  }
  .how-to-play-head .tag {
    margin-top: 8px;
  }
}

/* 書架：完結故事的書背（emma/ui-sketch） */
.shelf-group { margin-bottom: 22px; }
.shelf-label { color: var(--muted); font-size: 0.85rem; margin-bottom: 8px; }
.shelf {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
  padding: 0 8px;
  border-bottom: 3px solid var(--line);
}
.book-spine {
  display: block;
  writing-mode: vertical-rl;
  padding: 14px 10px;
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  text-decoration: none;
  color: var(--ink);
  font-family: var(--font-brand);
  font-size: 0.9rem;
  letter-spacing: 2px;
  transition: transform 0.15s ease;
}
.book-spine:hover { transform: translateY(-5px); }
.book-spine-title {
  display: block;
  max-height: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.book-tone-0 { background: #f3e8d9; height: 156px; }
.book-tone-1 { background: #fff3df; height: 148px; }
.book-tone-2 { background: #ede9dd; height: 160px; }
.book-tone-3 { background: #f0ddd4; height: 152px; }
/* 續卷系列：書背標題下的小字卷序（直排時 inline-block 沿行內軸往下排） */
.book-spine-serial .book-spine-title {
  display: inline-block;
  max-height: calc(100% - 40px);
  vertical-align: top;
}
.book-spine-vol {
  display: inline-block;
  margin-block-start: 10px;
  font-size: 0.72rem;
  letter-spacing: 1px;
  color: var(--muted);
  vertical-align: top;
}

/* 主頁去規則化：規則收成一個 info 圖示，點開才顯示（DESIGN-DIRECTION 3.7） */
.howto-fold { margin-top: 28px; display: flex; flex-direction: column; align-items: center; }
.howto-fold summary {
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 24px;
  text-align: center;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.howto-fold summary::-webkit-details-marker { display: none; }
.howto-fold:not([open]) .how-to-play { display: none; }
.howto-fold summary:hover,
.howto-fold[open] summary { border-color: var(--primary); color: var(--primary); }
.howto-fold[open] .how-to-play { margin-top: 14px; }

/* 「我」區塊：書寫足跡，而不是另一個書架 */
.me-panel {
  display: grid;
  gap: 12px;
}
.me-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.me-section-header {
  margin-bottom: 12px;
}
.me-section-header h3 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.4;
}
.me-section-header p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}
/* 開關列：說明在左、iOS 風格 switch 在右 */
.me-section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.me-section-toggle .me-section-header { margin-bottom: 0; min-width: 0; }
.switch { position: relative; display: inline-block; width: 46px; height: 28px; flex: 0 0 auto; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.switch-slider { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: background 0.15s ease; pointer-events: none; }
.switch-slider::before {
  content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s ease;
}
.switch input:checked + .switch-slider { background: var(--primary); }
.switch input:checked + .switch-slider::before { transform: translateX(18px); }
.switch input:focus-visible + .switch-slider { outline: 2px solid var(--primary); outline-offset: 2px; }
.switch input:disabled + .switch-slider { opacity: 0.5; }
.library-card {
  background: var(--mine);
  border-color: #e4d2bf;
}
.me-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.me-stat {
  min-width: 0;
  padding-top: 10px;
  border-top: 1px solid rgba(43, 38, 32, 0.12);
}
.me-stat-value {
  display: block;
  font-family: var(--font-ui);
  font-size: 1.5rem;
  line-height: 1.15;
}
.me-stat-label {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.8rem;
}
.me-placeholder {
  background: rgba(255, 255, 255, 0.58);
}
.me-placeholder > p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}
.settings-page { margin-top: 4px; }
.settings-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.settings-head h1 { margin-bottom: 2px; }
.settings-head p { margin: 0; }
.settings-sections {
  display: grid;
  gap: 12px;
}
.settings-sections .me-section-header h2 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.4;
}
.device-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
}
.device-current {
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}
.saved-lines-list {
  display: grid;
  gap: 10px;
}
.saved-line {
  padding: 12px 0 0;
  border-top: 1px solid var(--line);
}
.saved-line:first-child { padding-top: 0; border-top: none; }
.saved-line blockquote {
  margin: 0;
  font-family: var(--font-story);
  font-size: 1rem;
  line-height: 1.9;
}
.saved-line-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
  font-size: 0.78rem;
}
.saved-line-meta a {
  color: var(--muted);
  text-decoration: none;
}
.saved-line-meta a:hover { color: var(--primary); }
.saved-line-meta form { margin: 0; }

/* 故事頁書頁化：連續書頁排版取代聊天氣泡（DESIGN-DIRECTION 3.1） */
.manuscript {
  margin: 22px 0;
  font-family: var(--font-story);
  font-size: 17px;
  line-height: 2.1;
}
.ms-epigraph {
  color: var(--muted);
  font-style: italic;
  text-align: center;
  margin: 0 0 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
/* 續卷題詞區：前情提要沿用 ms-epigraph 的襯線斜體置中；上一卷連結是介面導覽，用黑體小字 */
.ms-prev-link {
  display: block;
  margin-bottom: 10px;
  font-family: var(--font-ui);
  font-style: normal;
  font-size: 0.8rem;
  line-height: 1.6;
  color: var(--muted);
  text-decoration: none;
}
.ms-prev-link:hover { color: var(--primary); }
.ms-recap-text { margin: 0; white-space: pre-wrap; word-break: break-word; }

/* 完結區的續寫入口：開下一卷／前往下一卷 */
.sequel-entry { text-align: center; margin: 26px 0 8px; }
.sequel-next { font-size: 0.95rem; text-decoration: none; color: var(--primary); }
.sequel-next:hover { text-decoration: underline; }
.ms-para { margin: 0; }
.ms-para:target { scroll-margin-top: 42vh; }
.ms-para summary {
  position: relative;
  display: block;
  list-style: none;
  padding-left: 22px;
  text-indent: 1.4em;
  margin-bottom: 6px;
  cursor: text;
  white-space: pre-wrap;
  word-break: break-word;
}
.ms-para summary::-webkit-details-marker { display: none; }
.ms-para:target .ms-line {
  animation: ink-deepen 1600ms ease-out both;
}
@keyframes ink-deepen {
  0% {
    color: rgba(43, 38, 32, 0.16);
    text-shadow: 0 0 8px rgba(181, 84, 58, 0.22);
  }
  45% {
    color: rgba(43, 38, 32, 0.55);
    text-shadow: 0 0 3px rgba(181, 84, 58, 0.12);
  }
  100% {
    color: var(--ink);
    text-shadow: none;
  }
}
.ms-mark {
  position: absolute;
  left: 0;
  top: 0.55em;
  text-indent: 0;
  font-family: var(--font-ui);
  font-size: 0.7rem;
  line-height: 1;
}
.ms-a .ms-mark { color: var(--primary); }
.ms-b .ms-mark { color: #4c7266; }
.ms-meta {
  margin: 0 0 12px 22px;
  font-family: var(--font-ui);
  font-size: 0.75rem;
  color: rgba(95, 87, 77, 0.58);
}
/* 範例故事頁：靜態、不可互動，沿用手稿排版但用獨立 class */
.demo-manuscript { margin-top: 18px; }
.demo-para { margin: 0; }
.demo-line {
  position: relative;
  margin: 0 0 6px;
  padding-left: 22px;
  text-indent: 1.4em;
  white-space: pre-wrap;
  word-break: break-word;
}
.demo-note {
  margin: 0 0 14px 22px;
  font-family: 'PingFang TC', system-ui, sans-serif;
  font-size: 0.82rem;
  color: var(--muted);
  text-indent: 0;
}
.demo-note .ms-comment-meta { font-size: 0.75rem; }
.demo-cta { margin-top: 26px; }

.save-line-form {
  display: inline-flex;
  margin: 0 0 0 8px;
  vertical-align: middle;
}
.save-line-form .btn-sm {
  min-height: 26px;
  padding: 2px 8px;
  font-size: 0.75rem;
}
.ms-compose {
  margin-top: 20px;
  padding-left: 22px;
  border-top: 1px dashed var(--line);
  padding-top: 16px;
}
.ms-compose textarea {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  resize: vertical;
  font-family: var(--font-story);
  font-size: 17px;
  line-height: 2.1;
  text-indent: 1.4em;
  color: var(--ink);
}
.ms-compose textarea:focus { outline: none; }
.ms-compose-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
}

.ms-compose-hint {
  font-family: var(--font-ui);
  font-size: 0.85rem;
  color: var(--primary);
  margin: 0 0 8px;
}
.ms-ending-notice {
  margin: 14px 0 0 22px;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  line-height: 1.7;
}

/* 旁注留言：掛在每則接龍下方，字體較小、與正文明顯區隔 */
.ms-comments {
  margin: 0 0 12px 22px;
  font-family: var(--font-ui);
  font-size: 0.8rem;
}
.ms-comment {
  margin: 0 0 4px;
  padding-left: 8px;
  /* 硃批：旁注用淡磚紅與正文墨色區隔，呼應紅筆眉批的傳統 */
  border-left: 2px solid rgba(181, 84, 58, 0.3);
  color: rgba(155, 79, 56, 0.92);
}
.ms-comment-meta { color: var(--muted); }
/* 眉批記號：段落行尾的 ※，平常極淡（暗示這裡可以吐槽），有吐槽時亮起帶數量 */
.ms-annot {
  display: inline-block;
  margin-left: 6px;
  text-indent: 0;
  font-family: var(--font-ui);
  font-size: 0.7rem;
  line-height: 1;
  vertical-align: super;
  color: var(--muted);
  opacity: 0.35;
  white-space: nowrap;
}
.ms-annot-on {
  color: var(--primary);
  opacity: 0.9;
}
/* 對方的悄悄話：只留痕跡不露內容 */
.ms-comment-hidden {
  color: var(--muted);
  font-style: italic;
  border-left-style: dashed;
}
/* 悄悄話導覽鈕：完結後掛在標題列，有未讀亮磚紅＋數字，看完轉灰 */
.ms-secret-nav { position: relative; color: var(--primary); }
.ms-secret-nav.is-read { color: var(--muted); }
.ms-secret-nav-count {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-family: var(--font-ui);
  font-size: 0.62rem;
  line-height: 15px;
  text-align: center;
}
.ms-secret-nav.is-read .ms-secret-nav-count { display: none; }
/* 翻到某則悄悄話時閃一下磚紅，指引視線 */
@keyframes note-flash {
  0% { background: rgba(181, 84, 58, 0.18); }
  100% { background: transparent; }
}
.ms-comment-onend.is-flash {
  border-radius: 4px;
  animation: note-flash 1600ms ease-out;
}
.ms-comment-form {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}
.ms-comment-form input[type='text'] {
  flex: 1 1 160px;
  min-width: 0;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.8rem;
}
/* 送出鈕：鋼筆 icon 帶磚紅，呼應硃批。
   雙類別選擇器蓋過全站 .btn { min-height: 44px } 觸控規則，鎖成與悄悄話藥丸等高的正圓 */
.ms-comment-form .ms-comment-send {
  color: var(--primary);
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  min-height: 26px;
}
.ms-comment-hint {
  flex-basis: 100%;
  min-height: 1.3em;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.3;
  opacity: 0;
  transition: opacity 120ms ease;
}
.ms-comment-hint-on {
  opacity: 1;
}
/* 揭露模式開關：先決定現在可見或完結揭曉，再寫旁注 */
.ms-comment-secret {
  position: relative;
  flex-shrink: 0;
  cursor: pointer;
}
.ms-comment-secret input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}
.ms-comment-secret > span {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  user-select: none;
}
.ms-comment-secret svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ms-eye-off { display: none; }
.ms-comment-secret input:checked + span {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(181, 84, 58, 0.08);
}
.ms-comment-secret input:checked + span .ms-eye-on { display: none; }
.ms-comment-secret input:checked + span .ms-eye-off { display: block; }
.ms-comment-secret input:focus-visible + span {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* 故事頁工具收進標題旁的圖示選單（§3.1 #5） */
.story-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  /* 釘在 topbar（高 79px）下方，故事在底下捲動時標題與注記/工具 icon 隨時可點 */
  position: sticky;
  top: 79px;
  z-index: 5; /* 高於內文、低於 topbar 的 z-index:10 */
  background: var(--bg);
  padding-top: 8px;
  margin-top: -8px; /* 抵銷 padding，維持原本與 topbar 的視覺間距 */
  padding-bottom: 8px;
  box-shadow: 0 6px 8px -6px rgba(43, 38, 32, 0.12); /* 與下方內文的分隔陰影 */
}
.story-head-main { min-width: 0; }
.tools-fold { position: relative; flex-shrink: 0; }
.tools-fold summary {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 1rem;
  line-height: 28px;
  text-align: center;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.tools-fold summary::-webkit-details-marker { display: none; }
.tools-fold summary:hover,
.tools-fold[open] summary { border-color: var(--primary); color: var(--primary); }
.tools-menu {
  position: absolute;
  right: 0;
  top: 36px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  min-width: 168px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.08);
}
.tools-menu-label { color: var(--muted); font-size: 0.75rem; padding: 0 2px 2px; }
.tools-menu .btn { text-align: center; }

/* 頁首導覽列：書桌／書架／我 */
.topbar { gap: 12px; }
.brand { flex-shrink: 0; }
.topnav {
  display: flex;
  gap: 2px;
  margin-right: auto;
  margin-left: 8px;
}
.topnav a {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  color: var(--muted);
  text-decoration: none;
}
.topnav a:hover,
.topnav a[aria-selected="true"] {
  color: var(--primary);
  background: var(--mine);
}
.topnav svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.section[id] { scroll-margin-top: 64px; }
@media (max-width: 480px) {
  .brand { display: none; }
  .topnav { margin-left: 0; }
}

/* 無障礙：觸控目標 ≥40–44px、鍵盤 focus 樣式（subagent 建議 #6/#8） */
.btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }
.btn-sm { min-height: 38px; }
.howto-fold summary { width: 40px; height: 40px; line-height: 38px; }
.tools-fold summary { width: 40px; height: 40px; line-height: 38px; }
a:focus-visible,
button:focus-visible,
summary:focus-visible,
.book-spine:focus-visible,
.story-item:focus-visible,
.topnav a:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* 分頁面板 tabIndex=0 仍可聚焦（鍵盤/螢幕閱讀器切分頁時會落在正確區塊），
   但整個面板畫一圈 focus 環又大又醜，且切分頁時瀏覽器常判定為 focus-visible 而冒出來；
   面板內的書、按鈕本身已有各自的 focus 環，故面板自身一律不畫外框。 */
.dashboard-panel:focus,
.dashboard-panel:focus-visible {
  outline: none;
}

/* 「怎麼開啟通知？」說明摺疊 */
.push-help summary { cursor: pointer; font-weight: 600; }
.push-help-body { margin-top: 8px; }
.push-help-plat { margin-bottom: 10px; }
.push-help-plat strong { display: block; margin-bottom: 2px; }
.push-help ol { margin: 4px 0 0; padding-left: 20px; }
.push-help li { margin: 2px 0; }

/* 盲測揭曉：猜對／猜錯視覺區分（修正 dead ternary） */
.guess-correct { background: #e6f2e0; }
.guess-wrong { background: #efe9df; }
/* 書桌：輪到你的那本加重，讓它比 CTA 更搶眼（subagent #5） */
.story-item-hot { border-color: var(--primary); background: var(--mine); }
/* 空書架／空我的留白文案（subagent #7） */
.section-empty { color: var(--muted); font-size: 0.9rem; padding: 4px 2px 2px; }
