:root {
  color: #172033;
  background: #f4f7fb;
  font-family: Inter, "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: #172033;
  background:
    linear-gradient(180deg, rgba(255,255,255,.96), rgba(244,247,251,.88) 380px),
    #f4f7fb;
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .58; }

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

.shell {
  width: min(1220px, calc(100% - 32px));
  margin: 0 auto;
  padding: 20px 0 42px;
}

.shell.is-locked {
  pointer-events: none;
  user-select: none;
  filter: blur(2px);
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(244, 247, 251, .88);
  backdrop-filter: blur(14px);
}

.auth-gate[hidden] {
  display: none;
}

.auth-card {
  width: min(390px, 100%);
  padding: 24px;
  border: 1px solid rgba(15, 23, 42, .1);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(15, 23, 42, .16);
}

.auth-card .brand-mark {
  margin-bottom: 16px;
}

.auth-card h2 {
  margin: 0 0 8px;
  font-size: 24px;
  letter-spacing: 0;
}

.auth-card p {
  margin: 0 0 18px;
  color: #64748b;
  line-height: 1.6;
}

.auth-card .btn {
  width: 100%;
  margin-top: 14px;
}

.topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0 18px;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #fff;
  background:
    linear-gradient(135deg, #155e75, #2563eb 50%, #16a34a);
  box-shadow: 0 14px 28px rgba(37, 99, 235, .18);
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.08;
  letter-spacing: 0;
}

.brand p {
  margin: 4px 0 0;
  color: #66758b;
  font-size: 13px;
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 5px;
  border: 1px solid rgba(15, 23, 42, .1);
  border-radius: 999px;
  background: rgba(255, 255, 255, .9);
  box-shadow: 0 12px 28px rgba(15, 23, 42, .07);
  overflow-x: auto;
}

.tabs button {
  min-height: 38px;
  border: 0;
  border-radius: 999px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: #4b5f78;
  background: transparent;
  font-weight: 850;
  white-space: nowrap;
}

.tabs button.active {
  color: #fff;
  background: #111827;
  box-shadow: 0 8px 18px rgba(15, 23, 42, .16);
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
  align-items: stretch;
  margin-bottom: 14px;
}

.hero > div:first-child {
  min-height: 178px;
  padding: 30px;
  border: 1px solid rgba(15, 23, 42, .08);
  border-radius: 8px;
  background: #fff;
  display: grid;
  align-content: center;
  box-shadow: 0 20px 48px rgba(15, 23, 42, .08);
}

.hero h2 {
  margin: 0 0 10px;
  max-width: 820px;
  font-size: clamp(30px, 4.8vw, 56px);
  line-height: 1.03;
  letter-spacing: 0;
}

.hero p {
  margin: 0;
  max-width: 740px;
  color: #607189;
  font-size: 16px;
  line-height: 1.7;
}

.hero-stack {
  padding: 20px;
  border-radius: 8px;
  color: #fff;
  background:
    radial-gradient(circle at 88% 16%, rgba(52, 211, 153, .52), transparent 28%),
    linear-gradient(135deg, #0f172a, #12385f 58%, #0f766e);
  display: grid;
  gap: 12px;
  align-content: center;
  box-shadow: 0 20px 48px rgba(15, 23, 42, .14);
}

.hero-stack span,
.hero-stack small {
  color: rgba(255,255,255,.72);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.hero-stack strong {
  font-size: 32px;
  line-height: 1;
}

.quick-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 18px;
}

.quick-row button {
  min-height: 42px;
  border: 1px solid rgba(15, 23, 42, .1);
  border-radius: 8px;
  color: #243247;
  background: rgba(255, 255, 255, .86);
  font-weight: 850;
  box-shadow: 0 10px 24px rgba(15, 23, 42, .05);
}

.panel {
  display: none;
  border-radius: 8px;
  border: 1px solid rgba(15, 23, 42, .08);
  background: #fff;
  box-shadow: 0 20px 50px rgba(15, 23, 42, .08);
  overflow: hidden;
}

.panel.active { display: block; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid rgba(15, 23, 42, .08);
  background: #fbfcff;
}

.panel-head h3 {
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
}

.panel-head p {
  margin: 4px 0 0;
  color: #64748b;
  font-size: 13px;
}

.editor-layout,
.grid {
  display: grid;
  grid-template-columns: minmax(320px, .82fr) minmax(0, 1.18fr);
}

.control-panel,
.side,
.result,
.canvas-area {
  padding: 18px;
  min-width: 0;
}

.control-panel,
.side {
  border-right: 1px solid rgba(15, 23, 42, .08);
  background: #fbfcff;
}

.timing-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 12px 14px;
  border: 1px solid rgba(15, 23, 42, .08);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 30px rgba(15, 23, 42, .05);
}

.timing-panel.running {
  border-color: rgba(37, 99, 235, .24);
  background: #f8fbff;
}

.timing-panel.done {
  border-color: rgba(15, 118, 110, .22);
  background: #f6fffc;
}

.timing-panel.error {
  border-color: rgba(220, 38, 38, .22);
  background: #fff8f8;
}

.timing-title {
  display: grid;
  gap: 4px;
}

.timing-title strong {
  color: #172033;
  font-size: 14px;
}

.timing-title span {
  color: #64748b;
  font-size: 12px;
}

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

.timing-values div {
  min-width: 88px;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(15, 23, 42, .04);
}

.timing-values small,
.timing-values b {
  display: block;
  letter-spacing: 0;
}

.timing-values small {
  margin-bottom: 2px;
  color: #64748b;
  font-size: 11px;
}

.timing-values b {
  color: #172033;
  font-size: 15px;
}

.retry-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 6px 10px;
  align-items: center;
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(15, 23, 42, .08);
  border-radius: 8px;
  background: #fff;
}

.retry-control label {
  margin: 0;
}

.retry-control select {
  height: 36px;
}

.retry-control small {
  grid-column: 1 / -1;
  color: #64748b;
  font-size: 12px;
  line-height: 1.45;
}

label {
  display: block;
  margin: 0 0 8px;
  color: #334155;
  font-size: 13px;
  font-weight: 850;
}

textarea, input, select {
  width: 100%;
  border: 1px solid rgba(15, 23, 42, .14);
  border-radius: 8px;
  outline: none;
  background: #fff;
  color: #172033;
}

textarea:focus,
input:focus,
select:focus {
  border-color: rgba(37, 99, 235, .62);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .1);
}

textarea {
  padding: 13px;
  resize: vertical;
  line-height: 1.58;
  font-size: 13px;
}

.prompt-box {
  min-height: 154px;
  font-family: inherit;
}

.prompt-box.code {
  min-height: 220px;
  font-family: "JetBrains Mono", Consolas, monospace;
}

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

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.actions,
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.btn,
.chip {
  min-height: 40px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 850;
}

.btn {
  border: 0;
  padding: 0 14px;
  color: #fff;
  background: #111827;
  transition: transform .15s ease, box-shadow .15s ease;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 24px rgba(15, 23, 42, .12);
}

.btn.secondary,
.chip {
  color: #172033;
  background: #fff;
  border: 1px solid rgba(15, 23, 42, .12);
  box-shadow: none;
}

.chip {
  padding: 0 13px;
}

.chip.active {
  color: #fff;
  border-color: #111827;
  background: #111827;
}

.btn.accent {
  background: linear-gradient(135deg, #0f766e, #2563eb);
}

.status {
  min-height: 22px;
  margin-top: 10px;
  color: #64748b;
  font-size: 13px;
  font-weight: 750;
}

.status.ok { color: #0f766e; }
.status.err { color: #b42318; }

.drop {
  min-height: 210px;
  border: 2px dashed rgba(15, 23, 42, .15);
  border-radius: 8px;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #f8fafc;
  color: #64748b;
  text-align: center;
  transition: border-color .15s ease, background .15s ease;
}

.drop.compact {
  min-height: 112px;
  margin-top: 12px;
}

.drop.drag {
  border-color: #2563eb;
  background: #eff6ff;
}

.drop strong {
  display: block;
  margin-bottom: 6px;
  color: #172033;
  font-size: 17px;
}

.reference-guide {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid rgba(37, 99, 235, .18);
  border-radius: 8px;
  background: #f8fbff;
}

.reference-guide-head {
  display: grid;
  gap: 3px;
}

.reference-guide-head strong {
  color: #172033;
  font-size: 15px;
}

.reference-guide-head span {
  color: #64748b;
  font-size: 13px;
  line-height: 1.5;
}

.reference-steps {
  display: grid;
  gap: 6px;
}

.reference-steps span {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 6px 8px;
  border: 1px solid rgba(15, 23, 42, .08);
  border-radius: 8px;
  background: #fff;
  color: #334155;
  font-size: 13px;
  line-height: 1.35;
}

.reference-steps b {
  display: inline-grid;
  place-items: center;
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #172033;
  color: #fff;
  font-size: 12px;
}

.reference-intent-field {
  display: grid;
  gap: 6px;
}

.reference-intent-field > span {
  color: #172033;
  font-size: 13px;
  font-weight: 800;
}

.reference-intent-field textarea {
  width: 100%;
  min-height: 86px;
  resize: vertical;
  border: 1px solid rgba(15, 23, 42, .14);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: #0f172a;
  font: inherit;
  line-height: 1.5;
  outline: none;
}

.reference-intent-field textarea:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.ref-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.ref-thumb {
  position: relative;
  border: 2px solid transparent;
  border-radius: 8px;
  overflow: hidden;
  min-height: 92px;
  background: #eef2f7;
}

.ref-thumb.active {
  border-color: #2563eb;
}

.ref-thumb.main {
  border-color: #0f766e;
}

.ref-thumb.active.main {
  box-shadow: 0 0 0 3px rgba(15, 118, 110, .16);
}

.ref-thumb img {
  width: 100%;
  height: 92px;
  display: block;
  object-fit: cover;
}

.ref-index,
.ref-role,
.ref-usage {
  position: absolute;
  z-index: 1;
  max-width: calc(100% - 10px);
  overflow: hidden;
  color: #fff;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: rgba(15, 23, 42, .78);
}

.ref-index {
  top: 5px;
  left: 5px;
  padding: 3px 5px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 800;
}

.ref-role {
  top: 5px;
  left: 5px;
  transform: translateX(34px);
  padding: 3px 6px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 800;
}

.ref-usage {
  right: 34px;
  bottom: 5px;
  left: 5px;
  padding: 4px 5px;
  border-radius: 6px;
  font-size: 10px;
}

.ref-thumb button {
  position: absolute;
  right: 4px;
  z-index: 2;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: rgba(15, 23, 42, .78);
}

.ref-thumb .ref-remove {
  top: 4px;
}

.ref-thumb .ref-main-btn {
  right: 5px;
  bottom: 5px;
  font-size: 15px;
  line-height: 1;
  color: #fde68a;
}

.ref-thumb .ref-main-btn.is-main {
  background: #0f766e;
  color: #fff;
}

.canvas-area {
  display: grid;
  gap: 14px;
  align-content: start;
}

.result {
  display: grid;
  gap: 14px;
  align-content: start;
}

.canvas-shell,
.preview {
  min-height: 430px;
  border-radius: 8px;
  border: 1px solid rgba(15, 23, 42, .08);
  background:
    linear-gradient(45deg, #f1f5f9 25%, transparent 25%),
    linear-gradient(-45deg, #f1f5f9 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f1f5f9 75%),
    linear-gradient(-45deg, transparent 75%, #f1f5f9 75%),
    #fff;
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  display: grid;
  place-items: center;
  padding: 14px;
  overflow: auto;
}

.canvas-shell {
  position: relative;
}

.canvas-shell canvas {
  display: none;
  max-width: 100%;
  max-height: 680px;
  border-radius: 8px;
  grid-area: 1 / 1;
  box-shadow: 0 14px 34px rgba(15, 23, 42, .1);
}

.canvas-shell.ready canvas {
  display: block;
}

#mask-canvas {
  cursor: crosshair;
}

.preview img {
  max-width: 100%;
  max-height: 620px;
  border-radius: 8px;
  object-fit: contain;
  box-shadow: 0 12px 30px rgba(15, 23, 42, .1);
}

.empty {
  color: #94a3b8;
  font-weight: 850;
  text-align: center;
}

.meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.metric {
  min-height: 66px;
  padding: 12px;
  border: 1px solid rgba(15, 23, 42, .08);
  border-radius: 8px;
  background: #fbfcff;
}

.metric small {
  display: block;
  margin-bottom: 6px;
  color: #64748b;
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.metric span {
  display: block;
  overflow-wrap: anywhere;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 13px;
  color: #172033;
}

.quality {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

input[type="range"] {
  height: 40px;
  padding: 0;
  box-shadow: none;
}

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

.image-card {
  border: 1px solid rgba(15, 23, 42, .08);
  border-radius: 8px;
  background: #fbfcff;
  overflow: hidden;
}

.image-card img {
  width: 100%;
  display: block;
  aspect-ratio: 1;
  object-fit: contain;
  background: #fff;
}

.image-card div {
  display: flex;
  gap: 8px;
  padding: 10px;
}

.image-card a,
.image-card button {
  flex: 1;
  min-height: 36px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #172033;
  background: #fff;
  border: 1px solid rgba(15, 23, 42, .12);
  text-decoration: none;
  font-size: 13px;
  font-weight: 850;
}

@media (max-width: 960px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .hero,
  .editor-layout,
  .grid,
  .quick-row {
    grid-template-columns: 1fr;
  }

  .control-panel,
  .side {
    border-right: 0;
    border-bottom: 1px solid rgba(15, 23, 42, .08);
  }

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

@media (max-width: 560px) {
  .shell {
    width: min(100% - 20px, 1220px);
    padding-top: 10px;
  }

  .hero > div:first-child {
    padding: 22px;
  }

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

  .timing-panel,
  .timing-values,
  .retry-control {
    grid-template-columns: 1fr;
  }

  .canvas-shell,
  .preview {
    min-height: 320px;
  }
}
