:root {
  color-scheme: dark;
  --bg: #171317;
  --bg-deep: #100d11;
  --surface: #211a20;
  --surface-raised: #2a2128;
  --surface-soft: #30262e;
  --surface-hover: #382c35;
  --ink: #f7f0ec;
  --ink-soft: #d9cbc8;
  --muted: #ab9ca2;
  --faint: #8f8187;
  --accent: #e58a78;
  --accent-strong: #f29b87;
  --rose: #b45c6c;
  --velvet: #742f47;
  --blush: #dba2a6;
  --lavender: #a99bb8;
  --safe: #9fc5ab;
  --danger: #e47c7c;
  --border: #40343d;
  --border-soft: #342a32;
  --focus: #f3b6a9;
  --shadow: 0 24px 70px rgba(7, 4, 7, 0.4);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --font-display: "Songti SC", SimSun, "Times New Roman", serif;
  --font-body: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --z-nav: 20;
  --z-task: 35;
  --z-sheet: 40;
  --z-toast: 50;
}

* { box-sizing: border-box; }

html { background: var(--bg); scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 84% -8%, rgba(116, 47, 71, 0.28), transparent 34rem),
    radial-gradient(circle at 16% 74%, rgba(169, 155, 184, 0.07), transparent 28rem),
    var(--bg);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button { color: inherit; }
button:not(:disabled) { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
svg { width: 1.25rem; height: 1.25rem; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
h1, h2, h3, p { margin-top: 0; }
h1, h2 { font-family: var(--font-display); font-weight: 600; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.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; }
.skip-link { position: fixed; z-index: 100; top: 8px; left: 8px; padding: 10px 14px; color: var(--bg); background: var(--ink); border-radius: 8px; transform: translateY(-140%); }
.skip-link:focus { transform: translateY(0); }

.app-shell { min-height: 100dvh; }
.app-stage { min-width: 0; }
.desktop-sidebar { display: none; }

.topbar {
  position: sticky;
  z-index: var(--z-nav);
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: calc(68px + env(safe-area-inset-top));
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid rgba(64, 52, 61, 0.74);
  background: rgba(23, 19, 23, 0.88);
  backdrop-filter: blur(18px);
}

.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand-mark { display: grid; width: 38px; height: 38px; place-items: center; color: var(--bg); background: var(--accent); border-radius: 12px 12px 12px 4px; }
.brand-mark svg { width: 21px; height: 21px; stroke-width: 1.9; }
.brand strong, .brand small { display: block; line-height: 1.05; }
.brand strong { font-family: var(--font-display); font-size: 18px; letter-spacing: 0.04em; }
.brand small { margin-top: 4px; color: var(--muted); font-size: 10px; letter-spacing: 0.12em; }

.agent-switcher {
  display: flex;
  min-height: 48px;
  max-width: 210px;
  align-items: center;
  gap: 9px;
  padding: 5px 8px 5px 6px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface);
  transition: border-color 180ms ease, background 180ms ease;
}
.agent-switcher:hover { border-color: #65525f; background: var(--surface-raised); }
.agent-switcher > svg { width: 16px; color: var(--muted); }
.agent-switcher__copy { min-width: 0; text-align: left; }
.agent-switcher small, .agent-switcher strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-switcher small { color: var(--muted); font-size: 10px; }
.agent-switcher strong { max-width: 112px; font-size: 13px; font-weight: 600; }

.avatar { display: grid; flex: 0 0 auto; width: 34px; height: 34px; place-items: center; color: #281b1c; background: #d8a091; border-radius: 50%; font-family: var(--font-display); font-weight: 700; }
.avatar--large { width: 52px; height: 52px; font-size: 20px; }
.avatar--rose { color: #25171e; background: #bd8494; }

main { width: min(100%, 1240px); margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
.view { animation: view-in 260ms var(--ease-out); }
.view[hidden] { display: none; }

.view-intro, .page-header { display: flex; min-height: 44px; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.view-intro h1, .page-header h1 { margin: 0; font-family: var(--font-body); font-size: 22px; font-weight: 700; line-height: 1.25; letter-spacing: -0.01em; }
.view-intro .status-pill { display: inline-flex; }
.context-toggle { display: inline-flex; min-height: 36px; align-items: center; gap: 6px; padding: 6px 10px; color: var(--muted); border: 1px solid var(--border); border-radius: 10px; background: var(--surface); font-size: 12px; white-space: nowrap; transition: color 160ms ease, border-color 160ms ease, background 160ms ease; }
.context-toggle:hover { color: var(--ink); border-color: #6b5864; background: var(--surface-raised); }
.context-toggle:focus-visible { outline: 2px solid var(--rose); outline-offset: 2px; }
.context-toggle svg { width: 14px; height: 14px; transition: transform 180ms var(--ease-out); }
.context-toggle[aria-expanded="true"] { color: #f0c6c8; border-color: rgba(219, 162, 166, 0.3); background: rgba(116, 47, 71, 0.14); }
.context-toggle[aria-expanded="true"] svg { transform: rotate(90deg); }
.eyebrow, .section-kicker { display: block; margin-bottom: 8px; color: var(--accent); font-family: var(--font-mono); font-size: 11px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }

.status-pill { display: inline-flex; min-height: 30px; align-items: center; gap: 6px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 999px; color: var(--ink-soft); background: var(--surface); font-size: 12px; white-space: nowrap; }
.status-pill svg { width: 14px; height: 14px; }
.status-pill--safe { color: #cbe5d2; border-color: rgba(159, 197, 171, 0.28); background: rgba(159, 197, 171, 0.08); }
.status-pill--dynamic { color: #f0c6c8; border-color: rgba(219, 162, 166, 0.3); background: rgba(116, 47, 71, 0.16); }
.status-pill--muted { color: var(--muted); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--safe); box-shadow: 0 0 0 4px rgba(159, 197, 171, 0.09); }

.reply-layout { display: grid; gap: 16px; }
.reply-layout.is-context-collapsed { grid-template-columns: minmax(0, 1fr); }
.context-rail {
  display: grid;
  gap: 0;
  padding: 5px 10px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  background: rgba(33, 26, 32, 0.74);
}
.context-rail[hidden] { display: none; }
.context-step { display: grid; grid-template-columns: 1fr auto; min-height: 52px; align-items: center; gap: 9px; padding: 5px 2px; border-bottom: 1px solid var(--border-soft); transition: background 180ms ease; }
.context-step:last-child { border-bottom: 0; }
.context-step:hover { background: rgba(255, 255, 255, 0.025); }
.context-step small, .context-step strong { display: block; }
.context-step small { margin-bottom: 2px; color: var(--muted); font-size: 11px; }
.context-step strong { font-size: 14px; }
.context-step button, .text-button { min-height: 44px; padding: 8px; border: 0; color: var(--accent); background: transparent; font-size: 13px; }
.context-step button:hover, .text-button:hover { color: var(--accent-strong); }
.context-step--worldbook { align-items: start; padding-top: 10px; padding-bottom: 11px; }
.context-step--worldbook > button { margin-top: -4px; }
.context-step--worldbook .selected-knowledge { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; width: 100%; margin-top: 2px; }
.context-step--worldbook .mini-reference { min-width: 0; min-height: 32px; max-width: 100%; padding: 6px 8px; overflow: hidden; color: var(--ink-soft); border: 1px solid var(--border-soft); border-radius: 9px; background: var(--surface-raised); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.context-step--worldbook .mini-reference span { margin-left: 3px; color: var(--muted); font-family: var(--font-mono); font-size: 8px; }
.context-step--worldbook .mini-reference:hover { color: #f4b0b0; border-color: rgba(228, 124, 124, 0.36); text-decoration: line-through; }
.context-references-empty { color: var(--faint); font-size: 10px; }

.reply-workspace { min-width: 0; }
.composer-card, .settings-card, .toolbar-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: 0 18px 50px rgba(7, 4, 7, 0.13);
}
.composer-card { padding: 15px; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.section-heading--compact { align-items: flex-end; }
.section-heading h2 { margin-bottom: 0; font-family: var(--font-body); font-size: 17px; font-weight: 700; line-height: 1.3; }
.runtime-note { display: block; margin-top: 3px; color: var(--faint); font-size: 10px; font-weight: 400; }
.runtime-note.is-api { color: var(--safe); }
.runtime-note.is-error { color: var(--danger); }
.section-heading .section-kicker { margin-bottom: 4px; }
.heading-actions { display: flex; align-items: center; gap: 4px; }
.input-quick-actions { display: flex; align-items: center; gap: 4px; }
.input-quick-action { display: inline-flex; min-height: 44px; align-items: center; justify-content: center; gap: 5px; padding: 8px 9px; color: var(--ink-soft); border: 1px solid var(--border-soft); border-radius: 10px; background: var(--surface-raised); font-size: 12px; transition: color 180ms ease, border-color 180ms ease, background 180ms ease; }
.input-quick-action:hover:not(:disabled) { color: var(--accent); border-color: #6b5864; background: var(--surface-hover); }
.input-quick-action svg { width: 15px; height: 15px; }
.input-quick-action--clear { color: var(--muted); }
.input-quick-action--clear:hover:not(:disabled) { color: #f4b0b0; border-color: rgba(228, 124, 124, 0.36); background: rgba(228, 124, 124, 0.07); }
.compact-action { display: inline-flex; min-height: 44px; align-items: center; gap: 6px; padding: 8px 10px; border: 1px solid var(--border-soft); border-radius: 11px; color: var(--ink-soft); background: var(--surface-raised); font-size: 12px; white-space: nowrap; }
.compact-action:hover { border-color: #6b5864; background: var(--surface-hover); }
.compact-action svg { width: 16px; height: 16px; color: var(--lavender); }
.text-button--icon { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.text-button--icon svg { width: 15px; height: 15px; }

textarea, input, select { width: 100%; color: var(--ink); border: 1px solid var(--border); background: var(--bg-deep); outline: none; transition: border-color 180ms ease, box-shadow 180ms ease; }
textarea:focus, input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(229, 138, 120, 0.12); }
textarea { resize: vertical; }
.composer-card textarea { min-height: 122px; padding: 16px; border: 0; border-radius: var(--radius-md); font-size: 18px; line-height: 1.65; box-shadow: inset 0 0 0 1px var(--border-soft); }
textarea::placeholder, input::placeholder { color: var(--faint); }
.composer-meta { display: flex; justify-content: space-between; gap: 12px; margin-top: 9px; color: var(--faint); font-family: var(--font-mono); font-size: 10px; }
.intent-block { margin-top: 17px; padding-top: 16px; border-top: 1px solid var(--border-soft); }
.intent-heading { display: flex; min-height: 30px; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.intent-heading label { display: flex; align-items: baseline; gap: 8px; color: var(--ink-soft); }
.intent-heading label strong { font-size: 14px; }
.intent-heading label span { color: var(--faint); font-family: var(--font-mono); font-size: 9px; }
.intent-actions { display: flex; align-items: center; gap: 5px; }
.intent-heading .input-quick-action { min-height: 32px; padding: 5px 8px; font-size: 11px; }
.intent-heading .input-quick-action svg { width: 13px; height: 13px; }
.composer-card .intent-block textarea { min-height: 68px; padding: 12px 13px; font-size: 15px; line-height: 1.55; }
.intent-block.is-active textarea { box-shadow: inset 0 0 0 1px rgba(219, 162, 166, 0.34), 0 0 0 3px rgba(116, 47, 71, 0.08); }

.posture-section { margin: 12px 0 4px; padding: 14px; border: 1px solid var(--border-soft); border-radius: var(--radius-md); background: var(--surface); }
.posture-heading-actions { display: flex; align-items: center; gap: 6px; }
.posture-current { z-index: 1; flex: 0 0 auto; padding: 5px 9px; color: #f0c6c8; border: 1px solid rgba(219, 162, 166, 0.25); border-radius: 999px; background: rgba(116, 47, 71, 0.18); font-family: var(--font-mono); font-size: 9px; }
.posture-config-button { display: inline-flex; min-height: 29px; align-items: center; gap: 4px; padding: 5px 8px; color: var(--muted); border: 1px solid var(--border-soft); border-radius: 9px; background: var(--bg-deep); font-size: 10px; }
.posture-config-button:hover { color: var(--accent); border-color: rgba(229, 138, 120, 0.42); background: var(--surface-raised); }
.posture-config-button svg { width: 13px; height: 13px; }
.posture-scale { display: grid; grid-auto-columns: minmax(78px, 1fr); grid-auto-flow: column; gap: 4px; overflow-x: auto; padding-bottom: 3px; scroll-snap-type: x proximity; scrollbar-width: thin; }
.posture-scale button { display: grid; min-width: 0; min-height: 52px; align-content: center; justify-items: center; padding: 7px 5px; color: var(--muted); border: 1px solid var(--border-soft); border-radius: 9px; background: var(--bg-deep); text-align: center; scroll-snap-align: start; transition: color 180ms ease, border-color 180ms ease, background 180ms ease; }
.posture-scale button:hover { color: var(--ink-soft); background: rgba(255, 255, 255, 0.025); }
.posture-scale button strong { display: block; color: var(--ink-soft); font-size: 10px; line-height: 1.2; overflow-wrap: anywhere; }
.posture-scale button.is-selected { color: var(--ink); border-color: rgba(219, 162, 166, 0.42); background: rgba(116, 47, 71, 0.2); box-shadow: inset 0 -2px 0 var(--rose); }
.posture-scale button.is-selected strong { color: #f4d7d7; }
.posture-note { display: flex; align-items: center; gap: 7px; margin: 10px 2px 0; color: var(--faint); font-size: 10px; }
.posture-note span { flex: 0 0 auto; width: 18px; height: 1px; background: var(--rose); }

.bottom-sheet--posture-definition { max-height: min(84dvh, 720px); }
.posture-definition-intro { margin: -5px 0 12px; color: var(--muted); font-size: 11px; }
.posture-definition-tabs { display: grid; grid-auto-columns: minmax(82px, 1fr); grid-auto-flow: column; gap: 5px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.posture-definition-tabs button { min-height: 42px; padding: 7px 8px; color: var(--muted); border: 1px solid var(--border-soft); border-radius: 10px; background: var(--bg-deep); font-size: 10px; white-space: nowrap; }
.posture-definition-tabs button:hover { color: var(--ink-soft); background: var(--surface-raised); }
.posture-definition-tabs button.is-selected { color: #f4d7d7; border-color: rgba(219, 162, 166, 0.42); background: rgba(116, 47, 71, 0.2); box-shadow: inset 0 -2px 0 var(--rose); }
.posture-definition-editor { margin-top: 10px; padding: 14px; border: 1px solid var(--border-soft); border-radius: 15px; background: var(--bg-deep); }
.posture-definition-editor__heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.posture-definition-editor__heading small, .posture-definition-editor__heading strong { display: block; }
.posture-definition-editor__heading small { color: var(--faint); font-family: var(--font-mono); font-size: 8px; }
.posture-definition-editor__heading strong { margin-top: 2px; color: var(--ink-soft); font-size: 15px; }
.posture-definition-editor__heading > span { color: var(--faint); font-family: var(--font-mono); font-size: 9px; }
.posture-definition-editor__heading > span.is-active { color: var(--safe); }
.posture-definition-editor > label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 10px; font-weight: 700; }
#posture-definition-input { min-height: 168px; padding: 12px 13px; border-radius: 11px; color: var(--ink-soft); font-size: 13px; line-height: 1.65; }
.posture-definition-meta { display: flex; justify-content: space-between; gap: 12px; margin-top: 7px; color: var(--faint); font-family: var(--font-mono); font-size: 8px; }
.posture-definition-meta span:last-child { text-align: right; }

.chip-row, .filter-row, .tag-row { display: flex; flex-wrap: wrap; gap: 8px; }
.filter-chip { min-height: 44px; padding: 9px 16px; border: 1px solid var(--border); border-radius: 999px; color: var(--ink-soft); background: var(--surface); transition: color 180ms ease, border-color 180ms ease, background 180ms ease; }
.filter-chip:hover { border-color: #6b5864; background: var(--surface-raised); }

.length-section { margin: 8px 0 2px; padding: 14px; border: 1px solid var(--border-soft); border-radius: var(--radius-md); background: rgba(33, 26, 32, 0.62); }
.length-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.length-heading .section-kicker { margin-bottom: 3px; }
.length-heading h2 { margin: 0; font-family: var(--font-body); font-size: 17px; font-weight: 700; }
.length-heading > strong { flex: 0 0 auto; color: var(--accent); font-family: var(--font-mono); font-size: 12px; }
.length-presets { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.length-chip { min-width: 0; min-height: 44px; padding: 8px 2px; border: 1px solid var(--border); border-radius: 11px; color: var(--ink-soft); background: var(--bg-deep); font-family: var(--font-mono); font-size: 10px; white-space: nowrap; }
.length-chip:hover { border-color: #6b5864; background: var(--surface-raised); }
.length-chip.is-selected { color: var(--ink); border-color: rgba(229, 138, 120, 0.5); background: rgba(229, 138, 120, 0.09); box-shadow: inset 0 -2px 0 var(--accent); }
.custom-length { display: grid; grid-template-columns: 1fr auto 1fr auto; align-items: end; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border-soft); }
.custom-length[hidden] { display: none; }
.custom-length label { color: var(--muted); font-size: 10px; }
.custom-length input { min-height: 44px; margin-top: 5px; padding: 8px 10px; border-radius: 10px; }
.custom-length > span { align-self: center; padding-top: 14px; color: var(--faint); }

.generate-controls { position: relative; display: grid; grid-template-columns: 72px minmax(0, 1fr); align-items: stretch; gap: 8px; margin-top: 12px; }
.reply-count-control { position: relative; min-width: 0; }
.reply-count-trigger { display: flex; width: 100%; height: 100%; min-height: 60px; align-items: center; justify-content: center; gap: 4px; padding: 8px 7px; color: var(--ink-soft); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); font-family: var(--font-mono); font-size: 10px; font-weight: 700; white-space: nowrap; }
.reply-count-trigger:hover, .reply-count-trigger[aria-expanded="true"] { color: var(--accent); border-color: rgba(229, 138, 120, 0.42); background: var(--surface-raised); }
.reply-count-trigger:focus-visible { outline: 2px solid var(--rose); outline-offset: 2px; }
.reply-count-trigger svg { width: 13px; height: 13px; transition: transform 160ms var(--ease-out); }
.reply-count-trigger[aria-expanded="true"] svg { transform: rotate(180deg); }
.reply-count-menu { position: absolute; z-index: 5; right: 0; bottom: calc(100% + 7px); left: 0; display: grid; gap: 4px; padding: 5px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-raised); box-shadow: var(--shadow); }
.reply-count-menu[hidden] { display: none; }
.reply-count-menu button { min-height: 40px; padding: 7px 4px; color: var(--muted); border: 1px solid transparent; border-radius: 8px; background: transparent; font-family: var(--font-mono); font-size: 10px; }
.reply-count-menu button:hover { color: var(--ink); background: var(--surface-hover); }
.reply-count-menu button.is-selected { color: var(--accent); border-color: rgba(229, 138, 120, 0.3); background: rgba(229, 138, 120, 0.08); }
.generate-button { display: grid; grid-template-columns: auto 1fr auto; width: 100%; min-width: 0; min-height: 60px; align-items: center; gap: 11px; padding: 12px 16px; border: 0; border-radius: var(--radius-md); color: #2b1816; background: var(--accent); box-shadow: 0 12px 30px rgba(180, 92, 108, 0.19); font-weight: 800; text-align: left; transition: filter 180ms ease, transform 180ms var(--ease-out), box-shadow 180ms ease; }
.generate-button:hover { filter: brightness(1.06); box-shadow: 0 15px 38px rgba(180, 92, 108, 0.28); }
.generate-button:active { transform: scale(0.985); }
.generate-button small { max-width: 154px; color: rgba(43, 24, 22, 0.7); font-family: var(--font-mono); font-size: 9px; font-weight: 700; line-height: 1.35; text-align: right; }
.generate-button.is-loading svg { animation: spin 900ms linear infinite; }

.candidate-section { padding-top: 18px; }
.candidate-list { display: grid; gap: 12px; }
.candidate-card { position: relative; overflow: hidden; padding: 19px 18px 16px 24px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.candidate-card::before { position: absolute; inset: 0 auto 0 0; width: 4px; content: ""; background: var(--accent); }
.candidate-card--plum::before { background: var(--rose); }
.candidate-card--lavender::before { background: var(--lavender); }
.candidate-index { margin-bottom: 12px; color: var(--faint); font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.12em; }
.candidate-card p { margin-bottom: 14px; color: var(--ink); font-family: var(--font-display); font-size: 19px; line-height: 1.65; }
.candidate-meta { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 16px; }
.candidate-meta span { padding: 4px 8px; color: var(--muted); border: 1px solid var(--border-soft); border-radius: 999px; font-size: 10px; }
.candidate-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.secondary-button, .primary-button, .copy-button, .danger-button { display: inline-flex; min-height: 44px; align-items: center; justify-content: center; gap: 7px; padding: 9px 14px; border-radius: 12px; font-weight: 700; transition: border-color 180ms ease, background 180ms ease, filter 180ms ease; }
.secondary-button { border: 1px solid var(--border); color: var(--ink-soft); background: var(--surface-raised); }
.secondary-button:hover { border-color: #725c69; background: var(--surface-hover); }
.secondary-button--full { width: 100%; margin-top: 12px; }
.primary-button, .copy-button { border: 1px solid var(--accent); color: #2b1816; background: var(--accent); }
.primary-button:hover, .copy-button:hover { filter: brightness(1.07); }
.danger-button { border: 1px solid rgba(228, 124, 124, 0.42); color: #f4b0b0; background: rgba(228, 124, 124, 0.08); }
.secondary-button svg, .primary-button svg, .copy-button svg, .danger-button svg { width: 17px; height: 17px; }

.bottom-nav { position: fixed; z-index: var(--z-nav); right: 0; bottom: 0; left: 0; display: grid; grid-template-columns: repeat(4, 1fr); min-height: calc(66px + env(safe-area-inset-bottom)); padding: 6px 8px env(safe-area-inset-bottom); border-top: 1px solid var(--border); background: rgba(23, 19, 23, 0.93); backdrop-filter: blur(20px); }
.nav-item { display: flex; min-width: 0; min-height: 50px; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 12px; color: var(--muted); background: transparent; }
.bottom-nav .nav-item { flex-direction: column; gap: 2px; font-size: 10px; }
.nav-item svg { width: 21px; height: 21px; }
.nav-item.is-active { color: var(--accent); background: rgba(229, 138, 120, 0.08); }

.page-header { align-items: center; }
.page-header > .secondary-button, .page-header > .primary-button { flex: 0 0 auto; }
.page-header--simple { margin-bottom: 12px; }
.toolbar-card { display: grid; gap: 10px; padding: 12px; }
.search-field { display: flex; min-height: 48px; align-items: center; gap: 8px; padding: 0 13px; border: 1px solid var(--border); border-radius: 13px; background: var(--bg-deep); }
.search-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(229, 138, 120, 0.12); }
.search-field svg { flex: 0 0 auto; color: var(--muted); }
.search-field input { min-height: 44px; padding: 0; border: 0; background: transparent; box-shadow: none; }
.search-field kbd { display: none; flex: 0 0 auto; min-width: 25px; padding: 3px 6px; color: var(--faint); border: 1px solid var(--border); border-bottom-color: #725f6a; border-radius: 6px; background: var(--surface-raised); font-family: var(--font-mono); font-size: 9px; text-align: center; }
.knowledge-module-tabs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-bottom: 12px; padding: 5px; border: 1px solid var(--border-soft); border-radius: 14px; background: var(--surface); }
.knowledge-module-tab { min-height: 46px; border: 0; border-radius: 10px; color: var(--muted); background: transparent; font-size: 13px; font-weight: 700; transition: color 180ms ease, background 180ms ease, box-shadow 180ms ease; }
.knowledge-module-tab:hover { color: var(--ink-soft); background: rgba(255, 255, 255, 0.025); }
.knowledge-module-tab.is-selected { color: var(--ink); background: var(--surface-soft); box-shadow: inset 0 -2px 0 var(--accent), inset 0 0 0 1px var(--border); }
.knowledge-module[hidden] { display: none; }
.phrase-toolbar { margin-bottom: 10px; }
.phrase-toolbar__actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.phrase-toolbar__actions .secondary-button { min-width: 0; white-space: nowrap; }
.facet-panel { display: grid; gap: 3px; padding: 9px 10px; border: 1px solid var(--border-soft); border-radius: 16px; background: rgba(33, 26, 32, 0.62); }
.facet-row { display: grid; grid-template-columns: 46px minmax(0, 1fr); min-width: 0; align-items: center; gap: 8px; }
.facet-row > strong { color: var(--faint); font-size: 10px; }
.facet-row > div { display: flex; min-width: 0; gap: 5px; overflow-x: auto; padding: 4px 0; scrollbar-width: none; }
.facet-row > div::-webkit-scrollbar { display: none; }
.facet-chip { flex: 0 0 auto; min-height: 44px; padding: 7px 11px; color: var(--muted); border: 1px solid transparent; border-radius: 999px; background: transparent; font-size: 11px; transition: color 180ms ease, border-color 180ms ease, background 180ms ease; }
.facet-chip:hover { color: var(--ink-soft); background: var(--surface-raised); }
.facet-chip.is-selected { color: var(--ink); border-color: var(--border); background: var(--surface-soft); box-shadow: inset 0 -2px 0 var(--rose); }
.facet-chip--strong.is-selected { color: #f3ced0; border-color: rgba(219, 162, 166, 0.34); background: rgba(116, 47, 71, 0.24); }
.library-result-bar { display: flex; min-height: 46px; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-family: var(--font-mono); font-size: 10px; }
.library-result-bar .text-button { font-family: var(--font-body); }
.phrase-library-list { display: grid; gap: 4px; }
.phrase-card { position: relative; overflow: hidden; padding: 7px 8px 8px 11px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface); transition: border-color 180ms ease, background 180ms ease, box-shadow 180ms ease; }
.phrase-card::before { position: absolute; top: 0; bottom: 0; left: 0; width: 2px; content: ""; background: linear-gradient(var(--rose), rgba(116, 47, 71, 0.2)); }
.phrase-card:hover { border-color: #6b5864; background: var(--surface-raised); box-shadow: 0 14px 34px rgba(7, 4, 7, 0.16); }
.phrase-card--new { animation: view-in 240ms var(--ease-out); }
.phrase-card__head { display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: 8px; }
.phrase-card__meta { display: flex; min-width: 0; min-height: 18px; align-items: center; gap: 3px; overflow: hidden; white-space: nowrap; }
.phrase-card__meta span { flex: 0 0 auto; padding: 2px 0; color: var(--muted); border: 0; background: transparent; font-size: 9px; line-height: 1.35; }
.phrase-card__meta span:not(:first-child)::before { margin: 0 5px 0 1px; color: var(--faint); content: "·"; }
.phrase-card__meta .phrase-kind { padding: 2px 7px; color: #efc7c8; border: 1px solid rgba(219, 162, 166, 0.24); border-radius: 999px; background: rgba(116, 47, 71, 0.1); }
.phrase-card__meta .intensity-badge--strong { color: #f2b9bd; }
.phrase-card__actions { display: flex; flex: 0 0 auto; gap: 2px; }
.phrase-card__actions button { display: inline-grid; width: 28px; height: 28px; min-width: 28px; min-height: 28px; padding: 0; place-items: center; color: var(--faint); border: 0; border-radius: 8px; background: transparent; }
.phrase-card__actions button:hover { color: var(--ink); background: var(--surface-soft); }
.phrase-card__actions button:focus-visible { color: var(--ink); outline: 2px solid var(--rose); outline-offset: 1px; }
.phrase-card__actions svg { width: 14px; height: 14px; }
.phrase-card > p { margin: 4px 2px 0; color: var(--ink); font-family: var(--font-display); font-size: clamp(14px, 3.8vw, 16px); line-height: 1.35; overflow-wrap: anywhere; }
.filter-row { margin: 16px 0; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
.filter-row::-webkit-scrollbar { display: none; }
.filter-chip { flex: 0 0 auto; padding: 8px 14px; }
.filter-chip span { margin-left: 4px; color: var(--faint); font-family: var(--font-mono); font-size: 10px; }
.filter-chip.is-selected { color: var(--ink); border-color: #6a5563; background: var(--surface-soft); }

.library-grid, .agent-grid { display: grid; gap: 12px; }
.library-card, .agent-card { padding: 18px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); }
.library-card h2, .agent-card h2 { margin: 14px 0 6px; font-family: var(--font-body); font-size: 18px; font-weight: 700; }
.library-card > p, .agent-card > p { color: var(--muted); font-size: 14px; }
.card-topline, .library-card footer, .agent-card footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.type-label { color: var(--accent); font-family: var(--font-mono); font-size: 10px; font-weight: 700; letter-spacing: 0.08em; }
.citation-label { padding: 4px 8px; color: #efb5aa; border: 1px solid rgba(229, 138, 120, 0.26); border-radius: 999px; font-size: 10px; }
.citation-label--reference { color: #c9bdd5; border-color: rgba(169, 155, 184, 0.27); }
.citation-label--locked { color: #cbe5d2; border-color: rgba(159, 197, 171, 0.28); }
.tag-row { margin-top: 14px; }
.tag-row span { color: var(--muted); font-size: 11px; }
.library-card footer, .agent-card footer { margin-top: 18px; padding-top: 13px; border-top: 1px solid var(--border-soft); color: var(--faint); font-size: 11px; }
.library-card footer button { display: grid; width: 44px; height: 44px; place-items: center; border: 0; color: var(--muted); background: transparent; }
.worldbook-filter-row { margin: 2px 0 4px; }
.worldbook-card { transition: border-color 180ms ease, background 180ms ease, box-shadow 180ms ease; }
.worldbook-card:hover { border-color: #6b5864; background: var(--surface-raised); box-shadow: 0 14px 34px rgba(7, 4, 7, 0.16); }
.worldbook-card.is-referenced { border-color: rgba(229, 138, 120, 0.42); box-shadow: inset 0 0 0 1px rgba(229, 138, 120, 0.06); }
.worldbook-card.is-disabled { opacity: 0.62; }
.worldbook-card.is-disabled:hover { border-color: var(--border); background: var(--surface); box-shadow: none; }
.worldbook-card > p { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 3; }
.worldbook-rule { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; margin-top: 12px; padding: 8px 10px; color: var(--faint); border: 1px solid var(--border-soft); border-radius: 10px; background: var(--bg-deep); font-family: var(--font-mono); font-size: 9px; }
.worldbook-card--new { animation: view-in 240ms var(--ease-out); }
.worldbook-card footer { flex-wrap: wrap; }
.worldbook-card footer > div { display: flex; align-items: center; gap: 6px; }
.worldbook-card footer .text-button { display: inline-flex; width: auto; min-height: 44px; padding: 0 8px; }
.worldbook-card footer .secondary-button { display: inline-flex; width: auto; min-width: 82px; height: auto; min-height: 44px; padding: 0 12px; border: 1px solid var(--border); color: var(--ink-soft); background: var(--surface-raised); }
.worldbook-card footer .secondary-button.is-added { color: #2b1816; border-color: var(--accent); background: var(--accent); }
.worldbook-card footer .secondary-button svg { width: 16px; height: 16px; }
.worldbook-card footer .add-state { min-width: 0; color: inherit; text-align: left; }
.empty-state { padding: 64px 20px; color: var(--muted); text-align: center; }
.empty-state > svg { width: 34px; height: 34px; margin-bottom: 10px; }
.empty-state h2 { margin-bottom: 6px; color: var(--ink); }
.empty-state--sheet { padding: 34px 16px 84px; }

.agent-card { display: flex; flex-direction: column; }
.agent-card.is-current { border-color: rgba(229, 138, 120, 0.48); box-shadow: inset 0 0 0 1px rgba(229, 138, 120, 0.07); }
.agent-card__head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.prompt-preview { margin-top: 16px; padding: 13px; border-left: 2px solid var(--rose); border-radius: 0 12px 12px 0; background: var(--bg-deep); }
.prompt-preview small { display: block; margin-bottom: 5px; color: var(--rose); font-family: var(--font-mono); font-size: 9px; text-transform: uppercase; }
.prompt-preview p { display: -webkit-box; overflow: hidden; margin: 0; color: var(--ink-soft); font-size: 12px; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.agent-card footer { margin-top: auto; }
.agent-card--new { min-height: 180px; align-items: center; justify-content: center; color: var(--ink-soft); border-style: dashed; text-align: center; }
.agent-card--new > span { display: grid; width: 48px; height: 48px; margin-bottom: 12px; place-items: center; color: var(--accent); border: 1px solid var(--border); border-radius: 50%; background: var(--surface-raised); }
.agent-card--new strong, .agent-card--new small { display: block; }
.agent-card--new small { margin-top: 5px; color: var(--muted); font-weight: 400; }

.settings-layout { display: grid; gap: 16px; }
.settings-tabs { display: flex; gap: 5px; overflow-x: auto; padding: 5px; border: 1px solid var(--border-soft); border-radius: 14px; background: var(--surface); scrollbar-width: none; }
.settings-tab { flex: 1 0 auto; min-height: 44px; padding: 9px 12px; border: 0; border-radius: 10px; color: var(--muted); background: transparent; }
.settings-tab.is-selected { color: var(--ink); background: var(--surface-soft); box-shadow: inset 0 0 0 1px var(--border); }
.settings-card { padding: 15px; }
.settings-card__heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.settings-card__heading h2 { margin-bottom: 0; font-family: var(--font-body); font-size: 18px; font-weight: 700; }
.settings-card__heading-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 8px; }
.llm-log-entry { display: inline-flex; min-height: 34px; align-items: center; gap: 6px; padding: 6px 9px; color: var(--ink-soft); border: 1px solid var(--border); border-radius: 9px; background: var(--surface-raised); font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.04em; }
.llm-log-entry:hover { color: var(--accent); border-color: #725c69; background: var(--surface-hover); }
.llm-log-entry svg { width: 14px; height: 14px; }
.llm-log-entry > span { display: grid; min-width: 18px; height: 18px; padding: 0 5px; place-items: center; color: var(--bg); border-radius: 999px; background: var(--accent); font-size: 8px; font-weight: 900; line-height: 1; }
form { display: grid; grid-template-columns: 1fr; gap: 16px; }
.form-field label { display: block; margin-bottom: 7px; color: var(--ink-soft); font-size: 13px; font-weight: 700; }
.form-field input, .form-field textarea { min-height: 48px; padding: 12px 13px; border-radius: 12px; }
.form-field select { min-height: 48px; padding: 0 40px 0 13px; border-radius: 12px; }
.form-field textarea { line-height: 1.65; }
.form-field small { display: block; margin-top: 6px; color: var(--faint); font-size: 11px; }
.password-field { position: relative; }
.password-field input { padding-right: 52px; }
.password-field button { position: absolute; top: 2px; right: 2px; display: grid; width: 44px; height: 44px; place-items: center; border: 0; color: var(--muted); background: transparent; }
.model-picker { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.manual-model-input { margin-top: 8px; }
.manual-model-input[hidden] { display: none; }
.api-tuning-grid { display: grid; gap: 16px; }
.range-input { min-height: 48px !important; padding: 0 !important; border: 0; accent-color: var(--accent); box-shadow: none !important; }
.form-field output { float: right; min-width: 42px; color: var(--accent); font-family: var(--font-mono); text-align: right; }
.form-actions { display: flex; justify-content: flex-end; gap: 9px; }
.form-actions .danger-button[hidden] { display: none; }
.form-feedback { margin: 0; padding: 10px 12px; color: var(--muted); border: 1px solid var(--border-soft); border-radius: 11px; background: var(--bg-deep); font-size: 12px; }
.form-feedback.is-success { color: #cbe5d2; border-color: rgba(159, 197, 171, 0.28); }
.form-feedback.is-error { color: #ffc0c0; border-color: rgba(228, 124, 124, 0.3); }
.data-actions { display: flex; flex-wrap: wrap; gap: 9px; padding: 14px 0; border-top: 1px solid var(--border-soft); }
.knowledge-editor-mode { display: grid; grid-column: 1 / -1; gap: 16px; }
.knowledge-editor-mode[hidden], .knowledge-worldbook-editor[hidden], #knowledge-worldbook-keys-field[hidden] { display: none; }
.knowledge-phrase-fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.knowledge-phrase-fields label { color: var(--ink-soft); font-size: 13px; font-weight: 700; }
.knowledge-phrase-fields select { width: 100%; min-height: 48px; margin-top: 7px; padding: 0 12px; border-radius: 12px; }
.knowledge-worldbook-editor { gap: 12px; }
.worldbook-editor-section { display: grid; gap: 13px; padding: 14px; border: 1px solid var(--border-soft); border-radius: 15px; background: var(--bg-deep); }
.worldbook-editor-section__heading { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.worldbook-editor-section__heading strong { color: var(--ink); font-size: 14px; }
.worldbook-editor-section__heading span { color: var(--faint); font-family: var(--font-mono); font-size: 9px; }
.worldbook-editor-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.worldbook-editor-grid--control { grid-template-columns: minmax(0, 1fr) minmax(120px, 0.55fr); }
.worldbook-enabled-row { grid-column: 1 / -1; display: flex; min-height: 62px; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 0 0; border-top: 1px solid var(--border-soft); }
.worldbook-enabled-row strong, .worldbook-enabled-row small { display: block; }
.worldbook-enabled-row strong { font-size: 13px; }
.worldbook-enabled-row small { margin-top: 3px; color: var(--faint); font-size: 10px; }
.form-inline-error { margin: 0; padding: 10px 12px; color: #ffc0c0; border: 1px solid rgba(228, 124, 124, 0.3); border-radius: 11px; background: rgba(228, 124, 124, 0.06); font-size: 12px; }
.notice-card { display: flex; gap: 12px; margin-top: 13px; padding: 15px; border: 1px solid rgba(159, 197, 171, 0.2); border-radius: var(--radius-md); background: rgba(159, 197, 171, 0.055); }
.notice-card > svg { flex: 0 0 auto; margin-top: 2px; color: var(--safe); }
.notice-card strong { display: block; margin-bottom: 4px; }
.notice-card p { margin: 0; color: var(--muted); font-size: 12px; }
.prompt-builder { grid-column: 1 / -1; padding: 15px; border: 1px solid var(--border-soft); border-radius: 15px; background: var(--bg-deep); }
.prompt-builder__heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.prompt-builder__heading strong { display: block; }
.prompt-builder__heading p { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.prompt-builder__heading > span { flex: 0 0 auto; color: var(--faint); font-size: 10px; }
.prompt-layer-list { display: grid; gap: 6px; margin: 6px 0; }
.prompt-layer { display: grid; grid-template-columns: 28px 1fr auto; min-height: 58px; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border-soft); border-radius: 12px; background: var(--surface); }
.prompt-layer > svg { width: 18px; height: 18px; color: var(--safe); }
.prompt-layer > div > strong, .prompt-layer > div > small { display: block; }
.prompt-layer > div > strong { font-size: 13px; }
.prompt-layer > div > small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.order-index { display: grid; width: 26px; height: 26px; place-items: center; color: var(--muted); border: 1px solid var(--border); border-radius: 50%; font-family: var(--font-mono); font-size: 9px; }
.prompt-layer--task-fixed { grid-template-columns: 28px 20px 1fr auto; color: var(--ink-soft); background: rgba(159, 197, 171, 0.045); }
.prompt-layer--task { background: rgba(229, 138, 120, 0.05); }
.prompt-layer--task > svg { color: var(--accent); }
.fixed-label { color: var(--muted); font-size: 9px; white-space: nowrap; }
.layer-actions { display: flex; gap: 4px; }
.layer-actions button { display: grid; width: 40px; height: 40px; place-items: center; border: 1px solid var(--border-soft); border-radius: 9px; color: var(--muted); background: var(--surface-raised); }
.layer-actions button:hover:not(:disabled) { color: var(--accent); border-color: #6b5864; }
.layer-actions button svg { width: 15px; height: 15px; }
.preference-row, .danger-zone { display: flex; min-height: 78px; align-items: center; justify-content: space-between; gap: 18px; padding: 15px 0; border-top: 1px solid var(--border-soft); }
.preference-row:first-of-type { border-top: 0; }
.preference-row strong, .danger-zone strong { display: block; }
.preference-row p, .danger-zone p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.switch { position: relative; flex: 0 0 auto; min-width: 52px; min-height: 44px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch > span:not(.sr-only) { position: absolute; top: 8px; right: 0; width: 48px; height: 28px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-soft); transition: background 180ms ease; }
.switch > span:not(.sr-only)::after { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; content: ""; background: var(--muted); border-radius: 50%; transition: transform 180ms var(--ease-out), background 180ms ease; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { background: #2b1816; transform: translateX(20px); }
.switch input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 3px; }
.danger-zone { margin-top: 12px; padding: 16px; border: 1px solid rgba(228, 124, 124, 0.18); border-radius: 14px; background: rgba(228, 124, 124, 0.04); }

.sheet-layer { position: fixed; z-index: var(--z-sheet); inset: 0; }
.sheet-layer[hidden] { display: none; }
.sheet-scrim { position: absolute; inset: 0; width: 100%; border: 0; background: rgba(7, 4, 7, 0.65); backdrop-filter: blur(4px); }
.bottom-sheet { position: absolute; right: 0; bottom: 0; left: 0; max-height: min(84dvh, 760px); overflow-y: auto; padding: 8px 16px calc(18px + env(safe-area-inset-bottom)); border: 1px solid var(--border); border-bottom: 0; border-radius: 26px 26px 0 0; background: var(--surface); box-shadow: var(--shadow); animation: sheet-in 260ms var(--ease-out); }
.bottom-sheet--compact { max-height: min(68dvh, 560px); }
.bottom-sheet--editor { max-height: 92dvh; }
.bottom-sheet--llm-log { max-height: 92dvh; }
.sheet-handle { width: 42px; height: 4px; margin: 2px auto 12px; background: #62545c; border-radius: 999px; }
.sheet-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 15px; }
.sheet-header h2 { margin-bottom: 0; font-family: var(--font-body); font-size: 20px; font-weight: 700; }
.icon-button { display: grid; flex: 0 0 auto; width: 44px; height: 44px; place-items: center; border: 1px solid var(--border); border-radius: 12px; color: var(--muted); background: var(--surface-raised); }
.filter-row--sheet { margin: 12px 0; }
.sheet-list { display: grid; gap: 8px; }
.sheet-item, .agent-option { display: grid; width: 100%; min-height: 70px; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--border-soft); border-radius: 14px; background: var(--bg-deep); text-align: left; }
.sheet-item { grid-template-columns: 1fr auto; }
.sheet-item strong, .sheet-item small, .agent-option strong, .agent-option small { display: block; }
.sheet-item small, .agent-option small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.sheet-item.is-added { border-color: rgba(229, 138, 120, 0.38); background: rgba(229, 138, 120, 0.055); }
.sheet-item:disabled { opacity: 0.5; }
.phrase-picker-list { margin-top: 12px; }
.phrase-picker-facets { margin-top: 10px; }
.phrase-picker-item { grid-template-columns: minmax(0, 1fr) auto; min-height: 62px; }
.phrase-picker-item[hidden] { display: none; }
.phrase-picker-item strong { overflow: hidden; color: var(--ink-soft); font-family: var(--font-display); font-size: 15px; font-weight: 500; line-height: 1.5; text-overflow: ellipsis; white-space: nowrap; }
.phrase-picker-item > span:last-child { color: var(--accent); font-size: 11px; white-space: nowrap; }
.phrase-picker-item:hover { border-color: rgba(229, 138, 120, 0.38); background: rgba(229, 138, 120, 0.055); }
.add-state { min-width: 58px; color: var(--accent); font-size: 12px; text-align: right; }
.sheet-footer { position: sticky; bottom: calc(-18px - env(safe-area-inset-bottom)); display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 14px -16px calc(-18px - env(safe-area-inset-bottom)); padding: 12px 16px calc(18px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: rgba(33, 26, 32, 0.96); backdrop-filter: blur(16px); }
.sheet-footer > span { color: var(--muted); font-size: 12px; }
.sheet-footer > div { display: flex; gap: 8px; }
.llm-log-overview { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin-bottom: 10px; }
.llm-log-overview > div { min-width: 0; padding: 9px 10px; border: 1px solid var(--border-soft); border-radius: 10px; background: var(--bg-deep); }
.llm-log-overview small, .llm-log-overview strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.llm-log-overview small { margin-bottom: 3px; color: var(--faint); font-family: var(--font-mono); font-size: 8px; letter-spacing: 0.08em; text-transform: uppercase; }
.llm-log-overview strong { color: var(--ink-soft); font-size: 11px; }
.llm-log-status.is-success { color: var(--safe); }
.llm-log-status.is-error { color: #ef9999; }
.llm-log-status.is-running { color: var(--accent); }
.llm-log-status.is-empty { color: var(--muted); }
.llm-log-history-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: -2px 2px 7px; color: var(--faint); font-family: var(--font-mono); font-size: 9px; }
.llm-log-history-heading strong { color: var(--muted); font-weight: 700; }
.llm-log-history { display: grid; grid-auto-columns: minmax(164px, 190px); grid-auto-flow: column; gap: 7px; overflow-x: auto; padding: 0 1px 9px; scroll-snap-type: x proximity; scrollbar-width: thin; }
.llm-log-history__item { display: grid; min-width: 0; min-height: 56px; grid-template-columns: 27px minmax(0, 1fr); gap: 8px; align-items: center; padding: 8px; color: var(--muted); border: 1px solid var(--border-soft); border-radius: 11px; background: var(--bg-deep); text-align: left; scroll-snap-align: start; }
.llm-log-history__item:hover { color: var(--ink-soft); border-color: var(--border); background: var(--surface-soft); }
.llm-log-history__item.is-selected { color: var(--ink); border-color: rgba(229, 138, 120, 0.46); background: rgba(229, 138, 120, 0.08); box-shadow: inset 0 -2px 0 rgba(229, 138, 120, 0.55); }
.llm-log-history__index { display: grid; width: 27px; height: 27px; place-items: center; color: var(--faint); border: 1px solid var(--border-soft); border-radius: 8px; font-family: var(--font-mono); font-size: 8px; }
.llm-log-history__item.is-running .llm-log-history__index { color: var(--accent); border-color: rgba(229, 138, 120, 0.3); }
.llm-log-history__item.is-success .llm-log-history__index { color: var(--safe); border-color: rgba(159, 197, 171, 0.25); }
.llm-log-history__item.is-error .llm-log-history__index { color: #ef9999; border-color: rgba(228, 124, 124, 0.28); }
.llm-log-history__copy { min-width: 0; }
.llm-log-history__copy strong, .llm-log-history__copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.llm-log-history__copy strong { color: inherit; font-size: 10px; }
.llm-log-history__copy small { margin-top: 3px; color: var(--faint); font-family: var(--font-mono); font-size: 8px; }
.llm-log-history__empty { grid-column: 1; min-width: min(100%, 260px); padding: 16px; color: var(--faint); border: 1px dashed var(--border-soft); border-radius: 11px; font-size: 10px; text-align: center; }
.llm-log-tabs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; padding: 4px; border: 1px solid var(--border-soft); border-radius: 11px; background: var(--bg-deep); }
.llm-log-tabs button { min-height: 38px; padding: 7px 10px; color: var(--muted); border: 0; border-radius: 8px; background: transparent; font-size: 11px; font-weight: 700; }
.llm-log-tabs button.is-selected { color: var(--ink); background: var(--surface-soft); box-shadow: inset 0 0 0 1px var(--border); }
.llm-log-viewer { margin-top: 10px; overflow: hidden; border: 1px solid var(--border-soft); border-radius: 14px; background: #0e0b0f; }
.llm-log-viewer__heading { display: flex; min-height: 52px; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 10px 8px 13px; border-bottom: 1px solid var(--border-soft); background: var(--bg-deep); }
.llm-log-viewer__heading small, .llm-log-viewer__heading strong { display: block; }
.llm-log-viewer__heading small { color: var(--accent); font-family: var(--font-mono); font-size: 8px; letter-spacing: 0.1em; }
.llm-log-viewer__heading strong { margin-top: 2px; color: var(--ink-soft); font-size: 12px; }
.llm-log-viewer__heading .text-button { display: inline-flex; min-height: 34px; align-items: center; gap: 5px; padding: 6px 8px; }
.llm-log-viewer__heading .text-button svg { width: 14px; height: 14px; }
#llm-log-content { min-height: 280px; max-height: min(46dvh, 440px); margin: 0; overflow: auto; padding: 14px; color: #d8ccd4; background: #0e0b0f; font-family: var(--font-mono); font-size: 10px; line-height: 1.65; overflow-wrap: anywhere; tab-size: 2; white-space: pre-wrap; }
.llm-log-note { margin: 9px 2px 0; color: var(--faint); font-size: 9px; }
.phrase-retag-card { display: grid; gap: 14px; padding: 15px; border: 1px solid var(--border-soft); border-radius: 16px; background: var(--bg-deep); }
.phrase-retag-card > p { margin: 0; color: var(--ink-soft); font-size: 13px; line-height: 1.6; }
.phrase-retag-taxonomy { display: flex; flex-wrap: wrap; gap: 6px; }
.phrase-retag-taxonomy span { padding: 6px 9px; color: #efc7c8; border: 1px solid rgba(219, 162, 166, 0.24); border-radius: 999px; background: rgba(116, 47, 71, 0.1); font-size: 10px; }
.phrase-retag-preserve { display: flex; align-items: flex-start; gap: 8px; padding: 10px 11px; color: var(--muted); border: 1px solid rgba(159, 197, 171, 0.2); border-radius: 11px; background: rgba(159, 197, 171, 0.05); font-size: 11px; line-height: 1.5; }
.phrase-retag-preserve svg { flex: 0 0 auto; width: 15px; height: 15px; margin-top: 1px; color: var(--safe); }
.phrase-retag-progress { display: grid; gap: 8px; }
.phrase-retag-progress > div:first-child { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.phrase-retag-progress strong { color: var(--ink-soft); font-size: 12px; }
.phrase-retag-progress > div:first-child span { color: var(--faint); font-family: var(--font-mono); font-size: 10px; }
.phrase-retag-track { height: 7px; overflow: hidden; border-radius: 999px; background: var(--surface-soft); }
.phrase-retag-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--rose), var(--accent)); transition: width 220ms var(--ease-out); }
.agent-option { grid-template-columns: auto 1fr auto; }
.agent-option > svg { opacity: 0; color: var(--accent); }
.agent-option.is-selected { border-color: rgba(229, 138, 120, 0.38); }
.agent-option.is-selected > svg { opacity: 1; }

.bottom-sheet--import { max-height: min(92dvh, 900px); }
.import-result-dialog { width: min(420px, calc(100% - 32px)); max-width: none; padding: 0; color: var(--ink); border: 1px solid var(--border); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); }
.import-result-dialog::backdrop { background: rgba(7, 4, 7, 0.72); backdrop-filter: blur(5px); }
.import-result-dialog[open] { animation: result-dialog-in 220ms var(--ease-out); }
.import-result-card { display: block; padding: 20px; }
.import-result-heading { display: flex; align-items: center; gap: 12px; }
.import-result-heading small, .import-result-heading h2 { display: block; }
.import-result-heading small { margin-bottom: 3px; color: var(--safe); font-family: var(--font-mono); font-size: 9px; letter-spacing: 0.05em; }
.import-result-heading h2 { margin: 0; font-family: var(--font-body); font-size: 20px; line-height: 1.3; }
.import-result-icon { display: grid; flex: 0 0 auto; width: 44px; height: 44px; place-items: center; color: var(--safe); border: 1px solid rgba(159, 197, 171, 0.3); border-radius: 14px; background: rgba(159, 197, 171, 0.08); }
.import-result-icon svg { width: 22px; height: 22px; }
.import-result-summary { margin: 16px 0 0; color: var(--ink-soft); font-size: 14px; font-weight: 700; line-height: 1.55; }
.import-result-details { margin: 9px 0 0; padding: 11px 12px; overflow-wrap: anywhere; color: var(--muted); border: 1px solid var(--border-soft); border-radius: 12px; background: var(--bg-deep); font-size: 12px; line-height: 1.6; }
.import-result-details[hidden] { display: none; }
.import-result-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.import-result-actions button[hidden] { display: none; }
.import-result-dialog.is-error .import-result-heading small, .import-result-dialog.is-error .import-result-icon { color: #ffc0c0; }
.import-result-dialog.is-error .import-result-icon { border-color: rgba(228, 124, 124, 0.34); background: rgba(228, 124, 124, 0.08); }
@keyframes result-dialog-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
.import-flow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: -2px 0 14px; }
.import-flow span { position: relative; min-width: 0; padding: 8px 6px; color: var(--faint); border-bottom: 2px solid var(--border-soft); font-family: var(--font-mono); font-size: 9px; text-align: center; }
.import-flow span.is-current { color: var(--accent); border-color: var(--accent); }
.import-section, .import-preview { margin-top: 10px; padding: 14px; border: 1px solid var(--border-soft); border-radius: 16px; background: var(--bg-deep); }
.import-section__heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 11px; }
.import-section__heading small, .import-section__heading strong { display: block; }
.import-section__heading small { margin-bottom: 2px; color: var(--faint); font-family: var(--font-mono); font-size: 9px; }
.import-section__heading strong { color: var(--ink-soft); font-size: 14px; }
.import-section__heading > span { color: var(--accent); font-family: var(--font-mono); font-size: 10px; white-space: nowrap; }
.source-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.source-toggle button { display: inline-flex; min-height: 44px; align-items: center; justify-content: center; gap: 6px; padding: 8px; color: var(--muted); border: 1px solid var(--border); border-radius: 11px; background: var(--surface); }
.source-toggle button.is-selected { color: var(--ink); border-color: rgba(229, 138, 120, 0.5); background: rgba(229, 138, 120, 0.08); }
.source-toggle svg { width: 15px; height: 15px; }
.import-file-state { margin: 8px 2px; color: var(--faint); font-size: 10px; }
#import-source { min-height: 172px; padding: 12px 13px; border-radius: 12px; font-size: 13px; line-height: 1.65; }
.import-settings-grid { display: grid; gap: 13px; }
.import-select { color: var(--muted); font-size: 11px; font-weight: 700; }
.import-select select { min-height: 46px; margin-top: 6px; padding: 0 38px 0 12px; border-radius: 11px; }
.split-options { margin: 0; padding: 0; border: 0; }
.split-options legend { margin-bottom: 7px; color: var(--muted); font-size: 11px; font-weight: 700; }
.split-options > div { display: flex; flex-wrap: wrap; gap: 6px; }
.split-chip { min-height: 44px; padding: 7px 10px; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; background: var(--surface); font-size: 11px; }
.split-chip.is-selected { color: var(--ink); border-color: rgba(169, 155, 184, 0.5); background: rgba(169, 155, 184, 0.1); }
.redact-option { display: flex; min-height: 58px; align-items: flex-start; gap: 10px; margin-top: 13px; padding: 11px; border: 1px solid rgba(159, 197, 171, 0.18); border-radius: 12px; background: rgba(159, 197, 171, 0.045); cursor: pointer; }
.redact-option input { flex: 0 0 auto; width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--safe); }
.redact-option strong, .redact-option small { display: block; }
.redact-option strong { color: var(--ink-soft); font-size: 12px; }
.redact-option small { margin-top: 3px; color: var(--faint); font-size: 10px; }
.auto-taxonomy { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-top: 13px; }
.auto-taxonomy > div { min-width: 0; padding: 10px; border: 1px solid var(--border-soft); border-radius: 11px; background: var(--surface); }
.auto-taxonomy small, .auto-taxonomy strong { display: block; }
.auto-taxonomy small { color: var(--faint); font-family: var(--font-mono); font-size: 8px; }
.auto-taxonomy strong { margin-top: 4px; color: var(--ink-soft); font-size: 9px; font-weight: 600; line-height: 1.45; }
.import-ai-note { display: flex; align-items: flex-start; gap: 8px; margin: 10px 2px 0; color: var(--muted); font-size: 10px; line-height: 1.55; }
.import-ai-note svg { flex: 0 0 auto; width: 15px; height: 15px; margin-top: 1px; color: var(--lavender); }
.import-feedback { margin-top: 10px; }
.analyze-import { width: 100%; margin-top: 12px; }
.analyze-import.is-loading svg { animation: spin 900ms linear infinite; }
.import-preview[hidden] { display: none; }
.import-candidate-list { display: grid; gap: 9px; }
.import-candidate { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; padding: 12px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface); }
.import-candidate-check-wrap { display: grid; width: 44px; height: 44px; place-items: center; margin: -1px 0 0 -7px; cursor: pointer; }
.import-candidate-check-wrap input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }
.import-candidate__body { min-width: 0; }
.import-candidate__body > input { min-height: 40px; padding: 8px 10px; border: 0; border-radius: 9px; background: var(--surface-raised); font-weight: 700; }
.import-candidate__eyebrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 7px; color: var(--faint); font-family: var(--font-mono); font-size: 8px; }
.import-candidate__eyebrow span:last-child { color: var(--safe); }
.import-candidate__fields { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: 7px; margin-top: 7px; }
.import-candidate__fields--taxonomy { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.import-candidate__fields label, .import-candidate__type-row label { min-width: 0; color: var(--faint); font-size: 8px; }
.import-candidate__fields select, .import-candidate__fields input, .import-candidate__type-row select { min-width: 0; min-height: 44px; margin-top: 4px; padding: 7px 27px 7px 8px; border-radius: 9px; color: var(--muted); font-size: 10px; }
.import-candidate__type-row { margin-top: 7px; }
.import-candidate__type-row select { width: 100%; }
.import-candidate__body textarea { min-height: 72px; margin-top: 7px; padding: 9px 10px; border-radius: 9px; color: var(--ink-soft); font-size: 11px; line-height: 1.55; }
.import-candidate__meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.import-candidate__meta span { padding: 3px 7px; color: var(--faint); border: 1px solid var(--border-soft); border-radius: 999px; font-family: var(--font-mono); font-size: 8px; }

.bottom-sheet--history { max-height: min(90dvh, 820px); }
.history-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.history-summary > div { padding: 12px; border: 1px solid var(--border-soft); border-radius: 12px; background: var(--bg-deep); }
.history-summary small, .history-summary strong { display: block; }
.history-summary small { color: var(--muted); font-size: 10px; }
.history-summary strong { margin-top: 4px; font-family: var(--font-mono); font-size: 12px; }
.history-range { margin: 0; padding: 13px; border: 1px solid var(--border); border-radius: 14px; }
.history-range legend { padding: 0 6px; color: var(--ink-soft); font-size: 12px; font-weight: 700; }
.history-range > div { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.history-range button { min-height: 44px; padding: 8px 4px; border: 1px solid var(--border-soft); border-radius: 10px; color: var(--muted); background: var(--surface-raised); font-family: var(--font-mono); font-size: 11px; }
.history-range button.is-selected { color: #2b1816; border-color: var(--accent); background: var(--accent); font-weight: 800; }
.history-range > small { display: block; margin-top: 8px; color: var(--faint); font-size: 10px; }
.history-boundary { display: flex; align-items: center; gap: 8px; margin: 15px 0 11px; color: var(--faint); font-family: var(--font-mono); font-size: 9px; white-space: nowrap; }
.history-boundary span { width: 100%; height: 1px; background: var(--border); }
.conversation-preview { display: grid; gap: 8px; padding-bottom: 4px; }
.conversation-time { margin: 2px 0; color: var(--faint); font-family: var(--font-mono); font-size: 9px; text-align: center; }
.chat-row { display: flex; flex-direction: column; align-items: flex-start; }
.chat-row--me { align-items: flex-end; }
.chat-row > span { margin: 0 5px 3px; color: var(--faint); font-size: 9px; }
.chat-bubble { position: relative; max-width: 82%; }
.chat-row p { margin: 0; padding: 10px 38px 10px 12px; border: 1px solid var(--border-soft); border-radius: 13px 13px 13px 4px; color: var(--ink-soft); background: var(--bg-deep); font-size: 13px; overflow-wrap: anywhere; }
.chat-row--me p { border-radius: 13px 13px 4px 13px; background: rgba(180, 92, 108, 0.1); }
.chat-delete-button { position: absolute; top: 5px; right: 5px; display: inline-grid; width: 28px; height: 28px; min-width: 28px; min-height: 28px; padding: 0; place-items: center; color: var(--faint); border: 0; border-radius: 8px; background: transparent; opacity: 0.68; transition: color 160ms ease, background 160ms ease, opacity 160ms ease; }
.chat-delete-button:hover { color: #f2b9bd; background: rgba(116, 47, 71, 0.2); opacity: 1; }
.chat-delete-button:focus-visible { color: #f2b9bd; outline: 2px solid var(--rose); outline-offset: 1px; opacity: 1; }
.chat-delete-button svg { width: 13px; height: 13px; }

.background-task-orb { position: fixed; z-index: var(--z-task); right: 16px; bottom: calc(82px + env(safe-area-inset-bottom)); display: grid; width: 54px; height: 54px; padding: 0; place-items: center; color: var(--accent); border: 1px solid rgba(229, 138, 120, 0.42); border-radius: 50%; background: rgba(42, 33, 40, 0.96); box-shadow: 0 14px 34px rgba(7, 4, 7, 0.48), inset 0 0 0 4px rgba(229, 138, 120, 0.05); backdrop-filter: blur(16px); transition: transform 160ms ease, border-color 160ms ease, background 160ms ease; }
.background-task-orb[hidden] { display: none; }
.background-task-orb:hover { transform: translateY(-2px); border-color: rgba(242, 155, 135, 0.78); background: var(--surface-raised); }
.background-task-orb::before { position: absolute; inset: -3px; content: ""; border: 2px solid transparent; border-top-color: var(--accent); border-right-color: rgba(229, 138, 120, 0.22); border-radius: inherit; opacity: 0; }
.background-task-orb.is-running::before { opacity: 1; animation: task-orb-spin 1.2s linear infinite; }
.background-task-orb.is-running { animation: task-orb-breathe 2.2s ease-in-out infinite; }
.background-task-orb.is-success { color: var(--safe); border-color: rgba(159, 197, 171, 0.45); }
.background-task-orb.is-error { color: #ffc0c0; border-color: rgba(228, 124, 124, 0.55); }
.background-task-orb.is-paused { color: var(--accent); border-color: rgba(229, 138, 120, 0.62); }
.background-task-orb__core { display: grid; width: 38px; height: 38px; place-items: center; border-radius: 50%; background: rgba(229, 138, 120, 0.09); }
.background-task-orb.is-success .background-task-orb__core { background: rgba(159, 197, 171, 0.09); }
.background-task-orb.is-error .background-task-orb__core { background: rgba(228, 124, 124, 0.09); }
.background-task-orb.is-paused .background-task-orb__core { background: rgba(229, 138, 120, 0.12); }
.background-task-orb__core svg { width: 19px; height: 19px; }
.background-task-orb__badge { position: absolute; top: -4px; right: -4px; display: grid; min-width: 20px; height: 20px; padding: 0 5px; place-items: center; color: #21171b; border: 2px solid var(--bg); border-radius: 999px; background: var(--accent-strong); font-family: var(--font-mono); font-size: 9px; font-weight: 800; line-height: 1; }
.background-task-orb.is-success .background-task-orb__badge { background: var(--safe); }
.background-task-orb.is-error .background-task-orb__badge { background: #ef9999; }
.bottom-sheet--tasks { max-height: min(76dvh, 660px); }
.background-task-summary { margin: -5px 0 12px; color: var(--muted); font-size: 12px; }
.background-task-list { display: grid; gap: 9px; }
.background-task-card { position: relative; display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 12px; border: 1px solid var(--border-soft); border-radius: 14px; background: var(--bg-deep); }
.background-task-card.is-unread { border-color: rgba(229, 138, 120, 0.38); box-shadow: inset 3px 0 0 var(--accent); }
.background-task-card__icon { display: grid; width: 38px; height: 38px; place-items: center; color: var(--accent); border: 1px solid rgba(229, 138, 120, 0.2); border-radius: 12px; background: rgba(229, 138, 120, 0.07); }
.background-task-card.is-success .background-task-card__icon { color: var(--safe); border-color: rgba(159, 197, 171, 0.22); background: rgba(159, 197, 171, 0.07); }
.background-task-card.is-error .background-task-card__icon { color: #ffc0c0; border-color: rgba(228, 124, 124, 0.26); background: rgba(228, 124, 124, 0.07); }
.background-task-card.is-paused { border-color: rgba(229, 138, 120, 0.3); }
.background-task-card.is-paused .background-task-card__icon { color: var(--accent); border-color: rgba(229, 138, 120, 0.28); background: rgba(229, 138, 120, 0.09); }
.background-task-card.is-running .background-task-card__icon svg { animation: task-orb-spin 1.2s linear infinite; }
.background-task-card__icon svg { width: 18px; height: 18px; }
.background-task-card__copy { min-width: 0; }
.background-task-card__topline { display: flex; min-width: 0; align-items: center; gap: 7px; }
.background-task-card__topline strong { overflow: hidden; color: var(--ink-soft); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.background-task-card__status { flex: 0 0 auto; color: var(--faint); font-family: var(--font-mono); font-size: 8px; }
.background-task-card.is-running .background-task-card__status { color: var(--accent); }
.background-task-card.is-success .background-task-card__status { color: var(--safe); }
.background-task-card.is-error .background-task-card__status { color: #ef9999; }
.background-task-card.is-paused .background-task-card__status { color: var(--accent); }
.background-task-card__copy > span { display: block; margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.background-task-card__action { min-height: 34px; padding: 6px 9px; color: var(--ink-soft); border: 1px solid var(--border); border-radius: 9px; background: var(--surface); font-size: 10px; }
.background-task-card__progress { grid-column: 2 / -1; height: 5px; overflow: hidden; border-radius: 999px; background: var(--surface-soft); }
.background-task-card__progress span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--rose), var(--accent)); transition: width 220ms var(--ease-out); }
.background-task-card__progress.is-indeterminate span { width: 42%; animation: task-progress-slide 1.4s ease-in-out infinite; }
.background-task-empty { display: grid; min-height: 160px; padding: 24px; place-items: center; align-content: center; color: var(--muted); text-align: center; }
.background-task-empty[hidden] { display: none; }
.background-task-empty svg { width: 30px; height: 30px; margin-bottom: 9px; color: var(--safe); }
.background-task-empty strong, .background-task-empty span { display: block; }
.background-task-empty strong { color: var(--ink-soft); font-size: 13px; }
.background-task-empty span { margin-top: 4px; font-size: 10px; }
.has-background-tasks .toast { bottom: calc(146px + env(safe-area-inset-bottom)); }

.toast { position: fixed; z-index: var(--z-toast); right: 16px; bottom: calc(82px + env(safe-area-inset-bottom)); display: flex; min-height: 46px; align-items: center; gap: 9px; padding: 11px 15px; color: #1c171b; border-radius: 13px; background: var(--ink); box-shadow: var(--shadow); font-weight: 700; animation: toast-in 220ms var(--ease-out); }
.toast[hidden] { display: none; }
.toast svg { width: 17px; }

@keyframes view-in { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: translateY(0); } }
@keyframes sheet-in { from { opacity: 0.7; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes task-orb-spin { to { transform: rotate(360deg); } }
@keyframes task-orb-breathe { 0%, 100% { box-shadow: 0 14px 34px rgba(7, 4, 7, 0.48), 0 0 0 0 rgba(229, 138, 120, 0); } 50% { box-shadow: 0 14px 34px rgba(7, 4, 7, 0.48), 0 0 0 7px rgba(229, 138, 120, 0.08); } }
@keyframes task-progress-slide { 0% { transform: translateX(-110%); } 55%, 100% { transform: translateX(240%); } }
@keyframes pulse { from { opacity: 0.45; transform: scale(0.86); } to { opacity: 1; transform: scale(1.12); } }

@media (min-width: 600px) {
  main { padding-right: 24px; padding-left: 24px; }
  .view-intro .status-pill { display: inline-flex; }
  .toolbar-card { grid-template-columns: 1fr auto; }
  .phrase-toolbar__actions { display: flex; }
  .search-field kbd { display: block; }
  .library-grid, .agent-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-field--wide, .form-actions, .prompt-builder { grid-column: 1 / -1; }
  .api-tuning-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .bottom-sheet { right: 50%; left: auto; width: min(660px, calc(100% - 32px)); border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); border-radius: 26px; transform: translateX(50%); bottom: 18px; }
  .sheet-footer { bottom: -18px; margin-bottom: -18px; border-radius: 0 0 26px 26px; }
  @keyframes sheet-in { from { opacity: 0.7; transform: translate(50%, 24px); } to { opacity: 1; transform: translate(50%, 0); } }
}

@media (min-width: 820px) {
  .reply-layout { grid-template-columns: 226px minmax(0, 1fr); align-items: start; gap: 22px; }
  .context-rail { position: sticky; top: 92px; }
  .posture-scale { grid-template-columns: repeat(7, minmax(0, 1fr)); grid-auto-columns: auto; grid-auto-flow: row; overflow: visible; padding-bottom: 0; }
  .posture-definition-tabs { grid-template-columns: repeat(7, minmax(0, 1fr)); grid-auto-columns: auto; grid-auto-flow: row; overflow: visible; padding-bottom: 0; }
  .candidate-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .candidate-card:first-child { grid-column: 1 / -1; }
  .candidate-list[data-count="1"] { grid-template-columns: 1fr; }
  .candidate-list[data-count="2"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .candidate-list[data-count="1"] .candidate-card:first-child, .candidate-list[data-count="2"] .candidate-card:first-child { grid-column: auto; }
  .phrase-library-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-layout { grid-template-columns: 180px minmax(0, 1fr); align-items: start; }
  .settings-tabs { position: sticky; top: 92px; flex-direction: column; }
  .settings-tab { flex: none; text-align: left; }
  .bottom-sheet--llm-log { width: min(900px, calc(100% - 40px)); }
  .llm-log-overview { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (min-width: 1024px) {
  .app-shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); }
  .desktop-sidebar { position: sticky; top: 0; display: flex; height: 100dvh; flex-direction: column; padding: 24px 16px; border-right: 1px solid var(--border-soft); background: rgba(16, 13, 17, 0.72); backdrop-filter: blur(18px); }
  .brand--sidebar { padding: 0 8px; }
  .brand--mobile { display: none; }
  .side-nav { display: grid; gap: 6px; margin-top: 36px; }
  .side-nav .nav-item { justify-content: flex-start; padding: 0 13px; font-size: 14px; }
  .side-nav .nav-item.is-active { box-shadow: inset 2px 0 0 var(--accent); }
  .sidebar-foot { display: flex; align-items: center; gap: 10px; margin-top: auto; padding: 13px; color: var(--muted); border: 1px solid var(--border-soft); border-radius: 14px; background: var(--surface); }
  .sidebar-foot svg { flex: 0 0 auto; color: var(--safe); }
  .sidebar-foot strong, .sidebar-foot span { display: block; }
  .sidebar-foot strong { color: var(--ink-soft); font-size: 12px; }
  .sidebar-foot span { margin-top: 2px; font-size: 9px; }
  .topbar { justify-content: flex-end; padding-right: 32px; padding-left: 32px; }
  main { padding: 24px 32px 64px; }
  .bottom-nav { display: none; }
  .toast { right: 28px; bottom: 28px; }
  .background-task-orb { right: 28px; bottom: 28px; }
  .has-background-tasks .toast { right: 96px; bottom: 28px; }
}

@media (min-width: 1240px) {
  .reply-layout { grid-template-columns: 250px minmax(0, 1fr); gap: 28px; }
  .candidate-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .candidate-card:first-child { grid-column: auto; }
  .library-grid, .agent-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .phrase-library-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (orientation: landscape) and (max-height: 560px) {
  .topbar { position: static; }
  .bottom-sheet { max-height: 96dvh; }
}

@media (max-width: 460px) {
  .section-heading { flex-wrap: wrap; }
  .heading-actions { width: 100%; justify-content: space-between; }
  .custom-length { grid-template-columns: 1fr auto 1fr; }
  .custom-length .secondary-button { grid-column: 1 / -1; }
  .model-picker { grid-template-columns: 1fr; }
  .prompt-builder__heading { display: block; }
  .prompt-builder__heading > span { display: block; margin-top: 6px; }
  .prompt-layer { grid-template-columns: 26px 1fr auto; }
  .prompt-layer--task-fixed { grid-template-columns: 26px 18px 1fr; }
  .prompt-layer--task-fixed .fixed-label { grid-column: 2 / -1; padding-left: 28px; }
  .layer-actions button { width: 36px; }
  .intent-heading { align-items: flex-start; }
  .intent-heading label { display: block; }
  .intent-heading label span { display: block; margin-top: 2px; }
  .generate-button { grid-template-columns: auto 1fr; }
  .generate-button small { display: none; }
  .import-candidate__fields { grid-template-columns: 1fr; }
  .knowledge-phrase-fields, .worldbook-editor-grid, .worldbook-editor-grid--control { grid-template-columns: 1fr; }
  .worldbook-editor-section { padding: 12px; }
  .worldbook-editor-section__heading { display: block; }
  .worldbook-editor-section__heading span { display: block; margin-top: 3px; }
  .sheet-footer { gap: 9px; }
  .sheet-footer > span { display: none; }
  .import-result-actions { display: grid; grid-template-columns: 1fr; }
  .import-result-actions .primary-button { grid-row: 1; }
  .background-task-card { grid-template-columns: 38px minmax(0, 1fr); }
  .background-task-card__action { grid-column: 2; justify-self: start; }
  .background-task-card__progress { grid-column: 1 / -1; }
}

@media (max-width: 340px) {
  .length-presets { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
