:root {
  color-scheme: dark;
  --bg: #111831;
  --panel: rgba(28, 38, 66, 0.94);
  --panel-strong: #141d33;
  --input: #0d1426;
  --line: rgba(217, 226, 255, 0.17);
  --line-strong: rgba(255, 193, 75, 0.72);
  --text: #f7f8ff;
  --muted: #c8d0e3;
  --soft: #8e98b0;
  --gold: #ffc24d;
  --orange: #ff8a65;
  --green: #7ee4a4;
  --red: #ff6476;
  --shadow: 0 24px 80px rgba(2, 7, 20, 0.38);
  font-family: Inter, "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 14% 8%, rgba(255, 194, 77, 0.12), transparent 28%),
    linear-gradient(135deg, #101631 0%, #1b2544 48%, #111827 100%);
  color: var(--text);
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

.edit-app {
  min-height: 100vh;
  padding: 0 44px 56px;
}

.topbar {
  height: 90px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.brand,
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand {
  font-size: 20px;
  font-weight: 900;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: #141a2d;
  background: linear-gradient(135deg, var(--gold), var(--orange));
  font-size: 13px;
}

.ghost-link,
.ghost-btn,
.tool-btn,
.mini-btn,
.file-btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.055);
  color: var(--text);
  border-radius: 14px;
  min-height: 44px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 850;
}

.ghost-link { color: var(--muted); border-radius: 999px; }

.hero {
  width: min(1760px, 100%);
  margin: 46px auto 24px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.2em;
}

.hero h1 {
  margin: 0;
  font-size: clamp(42px, 6vw, 84px);
  line-height: 1;
}

.hero p {
  max-width: 980px;
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 20px;
  line-height: 1.7;
}

.workspace {
  width: min(1760px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 410px;
  gap: 24px;
  align-items: start;
}

.stage-panel,
.side-panel,
.history-panel,
.debug-panel {
  background: linear-gradient(160deg, rgba(30, 40, 70, 0.96), rgba(22, 31, 54, 0.96));
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.stage-panel { padding: 24px; min-width: 0; }
.side-panel { padding: 22px; position: sticky; top: 24px; }
.history-panel { padding: 22px; margin-top: 20px; }
.debug-panel { padding: 18px; margin-top: 20px; box-shadow: none; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.file-btn input { display: none; }
.tool-btn.active { border-color: var(--line-strong); color: var(--gold); background: rgba(255, 193, 75, 0.13); }
.tool-btn:disabled, .ghost-btn:disabled, .primary-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.size-control {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-weight: 800;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
}

.size-control input { width: 120px; accent-color: var(--gold); }

.canvas-shell {
  position: relative;
  min-height: 520px;
  overflow: hidden;
  margin: 0 auto;
  border-radius: 20px;
  background: #080e1d;
  border: 1px solid rgba(255,255,255,0.1);
}

.canvas-shell.has-image {
  min-height: 0;
}

canvas {
  display: block;
  max-width: none;
}

#overlayCanvas {
  position: absolute;
  left: 0;
  top: 0;
  touch-action: none;
  cursor: crosshair;
  z-index: 2;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 22px;
  font-weight: 850;
  pointer-events: none;
  z-index: 3;
}

.section-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.section-title h2 {
  margin: 0;
  font-size: 28px;
}

.section-title.compact h2 { font-size: 20px; }

.count-pill {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  font-weight: 900;
}

.hint-card,
.empty-card {
  border: 1px dashed rgba(217, 226, 255, 0.24);
  border-radius: 16px;
  padding: 16px;
  color: var(--muted);
  background: rgba(8, 14, 29, 0.36);
}

.hint-card strong { color: var(--text); }
.hint-card p { margin: 8px 0 0; line-height: 1.65; }

.region-list {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.region-card {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  background: rgba(10, 16, 30, 0.55);
}

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

.region-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 950;
}

.color-dot {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  display: inline-block;
  box-shadow: 0 0 0 3px rgba(255,255,255,0.09);
}

.region-tools {
  display: flex;
  gap: 8px;
}

.mini-btn {
  min-height: 34px;
  padding: 0 10px;
  border-radius: 10px;
  color: var(--muted);
}

.region-card textarea {
  width: 100%;
  min-height: 92px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--input);
  color: var(--text);
  padding: 12px;
  line-height: 1.55;
  outline: none;
}

.reference-row {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.reference-name {
  color: var(--soft);
  font-size: 13px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 12px;
  margin-top: 18px;
}

.primary-btn {
  min-height: 58px;
  border: 0;
  border-radius: 16px;
  color: #10162a;
  background: linear-gradient(135deg, var(--gold), var(--orange));
  font-weight: 950;
  box-shadow: 0 16px 34px rgba(255, 138, 101, 0.24);
}

.log-box {
  height: 220px;
  overflow: auto;
  border-radius: 14px;
  background: #070d1a;
  padding: 12px;
  border: 1px solid rgba(126, 228, 164, 0.28);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
  color: #dbe7ff;
}

.log-row { display: grid; grid-template-columns: 74px 60px 1fr; gap: 8px; margin-bottom: 8px; }
.log-time { color: #8190ac; }
.log-level { color: var(--gold); font-weight: 950; }
.log-level.done { color: var(--green); }
.log-level.err { color: var(--red); }

.result-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.result-card {
  overflow: hidden;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(8, 14, 29, 0.45);
}

.result-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background: #fff;
  display: block;
}

.result-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.result-card a,
.result-card button {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  color: var(--gold);
  background: transparent;
  border: 0;
  border-top: 1px solid var(--line);
  border-right: 1px solid var(--line);
  cursor: pointer;
}

.result-card a:last-child,
.result-card button:last-child {
  border-right: 0;
}

@media (max-width: 1100px) {
  .edit-app { padding: 0 18px 36px; }
  .workspace { grid-template-columns: 1fr; }
  .side-panel { position: static; }
  .hero h1 { font-size: 46px; }
}
