:root {
  color-scheme: light;
  --page: #f6f7f4;
  --page-2: #ecefeb;
  --surface: #ffffff;
  --surface-soft: #f9faf8;
  --surface-muted: #f1f4f0;
  --ink: #151c18;
  --ink-soft: #2d3931;
  --muted: #68746c;
  --line: #dfe6df;
  --line-strong: #c6d0c7;
  --primary: #087a66;
  --primary-dark: #055c4d;
  --primary-soft: #e4f4ef;
  --coral: #c85b42;
  --amber: #b7811d;
  --violet: #5d6698;
  --focus: #13826e;
  --shadow: 0 18px 40px rgba(27, 38, 31, 0.08);
  --shadow-tight: 0 8px 22px rgba(27, 38, 31, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--page);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(8, 122, 102, 0.1), transparent 34%),
    linear-gradient(225deg, rgba(200, 91, 66, 0.08), transparent 30%),
    linear-gradient(180deg, #fbfcfa 0%, var(--page) 44%, var(--page-2) 100%);
  color: var(--ink);
}

body.viewer-open {
  overflow: hidden;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px;
}

.brandbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 560px);
  gap: 18px;
  align-items: center;
  margin-bottom: 18px;
  border: 1px solid rgba(223, 230, 223, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: var(--shadow-tight);
  padding: 16px;
  backdrop-filter: blur(14px);
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.18), transparent 42%),
    linear-gradient(160deg, var(--primary), #134f82);
  color: white;
  font-size: 1.65rem;
  font-weight: 900;
  box-shadow: inset 0 -12px 20px rgba(0, 0, 0, 0.14);
}

.layout {
  display: grid;
  grid-template-columns: minmax(380px, 0.74fr) minmax(0, 1.26fr);
  gap: 18px;
  align-items: start;
}

.control-panel,
.output-panel {
  min-width: 0;
  border: 1px solid rgba(223, 230, 223, 0.92);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.control-panel {
  display: grid;
  gap: 16px;
  padding: 18px;
  position: sticky;
  top: 18px;
}

.output-panel {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 112px);
  padding: 18px;
}

.panel-title,
.preview-head,
.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.panel-title {
  border-bottom: 1px solid var(--line);
  padding-bottom: 13px;
}

.preview-head {
  margin-bottom: 14px;
}

.history-head {
  margin-bottom: 12px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  color: #111815;
  font-size: clamp(2rem, 4.4vw, 4rem);
  font-weight: 900;
  line-height: 0.9;
}

h2 {
  color: var(--ink-soft);
  font-size: 1.05rem;
  font-weight: 840;
  line-height: 1.2;
}

.endpoint {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.endpoint span {
  display: grid;
  place-items: center;
  padding: 0 14px;
  background: #151c18;
  color: white;
  font-size: 0.72rem;
  font-weight: 900;
}

.endpoint code {
  display: block;
  min-width: 0;
  padding: 11px 13px;
  overflow: hidden;
  color: #3d4b42;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field {
  min-width: 0;
}

.field label:not(.check-row):not(.segmented label) {
  display: block;
  margin-bottom: 7px;
  color: #2f3e35;
  font-size: 0.88rem;
  font-weight: 780;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink);
  outline: none;
  transition:
    border-color 150ms ease,
    box-shadow 150ms ease,
    background-color 150ms ease;
}

input,
select {
  min-height: 43px;
  padding: 0 12px;
}

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

input:hover,
select:hover,
textarea:hover {
  border-color: #aebcb0;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(19, 130, 110, 0.15);
  background: #ffffff;
}

.secret-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.check-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 9px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 650;
}

.check-row input {
  width: 16px;
  min-height: auto;
  height: 16px;
  accent-color: var(--primary);
}

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

.wide {
  grid-column: span 2;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 3px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface-muted);
  padding: 3px;
}

.segmented label {
  min-width: 0;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  place-items: center;
  min-height: 36px;
  padding: 0 8px;
  border-radius: 6px;
  color: #405048;
  font-size: 0.8rem;
  font-weight: 800;
  white-space: nowrap;
}

.segmented input:checked + span {
  background: var(--surface);
  color: var(--primary-dark);
  box-shadow: 0 1px 8px rgba(27, 38, 31, 0.1);
}

.segmented input:focus-visible + span {
  box-shadow: 0 0 0 3px rgba(19, 130, 110, 0.16);
}

.prompt-tools,
.actions,
.preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.prompt-tools {
  margin-top: 10px;
}

.actions {
  align-items: center;
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.preview-actions {
  align-items: center;
  justify-content: flex-end;
}

.primary-button,
.secondary-button,
.ghost-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-size: 0.9rem;
  font-weight: 820;
  letter-spacing: 0;
  transition:
    transform 120ms ease,
    border-color 140ms ease,
    background-color 140ms ease,
    color 140ms ease,
    box-shadow 140ms ease,
    opacity 140ms ease;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 148px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: 0 12px 24px rgba(8, 122, 102, 0.2);
}

.primary-button:hover {
  background: linear-gradient(135deg, #0a876f, var(--primary-dark));
  box-shadow: 0 14px 28px rgba(8, 122, 102, 0.25);
}

.secondary-button,
.ghost-button {
  background: rgba(255, 255, 255, 0.84);
  border-color: var(--line-strong);
  color: #26342c;
}

.secondary-button:hover,
.ghost-button:hover {
  border-color: var(--primary);
  color: var(--primary-dark);
  background: #ffffff;
}

.ghost-button.danger:hover {
  border-color: var(--coral);
  color: var(--coral);
}

.compact {
  min-height: 36px;
  padding-inline: 11px;
  font-size: 0.84rem;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.56;
}

.primary-button:active:not(:disabled),
.secondary-button:active:not(:disabled),
.ghost-button:active:not(:disabled) {
  transform: translateY(1px);
}

.loader {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 850ms linear infinite;
}

.is-loading .loader {
  display: inline-block;
}

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

.timer-pill {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  border: 1px solid rgba(8, 122, 102, 0.24);
  border-radius: 8px;
  background: var(--primary-soft);
  padding: 0 11px;
  color: var(--primary-dark);
}

.timer-pill span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 780;
}

.timer-pill strong {
  min-width: 52px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.timer-pill.running {
  border-color: rgba(200, 91, 66, 0.36);
  background: #fff1ec;
  color: var(--coral);
}

.alert {
  margin-bottom: 13px;
  border: 1px solid rgba(200, 91, 66, 0.28);
  border-left-width: 4px;
  border-radius: 8px;
  background: #fff5f2;
  color: #7a291d;
  padding: 11px 12px;
  line-height: 1.45;
  font-size: 0.9rem;
}

.empty-state {
  display: grid;
  place-items: center;
  align-content: center;
  position: relative;
  min-height: 420px;
  overflow: hidden;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(8, 122, 102, 0.06) 1px, transparent 1px),
    linear-gradient(rgba(8, 122, 102, 0.06) 1px, transparent 1px),
    rgba(249, 250, 248, 0.88);
  background-size: 30px 30px;
  color: var(--muted);
  text-align: center;
}

.empty-state[hidden] {
  display: none;
}

.empty-state::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 34%, rgba(255, 255, 255, 0.72) 50%, transparent 66%);
  opacity: 0;
  transform: translateX(-100%);
}

.empty-state[data-state="loading"]::before {
  animation: panel-sweep 1.8s ease-in-out infinite;
  opacity: 1;
}

.waiting-visual {
  display: grid;
  grid-template-columns: repeat(3, 24px);
  grid-template-rows: repeat(3, 24px);
  gap: 7px;
  position: relative;
  z-index: 1;
  width: 112px;
  height: 112px;
  border: 1px solid rgba(8, 122, 102, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 14px 28px rgba(32, 45, 36, 0.08);
  padding: 15px;
}

.waiting-visual span,
.waiting-visual i {
  display: block;
  border-radius: 7px;
  background: var(--primary-soft);
}

.waiting-visual span:nth-child(1) {
  grid-column: 1 / 3;
  background: rgba(8, 122, 102, 0.18);
}

.waiting-visual span:nth-child(2) {
  grid-column: 3;
  grid-row: 1 / 3;
  background: rgba(93, 102, 152, 0.2);
}

.waiting-visual span:nth-child(3) {
  grid-column: 1;
  grid-row: 2 / 4;
  background: rgba(183, 129, 29, 0.2);
}

.waiting-visual i {
  grid-column: 2 / 4;
  grid-row: 3;
  background: rgba(8, 122, 102, 0.15);
}

.empty-state[data-state="loading"] .waiting-visual span,
.empty-state[data-state="loading"] .waiting-visual i {
  animation: tile-pulse 1.25s ease-in-out infinite;
}

.empty-state[data-state="loading"] .waiting-visual span:nth-child(2) {
  animation-delay: 120ms;
}

.empty-state[data-state="loading"] .waiting-visual span:nth-child(3) {
  animation-delay: 240ms;
}

.empty-state[data-state="loading"] .waiting-visual i {
  animation-delay: 360ms;
}

.empty-state p {
  position: relative;
  z-index: 1;
  margin: 12px 0 0;
  color: var(--ink-soft);
  font-weight: 760;
}

.empty-state small {
  position: relative;
  z-index: 1;
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 680;
}

@keyframes panel-sweep {
  0% {
    transform: translateX(-100%);
  }

  55%,
  100% {
    transform: translateX(100%);
  }
}

@keyframes tile-pulse {
  0%,
  100% {
    transform: translateY(0);
    background: var(--primary-soft);
  }

  50% {
    transform: translateY(-7px);
    background: var(--primary);
    box-shadow: 0 10px 18px rgba(8, 122, 102, 0.18);
  }
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.image-card {
  display: grid;
  gap: 10px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px;
  box-shadow: 0 8px 20px rgba(27, 38, 31, 0.06);
}

.image-frame {
  display: grid;
  place-items: center;
  min-height: 310px;
  overflow: hidden;
  border-radius: 8px;
  background:
    linear-gradient(45deg, #edf1ed 25%, transparent 25%),
    linear-gradient(-45deg, #edf1ed 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #edf1ed 75%),
    linear-gradient(-45deg, transparent 75%, #edf1ed 75%),
    #f8faf7;
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
}

.image-frame img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 64vh;
  object-fit: contain;
}

.zoomable-image {
  cursor: zoom-in;
}

.image-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.image-meta span {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.download-link {
  flex: 0 0 auto;
  min-height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--primary-dark);
  font-size: 0.82rem;
  font-weight: 820;
  text-decoration: none;
}

.download-link:hover {
  border-color: var(--primary);
  background: rgba(8, 122, 102, 0.08);
}

.history-section {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 17px;
}

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

.history-empty {
  margin: 0;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: rgba(249, 250, 248, 0.8);
  color: var(--muted);
  padding: 17px;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 700;
}

.history-item {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  padding: 8px;
  transition:
    border-color 140ms ease,
    box-shadow 140ms ease,
    background-color 140ms ease;
}

.history-item:hover {
  border-color: #b7c8bb;
  background: #ffffff;
  box-shadow: 0 8px 18px rgba(27, 38, 31, 0.06);
}

.history-thumb {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  overflow: hidden;
  border-radius: 8px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 780;
}

.history-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.history-main {
  min-width: 0;
}

.history-prompt {
  margin: 0 0 6px;
  overflow: hidden;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 780;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.history-meta span {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  padding: 3px 6px;
}

.history-actions {
  display: flex;
  gap: 7px;
}

.raw-panel {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(249, 250, 248, 0.86);
  padding: 10px 12px;
}

.raw-panel summary {
  cursor: pointer;
  color: #31433a;
  font-weight: 800;
}

.raw-panel pre {
  max-height: 260px;
  margin: 10px 0 0;
  overflow: auto;
  color: #24342b;
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  background: rgba(14, 20, 17, 0.82);
  backdrop-filter: blur(14px);
  padding: 18px;
}

.image-viewer[hidden] {
  display: none;
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  padding: 10px;
}

.viewer-toolbar span {
  min-width: 0;
  overflow: hidden;
  color: #ffffff;
  font-size: 0.92rem;
  font-weight: 760;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.viewer-actions .secondary-button {
  display: inline-grid;
  place-items: center;
  min-width: 60px;
  background: rgba(255, 255, 255, 0.92);
  text-decoration: none;
}

.viewer-canvas {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  overflow: auto;
}

.viewer-canvas img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.32);
  object-fit: contain;
}

@media (max-width: 1080px) {
  .brandbar,
  .layout {
    grid-template-columns: 1fr;
  }

  .control-panel {
    position: static;
  }

  .output-panel {
    min-height: 560px;
  }
}

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

  .brandbar,
  .control-panel,
  .output-panel {
    padding: 14px;
  }

  .brand-lockup,
  .preview-head,
  .history-head {
    align-items: stretch;
    flex-direction: column;
  }

  .brand-lockup {
    align-items: center;
    flex-direction: row;
  }

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

  .wide {
    grid-column: auto;
  }

  .segmented {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .secret-input {
    grid-template-columns: 1fr;
  }

  .preview-actions {
    justify-content: flex-start;
  }

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

  .history-item {
    grid-template-columns: 56px minmax(0, 1fr);
  }

  .history-thumb {
    width: 56px;
    height: 56px;
  }

  .history-actions {
    grid-column: 1 / -1;
  }

  .image-viewer {
    padding: 12px;
  }

  .viewer-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .viewer-actions {
    justify-content: flex-start;
  }

  h1 {
    font-size: 2.25rem;
  }
}
