:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-soft: #f4f7fb;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --text: #111827;
  --muted: #4b5563;
  --subtle: #9ca3af;
  --accent: #4f46e5;
  --accent-2: #312e81;
  --good: #0f766e;
  --bad: #b91c1c;
  --warn: #a16207;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 20px 36px rgba(15, 23, 42, 0.08);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  height: 100svh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 74px;
  display: grid;
  grid-template-columns: minmax(220px, 300px) 1fr minmax(150px, 180px);
  align-items: center;
  gap: 18px;
  padding: 10px 18px;
  background: rgba(248, 250, 252, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.search-wrap input {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 14px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.92);
  outline: none;
}

.search-wrap input:focus,
.date-wrap select:focus,
.sort-control select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(89, 105, 242, 0.13);
}

.board-tabs {
  height: 50px;
  display: flex;
  justify-content: center;
  gap: 14px;
  overflow-x: auto;
  scrollbar-width: none;
}

.board-tabs::-webkit-scrollbar {
  display: none;
}

.tab-button {
  min-width: 136px;
  height: 50px;
  border: 0;
  border-radius: 10px;
  color: var(--text);
  background: transparent;
  cursor: pointer;
  transition: transform 160ms ease, color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

.tab-button:hover {
  background: rgba(255, 255, 255, 0.75);
}

.tab-button.active {
  color: var(--text);
  background: rgba(79, 70, 229, 0.08);
  box-shadow: inset 0 0 0 1px rgba(79, 70, 229, 0.16);
  transform: translateY(-1px);
}

.date-wrap,
.sort-control {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.date-wrap {
  justify-content: flex-end;
}

.section-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.copy-category-titles {
  white-space: nowrap;
}

.date-wrap select,
.sort-control select {
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 9px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.category-rail {
  height: 66px;
  display: flex;
  gap: 2px;
  overflow-x: auto;
  padding: 8px 18px 10px;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--line);
}

.category-rail::-webkit-scrollbar {
  height: 8px;
}

.category-rail::-webkit-scrollbar-thumb {
  background: #8e939a;
  border-radius: 20px;
}

.category-chip {
  min-width: 112px;
  height: 48px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  transition: background 150ms ease, border-color 150ms ease, transform 150ms ease;
}

.category-chip:hover {
  background: rgba(255, 255, 255, 0.72);
}

.category-chip.active {
  background: #fff;
  box-shadow: inset 2px 0 0 var(--accent);
}

.category-chip span {
  max-width: 96px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.category-chip small {
  color: #101820;
  font-size: 12px;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 10px;
  padding: 12px 18px 10px;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--line);
}

.metric {
  min-height: 64px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  align-items: center;
  column-gap: 14px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.metric b {
  display: block;
  grid-area: value;
  font-size: 22px;
  line-height: 1.2;
}

.metric span {
  color: var(--subtle);
  font-size: 13px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.analysis-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fff;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  margin-bottom: 10px;
}

.analysis-panel.collapsed {
  min-height: 0;
}

.analysis-panel.expanded {
  display: block;
}

.analysis-head {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 18px 5px;
}

.analysis-head strong {
  display: block;
  font-size: 14px;
}

.analysis-head span {
  color: var(--muted);
  font-size: 12px;
}

.analysis-preview {
  padding: 7px 18px 8px;
}

.analysis-preview b {
  display: block;
  margin-bottom: 6px;
  color: #1c2927;
  font-size: 12px;
}

.analysis-tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 54px;
  overflow: hidden;
}

.analysis-tag-row span {
  min-height: 22px;
  padding: 3px 8px;
  border: 1px solid #dce4ff;
  border-radius: 999px;
  background: #f3f6ff;
  color: #3448c5;
  font-size: 12px;
  font-weight: 700;
}

.analysis-panel.collapsed .analysis-tag-row {
  flex-wrap: nowrap;
  max-height: 28px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
}

.analysis-actions {
  padding: 0 18px 8px;
}

.analysis-toggle {
  min-height: 34px;
  min-width: 128px;
  border: 0;
  border-radius: 6px;
  background: var(--text);
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  box-shadow: none;
}

.analysis-toggle:hover {
  background: #1f2937;
}

.analysis-summary {
  margin: 0;
  padding: 0 18px 8px;
  color: #24312f;
  font-size: 13px;
  line-height: 1.55;
}

.analysis-body {
  display: flex;
  flex-direction: column;
  gap: 1px;
  border-top: 1px solid var(--line);
  background: var(--line);
}

.analysis-block,
.analysis-note {
  min-width: 0;
  padding: 10px 14px 12px;
  background: #fff;
}

.analysis-block b,
.analysis-note b {
  display: block;
  margin-bottom: 7px;
  color: #1c2927;
  font-size: 12px;
}

.analysis-block span,
.analysis-note span {
  display: block;
  color: #4c5b58;
  font-size: 12px;
  line-height: 1.55;
}

.analysis-block strong {
  color: #14211f;
}

.analysis-panel.collapsed .analysis-body,
.analysis-panel.collapsed .analysis-head,
.analysis-panel.collapsed .analysis-summary {
  display: none;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  background: var(--surface-soft);
  overflow: hidden;
}

.list-pane {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.section-head {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
}

.section-head p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.section-head p:empty {
  display: none;
}

.table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: #fff;
}

.rank-scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 16px;
  background: var(--surface-soft);
}

.rank-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 14px;
  align-content: start;
}

.load-more-cell {
  grid-column: 1 / -1;
  padding: 12px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  cursor: pointer;
  user-select: none;
}

.load-more-cell:focus-visible {
  outline: 2px solid rgba(79, 70, 229, 0.34);
  outline-offset: 3px;
}

.book-card {
  position: relative;
  min-height: 170px;
  display: grid;
  grid-template-columns: 98px minmax(0, 1fr);
  gap: 16px;
  padding: 14px 18px 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.book-card:hover,
.book-card:focus-visible,
.book-card.selected {
  border-color: rgba(79, 70, 229, 0.28);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.book-card.selected {
  background: #fff;
}

.cover-stack {
  position: relative;
  display: flex;
  min-width: 0;
  flex-direction: column;
  align-items: center;
  gap: 9px;
}

.book-cover {
  width: 78px;
  height: 106px;
  border-radius: 8px;
  object-fit: cover;
  background: #e5e7eb;
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.12);
}

.card-rank {
  position: absolute;
  top: -10px;
  right: -8px;
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: #111827;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.card-rank.top-rank {
  background: #4f46e5;
  color: #fff;
}

.cover-category {
  max-width: 92px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.card-title-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
}

.card-title {
  margin: 0;
  color: var(--text);
  font-size: 17px;
  line-height: 1.35;
  letter-spacing: 0;
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.title-aliases {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.title-aliases-card {
  min-height: 20px;
  flex-wrap: wrap;
}

.title-aliases-detail {
  margin: 10px 0 10px;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 8px 10px;
}

.title-alias-label,
.title-alias,
.title-alias-more {
  max-width: 180px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #f8fafc;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.title-alias-item {
  min-width: 0;
  display: inline-flex;
  align-items: flex-start;
  gap: 4px;
}

.title-aliases-card .title-alias-item,
.title-aliases-detail .title-alias-item {
  max-width: 100%;
}

.title-aliases-detail .title-alias-item {
  gap: 50px;
}

.title-aliases-card .title-alias {
  max-width: 100%;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  overflow-wrap: anywhere;
}

.title-aliases-detail .title-alias {
  max-width: none;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  overflow-wrap: anywhere;
}

.title-alias-copy {
  flex: 0 0 auto;
  padding: 2px 6px;
  min-height: 0;
  line-height: 1.35;
}

.title-alias-label {
  flex: 0 0 auto;
  border-color: transparent;
  background: transparent;
  padding-left: 0;
  color: #6b7280;
  font-weight: 700;
}

.title-alias-more {
  flex: 0 0 auto;
}

.status-pill {
  height: 22px;
  padding: 0 7px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill.serial {
  border-color: #99d8c9;
  background: #e8f7f3;
  color: #04756f;
}

.status-pill.finished {
  border-color: #c7d2fe;
  background: #eef2ff;
  color: #4f46a5;
}

.card-author {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--muted);
  font-size: 12px;
}

.card-stats b {
  color: var(--text);
  font-weight: 700;
}

.card-delta {
  min-width: 64px;
}

.card-tags {
  min-height: 20px;
}

.card-actions {
  position: absolute;
  right: 24px;
  bottom: 16px;
  display: flex;
  justify-content: flex-end;
}

.read-link {
  min-width: 64px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  font-size: 12px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.read-link:hover {
  color: var(--accent);
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

thead {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f7f9fb;
  box-shadow: 0 1px 0 var(--line);
}

th,
td {
  padding: 12px 12px;
  border-bottom: 1px solid #edf1f3;
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}

th {
  color: #50606b;
  font-weight: 600;
}

.col-rank {
  width: 70px;
}

.num {
  width: 108px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

tbody tr {
  cursor: pointer;
  transition: background 120ms ease;
}

tbody tr:hover,
tbody tr.selected {
  background: #f5f8ff;
}

.empty-cell {
  height: 160px;
  text-align: center;
  color: var(--muted);
  cursor: default;
}

.book-title {
  font-weight: 700;
  line-height: 1.35;
}

.book-author {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-height: 46px;
  overflow: hidden;
}

.tag {
  max-width: 82px;
  padding: 3px 6px;
  border-radius: 5px;
  background: #eef2f3;
  color: #4b5a64;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.delta-up {
  color: var(--good);
  font-weight: 700;
}

.delta-down {
  color: var(--bad);
  font-weight: 700;
}

.detail-pane {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  background: #fff;
  border-left: 1px solid var(--line);
}

.empty-detail {
  height: 100%;
  min-height: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px;
  text-align: center;
  color: var(--muted);
}

.empty-detail span {
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
}

.detail {
  padding: 22px;
  animation: paneIn 180ms ease both;
}

@keyframes paneIn {
  from {
    opacity: 0;
    transform: translateX(10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.detail h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.35;
  letter-spacing: 0;
}

.detail-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.detail-copy-actions {
  display: flex;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.detail .author {
  margin: 7px 0 14px;
  color: var(--muted);
}

.book-id-line {
  margin: 6px 0 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.book-id-line code {
  color: var(--text);
  font-family: "Cascadia Mono", "Consolas", monospace;
}

.book-id-copy {
  min-height: 26px;
  padding: 0 8px;
  font-size: 12px;
}

.intro {
  margin: 14px 0 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
}

.intro h3 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 15px;
  line-height: 1.35;
}

.intro-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.intro-head h3 {
  margin: 0;
}

.intro div {
  max-height: none;
  overflow: visible;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.75;
  font-size: 13px;
}

.chapter-copy {
  margin: 14px 0 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.chapter-copy-head,
.chapter-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.chapter-copy h3 {
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
}

.mini-button,
.copy-button {
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.mini-button {
  height: 28px;
  padding: 0 9px;
  font-size: 12px;
}

.mini-button.official-link {
  border-color: rgba(79, 70, 229, 0.18);
  background: rgba(79, 70, 229, 0.06);
  color: #3730a3;
  font-weight: 700;
}

.copy-button {
  height: 34px;
  padding: 0 13px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

.catalog-copy-button {
  width: 100%;
  margin: 0 0 14px;
}

.mini-button:disabled,
.copy-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.chapter-options {
  display: grid;
  gap: 8px;
  margin: 12px 0;
  color: var(--muted);
  font-size: 13px;
}

.chapter-option {
  display: grid;
  grid-template-columns: 18px 24px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid #edf1f3;
  border-radius: 6px;
  background: #fbfcfd;
}

.chapter-option input {
  width: 16px;
  height: 16px;
}

.chapter-option strong {
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.copy-status {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

.novel-ai-panel {
  margin: 14px 0 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.novel-ai-head,
.novel-ai-actions,
.novel-ai-dialog-head,
.novel-ai-dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.novel-ai-head h3,
.novel-ai-dialog h3 {
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
}

.novel-ai-model-button {
  max-width: 62%;
  height: auto;
  min-height: 30px;
  text-align: left;
}

.novel-ai-model-button span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.novel-ai-prompt-wrap,
.novel-ai-dialog-field {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.novel-ai-prompt-wrap > span,
.novel-ai-dialog-field > span {
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.novel-ai-prompt,
.novel-ai-output {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 10px;
  color: var(--text);
  background: #fff;
  outline: none;
  resize: vertical;
  line-height: 1.65;
}

.novel-ai-prompt {
  min-height: 86px;
}

.novel-ai-prompt-wrap small,
.novel-ai-status {
  color: var(--muted);
  font-size: 12px;
}

.novel-ai-cost-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.novel-ai-cost-line strong {
  color: var(--text);
  font-weight: 800;
}

.novel-ai-actions {
  margin: 12px 0;
}

.novel-ai-generate {
  min-width: 88px;
  flex-shrink: 0;
}

.novel-ai-generate.is-stopping {
  border-color: var(--bad);
  background: var(--bad);
}

.novel-ai-output-head,
.ai-usage-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.novel-ai-output-head {
  margin: 12px 0 6px;
  color: #374151;
  font-size: 13px;
  font-weight: 800;
}

.novel-ai-output-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.novel-ai-output-head .mini-button,
.ai-usage-section-head .mini-button {
  min-height: 30px;
  padding: 5px 10px;
  white-space: nowrap;
}

.novel-ai-output {
  min-height: 190px;
  max-height: 440px;
  overflow: auto;
  resize: none;
}

.novel-ai-output-placeholder {
  color: var(--subtle);
}

.novel-ai-output > * {
  margin: 0 0 10px;
}

.novel-ai-output > *:last-child {
  margin-bottom: 0;
}

.novel-ai-output h3,
.novel-ai-output h4,
.novel-ai-output h5,
.novel-ai-output h6 {
  color: #111827;
  font-size: 14px;
  line-height: 1.45;
}

.novel-ai-output ul,
.novel-ai-output ol {
  padding-left: 20px;
}

.novel-ai-output li + li {
  margin-top: 4px;
}

.novel-ai-output blockquote {
  padding-left: 10px;
  border-left: 3px solid #c7d2fe;
  color: var(--muted);
}

.novel-ai-output code {
  border-radius: 4px;
  padding: 1px 4px;
  background: #eef2f7;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.92em;
}

.novel-ai-output pre {
  overflow: auto;
  padding: 10px;
  border-radius: 6px;
  background: #111827;
  color: #f8fafc;
}

.novel-ai-output pre code {
  padding: 0;
  background: transparent;
  color: inherit;
}

.novel-ai-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 130;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.42);
}

.novel-ai-dialog {
  width: min(560px, 100%);
  max-height: min(720px, calc(100svh - 36px));
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  overflow: auto;
  outline: none;
}

.novel-ai-provider-tabs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

.novel-ai-provider-tabs button {
  min-height: 52px;
  display: grid;
  gap: 2px;
  justify-items: start;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fbfcfd;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.novel-ai-provider-tabs button.active {
  border-color: rgba(79, 70, 229, 0.45);
  background: #eef2ff;
}

.novel-ai-provider-tabs span {
  font-size: 13px;
  font-weight: 800;
}

.novel-ai-provider-tabs small {
  color: var(--muted);
  font-size: 12px;
}

.novel-ai-dialog-field select,
.novel-ai-temperature-control input[type="number"] {
  height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
  color: var(--text);
  outline: none;
}

.novel-ai-temperature-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 82px;
  align-items: center;
  gap: 10px;
}

.novel-followup-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 128;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.42);
}

.novel-followup-dialog {
  width: min(860px, 100%);
  height: min(760px, calc(100svh - 36px));
  display: grid;
  grid-template-rows: auto auto minmax(220px, 1fr) minmax(130px, 0.42fr) auto;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  outline: none;
}

.novel-followup-head,
.novel-followup-toolbar,
.novel-followup-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.novel-followup-head h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.35;
}

.novel-followup-head span,
.novel-followup-actions span {
  color: var(--muted);
  font-size: 12px;
}

.novel-followup-toolbar {
  align-items: stretch;
}

.novel-followup-toolbar .novel-ai-model-button {
  max-width: min(460px, 68%);
}

.novel-followup-context {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  background: #fbfcfd;
}

.novel-followup-context.locked {
  color: var(--muted);
  cursor: default;
}

.novel-followup-field {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 6px;
}

.novel-followup-field > span {
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.novel-followup-field textarea,
.novel-followup-output {
  width: 100%;
  min-height: 0;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 10px;
  color: var(--text);
  background: #fff;
  line-height: 1.65;
  resize: none;
  outline: none;
}

.novel-followup-output {
  overflow: auto;
}

.novel-followup-field textarea:disabled,
.novel-followup-context input:disabled + span {
  color: var(--muted);
}

.novel-followup-actions {
  flex-wrap: wrap;
}

.novel-followup-actions .copy-button {
  min-width: 88px;
}

.novel-followup-actions .copy-button.is-stopping {
  border-color: var(--bad);
  background: var(--bad);
}

.context-menu {
  position: fixed;
  z-index: 20;
  min-width: 144px;
  padding: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.context-menu button {
  width: 100%;
  height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  padding: 0 10px;
}

.context-menu button:hover {
  background: #f2f5ff;
}

.context-menu button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.context-menu button:disabled:hover {
  background: transparent;
}

.copy-toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 30;
  padding: 10px 14px;
  border-radius: 8px;
  background: #17212b;
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 13px;
}

.sparkline {
  width: 100%;
  height: 94px;
  margin: 8px 0 16px;
  background: #f2f6f8;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.trend-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.trend-row {
  display: grid;
  grid-template-columns: 78px 54px 1fr 82px;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  background: #fff;
  font-size: 12px;
}

.trend-row .muted {
  color: var(--muted);
}

.rank-pill {
  display: inline-flex;
  min-width: 42px;
  height: 24px;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: #eef2ff;
  color: #3d4ed8;
  font-weight: 700;
}

@media (max-width: 1040px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100svh;
    overflow: visible;
  }

  .topbar {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .board-tabs {
    justify-content: flex-start;
  }

  .date-wrap {
    justify-content: flex-start;
  }

  .workspace {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .list-pane {
    overflow: visible;
  }

  .rank-scroll,
  .detail-pane {
    overflow: visible;
  }

  .detail-pane {
    border-top: 1px solid var(--line);
  }

}

@media (max-width: 680px) {
  .summary-strip {
    grid-template-columns: repeat(2, 1fr);
  }

  .analysis-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .rank-scroll {
    padding: 8px;
  }

  .rank-grid {
    grid-template-columns: 1fr;
  }

  .book-card {
    grid-template-columns: 76px minmax(0, 1fr);
    padding: 12px 12px 34px;
  }

  .card-actions {
    right: 16px;
    bottom: 12px;
  }

  .book-cover {
    width: 62px;
    height: 84px;
  }

  .card-title {
    font-size: 15px;
  }

  th:nth-child(4),
  td:nth-child(4),
  th:nth-child(7),
  td:nth-child(7) {
    display: none;
  }

  .num {
    width: 88px;
  }
}

.site-shell {
  width: 100%;
  height: 100svh;
  min-height: 0;
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  overflow: hidden;
  background: #f8fafc;
  transition: grid-template-columns 180ms ease;
}

.site-shell.sidebar-collapsed {
  grid-template-columns: 68px minmax(0, 1fr);
}

.site-sidebar {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
  padding: 16px 16px 18px;
  border-right: 1px solid #e5e7eb;
  background: rgba(255, 255, 255, 0.88);
}

.brand-block {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.sidebar-toggle,
.icon-button {
  width: 28px;
  height: 28px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  color: #111827;
  cursor: pointer;
  font-weight: 900;
}

.sidebar-toggle:hover,
.icon-button:hover {
  border-color: #4f46e5;
  color: #4f46e5;
}

.site-shell.sidebar-collapsed .site-nav-button span:not(.nav-icon),
.site-shell.sidebar-collapsed .sidebar-footer {
  display: none;
}

.site-shell.sidebar-collapsed .sidebar-toggle {
  display: grid;
  place-items: center;
  position: absolute;
  left: 52px;
  top: 16px;
  transform: rotate(180deg);
}

.site-shell.sidebar-collapsed .site-sidebar {
  position: relative;
  padding-inline: 14px;
}

.site-shell.sidebar-collapsed .site-nav-button {
  grid-template-columns: 1fr;
  padding: 0;
  justify-items: center;
}

.site-nav {
  display: grid;
  align-content: start;
  gap: 8px;
  padding-top: 6px;
}

.site-nav-button {
  height: 42px;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  border: 0;
  border-left: 2px solid transparent;
  border-radius: 8px;
  padding: 0 12px;
  color: #4b5563;
  background: transparent;
  cursor: pointer;
  font-weight: 800;
  text-align: left;
}

.site-nav-button[hidden] {
  display: none;
}

.site-nav-button:hover,
.site-nav-button.active {
  color: #111827;
  background: rgba(79, 70, 229, 0.06);
}

.site-nav-button.active {
  border-left-color: #4f46e5;
}

.nav-icon {
  width: 25px;
  height: 25px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  color: inherit;
  background: rgba(255, 255, 255, 0.86);
  font-size: 13px;
}

.sidebar-footer {
  display: grid;
  gap: 10px;
}

.login-button {
  height: 38px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  color: #111827;
  background: #fff;
  cursor: pointer;
  font-weight: 800;
}

.login-button:hover {
  border-color: #4f46e5;
  color: #4f46e5;
}

.login-button.compact {
  width: 86px;
  background: linear-gradient(135deg, #5a67f2, #24a8a1);
  color: #fff;
  border: 0;
}

.user-chip {
  min-height: 38px;
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  font-size: 12px;
}

.user-chip strong,
.user-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-chip span {
  color: #4b5563;
}

.user-chip .user-chip-expiry {
  color: #6b7280;
}

.site-content {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.site-page {
  height: 100%;
  min-height: 0;
  display: none;
}

.site-page.active {
  display: block;
}

.rank-page .app-shell {
  height: 100%;
}

.image-page {
  width: 100%;
  max-width: 100%;
  overflow: auto;
  overflow-x: hidden;
  padding: 28px clamp(18px, 4vw, 44px);
  background: #f8fafc;
}

.ai-usage-page {
  width: 100%;
  max-width: 100%;
  overflow: auto;
  overflow-x: hidden;
  padding: 28px clamp(18px, 4vw, 44px);
  background: #f8fafc;
}

.image-topbar {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.image-topbar p {
  margin: 0 0 4px;
  color: #4b5563;
  font-size: 13px;
  font-weight: 800;
}

.image-topbar h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
  letter-spacing: 0;
}

.ai-usage-header {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.ai-usage-header p {
  margin: 0 0 4px;
  color: #4b5563;
  font-size: 13px;
  font-weight: 800;
}

.ai-usage-header h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
  letter-spacing: 0;
}

.ai-usage-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.ai-usage-summary div {
  min-height: 76px;
  display: grid;
  align-content: center;
  gap: 6px;
  padding: 14px 16px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
}

.ai-usage-summary span {
  color: #6b7280;
  font-size: 13px;
  font-weight: 700;
}

.ai-usage-summary strong {
  color: #111827;
  font-size: 24px;
  line-height: 1.1;
}

.ai-usage-list {
  display: grid;
  gap: 12px;
}

.ai-usage-card {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 16px;
  padding: 14px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.05);
}

.ai-usage-card.no-media {
  grid-template-columns: minmax(0, 1fr);
}

.ai-usage-thumb {
  width: 112px;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: #eef2ff;
  cursor: pointer;
}

.ai-usage-thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.ai-usage-card-main {
  min-width: 0;
  display: grid;
  gap: 12px;
}

.ai-usage-card-main header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
}

.ai-usage-card-main header div {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.ai-usage-card-main strong {
  color: #111827;
  font-size: 16px;
}

.ai-usage-card-main header span {
  color: #6b7280;
  font-size: 12px;
}

.ai-usage-card-main header em {
  flex: 0 0 auto;
  padding: 6px 10px;
  border-radius: 999px;
  color: #4f46e5;
  background: #eef2ff;
  font-style: normal;
  font-size: 13px;
  font-weight: 900;
}

.ai-usage-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
  margin: 0;
}

.ai-usage-fields div {
  min-width: 0;
  display: grid;
  gap: 3px;
  padding: 9px 10px;
  border-radius: 8px;
  background: #f8fafc;
}

.ai-usage-fields dt {
  color: #6b7280;
  font-size: 12px;
  font-weight: 800;
}

.ai-usage-fields dd {
  margin: 0;
  overflow-wrap: anywhere;
  color: #111827;
  font-size: 13px;
  font-weight: 700;
}

.ai-usage-card-main section {
  display: grid;
  gap: 6px;
}

.ai-usage-section-head b {
  color: #374151;
  font-size: 13px;
}

.ai-usage-card-main pre {
  max-height: 180px;
  overflow: auto;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  color: #111827;
  background: #f9fafb;
  font: 13px/1.6 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ai-usage-protected,
.ai-usage-empty {
  margin: 0;
  padding: 14px 16px;
  border: 1px dashed #c7d2fe;
  border-radius: 8px;
  color: #4b5563;
  background: #fff;
}

.ai-usage-empty.error {
  color: #b91c1c;
  border-color: #fecaca;
}

.image-composer {
  position: relative;
  margin: 0 auto 18px;
  max-width: 1550px;
  min-height: 256px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  overflow: hidden;
}

.composer-head {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  border-bottom: 1px solid #e5e7eb;
}

.composer-head strong {
  color: #111827;
}

.composer-head span {
  color: #4b5563;
  font-size: 13px;
  font-weight: 750;
}

.composer-head span.error {
  color: #c13737;
}

.composer-form {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(104px, 1fr) auto auto;
  gap: 12px;
  padding: 14px;
}

.prompt-row {
  min-height: 104px;
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 12px;
}

.quick-test-actions {
  display: grid;
  align-content: start;
  gap: 8px;
  padding-top: 10px;
}

.quick-test-button {
  height: 36px;
  border: 1px solid #d7dde8;
  border-radius: 8px;
  background: #f8fafc;
  color: #111827;
  cursor: pointer;
  font-weight: 850;
}

.quick-test-button:hover,
.quick-test-button:focus-visible {
  border-color: rgba(79, 70, 229, 0.38);
  background: #eef2ff;
  outline: none;
}

.composer-form textarea {
  width: 100%;
  min-height: 104px;
  border: 0;
  resize: vertical;
  padding: 12px 0;
  color: #17212b;
  background: transparent;
  outline: none;
  line-height: 1.65;
}

.composer-options {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-top: 1px solid #e5e7eb;
  padding-top: 12px;
}

.composer-options select,
.file-pill,
.history-reference-button {
  height: 36px;
  border: 1px solid #e5e7eb;
  border-radius: 18px;
  padding: 0 12px;
  background: #fff;
  color: #111827;
  font-weight: 750;
  outline: none;
}

.history-reference-button {
  cursor: pointer;
  transition:
    border-color 0.18s ease,
    background 0.18s ease,
    color 0.18s ease;
}

.history-reference-button:hover,
.history-reference-button:focus-visible {
  border-color: rgba(90, 103, 242, 0.55);
  color: #4f46e5;
  outline: none;
}

.file-pill {
  width: 38px;
  justify-content: center;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  padding: 0;
}

.file-pill input {
  display: none;
}

.image-icon {
  width: 18px;
  height: 18px;
  display: inline-block;
  position: relative;
  border: 2px solid currentColor;
  border-radius: 4px;
}

.image-icon::before {
  content: "";
  position: absolute;
  width: 4px;
  height: 4px;
  right: 3px;
  top: 3px;
  border-radius: 50%;
  background: currentColor;
}

.image-icon::after {
  content: "";
  position: absolute;
  left: 3px;
  right: 3px;
  bottom: 3px;
  height: 7px;
  background: linear-gradient(135deg, transparent 43%, currentColor 44% 56%, transparent 57%),
    linear-gradient(45deg, transparent 43%, currentColor 44% 56%, transparent 57%);
  opacity: 0.86;
}

.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;
}

.generate-button {
  margin-left: auto;
  min-width: 112px;
  height: 38px;
  border: 0;
  border-radius: 9px;
  color: #fff;
  background: #111827;
  cursor: pointer;
  font-weight: 900;
  box-shadow: none;
}

.generate-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.auth-dialog.quick-test-dialog {
  width: min(920px, calc(100vw - 36px));
  max-height: min(820px, calc(100svh - 36px));
  display: grid;
  gap: 14px;
  overflow: auto;
}

.auth-dialog.quick-book-dialog {
  width: min(1180px, calc(100vw - 48px));
  max-height: min(820px, calc(100svh - 32px));
  grid-template-columns: minmax(320px, 0.72fr) minmax(0, 1.28fr);
  grid-template-areas:
    "head head"
    "input categories"
    "titles templates"
    "error error"
    "actions actions";
  align-items: start;
  gap: 16px 18px;
  padding: 18px;
}

.quick-book-dialog .auth-head {
  grid-area: head;
}

.quick-book-input-panel {
  grid-area: input;
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid #dfe6f0;
  border-radius: 8px;
  background: #f8fafc;
}

.quick-category-section {
  grid-area: categories;
  min-width: 0;
  height: 360px;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 12px;
  border: 1px solid #dfe6f0;
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.quick-title-section {
  grid-area: titles;
  min-width: 0;
  padding: 12px;
  border: 1px solid #dfe6f0;
  border-radius: 8px;
  background: #fff;
}

.quick-template-section {
  grid-area: templates;
  min-width: 0;
  padding: 12px;
  border: 1px solid #dfe6f0;
  border-radius: 8px;
  background: #fff;
}

.quick-book-dialog .auth-error {
  grid-area: error;
}

.quick-book-dialog .auth-actions {
  grid-area: actions;
}

.auth-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.auth-actions button {
  height: 38px;
  min-width: 86px;
  border: 1px solid #d7dde8;
  border-radius: 8px;
  padding: 0 14px;
  background: #fff;
  color: #111827;
  cursor: pointer;
  font-weight: 850;
}

.auth-actions button:hover,
.auth-actions button:focus-visible {
  border-color: rgba(79, 70, 229, 0.38);
  background: #eef2ff;
  outline: none;
}

.auth-actions button[type="submit"],
.auth-actions button:last-child {
  border-color: transparent;
  background: #111827;
  color: #fff;
  font-weight: 900;
}

.auth-actions button[type="submit"]:hover,
.auth-actions button[type="submit"]:focus-visible,
.auth-actions button:last-child:hover,
.auth-actions button:last-child:focus-visible {
  background: #020617;
}

.auth-actions button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.quick-test-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.quick-test-fields label,
.quick-book-author-field,
.quick-plot-field {
  display: grid;
  gap: 7px;
  color: #111827;
  font-size: 13px;
  font-weight: 850;
}

.quick-cover-extra-field {
  grid-column: 1 / -1;
}

.quick-test-fields input,
.quick-test-fields select,
.quick-test-fields textarea,
.quick-book-author-field input,
.quick-plot-field textarea {
  width: 100%;
  border: 1px solid #d7dde8;
  border-radius: 8px;
  padding: 9px 10px;
  color: #111827;
  background: #fff;
  outline: none;
}

.quick-test-fields textarea {
  min-height: 82px;
  resize: vertical;
  line-height: 1.55;
}

.quick-plot-field textarea {
  min-height: 180px;
  resize: vertical;
  line-height: 1.65;
}

.quick-book-primary-action {
  display: flex;
  justify-content: flex-end;
}

.quick-book-primary-action button {
  height: 38px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  background: #111827;
  color: #fff;
  cursor: pointer;
  font-weight: 900;
}

.quick-book-primary-action button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.quick-test-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.quick-test-section-head strong {
  color: #111827;
  font-size: 14px;
}

.quick-test-section-head span {
  color: #6b7280;
  font-size: 12px;
}

.quick-template-grid {
  display: grid;
  gap: 10px;
}

.quick-template-tools {
  display: grid;
  grid-template-columns: minmax(220px, 0.72fr) minmax(0, 1.28fr);
  gap: 8px;
  align-items: start;
}

.quick-template-tools > input,
.quick-template-tools select {
  width: 100%;
  height: 34px;
  border: 1px solid #d7dde8;
  border-radius: 8px;
  padding: 0 9px;
  background: #fff;
  color: #111827;
  outline: none;
}

.quick-template-tag-filter {
  min-width: 0;
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.quick-template-tags {
  min-width: 0;
  max-height: 76px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  overflow: auto;
  padding-right: 2px;
}

.quick-template-tag,
.quick-template-tag-clear {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  border: 1px solid #d7dde8;
  border-radius: 999px;
  background: #fff;
  color: #334155;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.quick-template-tag {
  position: relative;
  padding: 0 9px;
}

.quick-template-tag input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.quick-template-tag-clear {
  flex: 0 0 auto;
  padding: 0 10px;
}

.quick-template-tag.active,
.quick-template-tag-clear.active {
  border-color: rgba(79, 70, 229, 0.32);
  background: #eef2ff;
  color: #3730a3;
}

.quick-template-list {
  max-height: 300px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 8px;
  overflow: auto;
  padding-right: 3px;
}

.quick-template-option,
.quick-category-option,
.quick-title-option {
  cursor: pointer;
}

.quick-template-option {
  display: grid;
  grid-template-columns: 46px 48px minmax(0, 1fr);
  align-items: start;
  gap: 7px 9px;
  padding: 8px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
}

.quick-template-option input[type="number"] {
  width: 46px;
  height: 28px;
  border: 1px solid #d7dde8;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.92);
  color: #111827;
  font-weight: 850;
  text-align: center;
}

.quick-template-option img {
  grid-column: 2;
  grid-row: 1 / span 2;
  width: 48px;
  height: 64px;
  object-fit: cover;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #f3f6fb;
}

.quick-template-option span {
  grid-column: 3;
  color: #111827;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.quick-template-option small {
  grid-column: 3;
  color: #6b7280;
  font-size: 11px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.quick-category-grid,
.quick-title-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
}

.quick-category-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: start;
  min-height: 0;
  overflow: auto;
  gap: 10px;
  padding-right: 4px;
}

.quick-board-column {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.quick-board-column > strong {
  color: #111827;
  font-size: 13px;
  line-height: 1.25;
}

.quick-board-column > div {
  display: grid;
  gap: 6px;
}

.quick-book-dialog .quick-category-option {
  grid-template-columns: 15px minmax(0, 1fr) auto;
  gap: 5px 6px;
  min-height: 30px;
  padding: 6px 7px;
  border-radius: 7px;
}

.quick-book-dialog .quick-category-option span {
  font-size: 12px;
}

.quick-book-dialog .quick-category-option small {
  grid-column: 3;
  grid-row: 1;
  font-size: 10px;
}

.quick-book-dialog .quick-title-grid {
  max-height: 220px;
  overflow: auto;
}

.quick-book-dialog .quick-title-option {
  min-height: 48px;
  align-items: flex-start;
  padding: 8px 10px;
}

.quick-category-option,
.quick-title-option {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 8px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
}

.quick-category-option small {
  grid-column: 2;
  color: #6b7280;
  font-size: 11px;
}

.quick-category-option span,
.quick-title-option span {
  overflow: hidden;
  color: #111827;
  font-size: 13px;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quick-title-option span {
  display: block;
  overflow: visible;
  line-height: 1.45;
  overflow-wrap: anywhere;
  text-overflow: clip;
  white-space: normal;
}

.quick-title-option input {
  margin-top: 3px;
}

.quick-title-edit {
  width: 100%;
  min-height: 30px;
  border: 1px solid rgba(79, 70, 229, 0.42);
  border-radius: 6px;
  padding: 4px 6px;
  color: #111827;
  font-size: 13px;
  font-weight: 800;
  outline: none;
}

.quick-pair-preview {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.quick-pair-row {
  min-height: 30px;
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) 16px minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  padding: 6px 8px;
  border: 1px solid #e5e7eb;
  border-radius: 7px;
  background: #f8fafc;
  color: #475569;
  font-size: 12px;
}

.quick-pair-row span {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #eef2ff;
  color: #3730a3;
  font-weight: 900;
}

.quick-pair-row strong,
.quick-pair-row small {
  min-width: 0;
  color: #111827;
  font-size: 12px;
  font-weight: 850;
  overflow-wrap: anywhere;
}

.quick-pair-row em {
  color: #64748b;
  font-style: normal;
  font-weight: 900;
  text-align: center;
}

.quick-empty {
  padding: 12px;
  border: 1px dashed #d7dde8;
  border-radius: 8px;
  color: #6b7280;
  font-size: 13px;
}

.history-actions {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.reference-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #637180;
  font-size: 13px;
}

.reference-preview img {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #dde5ed;
}

.reference-preview span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reference-clear {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid #ccd7e4;
  border-radius: 50%;
  background: #fff;
  color: #1f2a37;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.reference-clear:hover {
  border-color: #c13737;
  color: #c13737;
}

.gallery-toolbar {
  width: 100%;
  max-width: 1550px;
  margin: 0 auto 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
}

.gallery-filters {
  flex: 0 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.gallery-search {
  flex: 1 1 360px;
  min-width: 180px;
  max-width: 420px;
  display: block;
}

.gallery-search input {
  width: 100%;
  height: 36px;
  border: 1px solid #d5dee8;
  border-radius: 18px;
  padding: 0 14px;
  outline: none;
  background: #fff;
}

.gallery-search input:focus {
  border-color: #5a67f2;
  box-shadow: 0 0 0 3px rgba(90, 103, 242, 0.12);
}

.custom-tag-anchor {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.filter-chip {
  height: 32px;
  border: 0;
  border-radius: 17px;
  padding: 0 15px;
  color: #1e2a37;
  background: #edf1f6;
  cursor: pointer;
  font-weight: 850;
  white-space: nowrap;
}

.filter-chip.active {
  color: #fff;
  background: #5a67f2;
}

.tag-filter-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.tag-filter-wrap .custom-filter-chip {
  padding-right: 30px;
}

.tag-delete-button {
  position: absolute;
  right: 5px;
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.7);
  color: #5d6b7b;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

.tag-delete-button:hover,
.tag-delete-button:focus-visible {
  color: #fff;
  background: #c13737;
  outline: none;
}

.ai-card-favorite {
  position: absolute;
  top: 10px;
  right: 50px;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: #cbd5e1;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  text-shadow: none;
  transition: color 160ms ease, background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.ai-card-favorite:hover,
.ai-card-favorite:focus-visible {
  transform: scale(1.04);
  border-color: rgba(220, 38, 38, 0.3);
  color: #ef4444;
  outline: none;
}

.ai-card-favorite.active {
  color: #ef4444;
}

.tag-manager {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tag-manager[hidden] {
  display: none;
}

.tag-manager input {
  width: 112px;
  height: 32px;
  border: 1px solid #d5dee8;
  border-radius: 16px;
  padding: 0 11px;
  outline: none;
}

.tag-manager input:focus {
  border-color: #5a67f2;
  box-shadow: 0 0 0 3px rgba(90, 103, 242, 0.12);
}

.tag-manager button {
  height: 32px;
  border: 0;
  border-radius: 16px;
  padding: 0 12px;
  color: #2730d6;
  background: #e9edff;
  cursor: pointer;
  font-weight: 850;
}

.add-prompt-inline {
  height: 36px;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 0;
  border-radius: 18px;
  padding: 0 16px 0 12px;
  color: #fff;
  background: linear-gradient(135deg, #5a67f2, #24a8a1);
  cursor: pointer;
  font-weight: 900;
  white-space: nowrap;
  box-shadow: 0 10px 24px rgba(36, 168, 161, 0.22);
  transition: transform 160ms ease, box-shadow 160ms ease, filter 160ms ease;
}

.add-prompt-inline span {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  font-size: 16px;
  line-height: 1;
}

.add-prompt-inline:hover,
.add-prompt-inline:focus-visible {
  transform: translateY(-1px);
  filter: saturate(1.05);
  box-shadow: 0 14px 30px rgba(90, 103, 242, 0.25);
  outline: none;
}

.ai-gallery {
  max-width: 1550px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 280px));
  gap: 16px;
  justify-content: start;
  padding-bottom: 34px;
}

.ai-card {
  position: relative;
  min-height: 300px;
  margin: 0;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  transition: transform 160ms ease, box-shadow 160ms ease, border-color 160ms ease;
}

.ai-card > * {
  position: relative;
  z-index: 1;
}

.ai-card:hover,
.ai-card:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(79, 70, 229, 0.22);
  box-shadow: 0 20px 36px rgba(15, 23, 42, 0.08);
  outline: none;
}

.ai-card.pending {
  cursor: default;
  border-color: rgba(79, 70, 229, 0.22);
  background: linear-gradient(180deg, #fff, #f8fafc);
}

.ai-card.pending.failed {
  cursor: pointer;
  border-color: rgba(185, 28, 28, 0.28);
  background: linear-gradient(180deg, #fff, #fff7f7);
}

.ai-card.pending:hover,
.ai-card.pending:focus-visible {
  transform: none;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.ai-card-loading {
  min-height: 310px;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 46%, rgba(79, 70, 229, 0.08), transparent 34%),
    #f8fafc;
}

.ai-card-loading span {
  width: 54px;
  height: 54px;
  border: 4px solid rgba(79, 70, 229, 0.16);
  border-top-color: #4f46e5;
  border-radius: 50%;
  animation: ai-spin 0.8s linear infinite;
}

.ai-card-failed {
  min-height: 310px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  padding: 22px;
  text-align: center;
  background:
    radial-gradient(circle at 50% 42%, rgba(185, 28, 28, 0.08), transparent 36%),
    #fff7f7;
}

.ai-card-failed strong {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #fee2e2;
  color: #b91c1c;
  font-size: 30px;
  line-height: 1;
}

.ai-card-failed span {
  max-width: 100%;
  color: #7f1d1d;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

@keyframes ai-spin {
  to {
    transform: rotate(360deg);
  }
}

.ai-card-delete {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 4;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.72);
  color: #fff;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.22);
}

.ai-card-delete:hover,
.ai-card-delete:focus-visible {
  background: #991b1b;
  outline: none;
}

.ai-card-delete:disabled {
  cursor: wait;
  opacity: 0.7;
}

.ai-card-zoom {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.72);
  color: #fff;
  cursor: pointer;
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.22);
}

.ai-card-zoom:hover,
.ai-card-zoom:focus-visible {
  background: #4f46e5;
  outline: none;
}

.ai-card-download {
  position: absolute;
  top: 10px;
  left: 50px;
  z-index: 2;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.72);
  color: #fff;
  cursor: pointer;
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
  text-decoration: none;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.22);
}

.ai-card-download:hover,
.ai-card-download:focus-visible {
  background: #0f766e;
  outline: none;
}

.history-delete-confirm {
  position: absolute;
  top: 48px;
  right: 10px;
  z-index: 5;
  width: min(230px, calc(100% - 20px));
  padding: 12px;
  border: 1px solid #f1c0c0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 20px 36px rgba(15, 23, 42, 0.08);
}

.history-delete-confirm strong,
.history-delete-confirm span {
  display: block;
}

.history-delete-confirm strong {
  color: #8d1f1f;
  font-size: 13px;
}

.history-delete-confirm span {
  margin-top: 4px;
  color: #5d4b4b;
  font-size: 12px;
  line-height: 1.4;
}

.history-delete-confirm div {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.history-delete-confirm button {
  flex: 1;
  min-width: 0;
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 800;
}

.history-delete-cancel {
  background: #edf2f7;
  color: #24323f;
}

.history-delete-danger {
  background: #c13737;
  color: #fff;
}

.ai-card img {
  width: 100%;
  height: 100%;
  min-height: 310px;
  object-fit: cover;
  display: block;
}

.ai-card-meta {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: end;
  padding: 42px 12px 12px;
  color: #fff;
  background: linear-gradient(180deg, transparent 0%, rgba(15, 23, 42, 0.72) 100%);
}

.ai-card-meta strong,
.ai-card-meta span {
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.45);
}

.ai-card-meta strong {
  font-size: 15px;
}

.ai-card-meta span {
  font-size: 12px;
  font-weight: 800;
}

.ai-empty {
  grid-column: 1 / -1;
  min-height: 260px;
  display: grid;
  place-items: center;
  color: #4b5563;
  border: 1px dashed #d1d5db;
  border-radius: 8px;
  background: #fff;
}

.auth-modal[hidden] {
  display: none;
}

.image-viewer-modal[hidden] {
  display: none;
}

.detail-modal[hidden] {
  display: none;
}

body.modal-open {
  overflow: hidden;
}

.detail-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: end center;
  padding: 18px;
}

.detail-modal-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(15, 23, 42, 0.46);
  backdrop-filter: blur(5px);
}

.detail-modal-dialog {
  position: relative;
  z-index: 1;
  width: min(760px, 100%);
  max-height: min(88svh, 760px);
  overflow-y: auto;
  border: 1px solid rgba(203, 213, 225, 0.9);
  border-radius: 12px 12px 10px 10px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.28);
}

.detail-modal-close {
  position: sticky;
  top: 10px;
  left: calc(100% - 46px);
  z-index: 2;
  margin: 10px 10px -38px auto;
}

.detail-modal .detail {
  padding: 52px 16px 18px;
}

.image-viewer-modal {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 28px;
}

.image-viewer-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(15, 23, 42, 0.82);
  cursor: zoom-out;
}

.image-viewer-dialog {
  position: relative;
  z-index: 1;
  max-width: min(94vw, 1280px);
  max-height: 92svh;
  display: grid;
  gap: 10px;
  margin: 0;
}

.image-viewer-dialog img {
  max-width: min(94vw, 1280px);
  max-height: calc(92svh - 44px);
  object-fit: contain;
  border-radius: 8px;
  background: #0f172a;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.32);
}

.image-viewer-close {
  position: absolute;
  top: -14px;
  right: -14px;
  z-index: 2;
}

.image-viewer-dialog figcaption {
  color: #e5e7eb;
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
}

.auth-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.36);
  backdrop-filter: blur(6px);
}

.error-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 20px;
}

.error-modal[hidden] {
  display: none;
}

.error-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(15, 23, 42, 0.42);
  cursor: pointer;
}

.error-dialog {
  position: relative;
  width: min(420px, calc(100vw - 32px));
  display: grid;
  gap: 12px;
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 18px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.22);
}

.error-dialog strong {
  color: #991b1b;
  font-size: 18px;
}

.error-dialog p {
  margin: 0;
  color: #1f2937;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.auth-dialog {
  position: relative;
  width: min(420px, calc(100vw - 28px));
  display: grid;
  gap: 14px;
  padding: 20px;
  border: 1px solid #dce3ec;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.22);
}

.auth-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.auth-head strong,
.auth-head span {
  display: block;
}

.auth-head strong {
  font-size: 20px;
}

.auth-head span {
  margin-top: 4px;
  color: #627184;
  font-size: 13px;
  line-height: 1.5;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 4px;
  border-radius: 8px;
  background: #eef2f7;
}

.auth-tabs button {
  height: 34px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  cursor: pointer;
  color: #526174;
  font-weight: 850;
}

.auth-tabs button.active {
  color: #fff;
  background: #5a67f2;
}

.auth-dialog label,
.form-field {
  display: grid;
  gap: 7px;
  color: #243244;
  font-weight: 800;
  font-size: 13px;
}

.auth-dialog label[hidden],
.auth-dialog .form-field[hidden] {
  display: none;
}

.auth-dialog input {
  height: 40px;
  border: 1px solid #d5dee8;
  border-radius: 8px;
  padding: 0 11px;
  outline: none;
}

.auth-dialog textarea,
.auth-dialog select {
  width: 100%;
  border: 1px solid #d5dee8;
  border-radius: 8px;
  padding: 10px 11px;
  outline: none;
  background: #fff;
  color: #17212b;
  font: inherit;
}

.auth-dialog input:focus,
.auth-dialog textarea:focus,
.auth-dialog select:focus {
  border-color: #5a67f2;
  box-shadow: 0 0 0 3px rgba(90, 103, 242, 0.14);
}

.prompt-dialog {
  width: min(1120px, calc(100vw - 40px));
  max-height: calc(100svh - 40px);
  grid-template-columns: minmax(320px, 0.92fr) minmax(360px, 1.08fr);
  align-items: start;
  gap: 18px;
  padding: 22px;
  overflow: hidden;
}

.prompt-dialog .auth-head {
  grid-column: 1 / -1;
}

.my-prompts-dialog {
  width: min(1360px, calc(100vw - 24px));
  max-height: calc(100svh - 24px);
  padding: 18px;
  overflow: hidden;
}

.my-prompts-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(250px, 320px) minmax(0, 1fr);
  gap: 14px;
  height: calc(100svh - 110px);
}

.my-prompts-side {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
}

.my-prompt-new-button {
  height: 40px;
  border: 1px solid #dfe7f0;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  cursor: pointer;
  font-weight: 850;
}

.my-prompt-new-button:hover,
.my-prompt-new-button:focus-visible {
  background: #374151;
  outline: none;
}

.my-prompts-list {
  min-height: 0;
  max-height: none;
  display: grid;
  align-content: start;
  gap: 8px;
  overflow-y: auto;
  padding: 2px;
}

.my-prompt-item {
  min-width: 0;
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border: 1px solid #dfe7f0;
  border-radius: 8px;
  padding: 8px;
  background: #fff;
  color: #17212b;
  cursor: pointer;
  text-align: left;
}

.my-prompt-item:hover,
.my-prompt-item:focus-visible {
  border-color: rgba(90, 103, 242, 0.45);
  outline: none;
}

.my-prompt-item.active {
  border-color: #5a67f2;
  background: #f3f5ff;
}

.my-prompt-item img {
  width: 58px;
  height: 76px;
  object-fit: cover;
  border-radius: 6px;
  background: #e8eef5;
}

.my-prompt-item span,
.my-prompt-item strong,
.my-prompt-item em {
  min-width: 0;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.my-prompt-item strong {
  font-size: 13px;
  font-weight: 900;
}

.my-prompt-item em {
  margin-top: 4px;
  color: #647386;
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.my-prompts-empty {
  padding: 18px;
  border: 1px dashed #cfd8e3;
  border-radius: 8px;
  color: #647386;
  text-align: center;
  background: #fff;
  font-weight: 800;
}

.my-prompt-editor {
  min-height: 0;
  max-height: none;
  display: grid;
  grid-template-columns: minmax(430px, 1.12fr) minmax(340px, 0.88fr);
  gap: 12px 16px;
  overflow-y: auto;
  padding-right: 2px;
}

.my-prompt-media,
.my-prompt-fields {
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 12px;
}

.my-prompt-fields > input[type="hidden"] {
  display: none;
}

.my-prompt-editor .my-prompt-preview {
  height: min(62svh, 580px);
  min-height: 460px;
}

.my-prompt-editor .my-prompt-preview img {
  width: min(100%, 500px);
  height: min(52svh, 500px);
  min-height: 0;
  object-fit: contain;
}

.my-prompt-editor .history-image-picker {
  max-height: min(20svh, 150px);
}

.my-prompt-editor[data-empty] .my-prompt-fields,
.my-prompt-editor[data-empty] .prompt-reference-source,
.my-prompt-editor[data-empty] .history-image-picker {
  opacity: 0.48;
  pointer-events: none;
}

.prompt-media-pane,
.prompt-form-pane {
  min-height: 0;
  display: grid;
  gap: 12px;
}

.prompt-media-pane {
  align-self: stretch;
  grid-template-rows: minmax(220px, 1fr) auto minmax(0, auto);
}

.prompt-form-pane {
  align-self: stretch;
  align-content: start;
  max-height: none;
  overflow-y: auto;
  padding-right: 2px;
}

.prompt-form-pane [hidden] {
  display: none !important;
}

.prompt-dialog.history-save-only .prompt-reference-source,
.prompt-dialog.history-save-only .history-image-picker {
  display: none !important;
}

.prompt-preview {
  min-height: 220px;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 10px;
  padding: 14px;
  border: 1px solid #e0e7ef;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(244, 248, 252, 0.98)),
    #f8fafc;
  cursor: pointer;
}

.prompt-preview img {
  width: min(100%, 360px);
  height: min(44svh, 460px);
  min-height: 240px;
  justify-self: center;
  align-self: center;
  object-fit: contain;
  border-radius: 8px;
  background: #e8eef5;
  box-shadow: 0 18px 42px rgba(19, 35, 52, 0.18);
}

.prompt-preview > div:not(.prompt-preview-empty) {
  min-width: 0;
  display: grid;
  gap: 3px;
  align-self: end;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 1px 0 rgba(18, 31, 45, 0.06);
}

.prompt-preview strong,
.prompt-preview span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prompt-preview span {
  margin-top: 4px;
  color: #647386;
  font-size: 12px;
  font-weight: 800;
}

.prompt-preview-empty {
  grid-column: 1 / -1;
  min-height: 360px;
  display: grid;
  place-items: center;
  gap: 4px;
  color: #647386;
  text-align: center;
}

.prompt-preview-empty strong {
  color: #17212b;
}

.history-detail-panel {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid #e0e7ef;
  border-radius: 8px;
  background: #fff;
}

.history-detail-panel[hidden] {
  display: none;
}

.history-detail-head {
  display: grid;
  gap: 3px;
}

.history-detail-head strong {
  color: #111827;
  font-size: 15px;
}

.history-detail-head span,
.history-detail-empty {
  color: #647386;
  font-size: 12px;
  line-height: 1.5;
}

.history-detail-panel section {
  display: grid;
  gap: 5px;
  padding: 10px;
  border: 1px solid #edf1f6;
  border-radius: 7px;
  background: #f8fafc;
}

.history-detail-panel b {
  color: #111827;
  font-size: 12px;
}

.history-detail-panel p {
  margin: 0;
  color: #273548;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.prompt-tag-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 44px;
  padding: 8px;
  border: 1px solid #d5dee8;
  border-radius: 8px;
  background: #fff;
}

.prompt-tag-option {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.prompt-tag-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.prompt-tag-option span {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 15px;
  padding: 0 12px;
  color: #445264;
  background: #eef2f7;
  font-size: 13px;
  font-weight: 850;
  transition: background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.prompt-tag-option input:checked + span {
  color: #fff;
  background: #5a67f2;
  box-shadow: 0 8px 18px rgba(90, 103, 242, 0.22);
}

.prompt-tag-option input:focus-visible + span {
  outline: 2px solid rgba(90, 103, 242, 0.45);
  outline-offset: 2px;
}

.prompt-tag-empty {
  width: 100%;
  padding: 4px 2px;
  color: #647386;
  font-size: 13px;
  font-weight: 800;
}

.visibility-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.visibility-switch label {
  position: relative;
  min-width: 0;
  cursor: pointer;
}

.visibility-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.visibility-switch span {
  min-height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid #dfe7f0;
  border-radius: 8px;
  background: #fff;
  color: #17212b;
  font-size: 13px;
  font-weight: 850;
}

.visibility-switch input:checked + span {
  border-color: #5a67f2;
  background: #f3f5ff;
  color: #2730d6;
}

.generated-prompt-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid #dfe7f0;
  border-radius: 8px;
  background: #f8fafc;
}

.generated-prompt-panel[hidden] {
  display: none;
}

.generated-prompt-head {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.generated-prompt-head strong {
  color: #111827;
  font-size: 13px;
}

.generated-prompt-head div {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.prompt-reference-source {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.prompt-reference-source[hidden] {
  display: none;
}

.history-image-picker[hidden] {
  display: none;
}

.history-image-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
  max-height: min(28svh, 260px);
  overflow-y: auto;
  padding: 2px;
}

.main-history-image-picker {
  margin-top: 12px;
  padding: 10px;
  border: 1px solid #dde5ef;
  border-radius: 12px;
  background: #fff;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
}

.history-image-option {
  min-width: 0;
  display: grid;
  gap: 5px;
  border: 2px solid transparent;
  border-radius: 8px;
  padding: 5px;
  background: #f8fafc;
  color: #526174;
  cursor: pointer;
  text-align: left;
}

.history-image-option:hover,
.history-image-option:focus-visible {
  border-color: rgba(90, 103, 242, 0.45);
  outline: none;
}

.history-image-option.active {
  border-color: #5a67f2;
  background: #eef2ff;
  color: #2631a8;
}

.history-image-option img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 6px;
  background: #e8eef5;
}

.history-image-option span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 800;
}

.history-image-empty {
  grid-column: 1 / -1;
  padding: 16px;
  border: 1px dashed #cfd8e3;
  border-radius: 8px;
  color: #647386;
  text-align: center;
  background: #fff;
}

.prompt-mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 4px;
  border-radius: 8px;
  background: #eef2f7;
}

.prompt-mode-switch label {
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 7px;
  color: #526174;
  cursor: pointer;
  font-size: 13px;
  font-weight: 850;
}

.prompt-mode-switch label:has(input:checked) {
  color: #fff;
  background: #5a67f2;
}

.prompt-mode-switch input {
  width: 14px;
  height: 14px;
  accent-color: currentColor;
}

.auth-error {
  margin: 0;
  color: #c13737;
  font-size: 13px;
  font-weight: 800;
}

.auth-success {
  margin: 0;
  color: #16835f;
  font-size: 13px;
  font-weight: 800;
}

.auth-submit {
  height: 42px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, #5a67f2, #24a8a1);
  cursor: pointer;
  font-weight: 900;
}

.access-gate {
  min-height: 260px;
  display: grid;
  place-items: center;
  padding: 24px;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  background: #fff;
  color: #5f6f80;
  text-align: center;
}

.access-gate strong {
  display: block;
  margin-bottom: 8px;
  color: #17212b;
  font-size: 18px;
}

.admin-page {
  width: 100%;
  max-width: 100%;
  overflow: auto;
  overflow-x: hidden;
  padding: 28px clamp(18px, 4vw, 44px);
  background: #f8fafc;
}

.admin-bulk {
  max-width: 1550px;
  margin: 0 auto 14px;
  display: grid;
  grid-template-columns: auto minmax(180px, 260px) auto minmax(180px, 260px) auto;
  align-items: center;
  gap: 10px;
}

.admin-bulk input {
  height: 34px;
  min-width: 0;
  width: 100%;
  border: 1px solid #d5dee8;
  border-radius: 8px;
  padding: 0 10px;
}

.admin-table-wrap {
  max-width: 1550px;
  margin: 0 auto;
  max-height: min(54vh, 620px);
  overflow: auto;
  border: 1px solid #dce4ee;
  border-radius: 8px;
  background: #fff;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.admin-table th:nth-child(1),
.admin-table td:nth-child(1) {
  width: 42px;
}

.admin-table th:nth-child(2),
.admin-table td:nth-child(2) {
  width: 17%;
}

.admin-table th:nth-child(3),
.admin-table td:nth-child(3) {
  width: 16%;
}

.admin-table th:nth-child(4),
.admin-table td:nth-child(4) {
  width: 110px;
}

.admin-table th:nth-child(5),
.admin-table td:nth-child(5) {
  width: 100px;
}

.admin-table th:nth-child(6),
.admin-table td:nth-child(6) {
  width: 124px;
}

.admin-table th:nth-child(7),
.admin-table td:nth-child(7) {
  width: auto;
}

.admin-table th,
.admin-table td {
  padding: 12px 14px;
  border-bottom: 1px solid #edf1f6;
  text-align: left;
  vertical-align: middle;
  overflow: hidden;
}

.admin-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafc;
}

.admin-table td > strong,
.admin-table td > span {
  display: block;
}

.admin-role,
.admin-credit-delta {
  height: 32px;
  border: 1px solid #d5dee8;
  border-radius: 7px;
  padding: 0 8px;
  max-width: 100%;
}

.admin-credit-value {
  color: #17212b;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.vip-expiry,
.admin-credit-value {
  white-space: nowrap;
}

.admin-audit {
  display: grid;
  gap: 4px;
  color: #5f6f80;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
}

.admin-audit span {
  white-space: nowrap;
}

.admin-actions {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) minmax(210px, 1.1fr) minmax(78px, auto) minmax(78px, auto);
  gap: 8px;
  min-width: 0;
  align-items: center;
}

.admin-action-group {
  min-width: 0;
  display: grid;
  align-items: center;
  grid-template-columns: auto minmax(86px, 1fr) auto auto;
  gap: 6px;
}

.admin-action-group + .admin-action-group {
  grid-template-columns: auto repeat(3, minmax(54px, 1fr));
}

.admin-action-group span {
  width: auto;
  color: #647386;
  font-size: 12px;
  font-weight: 900;
}

.admin-action-group input {
  width: 100%;
  min-width: 0;
}

.admin-actions button,
.admin-bulk button {
  height: 32px;
  border: 1px solid #d5dee8;
  border-radius: 7px;
  background: #fff;
  color: #1f2a37;
  cursor: pointer;
  font-weight: 800;
  white-space: nowrap;
}

.admin-actions button:hover,
.admin-bulk button:hover {
  border-color: #5a67f2;
  color: #2730d6;
}

.admin-password-dialog {
  width: min(440px, calc(100vw - 28px));
}

.admin-log-panel {
  max-width: 1550px;
  margin: 16px auto 0;
  padding: 14px;
  border: 1px solid #dce4ee;
  border-radius: 8px;
  background: #fff;
}

.admin-log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.admin-log-head strong {
  display: block;
  color: #111827;
  font-size: 16px;
}

.admin-log-head span {
  color: #647386;
  font-size: 12px;
}

.admin-log-list {
  display: grid;
  gap: 8px;
}

.admin-log-item {
  min-height: 54px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid #edf1f6;
  border-radius: 8px;
  background: #f8fafc;
}

.admin-log-item strong {
  display: block;
  color: #111827;
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.admin-log-item span {
  display: block;
  margin-top: 3px;
  color: #647386;
  font-size: 12px;
}

.admin-log-item em {
  min-width: 48px;
  border-radius: 999px;
  padding: 5px 9px;
  background: #eef2ff;
  color: #3730a3;
  font-size: 12px;
  font-style: normal;
  font-weight: 900;
  text-align: center;
}

.admin-log-empty {
  padding: 14px;
  border: 1px dashed #c7d2fe;
  border-radius: 8px;
  color: #647386;
  background: #f8fafc;
}

.admin-log-empty.error {
  color: #b91c1c;
  border-color: #fecaca;
}

@media (max-width: 1320px) {
  .admin-table-wrap {
    overflow-x: auto;
  }

  .admin-table {
    min-width: 1040px;
  }

  .admin-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1180px) {
  .ai-gallery {
    grid-template-columns: repeat(auto-fill, minmax(180px, 240px));
  }
}

@media (max-width: 720px) {
  .admin-header {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .admin-header .filter-chip {
    width: 100%;
  }

  .admin-table-wrap {
    overflow: visible;
    border: 0;
    background: transparent;
  }

  .admin-table {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0 10px;
  }

  .admin-table thead {
    display: none;
  }

  .admin-table,
  .admin-table tbody,
  .admin-table tr,
  .admin-table td {
    display: block;
    width: 100%;
  }

  .admin-table th:nth-child(1),
  .admin-table td:nth-child(1),
  .admin-table th:nth-child(2),
  .admin-table td:nth-child(2),
  .admin-table th:nth-child(3),
  .admin-table td:nth-child(3),
  .admin-table th:nth-child(4),
  .admin-table td:nth-child(4),
  .admin-table th:nth-child(5),
  .admin-table td:nth-child(5),
  .admin-table th:nth-child(6),
  .admin-table td:nth-child(6),
  .admin-table th:nth-child(7),
  .admin-table td:nth-child(7) {
    width: 100%;
  }

  .admin-table tr {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(104px, 0.85fr) minmax(92px, 0.75fr);
    column-gap: 8px;
    margin-bottom: 10px;
    padding: 12px;
    border: 1px solid #dce4ee;
    border-radius: 8px;
    background: #fff;
  }

  .admin-table tr:last-child {
    margin-bottom: 0;
  }

  .admin-table td {
    grid-column: 1 / -1;
    min-height: 36px;
    padding: 7px 0;
    border-bottom: 1px solid #edf1f6;
    overflow: visible;
  }

  .admin-table td.admin-mobile-primary {
    grid-column: auto;
    min-width: 0;
    border-bottom: 0;
  }

  .admin-table td.admin-mobile-primary + td.admin-mobile-primary {
    padding-left: 0;
  }

  .admin-table td[data-label="积分"] {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    border-top: 1px solid #edf1f6;
  }

  .admin-table td[data-label="积分"]::before {
    margin-bottom: 0;
  }

  .admin-table td:last-child {
    border-bottom: 0;
    padding-bottom: 0;
  }

  .admin-table td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 5px;
    color: #647386;
    font-size: 12px;
    font-weight: 900;
  }

  .admin-table td:first-child {
    min-height: 0;
    padding-top: 0;
  }

  .admin-table td:first-child::before {
    display: inline-block;
    margin: 0 8px 0 0;
    vertical-align: middle;
  }

  .admin-table td > strong,
  .admin-table td > span {
    overflow-wrap: anywhere;
  }

  .admin-role,
  .admin-credit-delta {
    width: 100%;
  }

  .admin-audit {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .admin-audit span {
    min-width: 0;
    padding: 6px 8px;
    border-radius: 7px;
    background: #f1f5f9;
    text-align: center;
  }

  .admin-actions {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .admin-action-group,
  .admin-action-group + .admin-action-group {
    grid-template-columns: minmax(0, 1fr) minmax(58px, auto) minmax(58px, auto);
    gap: 8px;
  }

  .admin-action-group span {
    grid-column: 1 / -1;
  }

  .admin-action-group + .admin-action-group {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .admin-action-group + .admin-action-group span {
    grid-column: 1 / -1;
  }

  .admin-actions button,
  .admin-bulk button {
    width: 100%;
    min-height: 36px;
    height: auto;
    padding: 8px 10px;
  }

  .admin-log-panel {
    padding: 12px;
  }

  .admin-log-item {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .admin-log-item em {
    width: max-content;
  }
}

@media (max-width: 900px) {
  .admin-page {
    padding: 16px 10px 24px;
  }

  .admin-bulk {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .admin-bulk strong {
    margin-top: 4px;
  }

  .admin-log-head {
    align-items: stretch;
    flex-direction: column;
  }

  .admin-table-wrap {
    max-height: none;
  }

  .site-shell,
  .site-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100svh;
    overflow-x: hidden;
  }

  .site-sidebar {
    min-height: auto;
    grid-template-columns: 1fr;
    grid-template-areas:
      "nav"
      "footer";
    grid-template-rows: auto auto;
    align-items: center;
    gap: 8px;
    padding: 10px 12px 12px;
  }

  .brand-block {
    display: none;
  }

  .sidebar-toggle {
    display: none;
  }

  .site-nav {
    grid-area: nav;
    display: flex;
    padding-top: 0;
    overflow-x: auto;
    gap: 8px;
  }

  .site-nav-button {
    flex: 0 0 auto;
    min-width: 92px;
  }

  .sidebar-footer {
    grid-area: footer;
    display: grid;
    gap: 8px;
  }

  .user-chip {
    width: 100%;
  }

  .site-shell.sidebar-collapsed .brand-block > div:not(.brand-mark),
  .site-shell.sidebar-collapsed .site-nav-button span:not(.nav-icon),
  .site-shell.sidebar-collapsed .sidebar-footer {
    display: block;
  }

  .site-shell.sidebar-collapsed .site-sidebar {
    padding-inline: 12px;
  }

  .site-shell.sidebar-collapsed .site-nav-button {
    grid-template-columns: 30px minmax(0, 1fr);
    padding: 0 12px;
    justify-items: stretch;
  }

  .site-content {
    min-height: 0;
    overflow: visible;
  }

  .site-page {
    height: auto;
    min-height: 0;
  }

  .rank-page .app-shell {
    height: auto;
    min-height: 0;
  }

  .workspace {
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .list-pane {
    overflow: visible;
  }

  .rank-scroll {
    overflow: visible;
    padding: 12px 0 16px;
  }

  .detail-pane {
    display: none;
  }

  .detail-modal {
    align-items: end;
    padding: 12px;
  }

  .detail-modal-dialog {
    width: 100%;
    max-height: calc(100svh - 24px);
  }

  .detail-modal .detail-title-row,
  .detail-modal .chapter-copy-head,
  .detail-modal .chapter-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .detail-modal .detail-copy-actions {
    justify-content: flex-start;
  }

  .ai-gallery {
    grid-template-columns: repeat(auto-fill, minmax(150px, 220px));
  }

  .prompt-row,
  .quick-test-fields {
    grid-template-columns: 1fr;
  }

  .quick-test-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding-top: 0;
  }

  .auth-dialog.quick-test-dialog {
    width: min(720px, calc(100vw - 24px));
    max-height: calc(100svh - 24px);
  }

  .auth-dialog.quick-book-dialog {
    grid-template-columns: 1fr;
    grid-template-areas:
      "head"
      "input"
      "categories"
      "titles"
      "templates"
      "error"
      "actions";
  }

  .quick-template-tools,
  .quick-category-grid {
    grid-template-columns: 1fr;
  }

  .prompt-dialog {
    width: min(720px, calc(100vw - 24px));
    max-height: calc(100svh - 24px);
    grid-template-columns: 1fr;
    overflow-y: auto;
  }

  .my-prompts-dialog {
    width: min(720px, calc(100vw - 24px));
    max-height: calc(100svh - 24px);
    overflow-y: auto;
  }

  .my-prompts-layout,
  .my-prompt-editor {
    grid-template-columns: 1fr;
  }

  .my-prompts-list,
  .my-prompt-editor {
    max-height: none;
    overflow: visible;
  }

  .my-prompt-media,
  .my-prompt-fields {
    grid-column: auto;
  }

  .my-prompt-editor .my-prompt-preview {
    height: auto;
    min-height: 150px;
  }

  .my-prompt-editor .my-prompt-preview img {
    width: min(100%, 300px);
    height: auto;
    max-height: 42svh;
  }

  .my-prompt-editor .history-image-picker {
    max-height: 220px;
  }

  .prompt-dialog .auth-head {
    grid-column: auto;
  }

  .prompt-media-pane {
    grid-template-rows: auto auto auto;
  }

  .prompt-form-pane {
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }

  .prompt-preview {
    min-height: 150px;
    grid-template-rows: auto auto;
  }

  .prompt-preview img {
    height: auto;
    min-height: 0;
    max-height: 42svh;
  }

  .prompt-preview-empty {
    min-height: 130px;
  }

  .novel-ai-output-head,
  .novel-ai-actions,
  .novel-followup-head,
  .novel-followup-toolbar,
  .novel-followup-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .novel-ai-output-tools {
    justify-content: flex-start;
  }

  .novel-ai-model-button,
  .novel-followup-toolbar .novel-ai-model-button {
    width: 100%;
    max-width: none;
  }

  .novel-followup-modal-backdrop {
    padding: 10px;
  }

  .novel-followup-dialog {
    width: 100%;
    height: calc(100svh - 20px);
    grid-template-rows: auto auto minmax(180px, 1fr) minmax(120px, 0.42fr) auto;
    padding: 12px;
  }
}

@media (max-width: 620px) {
  .image-page,
  .ai-usage-page {
    width: 100vw;
    max-width: 100vw;
    padding: 14px 10px 16px;
  }

  .image-topbar,
  .ai-usage-header {
    height: auto;
    min-height: 0;
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 14px;
    overflow: visible;
  }

  .ai-usage-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ai-usage-card {
    grid-template-columns: 76px minmax(0, 1fr);
    gap: 10px;
    padding: 10px;
  }

  .ai-usage-thumb {
    width: 76px;
  }

  .ai-usage-card-main header {
    flex-direction: column;
  }

  .gallery-search {
    order: 2;
    flex: 1 1 100%;
    min-width: 0;
    max-width: none;
  }

  .gallery-toolbar {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    flex-wrap: wrap;
  }

  .gallery-filters {
    width: 100%;
    max-width: 100%;
    flex: 1 1 100%;
    padding-bottom: 4px;
  }

  .gallery-filters .filter-chip,
  .gallery-filters .tag-filter-wrap,
  .gallery-filters .custom-tag-anchor {
    flex: 0 0 auto;
  }

  .ai-card-favorite {
    right: 44px;
  }

  .history-actions {
    width: 100%;
    max-width: 100%;
    min-height: 36px;
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }

  .history-actions .filter-chip {
    flex: 0 0 auto;
  }

  .gallery-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .tag-manager {
    width: 100%;
  }

  .tag-manager input {
    width: auto;
    flex: 1;
  }

  .add-prompt-inline {
    width: 100%;
    justify-content: center;
  }

  .composer-options {
    flex-wrap: wrap;
  }

  .history-reference-button {
    flex: 1;
  }

  .main-history-image-picker {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    max-height: 42svh;
  }

  .generate-button {
    width: 100%;
    margin-left: 0;
  }

  .ai-gallery {
    grid-template-columns: 1fr;
  }

  .image-viewer-modal {
    padding: 14px;
  }

  .image-viewer-dialog img {
    max-width: 94vw;
    max-height: 82svh;
  }
}
