:root {
  color-scheme: light;
  --bg: #eef1f0;
  --panel: #ffffff;
  --panel-strong: #f7f8f6;
  --ink: #151716;
  --muted: #69706d;
  --line: #d6dad7;
  --red: #a4121c;
  --red-strong: #e11d2e;
  --gold: #d99a25;
  --green: #12755a;
  --blue: #1e4f80;
  --shadow: 0 18px 50px rgba(20, 24, 22, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(164, 18, 28, 0.06), transparent 34%, rgba(18, 117, 90, 0.08)),
    var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei",
    sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

a {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 18px;
  border: 1px solid rgba(23, 18, 13, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.topbar h1,
.panel h2,
.admin-sidebar h1 {
  margin: 0;
}

.topbar h1 {
  font-size: clamp(24px, 2.2vw, 38px);
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--red);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.top-actions,
.toolbar-actions,
.admin-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(167, 17, 22, 0.28);
  border-radius: 999px;
  color: var(--red);
  background: #fff0f0;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 6px rgba(18, 117, 90, 0.12);
}

.ghost-link,
.back-link {
  text-decoration: none;
  color: var(--ink);
  font-weight: 800;
}

.workspace {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(420px, 500px) minmax(640px, 1fr);
  grid-template-rows: minmax(620px, calc(100vh - 132px)) minmax(280px, auto);
  grid-template-areas:
    "config image"
    "config explanation";
  gap: 14px;
}

.config-panel {
  grid-area: config;
}

.image-panel {
  grid-area: image;
}

.explanation-panel {
  grid-area: explanation;
  max-height: none;
}

.panel {
  min-height: 0;
  border: 1px solid rgba(23, 18, 13, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.config-panel,
.explanation-panel,
.admin-panel {
  overflow: auto;
  padding: 18px;
}

.panel-heading {
  margin-bottom: 16px;
}

.panel-heading p:not(.eyebrow) {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

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

label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  color: var(--ink);
  font-weight: 800;
}

label span {
  font-size: 14px;
}

.toggle-row {
  min-height: 68px;
  display: grid;
  grid-template-columns: 18px 1fr;
  grid-template-rows: auto auto;
  align-content: center;
  column-gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  grid-row: 1 / span 2;
  align-self: center;
}

.toggle-row small {
  font-size: 12px;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--ink);
  outline: none;
  transition:
    border-color 0.16s ease,
    box-shadow 0.16s ease;
}

input,
select {
  height: 42px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  min-height: 88px;
  padding: 12px;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(167, 17, 22, 0.65);
  box-shadow: 0 0 0 3px rgba(167, 17, 22, 0.12);
}

small {
  color: var(--muted);
  font-weight: 600;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.inline-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: -4px;
}

.inline-actions .secondary-button {
  flex: 0 0 auto;
}

.inline-status {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.env-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.env-card {
  display: grid;
  gap: 8px;
  min-height: 126px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(164, 18, 28, 0.05), transparent 44%),
    var(--panel-strong);
}

.env-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.env-card strong {
  width: fit-content;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 13px;
}

.env-card strong.ok {
  color: #07543d;
  background: rgba(18, 117, 90, 0.14);
}

.env-card strong.warn {
  color: #8a1018;
  background: rgba(164, 18, 28, 0.12);
}

.env-card code {
  overflow-wrap: anywhere;
  color: var(--blue);
  font-weight: 800;
}

input[readonly] {
  color: var(--muted);
  background: #f3f5f4;
}

.primary-button,
.secondary-button {
  height: 42px;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 900;
}

.primary-button {
  color: white;
  background: linear-gradient(135deg, var(--red), var(--red-strong));
  box-shadow: 0 10px 28px rgba(167, 17, 22, 0.24);
}

.secondary-button {
  padding: 0 13px;
  color: var(--ink);
  border: 1px solid var(--line);
  background: white;
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.reference-block {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.mini-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.mini-heading h3 {
  margin: 0;
}

.mini-heading span {
  color: var(--muted);
  font-size: 12px;
}

.reference-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.reference-grid img {
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  border-radius: 7px;
  border: 1px solid var(--line);
}

.image-panel {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.preview-toolbar h2 {
  margin: 0;
}

.canvas-frame {
  position: relative;
  flex: 1;
  min-height: 560px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 2px solid rgba(23, 18, 13, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(45deg, rgba(0, 0, 0, 0.035) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(0, 0, 0, 0.035) 25%, transparent 25%),
    #f8faf8;
  background-size: 28px 28px;
}

.ratio-16-9 {
  aspect-ratio: 16 / 9;
}

.ratio-4-3 {
  aspect-ratio: 4 / 3;
}

.ratio-1-1 {
  aspect-ratio: 1 / 1;
}

.empty-state,
.progress-state {
  width: min(420px, 90%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  color: var(--muted);
}

.empty-state strong,
.progress-state strong {
  color: var(--ink);
  font-size: 22px;
}

.satire-loader {
  width: min(340px, 92%);
  display: grid;
  gap: 14px;
  justify-items: center;
}

.ink-orbit {
  position: relative;
  width: 72px;
  height: 72px;
  border: 2px solid rgba(164, 18, 28, 0.22);
  border-radius: 50%;
  animation: spin 2.2s linear infinite;
}

.ink-orbit span {
  position: absolute;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 0 8px rgba(164, 18, 28, 0.08);
}

.ink-orbit span:nth-child(1) {
  left: 28px;
  top: -7px;
}

.ink-orbit span:nth-child(2) {
  right: 0;
  bottom: 7px;
  background: var(--green);
}

.ink-orbit span:nth-child(3) {
  left: 0;
  bottom: 7px;
  background: var(--gold);
}

.progress-track {
  width: 100%;
  height: 10px;
  overflow: hidden;
  border: 1px solid rgba(21, 23, 22, 0.12);
  border-radius: 999px;
  background: white;
}

.progress-bar {
  width: 8%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--red), var(--gold), var(--green));
  transition: width 0.6s ease;
}

.progress-state em {
  max-width: 420px;
  color: var(--red);
  font-size: 15px;
  font-style: normal;
  font-weight: 900;
}

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

.result-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #f8faf8;
}

.result-image.cover {
  object-fit: cover;
}

.error-box {
  padding: 12px;
  border: 1px solid rgba(167, 17, 22, 0.3);
  border-radius: 7px;
  color: #7a0f12;
  background: #fff1ef;
  line-height: 1.5;
}

.markdown-body {
  color: var(--ink);
  line-height: 1.7;
}

.explanation-panel .markdown-body {
  max-width: 980px;
}

.explanation-panel .markdown-body h2,
.explanation-panel .markdown-body h3,
.explanation-panel .markdown-body p,
.explanation-panel .markdown-body ul,
.explanation-panel .markdown-body ol {
  break-inside: avoid;
}

.markdown-body h2 {
  margin: 18px 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  font-size: 20px;
}

.markdown-body h2:first-child {
  margin-top: 0;
}

.markdown-body p {
  margin: 8px 0;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 20px;
}

.markdown-body code,
.markdown-body pre {
  border-radius: 6px;
  background: #edf1ee;
}

.markdown-body code {
  padding: 2px 5px;
}

.markdown-body pre {
  overflow: auto;
  padding: 12px;
}

.hidden {
  display: none !important;
}

.admin-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
  background: var(--bg);
}

.admin-sidebar {
  padding: 26px;
  color: white;
  background: linear-gradient(160deg, #17120d, #4a1011 62%, #7d151a);
}

.admin-sidebar p {
  color: rgba(255, 255, 255, 0.72);
  line-height: 1.65;
}

.admin-sidebar .back-link {
  display: inline-flex;
  margin-bottom: 24px;
  color: white;
}

.admin-content {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.admin-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.admin-panel {
  max-height: none;
}

.save-status {
  color: var(--green);
  font-weight: 800;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  display: grid;
  grid-template-columns: 150px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
}

.history-thumb {
  width: 150px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
}

.history-item img {
  width: 150px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 5px;
  border: 1px solid var(--line);
}

.history-item strong,
.history-item span {
  display: block;
}

.history-item span {
  color: var(--muted);
  font-size: 13px;
}

.history-link {
  display: inline-flex;
  margin-top: 6px;
  padding: 0;
  border: 0;
  color: var(--red);
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 900;
  text-decoration: none;
}

.history-muted {
  margin-top: 6px;
}

.image-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
}

.image-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 14, 13, 0.72);
}

.image-modal-card {
  position: relative;
  z-index: 1;
  width: min(1120px, 94vw);
  max-height: 92vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  padding: 16px;
  border-radius: 8px;
  background: white;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.32);
}

.image-modal-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.image-modal-card h2,
.image-modal-card p {
  margin: 0;
}

.image-modal-card img {
  max-width: 100%;
  max-height: calc(92vh - 142px);
  object-fit: contain;
  justify-self: center;
  border-radius: 7px;
  background: #f8faf8;
}

.image-modal-card > p {
  color: var(--muted);
  line-height: 1.5;
}

.icon-close {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: white;
  color: var(--ink);
  cursor: pointer;
  font-size: 28px;
  line-height: 1;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: min(420px, 100%);
  padding: 24px;
}

.login-card h1,
.login-card p {
  margin-top: 0;
}

.login-card > p:not(.eyebrow) {
  color: var(--muted);
  line-height: 1.55;
}

.error-text {
  min-height: 20px;
  color: var(--red);
  font-size: 13px;
  font-weight: 800;
}

@media (max-width: 1320px) {
  .workspace {
    grid-template-columns: minmax(380px, 430px) 1fr;
    grid-template-areas:
      "config image"
      "config explanation";
  }

  .config-panel {
    grid-area: config;
  }

  .image-panel {
    grid-area: image;
  }

  .explanation-panel {
    grid-area: explanation;
  }

  .explanation-panel .markdown-body {
    max-width: none;
  }
}

@media (max-width: 980px) {
  .app-shell {
    height: auto;
    min-height: 100vh;
  }

  .topbar,
  .preview-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace,
  .admin-shell {
    display: flex;
    flex-direction: column;
  }

  .canvas-frame {
    min-height: 360px;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }

  .env-grid {
    grid-template-columns: 1fr;
  }
}
