/* =====================================================================
   Inspiration Spark — design tokens & components
   Hand-written instead of the Tailwind Play CDN: ~9KB gzipped, zero network
   round-trips, works offline from the first paint. See README "技术选型说明".
   ===================================================================== */

:root {
  color-scheme: light dark;

  --bg:            #f6f7f9;
  --bg-elevated:   #ffffff;
  --bg-sunken:     #eceef2;
  --bg-hover:      #e8eaef;
  --border:        #e2e5ea;
  --border-strong: #cdd2da;
  --text:          #14161a;
  --text-muted:    #6b7280;
  --text-faint:    #9aa1ac;
  --accent:        #5b5bd6;
  --accent-hover:  #4a4ac4;
  --accent-soft:   #ececfb;
  --accent-text:   #ffffff;
  --danger:        #d1383a;
  --danger-soft:   #fdeced;
  --success:       #12805c;

  --radius:    12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
  --shadow:    0 1px 2px rgba(16, 18, 24, .05), 0 4px 16px rgba(16, 18, 24, .05);
  --shadow-lg: 0 8px 40px rgba(16, 18, 24, .14);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
          "Liberation Mono", monospace;
}

:root[data-theme="dark"] {
  --bg:            #0f1115;
  --bg-elevated:   #171a20;
  --bg-sunken:     #1e222a;
  --bg-hover:      #242933;
  --border:        #262b34;
  --border-strong: #363d49;
  --text:          #e7e9ee;
  --text-muted:    #98a0ae;
  --text-faint:    #6d7583;
  --accent:        #7c7cf0;
  --accent-hover:  #8f8ff5;
  --accent-soft:   #22243a;
  --accent-text:   #ffffff;
  --danger:        #f0666b;
  --danger-soft:   #2c1b1e;
  --success:       #3ecf9a;
  --shadow:    0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, .5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            #0f1115;
    --bg-elevated:   #171a20;
    --bg-sunken:     #1e222a;
    --bg-hover:      #242933;
    --border:        #262b34;
    --border-strong: #363d49;
    --text:          #e7e9ee;
    --text-muted:    #98a0ae;
    --text-faint:    #6d7583;
    --accent:        #7c7cf0;
    --accent-hover:  #8f8ff5;
    --accent-soft:   #22243a;
    --danger:        #f0666b;
    --danger-soft:   #2c1b1e;
    --success:       #3ecf9a;
    --shadow:    0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, .5);
  }
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.65;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; padding: 0; }
a { color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.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;
}

.hidden { display: none !important; }

/* --------------------------------------------------------------- layout */
.shell {
  max-width: 780px;
  margin: 0 auto;
  padding: 0 16px 140px;
}

/* --------------------------------------------------------------- header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 780px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  letter-spacing: -.01em;
  margin-right: auto;
}
.brand-mark { font-size: 20px; line-height: 1; }
.brand-text { font-size: 15px; }
@media (max-width: 420px) { .brand-text { display: none; } }

.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------------------------------------------------------- composer */
.composer {
  margin-top: 18px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  transition: border-color .18s, box-shadow .18s;
}
.composer:focus-within {
  border-color: var(--accent);
  box-shadow: var(--shadow), 0 0 0 3px var(--accent-soft);
}

/* Scenario tabs */
.scn-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 8px 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.scn-tabs::-webkit-scrollbar { display: none; }

.scn-tab {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 13.5px;
  color: var(--text-muted);
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.scn-tab:hover { background: var(--bg-hover); color: var(--text); }
.scn-tab[aria-selected="true"] {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 550;
}
.scn-tab-add {
  color: var(--text-faint);
  font-size: 16px;
  padding: 5px 10px;
}

#editor {
  width: 100%;
  min-height: 92px;
  max-height: 45vh;
  padding: 12px 16px 4px;
  border: none;
  background: none;
  resize: none;
  font-size: 16px;      /* ≥16px stops iOS Safari zooming on focus */
  line-height: 1.6;
  outline: none;
}
#editor::placeholder { color: var(--text-faint); }

.composer-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px 10px 16px;
  border-top: 1px solid var(--border);
}
.composer-hint {
  font-size: 12px;
  color: var(--text-faint);
  margin-right: auto;
}
kbd {
  font-family: var(--mono);
  font-size: 11px;
  padding: 1.5px 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--bg-sunken);
}

/* --------------------------------------------------------------- buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 15px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 550;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, opacity .15s, transform .06s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-ghost { color: var(--text-muted); border-color: var(--border); background: var(--bg-elevated); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text); }

.btn-danger { color: var(--danger); border-color: var(--border); background: var(--bg-elevated); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }

.btn-sm { padding: 4px 10px; font-size: 12.5px; border-radius: 7px; }

/* ----------------------------------------------------------- filter bar */
.filters {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 20px 0 12px;
}

.search-wrap { position: relative; flex: 1; min-width: 0; }
.search-wrap svg {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--text-faint); pointer-events: none;
}
#search {
  width: 100%;
  padding: 7px 12px 7px 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
#search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}
.tag-chip {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  background: var(--bg-sunken);
  color: var(--text-muted);
  transition: background .15s, color .15s;
}
.tag-chip:hover { background: var(--bg-hover); color: var(--text); }
.tag-chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
.tag-chip span { opacity: .6; margin-left: 3px; font-size: 11px; }

/* --------------------------------------------------------------- cards */
.timeline { display: flex; flex-direction: column; gap: 12px; }

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: rise .22s ease-out;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .card { animation: none; }
  * { transition-duration: .01ms !important; }
}

.card.is-pinned { border-color: var(--accent); }

.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px 0;
  font-size: 12px;
  color: var(--text-faint);
}
.card-scn {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--text-muted); font-weight: 550;
}
.card-actions { margin-left: auto; display: flex; gap: 2px; }
.card-actions .icon-btn { width: 28px; height: 28px; }
.card-actions .icon-btn svg { width: 15px; height: 15px; }
.card-actions .icon-btn.is-on { color: var(--accent); }

.card-body { padding: 6px 14px 12px; }

/* Minimal markdown rendering */
.md > *:first-child { margin-top: 0; }
.md > *:last-child  { margin-bottom: 0; }
.md p { margin: .5em 0; }
.md h1, .md h2, .md h3 { margin: .9em 0 .4em; font-size: 1em; font-weight: 650; line-height: 1.4; }
.md h1 { font-size: 1.15em; }
.md h2 { font-size: 1.07em; }
.md ul, .md ol { margin: .5em 0; padding-left: 1.35em; }
.md li { margin: .2em 0; }
.md blockquote {
  margin: .6em 0; padding: .1em 0 .1em .9em;
  border-left: 3px solid var(--border-strong); color: var(--text-muted);
}
.md code {
  font-family: var(--mono); font-size: .875em;
  background: var(--bg-sunken); padding: .12em .38em; border-radius: 5px;
}
.md pre {
  background: var(--bg-sunken); padding: 11px 13px; border-radius: var(--radius-sm);
  overflow-x: auto; margin: .6em 0;
}
.md pre code { background: none; padding: 0; font-size: .85em; line-height: 1.55; }
.md hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }
.md a { text-decoration: underline; text-underline-offset: 2px; }
.md strong { font-weight: 650; }
.md .tag-inline { color: var(--accent); font-weight: 550; cursor: pointer; }

.card-editing textarea {
  width: 100%; min-height: 100px; padding: 10px 12px;
  border: 1px solid var(--accent); border-radius: var(--radius-sm);
  background: var(--bg); resize: vertical; outline: none; font-size: 15px;
}

/* Quick action row */
.quick-row {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 0 14px 12px;
}
.quick-btn {
  padding: 4.5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-muted);
  background: var(--bg-elevated);
  transition: background .15s, border-color .15s, color .15s;
}
.quick-btn:hover:not(:disabled) {
  border-color: var(--accent); color: var(--accent); background: var(--accent-soft);
}
.quick-btn:disabled { opacity: .5; cursor: progress; }

/* AI expansion blocks */
.expansions { border-top: 1px solid var(--border); }
.expansion {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--accent-soft) 45%, transparent);
}
.expansion:last-child { border-bottom: none; }

.expansion-head {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--text-muted); margin-bottom: 5px;
}
.expansion-label { font-weight: 600; color: var(--accent); }
.expansion-model { font-family: var(--mono); font-size: 10.5px; color: var(--text-faint); }
.expansion-tools { margin-left: auto; display: flex; gap: 2px; }
.expansion-tools .icon-btn { width: 24px; height: 24px; }
.expansion-tools .icon-btn svg { width: 13px; height: 13px; }

.expansion .md { font-size: 14px; }

/* streaming caret */
.streaming::after {
  content: '';
  display: inline-block;
  width: 7px; height: 1em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background: var(--accent);
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ------------------------------------------------------------ skeleton */
.skeleton {
  height: 92px; border-radius: var(--radius);
  background: linear-gradient(90deg, var(--bg-sunken) 25%, var(--bg-hover) 37%, var(--bg-sunken) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

.empty {
  text-align: center;
  padding: 56px 20px;
  color: var(--text-faint);
}
.empty-icon { font-size: 40px; margin-bottom: 10px; }

/* --------------------------------------------------------------- modal */
.overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(10, 12, 16, .5);
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
  padding: 16px;
  animation: fade .15s ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 100%; max-width: 540px;
  max-height: 88vh; overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.modal-head {
  display: flex; align-items: center;
  padding: 16px 18px 0;
  font-size: 16px; font-weight: 650;
}
.modal-head .icon-btn { margin-left: auto; }
.modal-body { padding: 14px 18px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 0 18px 18px;
}

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.field-hint { font-size: 11.5px; color: var(--text-faint); line-height: 1.5; }
.field input, .field textarea, .field select {
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field textarea { resize: vertical; min-height: 76px; line-height: 1.55; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.field-row .field.narrow { flex: 0 0 84px; }

.action-editor {
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--bg);
}
.action-editor-head {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-muted);
}
.action-editor-head .icon-btn { margin-left: auto; width: 24px; height: 24px; }
.action-editor-head .icon-btn svg { width: 14px; height: 14px; }

.divider { height: 1px; background: var(--border); }

/* --------------------------------------------------------------- toast */
.toasts {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  z-index: 90; display: flex; flex-direction: column; gap: 8px;
  align-items: center; pointer-events: none;
}
.toast {
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-in .2s ease-out;
  max-width: 90vw;
}
.toast.err { background: var(--danger); color: #fff; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px) scale(.96); }
  to   { opacity: 1; transform: none; }
}

/* -------------------------------------------------------------- footer */
.load-more { display: grid; place-items: center; padding: 18px 0 4px; }

/* -------------------------------------------------------- radio cards */
.radio-group { display: flex; flex-direction: column; gap: 8px; }
.radio-card {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--bg);
  cursor: pointer; transition: border-color .15s, background .15s;
}
.radio-card:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.radio-card input[type="radio"] { margin-top: 3px; accent-color: var(--accent); cursor: pointer; }
.radio-content { display: flex; flex-direction: column; gap: 2px; }
.radio-content strong { font-size: 13.5px; color: var(--text); }
.radio-content span { font-size: 12px; color: var(--text-faint); line-height: 1.4; }

/* ---------------------------------------------------- custom prompt */
.custom-prompt-wrap {
  width: 100%;
  display: flex; gap: 6px; align-items: center;
  margin-top: 6px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
  animation: fade .15s ease-out;
}
.custom-prompt-input {
  flex: 1;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-elevated);
  font-size: 13px;
  outline: none;
}
.custom-prompt-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.foot-note {
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
  padding: 26px 0 0;
}
