:root {
  --paper: #fffaf2;
  --paper-strong: #ffffff;
  --ink: #221713;
  --muted: #735f55;
  --line: #ead6c5;
  --red: #d71920;
  --red-dark: #a90f16;
  --yellow: #ffc940;
  --green: #186f5a;
  --shadow: 0 18px 42px rgba(98, 38, 24, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background:
    linear-gradient(135deg, rgba(215, 25, 32, 0.08) 25%, transparent 25%) 0 0 / 28px 28px,
    linear-gradient(135deg, transparent 75%, rgba(255, 201, 64, 0.18) 75%) 0 0 / 28px 28px,
    linear-gradient(180deg, #fff7e8 0%, #fff 42%, #fff2e4 100%);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

.topbar,
.site-footer,
.app {
  width: min(1120px, calc(100% - 28px));
  margin: 0 auto;
}

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

.topbar-brand {
  min-height: 36px;
  padding: 5px 10px 5px 6px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(117, 58, 29, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  color: #5b2b20;
  font-size: 14px;
  font-weight: 900;
  text-decoration: none;
}

.brand-mark {
  width: 24px;
  height: 24px;
  display: inline-grid;
  place-items: center;
  border-radius: 6px;
  background: var(--red);
  color: #fff;
  font-size: 15px;
  line-height: 1;
}

.tab-nav {
  display: flex;
  gap: 6px;
  flex: 1 1 auto;
  justify-content: center;
  flex-wrap: wrap;
}

.tab-link {
  border: 1px solid rgba(117, 58, 29, 0.18);
  border-radius: 8px;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.82);
  color: #5b2b20;
  font-weight: 800;
  font-size: 14px;
  transition: transform 160ms ease, background 160ms ease, color 160ms ease;
}

.tab-link:hover {
  transform: translateY(-1px);
}

.tab-link.active {
  background: var(--red);
  color: #fff;
  border-color: var(--red-dark);
  box-shadow: 0 4px 0 var(--red-dark);
}

.tab-panel.hidden {
  /* !important wins over the later .tab-panel[data-tab-panel="generate"]
     display rule when the generate panel is hidden. */
  display: none !important;
}

.app {
  flex: 1 0 auto;
  padding: 14px 0 12px;
  display: block;
}

.tab-panel[data-tab-panel="generate"] {
  display: grid;
  gap: 14px;
  align-items: stretch;
}

.generator-card,
.history-card {
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(117, 58, 29, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.generator-card {
  padding: 0 18px 18px;
}

.history-card {
  padding: 18px;
}

.hero-strip {
  display: grid;
  grid-template-columns: 72px 1fr 72px;
  gap: 8px;
  margin: 0 -18px 18px;
  padding: 8px;
  background: var(--red);
}

.stripe {
  height: 16px;
  border-radius: 2px;
  background: var(--paper-strong);
}

.stripe.wide {
  background:
    repeating-linear-gradient(90deg, #fff 0 22px, var(--yellow) 22px 44px);
}

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.section-kicker {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(36px, 6vw, 72px);
  line-height: 0.95;
}

h2 {
  font-size: 20px;
  line-height: 1.25;
}

.art-title {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 14px;
}

.title-main {
  position: relative;
  display: inline-block;
  color: var(--red);
  font-size: clamp(48px, 8vw, 88px);
  font-weight: 950;
  line-height: 0.9;
  text-shadow:
    2px 2px 0 #fff7df,
    5px 5px 0 rgba(255, 201, 64, 0.72),
    8px 8px 0 rgba(34, 23, 19, 0.1);
}

.title-main::after {
  position: absolute;
  right: 4px;
  bottom: -10px;
  left: 8px;
  height: 8px;
  content: "";
  border-radius: 999px;
  background:
    repeating-linear-gradient(90deg, var(--red) 0 18px, var(--yellow) 18px 36px);
  transform: rotate(-1deg);
}

.title-sub {
  padding: 8px 11px 7px;
  display: inline-block;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #fff6e3;
  color: var(--ink);
  font-size: clamp(20px, 3.2vw, 34px);
  font-weight: 950;
  line-height: 1;
  box-shadow: 4px 4px 0 var(--red);
  transform: rotate(-2deg);
}

.repo-link {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #e5b99c;
  border-radius: 8px;
  background: #fff4e5;
  color: #7e2a18;
  font-size: 14px;
  font-weight: 900;
  line-height: 1;
  text-decoration: none;
  transition: transform 160ms ease, border-color 160ms ease, color 160ms ease;
}

.repo-icon {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.repo-link:hover {
  transform: translateY(-1px);
  border-color: var(--red);
  color: var(--red-dark);
}

.repo-link:focus-visible {
  outline: 3px solid rgba(255, 201, 64, 0.46);
  outline-offset: 3px;
}

.food-mark {
  flex: 0 0 auto;
  width: 134px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 3px solid #fff4dc;
  border-radius: 18px;
  background: #fff8ea;
  box-shadow: 8px 8px 0 var(--red);
  transform: rotate(3deg);
  overflow: hidden;
}

.food-mark img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.controls {
  display: grid;
  gap: 14px;
}

.field,
.style-field {
  display: grid;
  gap: 8px;
}

label,
legend {
  color: #3a261e;
  font-weight: 800;
}

.style-field {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

input {
  width: 100%;
  min-height: 48px;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 11px 13px;
  background: #fff;
  color: var(--ink);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

input:focus {
  outline: 3px solid rgba(255, 201, 64, 0.46);
  border-color: var(--yellow);
}

.style-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.style-chip {
  min-height: 42px;
  border: 1px solid #ead3bf;
  border-radius: 8px;
  background: #fff8ec;
  color: #5c3426;
  font-weight: 800;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.style-chip:hover {
  transform: translateY(-1px);
  border-color: #d9a45c;
}

.style-chip.active {
  border-color: var(--red);
  background: var(--red);
  color: #fff;
  box-shadow: 0 8px 0 rgba(169, 15, 22, 0.18);
}

.button-row {
  display: block;
}

.btn {
  min-height: 50px;
  border: 0;
  border-radius: 8px;
  font-weight: 900;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.72;
}

/* In-flight state — set by JS while a request is pending. */
.btn.is-loading,
.btn.is-loading:disabled {
  cursor: wait;
}

.primary {
  background: var(--red);
  color: #fff;
  box-shadow: 0 8px 0 var(--red-dark);
}

.primary:active {
  transform: translateY(5px);
  box-shadow: 0 3px 0 var(--red-dark);
}

.button-row .btn {
  width: 100%;
}

.result-wrap {
  position: relative;
  margin-top: 18px;
  padding: 18px;
  border: 2px solid #2d211b;
  border-radius: 8px;
  background:
    linear-gradient(#fffdf8, #fffdf8) padding-box,
    repeating-linear-gradient(90deg, var(--red) 0 14px, #fff 14px 28px) border-box;
}

.result-wrap::before,
.result-wrap::after {
  position: absolute;
  top: 50%;
  width: 18px;
  height: 18px;
  content: "";
  border-radius: 50%;
  background: var(--paper);
  border: 2px solid #2d211b;
}

.result-wrap::before {
  left: -11px;
}

.result-wrap::after {
  right: -11px;
}

.result-head,
.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.copy-btn,
.text-btn {
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #9a2b17;
  font-weight: 900;
}

.copy-btn {
  min-width: 70px;
  min-height: 40px;
  border: 1px solid #f0c5aa;
  background: #fff3e6;
}

.copy-btn:hover,
.text-btn:hover {
  color: var(--red-dark);
}

.result-text {
  min-height: 104px;
  margin: 16px 0 0;
  padding-top: 16px;
  border-top: 1px dashed #d9b69c;
  color: #261812;
  font-size: 18px;
  font-weight: 750;
  line-height: 1.75;
  white-space: pre-wrap;
}

.copy-feedback {
  min-height: 20px;
  margin: 10px 0 0;
  color: var(--green);
  font-size: 14px;
  font-weight: 800;
}

.history-list {
  display: grid;
  gap: 10px;
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
}

.history-list li {
  position: relative;
  padding: 12px 12px 12px 18px;
  border: 1px solid #ead8c7;
  border-radius: 8px;
  background: #fffaf1;
  line-height: 1.55;
}

.history-list li::before {
  position: absolute;
  top: 12px;
  bottom: 12px;
  left: 8px;
  width: 3px;
  content: "";
  border-radius: 2px;
  background: var(--red);
}

.history-list .empty {
  color: var(--muted);
}

.history-list .empty::before {
  background: #d8c5b6;
}

.site-footer {
  flex: 0 0 auto;
  padding: 0 0 16px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 12px;
  color: #7b5a4c;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.45;
}

.subtle {
  color: var(--muted);
}

@media (min-width: 760px) {
  .tab-panel[data-tab-panel="generate"] {
    display: grid;
    gap: 14px;
    grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  }

  .tab-panel[data-tab-panel="generate"] .generator-card,
  .tab-panel[data-tab-panel="generate"] .history-card {
    min-height: 620px;
  }

  .style-options {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .app {
    width: min(100% - 20px, 1120px);
    padding: 10px 0 12px;
  }

  .generator-card,
  .history-card {
    box-shadow: 0 10px 28px rgba(98, 38, 24, 0.14);
  }

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

  .topbar,
  .site-footer {
    width: min(100% - 20px, 1120px);
  }

  .food-mark {
    width: 88px;
    box-shadow: 5px 5px 0 var(--red);
  }

}

.corpus-card,
.submit-card {
  position: relative;
  overflow: hidden;
  padding: 18px;
  border: 1px solid rgba(117, 58, 29, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.corpus-head,
.submit-head {
  margin-bottom: 14px;
}

.corpus-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.corpus-controls input {
  min-height: 44px;
}

.filter-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pill {
  min-height: 36px;
  padding: 4px 14px;
  border: 1px solid rgba(117, 58, 29, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  color: #5b2b20;
  font-weight: 800;
  font-size: 13px;
  transition: transform 160ms ease, background 160ms ease, color 160ms ease;
}

.pill:hover {
  transform: translateY(-1px);
}

.pill.active {
  background: var(--red);
  color: #fff;
  border-color: var(--red-dark);
}

.corpus-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.corpus-list .empty {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.6);
}

.corpus-item {
  position: relative;
  padding: 12px 14px;
  border: 1px solid #ead8c7;
  border-radius: 8px;
  background: #fffaf1;
}

.corpus-item.status-pending {
  background: #fff6df;
  border-color: #e6c870;
}

.corpus-text {
  margin: 0 0 6px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.corpus-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.corpus-status {
  font-weight: 800;
}

.corpus-status-approved {
  color: var(--green);
}

.corpus-status-pending {
  color: #9a6b00;
}

.corpus-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}

.page-info {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}

.page-jump {
  width: 56px;
  min-height: 30px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  text-align: center;
  -moz-appearance: textfield;
}

.page-jump::-webkit-outer-spin-button,
.page-jump::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.page-jump:focus {
  outline: 2px solid rgba(255, 201, 64, 0.46);
  border-color: var(--yellow);
}

.page-jump:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn.ghost {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid rgba(117, 58, 29, 0.22);
  background: rgba(255, 255, 255, 0.86);
  color: #5b2b20;
  border-radius: 8px;
  font-weight: 800;
}

.btn.ghost:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn.ghost:disabled {
  opacity: 0.5;
  cursor: default;
}

.submit-help {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.submit-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.submit-form textarea {
  width: 100%;
  min-height: 132px;
  padding: 12px 13px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.6;
  resize: vertical;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.submit-form textarea:focus {
  outline: 3px solid rgba(255, 201, 64, 0.46);
  border-color: var(--yellow);
}

.char-counter {
  align-self: flex-end;
  font-size: 12px;
  color: var(--muted);
}

.char-counter.out-of-range {
  color: var(--red);
}

.char-counter[data-hint]:not([data-hint=""])::after {
  content: " · " attr(data-hint);
}

.toast-host {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
  max-width: min(340px, calc(100vw - 32px));
}

.toast {
  padding: 12px 14px;
  border-radius: 8px;
  background: #2d211b;
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: 0 10px 28px rgba(45, 33, 27, 0.32);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast-success {
  background: var(--green);
}

.toast-error {
  background: var(--red);
  box-shadow: 0 10px 28px rgba(215, 25, 32, 0.34);
}

.admin-page {
  background:
    linear-gradient(135deg, rgba(215, 25, 32, 0.05) 25%, transparent 25%) 0 0 / 28px 28px,
    linear-gradient(180deg, #fff7e8 0%, #fff 60%, #fff2e4 100%);
}

.admin-shell {
  width: min(720px, calc(100% - 28px));
  margin: 18px auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.admin-back {
  text-decoration: none;
}

.token-gate,
.queue-card {
  padding: 18px;
  border: 1px solid rgba(117, 58, 29, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.token-gate form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.token-gate input {
  flex: 1;
}

.token-gate .btn.primary {
  min-width: 96px;
}

.form-error {
  margin: 10px 0 0;
  color: var(--red-dark);
  font-weight: 800;
  font-size: 14px;
}

.queue-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.queue-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.queue-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.queue-list .empty {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.6);
}

.queue-item {
  padding: 14px;
  border: 1px solid #e6c870;
  border-radius: 8px;
  background: #fff6df;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.queue-item-check {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin-top: 2px;
  cursor: pointer;
  accent-color: var(--red);
}

.queue-item-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.queue-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px 12px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.6);
}

.queue-select-all {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
}

.queue-select-all input {
  width: 18px;
  height: 18px;
  margin: 0;
  cursor: pointer;
  accent-color: var(--red);
}

.queue-select-all input:disabled {
  cursor: default;
}

.queue-toolbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.queue-toolbar-actions .btn {
  min-height: 36px;
  padding: 0 14px;
  font-size: 13px;
}

.queue-text {
  margin: 0;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.queue-meta {
  margin: 0;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
}

.queue-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.queue-actions .btn {
  min-height: 38px;
  padding: 0 16px;
}

.btn.ghost.danger {
  color: var(--red-dark);
  border-color: rgba(169, 15, 22, 0.32);
}

.admin-link {
  text-decoration: none;
}
