:root {
  color-scheme: light;
  --ink: #111827;
  --muted: #667085;
  --line: rgba(17, 24, 39, 0.12);
  --panel: rgba(255, 255, 255, 0.88);
  --panel-solid: #ffffff;
  --bg: #edf2f7;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --coral: #e85d48;
  --gold: #c7902f;
  --blue: #2563eb;
  --shadow: 0 24px 70px rgba(15, 23, 42, 0.14);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(237, 242, 247, 0.78)),
    url("/assets/noise.png");
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(15, 118, 110, 0.08), transparent 32%),
    linear-gradient(120deg, transparent 58%, rgba(232, 93, 72, 0.08));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  width: min(1480px, calc(100% - 32px));
  min-height: 74px;
  margin: 0 auto;
  padding: 14px 0;
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: white;
  font-weight: 900;
  background: linear-gradient(135deg, #101827, #0f766e 52%, #e85d48);
  box-shadow: 0 12px 30px rgba(15, 118, 110, 0.25);
}

.brand strong,
.brand small {
  display: block;
  line-height: 1.05;
}

.brand strong {
  font-size: 18px;
}

.brand small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.meter {
  display: flex;
  align-items: baseline;
  gap: 7px;
  min-width: 90px;
  height: 42px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
}

.meter-label {
  color: var(--muted);
  font-size: 13px;
}

.meter strong {
  color: var(--teal-dark);
  font-size: 20px;
  line-height: 1;
}

.icon-button,
.ghost-button,
.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.icon-button {
  width: 42px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: rgba(255, 255, 255, 0.76);
}

.icon-button:hover,
.ghost-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.08);
}

.workspace {
  position: relative;
  display: grid;
  grid-template-columns: minmax(292px, 360px) minmax(0, 1fr) minmax(280px, 330px);
  gap: 18px;
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 8px 0 36px;
}

.panel {
  border: 1px solid rgba(255, 255, 255, 0.74);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

.composer-panel,
.side-panel {
  align-self: start;
}

.composer-panel {
  padding: 18px;
}

.side-panel {
  display: grid;
  gap: 14px;
}

.quota-panel,
.identity-panel,
.history-panel {
  padding: 16px;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.panel-heading.tight {
  align-items: center;
  margin-bottom: 12px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--teal);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

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

h1 {
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.05;
}

h2 {
  font-size: 22px;
  line-height: 1.16;
}

.status-dot {
  width: 12px;
  height: 12px;
  margin-top: 8px;
  border-radius: 50%;
  background: #9ca3af;
  box-shadow: 0 0 0 5px rgba(156, 163, 175, 0.16);
}

.status-dot.ready {
  background: #10b981;
  box-shadow: 0 0 0 5px rgba(16, 185, 129, 0.16);
}

.status-dot.warn {
  background: var(--gold);
  box-shadow: 0 0 0 5px rgba(199, 144, 47, 0.16);
}

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

.field {
  display: grid;
  gap: 8px;
}

.field span {
  color: #344054;
  font-size: 13px;
  font-weight: 750;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.84);
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.field input,
.field select {
  height: 44px;
  padding: 0 12px;
}

.field textarea {
  min-height: 148px;
  max-height: 280px;
  resize: vertical;
  padding: 12px;
  line-height: 1.55;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: rgba(15, 118, 110, 0.62);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.1);
}

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

.prompt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.prompt-actions {
  display: grid;
  grid-template-columns: minmax(0, 180px) minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.prompt-actions .secondary-button {
  width: 100%;
}

.prompt-actions span {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

.prompt-chips button {
  min-height: 34px;
  border: 1px solid rgba(15, 118, 110, 0.18);
  border-radius: 999px;
  padding: 0 12px;
  color: var(--teal-dark);
  background: rgba(15, 118, 110, 0.08);
  cursor: pointer;
}

.primary-button,
.secondary-button,
.ghost-button {
  min-width: 0;
  padding: 0 14px;
  font-weight: 800;
  text-decoration: none;
}

.primary-button {
  width: 100%;
  height: 52px;
  color: white;
  background: linear-gradient(135deg, var(--ink), var(--teal-dark) 55%, var(--coral));
  box-shadow: 0 18px 38px rgba(15, 118, 110, 0.24);
}

.primary-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 24px 50px rgba(15, 118, 110, 0.3);
}

.primary-button:disabled,
.secondary-button:disabled {
  opacity: 0.62;
  cursor: wait;
  transform: none;
}

.secondary-button {
  width: 100%;
  height: 44px;
  border: 1px solid rgba(15, 118, 110, 0.2);
  color: var(--teal-dark);
  background: rgba(15, 118, 110, 0.08);
}

.ghost-button {
  height: 40px;
  border: 1px solid var(--line);
  color: #344054;
  background: rgba(255, 255, 255, 0.72);
}

.divider {
  height: 1px;
  margin: 18px 0;
  background: var(--line);
}

.compact-form {
  gap: 12px;
}

.form-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.file-field input {
  padding-top: 10px;
}

.stage {
  min-width: 0;
}

.stage-hero {
  position: relative;
  min-height: 315px;
  overflow: hidden;
  border-radius: var(--radius);
  background: #111827;
  box-shadow: var(--shadow);
}

.stage-hero img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 315px;
  object-fit: cover;
}

.stage-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(17, 24, 39, 0.05), rgba(17, 24, 39, 0.58));
}

.stage-caption {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 1;
  display: grid;
  gap: 5px;
  min-width: 190px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  color: white;
  background: rgba(17, 24, 39, 0.48);
  backdrop-filter: blur(12px);
}

.stage-caption span {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.76);
}

.stage-caption strong {
  font-size: 20px;
}

.result-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 18px 0 14px;
}

.notice {
  margin-bottom: 14px;
  border: 1px solid rgba(199, 144, 47, 0.22);
  border-radius: 8px;
  padding: 12px 14px;
  color: #744210;
  background: rgba(255, 247, 214, 0.86);
}

.notice.error {
  border-color: rgba(232, 93, 72, 0.22);
  color: #8a2c1e;
  background: rgba(255, 237, 232, 0.9);
}

.progress-panel {
  margin-bottom: 14px;
  border: 1px solid rgba(15, 118, 110, 0.16);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}

.progress-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.progress-header div {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.progress-header span {
  color: var(--ink);
  font-size: 15px;
  font-weight: 850;
}

.progress-header strong {
  color: var(--teal-dark);
  font-size: 22px;
  line-height: 1;
}

.progress-header small {
  overflow: hidden;
  max-width: 45%;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-track {
  position: relative;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(17, 24, 39, 0.08);
}

.progress-track span {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--blue) 58%, var(--coral));
  box-shadow: 0 0 18px rgba(15, 118, 110, 0.28);
  transition: width 0.38s ease;
}

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

.image-card {
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.74);
  border-radius: var(--radius);
  background: var(--panel-solid);
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.1);
}

.image-frame {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border: 0;
  padding: 0;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.08), rgba(232, 93, 72, 0.06)),
    url("/assets/noise.png");
  cursor: zoom-in;
}

.image-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.24s ease;
}

.image-frame:hover img {
  transform: scale(1.025);
}

.image-actions {
  display: flex;
  justify-content: flex-end;
  padding: 10px;
}

.download-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  border-radius: 8px;
  padding: 0 12px;
  color: var(--teal-dark);
  font-weight: 800;
  text-decoration: none;
  background: rgba(15, 118, 110, 0.08);
}

.credit-pill {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  min-height: 36px;
  border-radius: 999px;
  padding: 7px 12px;
  color: var(--teal-dark);
  background: rgba(15, 118, 110, 0.08);
}

.redeem-form {
  display: grid;
  gap: 10px;
}

#clientIdText {
  display: block;
  overflow-wrap: anywhere;
  border-radius: 8px;
  padding: 11px;
  color: #344054;
  background: rgba(17, 24, 39, 0.05);
}

.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
  border-bottom: 1px solid rgba(17, 24, 39, 0.08);
  color: var(--muted);
}

.stat-row:last-child {
  border-bottom: 0;
}

.stat-row strong {
  color: var(--ink);
}

.history-list {
  display: grid;
  gap: 10px;
  max-height: 420px;
  overflow: auto;
}

.history-item {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border: 1px solid rgba(17, 24, 39, 0.08);
  border-radius: 8px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.58);
  cursor: zoom-in;
  text-align: left;
}

.history-item img {
  width: 64px;
  height: 64px;
  border-radius: 7px;
  object-fit: cover;
  background: #e5e7eb;
}

.history-item strong,
.history-item span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item strong {
  font-size: 13px;
}

.history-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 220px;
  border: 1px dashed rgba(17, 24, 39, 0.18);
  border-radius: var(--radius);
  padding: 24px;
  color: var(--muted);
  text-align: center;
  background: rgba(255, 255, 255, 0.55);
}

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

.lightbox[hidden] {
  display: none;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.78);
  backdrop-filter: blur(18px);
}

.lightbox-dialog {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1160px, 100%);
  height: min(88vh, 920px);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(8, 13, 23, 0.92);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.36);
}

.lightbox-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 66px;
  padding: 12px 14px;
  color: white;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.lightbox-toolbar span,
.lightbox-toolbar strong {
  display: block;
}

.lightbox-toolbar span {
  margin-bottom: 4px;
  color: rgba(255, 255, 255, 0.62);
  font-size: 12px;
}

.lightbox-toolbar strong {
  overflow: hidden;
  max-width: 56vw;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lightbox-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lightbox-actions .ghost-button,
.lightbox-actions .icon-button {
  color: white;
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.1);
}

.lightbox-stage {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 18px;
}

.lightbox-stage img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  object-fit: contain;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.42);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  }

  .side-panel {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .topbar,
  .workspace {
    width: min(100% - 22px, 680px);
  }

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

  .side-panel {
    grid-template-columns: 1fr;
  }

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

  .stage-caption {
    left: 12px;
    right: 12px;
    bottom: 12px;
    min-width: 0;
  }

  .progress-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .progress-header small {
    max-width: 100%;
    text-align: left;
  }
}

@media (max-width: 520px) {
  .topbar {
    min-height: 66px;
  }

  .brand small {
    display: none;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .meter {
    min-width: 76px;
    padding: 8px 10px;
  }

  .workspace {
    width: calc(100% - 18px);
    gap: 12px;
  }

  .composer-panel,
  .quota-panel,
  .identity-panel,
  .history-panel {
    padding: 14px;
  }

  h1 {
    font-size: 32px;
  }

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

  .prompt-actions {
    grid-template-columns: 1fr;
  }

  .stage-hero,
  .stage-hero img {
    min-height: 250px;
  }

  .result-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .lightbox {
    padding: 10px;
  }

  .lightbox-dialog {
    height: 92vh;
  }

  .lightbox-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .lightbox-toolbar strong {
    max-width: calc(100vw - 48px);
  }
}
