:root {
  color-scheme: light;
  --bg: #f7f4ec;
  --surface: #ffffff;
  --ink: #1a1814;
  --ink-soft: #5b5247;
  --line: #e6dfd0;
  --accent: #7a3b2e;
  --brand-ink: #0f1b1b;
  --brand-cream: #f8f4ea;
  --card-shadow: 0 1px 2px rgba(26, 24, 20, 0.04), 0 8px 24px rgba(26, 24, 20, 0.04);
  --card-shadow-hover: 0 2px 4px rgba(26, 24, 20, 0.06), 0 16px 36px rgba(26, 24, 20, 0.08);
  --serif: "Fraunces", "Iowan Old Style", "Georgia", "Times New Roman", serif;
  --sans:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body.has-lightbox {
  overflow: hidden;
}

body.chat-body {
  background: #f5f7f4;
}

button,
input,
select {
  font: inherit;
}

a {
  color: inherit;
}

.shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 16px;
}

.workspace {
  min-height: calc(100vh - 32px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 0 22px;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 14px;
}

.brand-mark {
  width: clamp(46px, 8vw, 58px);
  height: clamp(46px, 8vw, 58px);
  flex: 0 0 auto;
  display: block;
  background: #f8f4ea;
  border-radius: 14px;
  box-shadow: 0 8px 22px rgba(15, 27, 27, 0.12);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(28px, 4.5vw, 42px);
  line-height: 1;
  letter-spacing: 0;
  color: var(--ink);
}

.brand p {
  margin-top: 6px;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 400;
}

.topbar-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.lang-toggle {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  border: 0;
  background: transparent;
  padding: 4px 2px;
  color: var(--ink-soft);
  font-size: 13px;
  cursor: pointer;
  line-height: 1.2;
}

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

.lang-option {
  color: var(--ink-soft);
  font-family: var(--sans);
  font-weight: 400;
  transition: color 160ms ease;
}

.lang-divider {
  color: var(--ink-soft);
  opacity: 0.55;
}

.lang-toggle[data-active-lang="zh"] .lang-option[data-lang="zh"],
.lang-toggle[data-active-lang="en"] .lang-option[data-lang="en"] {
  color: var(--ink);
  font-family: var(--serif);
  font-weight: 500;
  letter-spacing: 0;
}

@media (hover: hover) {
  .lang-toggle:hover .lang-option {
    color: var(--ink-soft);
  }

  .lang-toggle[data-active-lang="zh"]:hover .lang-option[data-lang="en"],
  .lang-toggle[data-active-lang="en"]:hover .lang-option[data-lang="zh"] {
    color: var(--ink);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 1px;
  }
}

@media (max-width: 640px) {
  .chat-shell {
    padding: 10px;
  }

  .chat-workspace {
    min-height: calc(100vh - 20px);
  }

  .chat-topbar {
    align-items: flex-start;
  }

  .chat-form {
    grid-template-columns: 1fr;
  }

  .chat-send {
    width: 100%;
  }

  .chat-message {
    max-width: 92%;
  }
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(150px, 220px) minmax(150px, 210px);
  gap: 10px;
  align-items: end;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(26, 24, 20, 0.03);
}

.search-field,
.select-field {
  display: grid;
  gap: 6px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 400;
}

.search-control,
.select-control {
  position: relative;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 14px;
  outline: none;
  transition: border-color 160ms ease, outline-color 160ms ease;
}

select {
  appearance: none;
  cursor: pointer;
  padding-right: 44px;
}

.select-control::after {
  position: absolute;
  top: 50%;
  right: 16px;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--ink-soft);
  border-bottom: 2px solid var(--ink-soft);
  content: "";
  pointer-events: none;
  transform: translateY(-65%) rotate(45deg);
}

input:focus,
select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-color: var(--accent);
}

button:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.chat-shell {
  width: min(860px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 16px;
}

.chat-workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: calc(100vh - 32px);
  gap: 12px;
}

.chat-topbar,
.chat-panel {
  border: 1px solid #dce4d9;
  border-radius: 8px;
  background: #ffffff;
}

.chat-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
}

.chat-brand {
  min-width: 0;
}

.chat-brand h1 {
  font-family: var(--serif);
  font-size: 28px;
  line-height: 1.05;
}

.chat-brand p,
.chat-status {
  color: #566153;
  font-size: 13px;
}

.chat-back {
  flex: 0 0 auto;
  color: #235b42;
  font-size: 14px;
  text-decoration: none;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(240px, 1fr) auto;
  min-height: 0;
  overflow: hidden;
}

.chat-status {
  padding: 10px 14px;
  border-bottom: 1px solid #e4e9e1;
}

.chat-status[data-state="chatStatusError"],
.chat-status[data-state="chatStatusClosed"] {
  color: #8a2f28;
}

.chat-messages {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding: 14px;
}

.chat-empty {
  margin: auto;
  color: #697365;
  font-size: 14px;
}

.chat-message {
  max-width: min(78%, 560px);
  border-radius: 8px;
  padding: 10px 12px;
  color: #1b2119;
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.chat-message-user {
  align-self: flex-end;
  background: #dceee4;
}

.chat-message-assistant {
  align-self: flex-start;
  background: #f1f2ee;
}

.chat-message-error {
  align-self: flex-start;
  background: #fef2f2;
  color: #991b1b;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border-top: 1px solid #e4e9e1;
}

.chat-input-label {
  display: grid;
  gap: 6px;
  color: #566153;
  font-size: 12px;
}

.chat-input-label textarea {
  width: 100%;
  min-height: 72px;
  resize: vertical;
  border: 1px solid #dce4d9;
  border-radius: 8px;
  padding: 10px 12px;
  color: #1b2119;
  font: inherit;
}

.chat-send {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: #235b42;
  color: #ffffff;
  padding: 0 18px;
  cursor: pointer;
}

.grid {
  --masonry-columns: 4;
  display: grid;
  grid-template-columns: repeat(var(--masonry-columns), minmax(0, 1fr));
  align-items: start;
  gap: 14px;
  padding: 16px 0 24px;
}

.grid-column {
  display: grid;
  min-width: 0;
  align-content: start;
  gap: 14px;
}

.prompt-card {
  display: block;
  overflow: hidden;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--card-shadow);
  transition: box-shadow 220ms ease;
}

.gallery-image-link {
  display: block;
  width: 100%;
  color: inherit;
  cursor: pointer;
  text-decoration: none;
}

.gallery-image {
  width: 100%;
  display: block;
  height: auto;
  transition: transform 220ms ease;
}

@media (hover: hover) {
  .prompt-card:hover {
    box-shadow: var(--card-shadow-hover);
  }

  .prompt-card:hover .gallery-image {
    transform: scale(1.02);
  }
}

.load-status {
  display: flex;
  width: min(320px, 100%);
  min-height: 40px;
  align-items: center;
  justify-content: center;
  margin: 8px auto 20px;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  padding: 0 14px;
  font-size: 14px;
  font-weight: 500;
}

.load-status[hidden] {
  display: none;
}

.load-status[data-state="error"] {
  border: 1px solid rgba(122, 59, 46, 0.32);
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
}

.load-status[data-state="loading"]::before {
  width: 14px;
  height: 14px;
  margin-right: 8px;
  border: 2px solid rgba(91, 82, 71, 0.22);
  border-top-color: var(--accent);
  border-radius: 999px;
  content: "";
  animation: load-spin 0.8s linear infinite;
}

@keyframes load-spin {
  to {
    transform: rotate(360deg);
  }
}

.load-sentinel {
  width: 100%;
  height: 1px;
}

.lightbox[hidden] {
  display: none;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  align-items: start;
  justify-items: center;
  overflow: auto;
  padding: 18px;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(26, 24, 20, 0.42);
  cursor: zoom-out;
}

.lightbox-panel {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1280px, 100%);
  margin: auto 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 60px rgba(26, 24, 20, 0.16);
}

.lightbox-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 50px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 244, 236, 0.92);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: var(--ink);
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  padding: 6px 4px;
  color: var(--ink-soft);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 400;
  text-decoration: none;
  cursor: pointer;
  line-height: 1;
}

.back-link::before {
  content: "\2190";
  display: inline-block;
  font-size: 16px;
  line-height: 1;
}

@media (hover: hover) {
  .back-link:hover {
    color: var(--ink);
  }
}

.detail-layout {
  display: grid;
  grid-template-columns: 1fr;
  min-height: 0;
}

.detail-media,
.detail-info {
  min-height: 0;
}

.detail-media {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.lightbox-image-wrap {
  display: grid;
  min-height: 0;
  place-items: center;
  padding: 12px;
}

.lightbox-image-wrap img {
  max-width: 100%;
  max-height: calc(min(88vh, 900px) - 84px);
  display: block;
  object-fit: contain;
  border-radius: 4px;
}

.detail-output-strip,
.detail-input-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.detail-output-strip {
  border-top: 1px solid var(--line);
  padding: 10px 12px;
}

.detail-input-strip {
  flex-wrap: wrap;
  padding-bottom: 2px;
}

.detail-info {
  display: grid;
  align-content: start;
  gap: 18px;
  padding: 20px 22px 28px;
  color: var(--ink);
}

.detail-section {
  display: grid;
  gap: 8px;
}

.detail-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.detail-section h2 {
  color: var(--ink-soft);
  font-family: var(--serif);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}

.detail-section pre.prompt-text,
pre.prompt-text {
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.55;
  letter-spacing: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.detail-section pre.prompt-text code,
pre.prompt-text code {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: transparent;
  padding: 0;
  display: block;
  white-space: pre-wrap;
}

.copy-button {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 14px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease;
}

@media (hover: hover) {
  .copy-button:hover {
    border-color: var(--accent);
    color: var(--accent);
  }
}

.detail-image-button {
  position: relative;
  width: 72px;
  height: 72px;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 0;
  cursor: pointer;
}

.detail-image-button[data-active="true"] {
  border-color: var(--accent);
}

.detail-image-button img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.empty-state {
  margin: 24px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 28px;
  text-align: center;
  color: var(--ink-soft);
}

.detail-page {
  max-width: 1280px;
}

.example-detail-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  align-items: start;
}

.example-media {
  display: grid;
  gap: 14px;
  justify-items: center;
}

.example-media img {
  width: 100%;
  display: block;
  height: auto;
  margin: 0;
}

.example-inputs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 132px));
  gap: 12px;
}

.example-inputs .example-figure img {
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
}

.example-figure {
  margin: 0;
}

.example-figure img {
  width: 100%;
  display: block;
  height: auto;
}

.example-copy {
  display: grid;
  gap: 14px;
}

.detail-section-light {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 0;
}

.detail-section-light h2 {
  color: var(--ink-soft);
  font-family: var(--serif);
  font-size: 13px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}

@media (max-width: 1180px) {
  .grid {
    --masonry-columns: 3;
  }
}

@media (max-width: 820px) {
  .shell {
    padding: 12px;
  }

  .topbar {
    align-items: flex-start;
  }

  .toolbar {
    grid-template-columns: minmax(0, 1fr) minmax(104px, 0.62fr) minmax(104px, 0.62fr);
    gap: 8px;
    padding: 10px;
  }

  .search-field,
  .select-field {
    min-width: 0;
    gap: 5px;
  }

  input,
  select {
    min-height: 42px;
    padding: 0 10px;
  }

  select {
    padding-right: 32px;
    text-overflow: ellipsis;
  }

  .select-control::after {
    right: 12px;
  }

  .grid {
    --masonry-columns: 2;
    gap: 12px;
    padding-top: 12px;
  }

  .grid-column {
    gap: 12px;
  }

  .detail-layout {
    grid-template-columns: 1fr;
  }

  .detail-media {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .example-detail-layout {
    grid-template-columns: 1fr;
  }

  .example-copy {
    position: static;
  }
}

@media (max-width: 540px) {
  .shell {
    padding: 10px;
  }

  .toolbar {
    grid-template-columns: minmax(0, 1fr) minmax(82px, 0.58fr) minmax(82px, 0.58fr);
    gap: 6px;
    padding: 8px;
  }

  .search-field > span,
  .select-field > span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  input,
  select {
    min-height: 40px;
    padding: 0 9px;
    font-size: 13px;
  }

  select {
    padding-right: 28px;
  }

  .select-control::after {
    right: 10px;
  }

  .grid {
    --masonry-columns: 2;
    gap: 10px;
    padding-top: 10px;
  }

  .grid-column {
    gap: 10px;
  }

  .topbar {
    flex-direction: row;
    align-items: center;
    gap: 10px;
  }

  .topbar-actions {
    width: auto;
  }

  .brand {
    gap: 10px;
  }

  .brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 12px;
  }

  .lightbox {
    padding: 10px;
  }

  .detail-info {
    padding: 16px 14px 22px;
  }

  .detail-section pre.prompt-text,
  pre.prompt-text {
    font-size: 15px;
  }
}
