/* ── SIDE STORIES (เรื่องเสริม) · about-side.js ───────────────────────────────
   Chips sit at the foot of each archive chapter; the story opens in a sheet
   (right drawer ≥ 721px, bottom sheet on phones). Dark = deep-dive glass,
   light = white card with a 4px bottom edge (Design.md §16.1). */

/* chapter rail */
.side-rail { margin-top: 6px; padding-top: 18px; border-top: 1px dashed rgba(226, 201, 143, 0.32); }
.side-rail[hidden] { display: none; }
html[data-theme="light"] .side-rail { border-top-color: #d8c9ad; }
.side-rail-head {
  margin: 0 0 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-family: var(--font-heading, 'Mitr', sans-serif); font-size: 15px; font-weight: 600; line-height: 1.45;
  color: #e2c98f;
}
html[data-theme="light"] .side-rail-head { color: #92400e; }
.side-rail-n {
  font-size: 12px; font-weight: 500; padding: 2px 9px; border-radius: 999px;
  background: rgba(226, 201, 143, 0.14); color: #f3e3bd;
}
html[data-theme="light"] .side-rail-n { background: #fef3c7; color: #92400e; }
.side-rail-sub { margin: -6px 0 12px; font-size: 14px; line-height: 1.6; color: #b9c4d6; }
html[data-theme="light"] .side-rail-sub { color: #4b5568; }
.side-rail-undo { margin-top: 12px; }
.side-rail-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }

.side-chip {
  display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 12px 14px; text-align: left;
  border-radius: 16px; cursor: pointer; font: inherit; color: #eef2f8;
  border: 1px solid rgba(226, 201, 143, 0.28);
  background: linear-gradient(145deg, #2a3656, #1b243d);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.side-chip:hover, .side-chip:focus-visible {
  transform: translateY(-2px); border-color: rgba(236, 220, 180, 0.7);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(236, 220, 180, 0.25);
}
.side-chip:focus-visible { outline: 2px solid #ecdcb4; outline-offset: 2px; }
html[data-theme="light"] .side-chip {
  color: #142032; background: #ffffff; border-color: #a9b8cc; border-bottom-width: 4px;
  box-shadow: 0 6px 16px rgba(20, 32, 50, 0.06);
}
html[data-theme="light"] .side-chip:hover, html[data-theme="light"] .side-chip:focus-visible { border-color: #b08a2e; }
html[data-theme="light"] .side-chip:focus-visible { outline-color: #92400e; }
.side-chip-emo {
  flex: 0 0 auto; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px;
  font-size: 21px; line-height: 1; background: linear-gradient(145deg, #ecdcb4, #c9ab6c); color: #2b2212;
}
.side-chip-txt { display: grid; gap: 2px; min-width: 0; flex: 1 1 auto; }
.side-chip-txt b { font-family: var(--font-heading, 'Mitr', sans-serif); font-weight: 600; font-size: 15px; line-height: 1.45; overflow-wrap: anywhere; }
.side-chip-txt small { font-size: 13px; color: #b9c4d6; line-height: 1.45; }
html[data-theme="light"] .side-chip-txt small { color: #4b5568; }
.side-chip-go { flex: 0 0 auto; font-size: 18px; color: #ecdcb4; transition: transform 0.2s ease; }
html[data-theme="light"] .side-chip-go { color: #92400e; }
.side-chip:hover .side-chip-go { transform: translateX(3px); }
.side-chip.is-add { background: transparent; border-style: dashed; border-color: rgba(226, 201, 143, 0.45); box-shadow: none; }
.side-chip.is-add .side-chip-emo { background: rgba(226, 201, 143, 0.14); color: #ecdcb4; }
html[data-theme="light"] .side-chip.is-add { background: #fffdf8; border-color: #b08a2e; border-bottom-width: 1px; }
html[data-theme="light"] .side-chip.is-add .side-chip-emo { background: #fef3c7; color: #92400e; }

/* count in the archive trigger */
.summary-side-count {
  display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: rgba(226, 201, 143, 0.16); color: #f3e3bd;
}
.summary-side-count[hidden] { display: none; }
html[data-theme="light"] .summary-side-count { background: #fef3c7; color: #92400e; }

/* sheet */
.side-sheet {
  position: fixed; inset: 0 0 0 auto; margin: 0; padding: 0; border: 0; background: transparent;
  width: min(560px, 100vw); max-width: 100vw; height: 100dvh; max-height: 100dvh; overflow: visible; color: #e6ebf3;
}
.side-sheet::backdrop { background: rgba(4, 8, 20, 0.62); backdrop-filter: blur(3px); }
.side-sheet-panel {
  position: relative; height: 100%; overflow-y: auto; overscroll-behavior: contain;
  background: linear-gradient(145deg, #22304f 0%, #141c31 70%);
  border-left: 1px solid rgba(226, 201, 143, 0.3);
  box-shadow: -18px 0 50px rgba(0, 0, 0, 0.45);
}
.side-sheet-panel::before {
  content: ""; position: absolute; top: 0; right: 0; width: 220px; height: 220px; pointer-events: none;
  background: radial-gradient(circle at top right, rgba(236, 220, 180, 0.16), transparent 70%);
}
.side-sheet[open] .side-sheet-panel { animation: sideIn 0.32s cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes sideIn { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
html[data-theme="light"] .side-sheet { color: #1c2433; }
html[data-theme="light"] .side-sheet-panel { background: #ffffff; border-left-color: #a9b8cc; box-shadow: -18px 0 50px rgba(20, 32, 50, 0.18); }
html[data-theme="light"] .side-sheet-panel::before { background: radial-gradient(circle at top right, rgba(176, 138, 46, 0.12), transparent 70%); }
.side-sheet-grip { display: none; }
.side-sheet-body { position: relative; padding: 30px 32px 40px; display: grid; gap: 20px; }

.side-sheet-head { position: relative; padding-right: 52px; display: grid; gap: 6px; }
.side-kicker { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: 0.02em; color: #e2c98f; line-height: 1.45; }
html[data-theme="light"] .side-kicker { color: #92400e; }
.side-sheet-head h2 {
  max-width: none; text-wrap: pretty; margin: 0; font-family: var(--font-heading, 'Mitr', sans-serif); font-weight: 700; font-size: clamp(22px, 3vw, 27px); line-height: 1.45; color: #ffffff;
  padding-bottom: 12px; border-bottom: 2px solid transparent; border-image: linear-gradient(90deg, #ecdcb4, rgba(236, 220, 180, 0)) 1;
}
html[data-theme="light"] .side-sheet-head h2 { color: #0f172a; border-image: linear-gradient(90deg, #b08a2e, rgba(176, 138, 46, 0)) 1; }
.side-meta { margin: 0; font-size: 13px; color: #b9c4d6; }
html[data-theme="light"] .side-meta { color: #4b5568; }
.side-close {
  position: absolute; top: -4px; right: 0; width: 44px; height: 44px; border-radius: 50%; cursor: pointer; font-size: 18px;
  border: 1px solid rgba(255, 255, 255, 0.22); background: rgba(255, 255, 255, 0.06); color: #eef2f8;
}
.side-close:hover, .side-close:focus-visible { background: rgba(236, 220, 180, 0.18); border-color: #ecdcb4; }
html[data-theme="light"] .side-close { border-color: #a9b8cc; background: #f4f6fa; color: #142032; }

.side-fig { margin: 0; display: grid; gap: 8px; }
.side-fig img { width: 100%; max-height: 380px; object-fit: cover; border-radius: 14px; border: 6px solid #ffffff; box-shadow: 0 10px 26px rgba(0, 0, 0, 0.35); background: #ffffff; }
.side-fig figcaption { font-size: 13px; line-height: 1.6; color: #b9c4d6; text-align: center; }
html[data-theme="light"] .side-fig img { border-color: #f4f1ea; box-shadow: 0 8px 20px rgba(20, 32, 50, 0.12); }
html[data-theme="light"] .side-fig figcaption { color: #4b5568; }
.side-prose p { margin: 0 0 14px; font-size: 16px; line-height: 1.95; color: #d6deea; }
html[data-theme="light"] .side-prose p { color: #334155; }
.side-prose .side-empty { color: #9aa6ba; font-style: italic; }
.side-foot { padding-top: 8px; border-top: 1px solid rgba(255, 255, 255, 0.1); }
html[data-theme="light"] .side-foot { border-top-color: #e2d9cc; }
.side-back {
  min-height: 44px; padding: 10px 18px; border-radius: 999px; cursor: pointer; font: inherit; font-weight: 600;
  border: 0; background: linear-gradient(145deg, #ecdcb4, #c9ab6c); color: #2b2212;
}
.side-back:hover, .side-back:focus-visible { filter: brightness(1.06); outline: 2px solid #ecdcb4; outline-offset: 2px; }

/* owner tools + buttons */
.side-owner { display: flex; flex-wrap: wrap; gap: 8px; }
.side-btn {
  min-height: 40px; padding: 8px 14px; border-radius: 12px; cursor: pointer; font: inherit; font-size: 14px; font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.22); background: rgba(255, 255, 255, 0.06); color: #eef2f8;
}
.side-btn:hover:not(:disabled), .side-btn:focus-visible { border-color: #ecdcb4; background: rgba(236, 220, 180, 0.14); }
.side-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.side-btn.is-primary { border: 0; background: linear-gradient(145deg, #ecdcb4, #c9ab6c); color: #2b2212; }
.side-btn.is-danger { color: #fca5a5; border-color: rgba(252, 165, 165, 0.4); }
.side-btn.is-danger:hover { background: rgba(239, 68, 68, 0.14); border-color: #fca5a5; }
.side-btn.is-ghost { background: transparent; }
html[data-theme="light"] .side-btn { border-color: #a9b8cc; background: #f4f6fa; color: #142032; }
html[data-theme="light"] .side-btn.is-primary { background: linear-gradient(145deg, #ecdcb4, #c9ab6c); color: #2b2212; border: 0; }
html[data-theme="light"] .side-btn.is-danger { color: #b91c1c; border-color: #f0b4b4; background: #fff5f5; }
html[data-theme="light"] .side-btn.is-ghost { background: transparent; }

/* editor */
.side-editor { display: grid; gap: 16px; }
.side-editor fieldset { margin: 0; padding: 14px 0 0; border: 0; border-top: 1px solid rgba(255, 255, 255, 0.12); display: grid; gap: 10px; }
html[data-theme="light"] .side-editor fieldset { border-top-color: #e2d9cc; }
.side-editor legend { padding: 0 0 6px; font-family: var(--font-heading, 'Mitr', sans-serif); font-weight: 600; font-size: 15px; color: #ecdcb4; }
html[data-theme="light"] .side-editor legend { color: #92400e; }
.side-editor legend em { font-style: normal; font-weight: 400; font-size: 13px; color: #b9c4d6; }
html[data-theme="light"] .side-editor legend em { color: #4b5568; }
.side-editor label { display: grid; gap: 5px; font-size: 13px; font-weight: 600; color: #c8d2e2; }
html[data-theme="light"] .side-editor label { color: #3b4960; }
.side-editor input, .side-editor textarea {
  width: 100%; box-sizing: border-box; font: inherit; font-size: 16px; font-weight: 400; line-height: 1.6; padding: 10px 12px; border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2); background: rgba(6, 10, 22, 0.55); color: #f1f5fb; color-scheme: dark;
}
.side-editor textarea { resize: vertical; min-height: 180px; }
.side-editor input:focus, .side-editor textarea:focus { outline: 2px solid #ecdcb4; outline-offset: 1px; border-color: transparent; }
html[data-theme="light"] .side-editor input, html[data-theme="light"] .side-editor textarea { background: #ffffff; border-color: #a9b8cc; color: #142032; color-scheme: light; }
html[data-theme="light"] .side-editor input:focus, html[data-theme="light"] .side-editor textarea:focus { outline-color: #b08a2e; }
.side-row { display: flex; gap: 10px; }
.side-emo-field { flex: 0 0 76px; }
.side-emo-field input { text-align: center; font-size: 20px; }
.side-grow { flex: 1 1 auto; min-width: 0; }
.side-img-pick { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.side-img-prev {
  width: 112px; height: 84px; border-radius: 12px; overflow: hidden; display: grid; place-items: center; align-content: center; gap: 2px;
  border: 1px dashed rgba(226, 201, 143, 0.45); color: #b9c4d6; font-size: 22px;
}
.side-img-prev small { font-size: 12px; }
.side-img-prev img { width: 100%; height: 100%; object-fit: cover; }
html[data-theme="light"] .side-img-prev { border-color: #b08a2e; color: #4b5568; background: #fffdf8; }
.side-img-acts { display: flex; gap: 8px; flex-wrap: wrap; }
.side-form-msg { margin: 0; min-height: 1.4em; font-size: 14px; color: #b9c4d6; }
.side-form-msg[data-tone="ok"] { color: #86efac; }
.side-form-msg[data-tone="warn"] { color: #fcd34d; }
.side-form-msg[data-tone="err"] { color: #fca5a5; }
html[data-theme="light"] .side-form-msg { color: #4b5568; }
html[data-theme="light"] .side-form-msg[data-tone="ok"] { color: #047857; }
html[data-theme="light"] .side-form-msg[data-tone="warn"] { color: #92400e; }
html[data-theme="light"] .side-form-msg[data-tone="err"] { color: #b91c1c; }
.side-editor-acts { display: flex; gap: 10px; flex-wrap: wrap; }

/* toast */
.side-toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 2147483000; max-width: calc(100vw - 32px);
  display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 16px; border-radius: 14px; font-size: 14px; line-height: 1.5;
  background: #0f1729; color: #f1f5fb; border: 1px solid rgba(226, 201, 143, 0.4); box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}
.side-toast[hidden] { display: none; }
.side-toast[data-tone="err"] { border-color: #fca5a5; }
.side-toast-undo { min-height: 36px; padding: 6px 12px; border-radius: 10px; border: 0; cursor: pointer; font: inherit; font-weight: 700; background: linear-gradient(145deg, #ecdcb4, #c9ab6c); color: #2b2212; white-space: nowrap; }

/* phones: bottom sheet */
@media (max-width: 720px) {
  .side-sheet { inset: auto 0 0 0; width: 100vw; height: auto; max-height: 90dvh; }
  .side-sheet-panel { max-height: 90dvh; border-left: 0; border-top: 1px solid rgba(226, 201, 143, 0.3); border-radius: 22px 22px 0 0; box-shadow: 0 -18px 50px rgba(0, 0, 0, 0.45); }
  html[data-theme="light"] .side-sheet-panel { border-top-color: #a9b8cc; }
  .side-sheet[open] .side-sheet-panel { animation-name: sideUp; }
  .side-sheet-grip { display: block; width: 44px; height: 5px; border-radius: 999px; margin: 10px auto 0; background: rgba(255, 255, 255, 0.28); }
  html[data-theme="light"] .side-sheet-grip { background: #c4ccd8; }
  .side-sheet-body { padding: 16px 18px 28px; gap: 16px; }
  .side-rail-list { grid-template-columns: 1fr; }
}
@keyframes sideUp { from { transform: translateY(48px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .side-sheet[open] .side-sheet-panel { animation: none; }
  .side-chip, .side-chip-go { transition: none; }
}
