:root {
  color-scheme: light dark;
  --bg: #fdf7ef;
  --surface: #ffffff;
  --surface-2: #fff4e6;
  --text: #241d16;
  --muted: #6f6357;
  --line: #e8dccd;
  --accent: #d9542b;
  --accent-strong: #b5401f;
  --accent-soft: #ffe4d7;
  --danger: #a3231a;
  --shadow: 0 1px 2px rgba(36, 29, 22, .08), 0 8px 24px rgba(36, 29, 22, .06);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17130f;
    --surface: #211b16;
    --surface-2: #2a221b;
    --text: #f6ece0;
    --muted: #b8a795;
    --line: #3a3028;
    --accent: #ff8a5c;
    --accent-strong: #ffa27d;
    --accent-soft: #3a2418;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 10px 28px rgba(0, 0, 0, .35);
  }
}
body.theme-dark {
  --bg: #17130f; --surface: #211b16; --surface-2: #2a221b; --text: #f6ece0; --muted: #b8a795;
  --line: #3a3028; --accent: #ff8a5c; --accent-strong: #ffa27d; --accent-soft: #3a2418;
}
body.theme-light {
  --bg: #fdf7ef; --surface: #ffffff; --surface-2: #fff4e6; --text: #241d16; --muted: #6f6357;
  --line: #e8dccd; --accent: #d9542b; --accent-strong: #b5401f; --accent-soft: #ffe4d7;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", sans-serif;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.page { padding: 0; }
.app { max-width: 720px; margin: 0 auto; padding: 18px 16px 32px; }
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.title { font-size: 20px; line-height: 1.3; margin: 0; letter-spacing: .01em; }
.title::before { content: "🎭"; margin-right: 8px; }
.chip {
  font-size: 12px; padding: 2px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-strong); white-space: nowrap;
}

.composer {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.field-row { display: flex; gap: 8px; }
.field {
  flex: 1 1 auto; min-width: 0; padding: 11px 12px; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
}
.field:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.field::placeholder { color: var(--muted); opacity: .85; }

button { cursor: pointer; border-radius: 10px; border: 1px solid transparent; padding: 10px 14px; transition: .15s ease; }
button:disabled { opacity: .55; cursor: default; }
.primary { background: var(--accent); color: #fff; font-weight: 600; min-height: 44px; }
.primary:hover:not(:disabled) { background: var(--accent-strong); }
.ghost { background: var(--surface-2); color: var(--text); border-color: var(--line); min-height: 44px; }
.ghost:hover:not(:disabled) { border-color: var(--accent); }
.wide { width: 100%; margin-top: 10px; }
.small { min-height: 36px; padding: 8px 12px; font-size: 13px; }
.link { background: none; border: 0; color: var(--accent-strong); text-decoration: underline; padding: 4px 6px; min-height: 36px; }

.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--accent-soft); color: var(--accent-strong);
  border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; margin-bottom: 12px; font-size: 14px;
}

.result {
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 18px;
}
.result-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.result-setup { margin: 0 0 10px; color: var(--text); white-space: pre-wrap; word-break: break-word; }
.result-punchline {
  margin: 0; font-size: 17px; line-height: 1.65; font-weight: 600; color: var(--accent-strong);
  white-space: pre-wrap; word-break: break-word;
}
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.result-loading { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%, 100% { opacity: .25; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-2px); } }
@media (prefers-reduced-motion: reduce) { .dots i { animation: none; opacity: .7; } }

.history-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.history h2 { font-size: 15px; margin: 0; }
.count { font-size: 12px; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.item {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
}
.item-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.item-theme { font-size: 12px; color: var(--muted); }
.item-setup { margin: 0 0 6px; color: var(--muted); font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.item-punchline { margin: 0; font-weight: 600; white-space: pre-wrap; word-break: break-word; }
.item-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; }
.item-time { font-size: 12px; color: var(--muted); }
.danger { background: none; border: 1px solid var(--line); color: var(--danger); padding: 6px 10px; font-size: 12px; min-height: 32px; }
.empty { color: var(--muted); font-size: 14px; background: var(--surface); border: 1px dashed var(--line); border-radius: 12px; padding: 18px; text-align: center; }
.foot { margin-top: 22px; font-size: 12px; color: var(--muted); text-align: center; }

.boot { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 48px 20px; color: var(--muted); }
.boot.compact { padding: 18px; }
.boot-emoji { font-size: 28px; }
.fatal { padding: 40px 20px; max-width: 520px; margin: 0 auto; text-align: center; }
.fatal-title { font-size: 16px; font-weight: 600; color: var(--text); margin: 0 0 8px; }
.fatal-text { color: var(--muted); margin: 0 0 16px; }

/* Message card (embedded_card) */
.card-page { background: transparent; padding: 0; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: 12px; padding: 12px 14px; margin: 0; overflow: hidden;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card-title { font-size: 13px; font-weight: 600; letter-spacing: .04em; color: var(--muted); }
.card-setup { margin: 0 0 8px; font-size: 14px; color: var(--text); white-space: pre-wrap; word-break: break-word; }
.card-punchline { margin: 0; font-size: 15px; font-weight: 600; color: var(--accent-strong); white-space: pre-wrap; word-break: break-word; }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.card-author { font-size: 12px; color: var(--muted); }
.card-error { margin: 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--muted); font-size: 13px; }
.card-error p { margin: 0 0 8px; }

@media (max-width: 480px) {
  .app { padding: 14px 12px 26px; }
  .field-row { flex-direction: column; }
  .field-row .primary { width: 100%; }
  .result-punchline { font-size: 16px; }
  .title { font-size: 18px; }
  .item-foot { flex-direction: column; align-items: flex-start; }
  .result-actions .ghost, .result-actions .primary { flex: 1 1 140px; }
}
@media (max-width: 360px) {
  .app { padding: 12px 10px 22px; }
  .chip { font-size: 11px; }
}
