:root {
  --paper: #f6f1e7;
  --paper-2: #efe7d8;
  --card: #fffdf8;
  --ink: #1d1a16;
  --ink-2: #4a443b;
  --muted: #8a8174;
  --line: #e2d8c6;
  --line-2: #d3c6af;
  --accent: #e0532c;
  --accent-ink: #b63b18;
  --accent-soft: #fbe3d9;
  --green: #2f6b4f;
  --green-soft: #dcebe1;
  --blue: #2c5aa0;
  --danger: #c0392b;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 8px 24px -12px rgba(40, 30, 10, .18);
  --serif: 'Noto Serif TC', 'Songti TC', serif;
  --sans: 'Noto Sans TC', -apple-system, 'PingFang TC', 'Microsoft JhengHei', sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.65 var(--sans); }
a { color: inherit; }
img, video { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.25; margin: 0; }
em.hl { font-style: normal; font-family: var(--serif); color: var(--accent); }

/* ---------- 按鈕與表單 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--line-2); background: var(--card); color: var(--ink);
  padding: 9px 16px; border-radius: 999px; cursor: pointer; text-decoration: none;
  font-weight: 500; transition: background .15s, border-color .15s, transform .1s; white-space: nowrap;
}
.btn:hover { border-color: var(--ink-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.btn.primary:hover { background: #000; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.accent:hover { background: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--paper-2); }
.btn.sm { padding: 5px 12px; font-size: 13px; }
.btn.lg { padding: 13px 26px; font-size: 16px; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }

.input, .select, .textarea {
  width: 100%; border: 1px solid var(--line-2); background: var(--card); border-radius: var(--radius-sm);
  padding: 9px 12px; outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--ink-2); box-shadow: 0 0 0 3px rgba(224, 83, 44, .12); }
.textarea { resize: vertical; min-height: 90px; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 5px; font-weight: 500; }
.hint { font-size: 12.5px; color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line-2); background: var(--card); border-radius: 999px; padding: 5px 12px;
  cursor: pointer; font-size: 13.5px; transition: all .15s; user-select: none;
}
.chip:hover { border-color: var(--ink-2); }
.chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.badge { display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--paper-2); color: var(--ink-2); font-weight: 500; }
.badge.accent { background: var(--accent-soft); color: var(--accent-ink); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: #f8dcd8; color: var(--danger); }

/* ---------- Toast / Modal ---------- */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 1000; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px; font-size: 14px; box-shadow: var(--shadow); animation: pop .2s ease-out; max-width: 90vw; }
.toast.err { background: var(--danger); }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }
.modal-bg { position: fixed; inset: 0; background: rgba(29, 26, 22, .45); z-index: 900; display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--card); border-radius: var(--radius); width: min(520px, 100%); max-height: 90vh; overflow: auto; padding: 24px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal h3 { font-size: 18px; margin-bottom: 14px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.lightbox { position: fixed; inset: 0; background: rgba(15, 12, 8, .9); z-index: 950; display: flex; align-items: center; justify-content: center; padding: 20px; flex-direction: column; gap: 14px; }
.lightbox img, .lightbox video { max-height: 80vh; max-width: 92vw; border-radius: 8px; }
.lightbox .row .btn { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .25); color: #fff; }

.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--muted); padding: 50px 20px; }
.empty .big { font-family: var(--serif); font-size: 22px; color: var(--ink-2); margin-bottom: 6px; }

/* ---------- Markdown ---------- */
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md pre, .md table, .md blockquote { margin: 0 0 .8em; }
.md h1, .md h2, .md h3, .md h4 { margin: 1.1em 0 .5em; font-size: 1.08em; }
.md h1 { font-size: 1.25em; }
.md ul, .md ol { padding-left: 1.4em; }
.md code { font-family: var(--mono); font-size: .88em; background: var(--paper-2); padding: 1px 5px; border-radius: 5px; }
.md pre { background: #221f1b; color: #f3ede2; padding: 14px 16px; border-radius: 10px; overflow-x: auto; position: relative; }
.md pre code { background: none; padding: 0; color: inherit; font-size: 13px; line-height: 1.55; }
.md pre .copy { position: absolute; top: 6px; right: 6px; font-size: 12px; background: rgba(255, 255, 255, .1); border: 0; color: #ddd; padding: 3px 9px; border-radius: 6px; cursor: pointer; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line-2); padding: 6px 10px; text-align: left; }
.md th { background: var(--paper-2); }
.md blockquote { border-left: 3px solid var(--line-2); padding-left: 12px; color: var(--ink-2); }
.md a { color: var(--accent-ink); }
