:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-muted: #efeee9;
  --text: #201f1c;
  --muted: #706e67;
  --border: #dedcd4;
  --primary: #e89a2e;
  --primary-strong: #c97816;
  --primary-soft: #fff0d7;
  --rose: #b85564;
  --green: #4b7661;
  --shadow: 0 14px 36px rgba(40, 36, 27, .09);
  --shadow-soft: 0 5px 18px rgba(40, 36, 27, .06);
  --header-height: 64px;
  --sidebar-width: 248px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171714;
  --surface: #22221e;
  --surface-muted: #2c2b26;
  --text: #f3f0e8;
  --muted: #aaa79e;
  --border: #3c3a33;
  --primary: #f2ad4c;
  --primary-strong: #ffc46f;
  --primary-soft: #3d2d18;
  --rose: #e38191;
  --green: #7fb99d;
  --shadow: 0 16px 40px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }

.app-header {
  position: fixed;
  inset: 0 0 auto;
  z-index: 40;
  height: var(--header-height);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
  box-shadow: 0 1px 12px rgba(36, 32, 24, .035);
}
.header-inner {
  height: 100%;
  display: flex;
  align-items: center;
  gap: 24px;
  max-width: 1480px;
  margin: 0 auto;
  padding: 0 24px;
}
.brand { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  color: #fff;
  background: var(--primary);
  font-family: Georgia, serif;
  font-weight: 800;
  font-size: 20px;
}
.brand-name { font-family: Georgia, "Songti SC", serif; font-weight: 800; font-size: 21px; }
.brand-count { color: var(--muted); font-size: 12px; padding-left: 2px; }
.desktop-nav { display: flex; align-items: stretch; height: 100%; gap: 24px; margin-left: 20px; }
.desktop-nav a { display: grid; place-items: center; color: var(--muted); font-size: 14px; position: relative; }
.desktop-nav a.active { color: var(--text); font-weight: 700; }
.desktop-nav a.active::after { content: ""; position: absolute; bottom: 0; left: 0; right: 0; height: 3px; background: var(--primary); }
.header-actions { display: flex; gap: 6px; margin-left: auto; }
.icon-button {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 7px;
  background: transparent;
  cursor: pointer;
}
.icon-button:hover { background: var(--surface-muted); }
.icon-button svg { width: 19px; height: 19px; }

.app-shell { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); max-width: 1480px; margin: 0 auto; padding-top: var(--header-height); min-height: 100vh; }
.sidebar {
  position: sticky;
  top: var(--header-height);
  height: calc(100vh - var(--header-height));
  overflow-y: auto;
  padding: 28px 18px 36px;
  border-right: 1px solid var(--border);
  background: var(--bg);
}
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 0 10px 16px; }
.sidebar-header strong { font-size: 13px; color: var(--muted); }
.category-link {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font-size: 14px;
}
.category-link span:last-child { color: var(--muted); font-size: 12px; }
.category-link:hover { background: var(--surface-muted); }
.category-link.active { background: var(--primary-soft); color: var(--primary-strong); font-weight: 700; }
.category-group { margin-top: 8px; }
.category-parent { font-weight: 700; margin-top: 4px; }
.category-child { padding-left: 24px; color: var(--muted); }

.main-content { min-width: 0; padding: 38px clamp(24px, 4vw, 64px) 80px; }
.list-view { max-width: 1120px; margin: 0 auto; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 24px; padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.eyebrow { margin: 0 0 7px; color: var(--primary-strong); font-size: 12px; font-weight: 800; text-transform: uppercase; }
h1, h2, h3, p { overflow-wrap: anywhere; }
h1 { margin: 0; font-family: Georgia, "Songti SC", serif; font-size: clamp(30px, 4vw, 46px); line-height: 1.08; }
.result-count { margin: 0; color: var(--muted); font-size: 13px; white-space: nowrap; }

.search-tools { display: grid; grid-template-columns: minmax(240px, 1fr) auto auto; gap: 10px; align-items: center; margin-bottom: 14px; }
.search-field { height: 46px; display: flex; align-items: center; gap: 10px; padding: 0 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 7px; }
.search-field:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
.search-field > svg { width: 18px; color: var(--muted); flex: 0 0 auto; }
.search-field input { min-width: 0; flex: 1; border: 0; outline: 0; color: var(--text); background: transparent; }
.clear-search { width: 28px; height: 28px; border: 0; border-radius: 5px; background: transparent; cursor: pointer; color: var(--muted); }
.clear-search:hover { background: var(--surface-muted); }
.clear-search svg { width: 15px; }
.segmented { display: flex; height: 40px; padding: 3px; background: var(--surface-muted); border-radius: 7px; }
.segmented button { min-width: 58px; border: 0; border-radius: 5px; background: transparent; cursor: pointer; color: var(--muted); font-size: 13px; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.08); font-weight: 700; }
.filter-button, .primary-button, .load-more, .action-button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 15px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
}
.filter-button svg, .action-button svg { width: 17px; }
.filter-button:hover, .action-button:hover { border-color: var(--primary); color: var(--primary-strong); }
.primary-button { color: #fff; background: var(--primary); border-color: var(--primary); }
.primary-button:hover { background: var(--primary-strong); }
.filter-panel { display: grid; grid-template-columns: 1fr auto; gap: 30px; padding: 18px; margin-bottom: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 7px; box-shadow: var(--shadow); }
.filter-group > span { display: block; margin-bottom: 10px; color: var(--muted); font-size: 12px; font-weight: 700; }
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { height: 32px; padding: 0 12px; border: 1px solid var(--border); border-radius: 6px; background: transparent; cursor: pointer; font-size: 12px; }
.chip.active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-strong); font-weight: 700; }
.toggle-row { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.toggle-row > span:first-child { display: grid; gap: 3px; }
.toggle-row strong { font-size: 13px; }
.toggle-row small { color: var(--muted); font-size: 11px; }
.toggle-row input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-ui { width: 42px; height: 24px; border-radius: 12px; background: var(--border); position: relative; flex: 0 0 auto; }
.toggle-ui::after { content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%; background: #fff; top: 3px; left: 3px; transition: transform .2s; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.toggle-row input:checked + .toggle-ui { background: var(--primary); }
.toggle-row input:checked + .toggle-ui::after { transform: translateX(18px); }
.active-filter { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; margin-bottom: 14px; border-left: 3px solid var(--primary); background: var(--primary-soft); font-size: 13px; }
.active-filter button { border: 0; background: transparent; cursor: pointer; color: var(--primary-strong); font-weight: 700; }

.card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.role-card {
  min-width: 0;
  display: grid;
  grid-template-columns: 154px minmax(0, 1fr);
  min-height: 218px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 96%, var(--primary-soft));
  cursor: pointer;
  transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.role-card:hover { transform: translateY(-3px); border-color: color-mix(in srgb, var(--primary) 60%, var(--border)); box-shadow: var(--shadow); }
.card-cover { position: relative; background: var(--surface-muted); overflow: hidden; }
.card-cover img { width: 100%; height: 100%; display: block; object-fit: cover; transition: transform .28s ease; }
.role-card:hover .card-cover img { transform: scale(1.035); }
.card-type { position: absolute; top: 10px; left: 10px; padding: 5px 7px; border-radius: 5px; background: rgba(20,20,18,.76); color: #fff; backdrop-filter: blur(6px); font-size: 11px; font-weight: 700; }
.favorite-card { position: absolute; right: 8px; top: 8px; width: 34px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 6px; background: rgba(255,255,255,.88); color: #403d36; cursor: pointer; }
.favorite-card.active { color: var(--rose); }
.favorite-card svg { width: 17px; }
.card-body { min-width: 0; display: flex; flex-direction: column; padding: 16px; }
.card-title { margin: 0; font-family: Georgia, "Songti SC", serif; font-size: 19px; line-height: 1.3; }
.card-description { margin: 8px 0 12px; color: var(--muted); font-size: 13px; line-height: 1.65; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.role-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 12px; }
.role-tag { padding: 4px 6px; border-radius: 4px; background: var(--surface-muted); color: var(--muted); font-size: 11px; }
.card-meta { display: flex; align-items: center; gap: 10px; margin-top: auto; color: var(--muted); font-size: 11px; }
.author-avatar { width: 22px; height: 22px; object-fit: cover; border-radius: 50%; background: var(--surface-muted); }
.view-count { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; }
.view-count svg { width: 14px; }
.load-more { display: flex; margin: 24px auto 0; min-width: 150px; }
.empty-state { min-height: 360px; display: grid; place-items: center; align-content: center; text-align: center; color: var(--muted); }
.empty-state svg { width: 44px; height: 44px; margin-bottom: 12px; }
.empty-state h2 { margin: 0; color: var(--text); font-size: 20px; }
.empty-state p { margin: 8px 0 18px; }

.detail-view { max-width: 980px; margin: 0 auto; }
.detail-back { margin-bottom: 18px; }
.detail-hero { position: relative; min-height: 440px; display: flex; align-items: flex-end; overflow: hidden; border-radius: 8px; background: var(--surface-muted); }
.detail-hero > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.detail-hero::after { content: ""; position: absolute; inset: 24% 0 0; background: linear-gradient(transparent, rgba(12,12,11,.88)); }
.detail-intro { position: relative; z-index: 1; width: 100%; padding: clamp(26px, 5vw, 52px); color: #fff; }
.detail-intro h1 { max-width: 760px; font-size: clamp(32px, 6vw, 60px); }
.detail-intro p { max-width: 700px; margin: 14px 0 0; color: rgba(255,255,255,.82); line-height: 1.7; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 18px; font-size: 12px; color: rgba(255,255,255,.75); }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 24px; }
.detail-tabs { position: sticky; top: var(--header-height); z-index: 12; display: flex; gap: 6px; overflow-x: auto; padding: 10px 0; background: var(--bg); border-bottom: 1px solid var(--border); }
.detail-tabs button { flex: 0 0 auto; min-height: 36px; padding: 0 12px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; }
.detail-tabs button.active { background: var(--primary-soft); color: var(--primary-strong); font-weight: 700; }
.detail-section { padding: 34px 0; border-bottom: 1px solid var(--border); }
.detail-section h2 { margin: 0 0 20px; font-size: 24px; }
.detail-section h3 { margin: 24px 0 10px; font-size: 16px; }
.detail-section p, .detail-copy { margin: 0; white-space: pre-wrap; line-height: 1.85; color: color-mix(in srgb, var(--text) 86%, var(--muted)); font-size: 14px; }
.dialogue-quote { margin: 0; padding: 24px 28px; border-left: 4px solid var(--primary); background: var(--primary-soft); font-family: Georgia, "Songti SC", serif; font-size: 22px; line-height: 1.6; }
.role-profile { display: grid; grid-template-columns: 110px minmax(0,1fr); gap: 20px; padding: 20px 0; border-top: 1px solid var(--border); }
.role-profile:first-of-type { border-top: 0; }
.role-profile img { width: 110px; aspect-ratio: 1; object-fit: cover; border-radius: 7px; background: var(--surface-muted); }
.role-profile h3 { margin: 0 0 8px; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
.field-item { padding: 16px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); }
.field-item.full { grid-column: 1 / -1; }
.field-item h3 { margin: 0 0 8px; color: var(--primary-strong); font-size: 13px; }
.field-item p { font-size: 13px; }
.opening-content { max-height: 720px; overflow: auto; padding: 22px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); white-space: pre-wrap; line-height: 1.8; font-size: 14px; }
.loading-detail { min-height: 60vh; display: grid; place-items: center; color: var(--muted); }
.image-fallback { display: grid; width: 100%; height: 100%; place-items: center; padding: 16px; background: var(--surface-muted); color: var(--muted); text-align: center; font-size: 13px; }
.favorite-active { color: #d95f52 !important; border-color: color-mix(in srgb, #d95f52 42%, var(--border)) !important; background: color-mix(in srgb, #d95f52 9%, var(--surface)) !important; }

.history-route .app-shell { grid-template-columns: minmax(0, 1fr); max-width: 1280px; }
.history-route .sidebar { display: none; }
.history-view { max-width: 1020px; margin: 0 auto; }
.history-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 28px; padding: 10px 0 28px; border-bottom: 1px solid var(--border); }
.history-heading h1 { font-size: clamp(34px, 5vw, 54px); }
.history-heading > div:first-child > p:last-child { margin: 10px 0 0; color: var(--muted); }
.history-stats { display: flex; gap: 8px; }
.history-stats > div { min-width: 116px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); box-shadow: var(--shadow-soft); }
.history-stats strong { display: block; color: var(--primary-strong); font-family: Georgia, serif; font-size: 25px; }
.history-stats span { color: var(--muted); font-size: 11px; }
.history-search { width: min(520px, 100%); height: 44px; display: flex; align-items: center; gap: 10px; margin: 22px 0 14px; padding: 0 13px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); }
.history-search:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent); }
.history-search svg { width: 17px; color: var(--muted); }
.history-search input { min-width: 0; flex: 1; border: 0; outline: 0; color: var(--text); background: transparent; }
.history-list { display: grid; gap: 10px; }
.history-item { position: relative; overflow: hidden; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow-soft); transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease; }
.history-item:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); box-shadow: var(--shadow); }
.history-main { display: grid; grid-template-columns: 86px minmax(0,1fr); gap: 16px; min-height: 112px; padding: 13px 64px 13px 13px; }
.history-cover { position: relative; width: 86px; aspect-ratio: 1; overflow: hidden; border-radius: 7px; background: var(--primary-soft); }
.history-cover img { width: 100%; height: 100%; object-fit: cover; }
.history-cover > span { display: grid; width: 100%; height: 100%; place-items: center; color: var(--primary-strong); font-family: Georgia, serif; font-size: 28px; }
.history-cover > svg { position: absolute; right: 5px; bottom: 5px; width: 24px; height: 24px; padding: 5px; border-radius: 50%; color: #fff; background: var(--green); }
.history-copy { min-width: 0; align-self: center; }
.history-title { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; }
.history-title h2 { margin: 0; font-family: Georgia, "Songti SC", serif; font-size: 19px; }
.history-title time { flex: 0 0 auto; color: var(--muted); font-size: 11px; }
.history-copy > p { margin: 8px 0 10px; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.history-meta { display: flex; flex-wrap: wrap; gap: 8px 16px; color: var(--muted); font-size: 11px; }
.history-meta span { display: inline-flex; align-items: center; gap: 5px; }
.history-meta svg { width: 13px; }
.history-delete { position: absolute; top: 50%; right: 15px; width: 36px; height: 36px; display: grid; place-items: center; transform: translateY(-50%); border: 0; border-radius: 6px; color: var(--muted); background: transparent; cursor: pointer; }
.history-delete:hover { color: var(--rose); background: color-mix(in srgb, var(--rose) 10%, transparent); }
.history-delete svg { width: 17px; }
.history-empty { min-height: 360px; display: grid; place-items: center; align-content: center; text-align: center; color: var(--muted); }
.history-empty > svg { width: 48px; height: 48px; margin-bottom: 14px; color: var(--primary); }
.history-empty h2 { margin: 0; color: var(--text); }
.history-empty p { margin: 8px 0 18px; }

.chat-route .app-shell { grid-template-columns: minmax(0, 1fr); max-width: none; }
.chat-route .sidebar, .chat-route .mobile-nav { display: none; }
.chat-route .main-content { padding: 0; }
.chat-view { height: calc(100vh - var(--header-height)); background: color-mix(in srgb, var(--surface-muted) 88%, var(--green)); }
.chat-shell { height: 100%; display: grid; grid-template-rows: 68px minmax(0, 1fr) auto; max-width: 980px; margin: 0 auto; background: var(--surface); border-inline: 1px solid var(--border); box-shadow: 0 0 50px rgba(38,34,28,.08); }
.chat-header { display: flex; align-items: center; gap: 12px; padding: 0 16px; border-bottom: 1px solid var(--border); }
.chat-character { min-width: 0; display: flex; align-items: center; gap: 10px; }
.chat-character img { width: 40px; height: 40px; object-fit: cover; border-radius: 50%; background: var(--surface-muted); }
.chat-character div { min-width: 0; display: grid; gap: 3px; }
.chat-character strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.chat-character span { display: flex; align-items: center; gap: 5px; color: var(--green); font-size: 11px; }
.chat-character span i { width: 6px; height: 6px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 14%, transparent); }
.chat-header-actions { display: flex; align-items: center; gap: 3px; margin-left: auto; }
.model-indicator { display: inline-flex; align-items: center; gap: 5px; margin-right: 6px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 5px; color: var(--muted); background: var(--bg); font-size: 10px; }
.model-indicator svg { width: 13px; }
.chat-messages { overflow-y: auto; padding: 24px clamp(14px, 4vw, 36px); scroll-behavior: smooth; }
.chat-message { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 10px; align-items: flex-start; margin-bottom: 22px; }
.chat-message.user { grid-template-columns: minmax(0, 1fr) 34px; }
.chat-message.user .message-avatar { grid-column: 2; }
.chat-message.user .message-wrap { grid-column: 1; grid-row: 1; justify-self: end; align-items: flex-end; }
.chat-message.user .message-content { color: #fff; background: var(--primary); border-color: var(--primary); }
.chat-message.error .message-content { color: #a43737; background: color-mix(in srgb, #d95f52 10%, var(--surface)); border-color: color-mix(in srgb, #d95f52 35%, var(--border)); }
.message-avatar { width: 34px; height: 34px; display: grid; place-items: center; overflow: hidden; border-radius: 50%; color: var(--primary-strong); background: var(--primary-soft); }
.message-avatar img { width: 100%; height: 100%; object-fit: cover; }
.message-avatar svg { width: 17px; }
.message-wrap { max-width: min(720px, 88%); display: flex; flex-direction: column; gap: 5px; align-items: flex-start; }
.message-wrap time { color: var(--muted); font-size: 10px; }
.message-content { max-width: 100%; padding: 12px 15px; border: 1px solid var(--border); border-radius: 7px; background: var(--bg); white-space: pre-wrap; line-height: 1.75; font-size: 14px; box-shadow: 0 3px 12px rgba(35,31,24,.035); }
.chat-composer { position: relative; display: grid; grid-template-columns: 44px 44px minmax(0, 1fr) 44px; gap: 10px; padding: 14px clamp(14px, 4vw, 30px) calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--surface); }
.chat-composer textarea { width: 100%; min-height: 44px; max-height: 160px; resize: none; padding: 11px 13px; border: 1px solid var(--border); border-radius: 7px; outline: 0; color: var(--text); background: var(--bg); line-height: 1.5; }
.chat-composer textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
.send-button { width: 44px; height: 44px; min-height: 44px; padding: 0; }
.send-button svg { width: 18px; }
.speech-button { width: 44px; height: 44px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 7px; color: var(--muted); background: var(--surface); cursor: pointer; }
.speech-button:hover { border-color: var(--primary); color: var(--primary-strong); }
.speech-button.listening { color: #fff; border-color: #c54b4b; background: #c54b4b; animation: speech-pulse 1.3s ease-in-out infinite; }
.speech-button svg { width: 19px; }
.speech-upload { position: relative; }
.speech-upload input { position: absolute; inset: 0; opacity: 0; pointer-events: none; }
.speech-status { position: absolute; left: clamp(14px, 4vw, 30px); bottom: calc(100% + 8px); max-width: min(440px, calc(100vw - 28px)); padding: 8px 11px; border: 1px solid var(--border); border-radius: 6px; color: var(--text); background: var(--surface); box-shadow: var(--shadow); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes speech-pulse { 50% { box-shadow: 0 0 0 7px color-mix(in srgb, #c54b4b 18%, transparent); } }

.settings-dialog { width: min(520px, calc(100vw - 28px)); padding: 0; border: 1px solid var(--border); border-radius: 8px; color: var(--text); background: var(--surface); box-shadow: 0 24px 80px rgba(0,0,0,.28); }
.settings-dialog::backdrop { background: rgba(0,0,0,.48); backdrop-filter: blur(3px); }
.settings-dialog form { display: grid; gap: 16px; padding: 22px; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.dialog-header h2 { margin: 0; font-size: 24px; }
.model-presets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.local-model-preset { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 13px; border: 1px solid color-mix(in srgb, var(--green) 45%, var(--border)); border-radius: 7px; color: var(--text); background: color-mix(in srgb, var(--green) 8%, var(--surface)); cursor: pointer; text-align: left; }
.local-model-preset:hover { border-color: var(--green); }
.local-model-preset.roleplay { border-color: color-mix(in srgb, var(--rose) 45%, var(--border)); background: color-mix(in srgb, var(--rose) 8%, var(--surface)); }
.local-model-preset.roleplay:hover { border-color: var(--rose); }
.local-model-preset.roleplay > svg { color: var(--rose); }
.local-model-preset.grok { border-color: color-mix(in srgb, var(--text) 35%, var(--border)); background: color-mix(in srgb, var(--text) 5%, var(--surface)); }
.local-model-preset.grok:hover { border-color: var(--text); }
.local-model-preset.grok > svg { color: var(--text); }
.local-model-preset > svg { width: 22px; flex: 0 0 auto; color: var(--green); }
.local-model-preset span { display: grid; gap: 3px; }
.local-model-preset strong { font-size: 13px; }
.local-model-preset small { color: var(--muted); font-size: 11px; }
.form-field { display: grid; gap: 7px; }
.form-field span { font-size: 12px; font-weight: 700; }
.form-field input, .form-field textarea { width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 6px; outline: 0; color: var(--text); background: var(--bg); }
.form-field input:focus, .form-field textarea:focus { border-color: var(--primary); }
.form-field textarea { resize: vertical; line-height: 1.6; }
.settings-note { margin: -2px 0 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.mobile-nav, .mobile-only { display: none; }
.scrim { position: fixed; inset: 0; z-index: 49; background: rgba(0,0,0,.42); }
.toast { position: fixed; left: 50%; bottom: 28px; z-index: 80; transform: translate(-50%, 18px); opacity: 0; pointer-events: none; padding: 10px 14px; border-radius: 6px; color: #fff; background: #292824; box-shadow: var(--shadow); transition: .2s; font-size: 13px; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 1050px) {
  .card-grid { grid-template-columns: 1fr; }
  .role-card { grid-template-columns: 180px minmax(0,1fr); }
}

@media (max-width: 760px) {
  :root { --header-height: 56px; }
  .mobile-only { display: inline-grid; }
  .brand-count, .desktop-nav { display: none; }
  .brand-name { font-size: 18px; }
  .brand-mark { width: 32px; height: 32px; font-size: 17px; }
  .header-inner { gap: 8px; padding: 0 10px; }
  .app-shell { display: block; padding-top: var(--header-height); }
  .sidebar { position: fixed; z-index: 55; top: 0; left: 0; width: min(86vw, 330px); height: 100vh; padding-top: 16px; transform: translateX(-102%); transition: transform .22s ease; background: var(--surface); box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .main-content { padding: 26px 14px 92px; }
  .page-heading { align-items: flex-start; margin-bottom: 18px; }
  .result-count { padding-top: 5px; }
  .search-tools { grid-template-columns: 1fr auto; }
  .search-field { grid-column: 1 / -1; }
  .segmented button { min-width: 52px; }
  .filter-button span { display: none; }
  .filter-panel { grid-template-columns: 1fr; gap: 18px; }
  .card-grid { gap: 12px; }
  .role-card { grid-template-columns: 126px minmax(0,1fr); min-height: 190px; }
  .card-body { padding: 13px; }
  .card-title { font-size: 16px; }
  .card-description { -webkit-line-clamp: 3; margin-top: 6px; line-height: 1.55; }
  .role-tags { display: none; }
  .card-meta { gap: 6px; }
  .card-meta .author-name { max-width: 92px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .detail-hero { min-height: 430px; margin: 0 -14px; border-radius: 0; }
  .detail-intro { padding: 28px 20px; }
  .detail-intro h1 { font-size: 34px; }
  .detail-tabs { top: var(--header-height); }
  .field-grid { grid-template-columns: 1fr; }
  .field-item.full { grid-column: auto; }
  .role-profile { grid-template-columns: 76px minmax(0,1fr); gap: 14px; }
  .role-profile img { width: 76px; }
  .dialogue-quote { padding: 20px; font-size: 19px; }
  .mobile-nav { position: fixed; display: grid; grid-template-columns: repeat(4, 1fr); z-index: 35; left: 0; right: 0; bottom: 0; height: calc(62px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--surface); border-top: 1px solid var(--border); }
  .mobile-nav a, .mobile-nav button { display: grid; place-items: center; align-content: center; gap: 3px; border: 0; background: transparent; color: var(--muted); font-size: 10px; }
  .mobile-nav svg { width: 20px; height: 20px; }
  .mobile-nav .active { color: var(--primary-strong); }
  .toast { bottom: 82px; }
  .chat-route .app-header { display: none; }
  .chat-route .app-shell { padding-top: 0; }
  .chat-route .chat-view { height: 100dvh; }
  .chat-shell { grid-template-rows: 60px minmax(0,1fr) auto; border: 0; }
  .chat-header { padding: 0 8px; }
  .chat-messages { padding: 18px 12px; }
  .message-content { max-width: 92%; }
  .chat-composer { padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); }
  .settings-dialog form { padding: 18px; }
  .model-presets { grid-template-columns: 1fr; }
  .history-heading { align-items: flex-start; flex-direction: column; padding-top: 0; }
  .history-stats { width: 100%; }
  .history-stats > div { min-width: 0; flex: 1; }
  .history-search { margin-top: 16px; }
  .history-main { grid-template-columns: 68px minmax(0,1fr); min-height: 96px; padding: 12px 48px 12px 12px; gap: 12px; }
  .history-cover { width: 68px; }
  .history-title { display: block; }
  .history-title h2 { font-size: 17px; }
  .history-title time { display: block; margin-top: 3px; }
  .history-meta span:first-child { display: none; }
  .history-delete { right: 7px; }
  .model-indicator { display: none; }
}

@media (max-width: 410px) {
  .role-card { grid-template-columns: 110px minmax(0,1fr); }
  .view-count { display: none; }
  .segmented button { min-width: 47px; padding: 0 6px; }
}

/* Story setup and original-site-style selectors */
.story-dialog,
.sheet-dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: min(820px, calc(100vh - 32px));
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(24, 21, 16, .25);
}
.story-dialog::backdrop,
.sheet-dialog::backdrop { background: rgba(17, 16, 13, .56); backdrop-filter: blur(3px); }
.story-dialog form,
.sheet-dialog form { display: flex; flex-direction: column; max-height: inherit; }
.story-dialog .dialog-header,
.sheet-dialog .dialog-header { flex: 0 0 auto; padding: 20px 22px 14px; }
.setup-character { display: flex; align-items: center; gap: 12px; margin: 0 22px 16px; padding: 12px; background: var(--surface-muted); border-radius: 7px; }
.setup-character img,
.setup-character > span { width: 52px; height: 52px; border-radius: 6px; object-fit: cover; display: grid; place-items: center; background: var(--primary); color: #fff; font-size: 22px; font-weight: 800; }
.setup-character div { min-width: 0; display: grid; gap: 4px; }
.setup-character strong { font-size: 16px; }
.setup-character small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.setup-section { padding: 0 22px 18px; }
.setup-section-title { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 9px; }
.setup-section-title > span { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 800; }
.setup-section-title b { width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; color: #fff; background: var(--primary); font-size: 11px; }
.setup-section-title small { color: var(--muted); font-size: 11px; }
.identity-options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.identity-option,
.setup-picker { width: 100%; min-width: 0; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); cursor: pointer; text-align: left; }
.identity-option { min-height: 76px; display: grid; grid-template-columns: 28px 1fr 18px; align-items: center; gap: 10px; padding: 10px 12px; }
.identity-option.active { border-color: var(--primary); background: var(--primary-soft); }
.identity-option > svg { width: 20px; color: var(--primary-strong); }
.identity-option > svg:last-child { width: 16px; justify-self: end; }
.identity-option span,
.setup-picker > span > span { min-width: 0; display: grid; gap: 3px; }
.identity-option strong,
.setup-picker strong { font-size: 13px; }
.identity-option small,
.setup-picker small { color: var(--muted); font-size: 11px; line-height: 1.45; }
#storyPersona { width: 100%; resize: vertical; margin-top: 8px; padding: 11px 12px; border: 1px solid var(--border); border-radius: 7px; color: var(--text); background: var(--surface); outline: none; }
#storyPersona:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent); }
.setup-picker { min-height: 66px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 12px; }
.setup-picker:hover { border-color: var(--primary); }
.setup-picker > span { min-width: 0; display: flex; align-items: center; gap: 11px; }
.setup-picker > span > svg { width: 21px; color: var(--primary-strong); flex: 0 0 auto; }
.setup-picker > svg { width: 17px; color: var(--muted); flex: 0 0 auto; }
.story-dialog .dialog-actions,
.sheet-dialog .dialog-actions { flex: 0 0 auto; margin-top: auto; padding: 14px 22px max(14px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--surface); }

.sheet-dialog { width: min(620px, 100vw); }
.sheet-handle { display: none; }
.model-tabs { display: flex; gap: 20px; padding: 0 22px; overflow-x: auto; border-bottom: 1px solid var(--border); }
.model-tabs button { min-width: max-content; height: 42px; padding: 0 2px; border: 0; border-bottom: 3px solid transparent; background: transparent; color: var(--muted); cursor: pointer; }
.model-tabs button.active { color: var(--text); border-color: var(--primary); font-weight: 800; }
.model-list,
.preset-list { min-height: 240px; overflow-y: auto; padding: 16px 22px; }
.model-search { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 8px; margin-bottom: 12px; padding: 9px 11px; border: 1px solid var(--border); border-radius: 7px; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(8px); }
.model-search svg { width: 16px; color: var(--muted); }
.model-search input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; font-size: 13px; }
.model-choice { position: relative; width: 100%; display: grid; gap: 8px; margin-bottom: 10px; padding: 15px 16px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); color: var(--text); cursor: pointer; text-align: left; }
.model-choice.active { border-color: var(--primary); background: color-mix(in srgb, var(--primary-soft) 48%, var(--surface)); box-shadow: inset 3px 0 var(--primary); }
.model-choice > svg { position: absolute; right: 14px; bottom: 14px; width: 20px; color: transparent; }
.model-choice.active > svg { color: var(--primary-strong); }
.model-choice-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-right: 2px; }
.model-choice-top strong { font-size: 16px; }
.model-status { display: inline-flex; align-items: center; gap: 5px; color: #b26d18; font-size: 11px; }
.model-status i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.model-status.online { color: #27845c; }
.model-status.local { color: #27845c; }
.model-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.model-tags em { padding: 3px 6px; border-radius: 4px; background: var(--surface-muted); color: var(--muted); font-style: normal; font-size: 10px; }
.model-description,
.model-preset { color: var(--muted); font-size: 12px; line-height: 1.55; padding-right: 28px; }
.model-preset { color: var(--primary-strong); }
.preset-list { display: grid; align-content: start; gap: 8px; }
.preset-choice { width: 100%; min-height: 66px; display: grid; grid-template-columns: 20px 1fr auto; align-items: center; gap: 12px; padding: 11px 12px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); cursor: pointer; text-align: left; }
.preset-choice.active { border-color: var(--primary); background: var(--primary-soft); }
.preset-radio { width: 18px; height: 18px; border: 2px solid var(--border); border-radius: 50%; position: relative; }
.preset-choice.active .preset-radio { border-color: var(--primary); }
.preset-choice.active .preset-radio::after { content: ""; position: absolute; inset: 3px; border-radius: 50%; background: var(--primary); }
.preset-choice > span:nth-child(2) { display: grid; gap: 4px; }
.preset-choice strong { font-size: 13px; }
.preset-choice small { color: var(--muted); font-size: 11px; }
.preset-choice em { padding: 3px 6px; border-radius: 4px; color: var(--primary-strong); background: color-mix(in srgb, var(--primary-soft) 80%, var(--surface)); font-style: normal; font-size: 10px; }
.chat-header .model-indicator { border: 1px solid var(--border); cursor: pointer; color: var(--muted); background: var(--surface); }

@media (max-width: 640px) {
  .story-dialog { width: calc(100vw - 16px); max-height: calc(100vh - 16px); }
  .story-dialog .dialog-header { padding: 16px 16px 12px; }
  .setup-character { margin: 0 16px 14px; }
  .setup-section { padding: 0 16px 16px; }
  .identity-options { grid-template-columns: 1fr; }
  .setup-section-title small { display: none; }
  .sheet-dialog { width: 100vw; max-width: none; max-height: 88vh; margin: auto 0 0; border: 0; border-top: 1px solid var(--border); border-radius: 8px 8px 0 0; }
  .sheet-handle { display: block; width: 42px; height: 4px; margin: 9px auto 0; border-radius: 2px; background: var(--border); }
  .sheet-dialog .dialog-header { padding: 12px 16px 10px; }
  .model-tabs { padding: 0 16px; }
  .model-list, .preset-list { padding: 14px 16px; }
  .story-dialog .dialog-actions, .sheet-dialog .dialog-actions { padding-left: 16px; padding-right: 16px; }
}
