:root {
  --bg: #f4f8ff;
  --panel: rgba(255, 255, 255, 0.74);
  --panel-strong: rgba(255, 255, 255, 0.94);
  --line: rgba(47, 128, 255, 0.14);
  --text: #123054;
  --muted: rgba(18, 48, 84, 0.64);
  --accent: #2f80ff;
  --accent-2: #7ab8ff;
  --danger: #e85d75;
  --ok: #23a36f;
  --shadow: 0 18px 60px rgba(34, 87, 180, 0.16);
  --radius: 22px;
  --radius-sm: 16px;
  --dock-h: 74px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: radial-gradient(circle at top, #ffffff 0, #eef5ff 48%, #e6f0ff 100%); color: var(--text); }
body { overflow-x: hidden; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }

.bg-grid {
  position: fixed; inset: 0; pointer-events: none; opacity: 0.22;
  background-image:
    linear-gradient(rgba(47,128,255,.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(47,128,255,.05) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(circle at center, black 58%, transparent 100%);
}

#app { position: relative; min-height: 100vh; }

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 18px 20px 0;
}

.brand {
  display: flex; align-items: center; gap: 12px; min-width: 0;
}
.brand-mark {
  width: 38px; height: 38px; border-radius: 14px;
  background: linear-gradient(145deg, rgba(47,128,255,.96), rgba(122,184,255,.9));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.68), 0 10px 30px rgba(47, 128, 255, .22);
}
.brand h1 { margin: 0; font-size: 18px; letter-spacing: .02em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.glass {
  background: linear-gradient(180deg, rgba(255,255,255,.92), rgba(244,249,255,.74));
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px) saturate(1.15);
  -webkit-backdrop-filter: blur(24px) saturate(1.15);
}

.seg {
  display: flex;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 4px;
  border-radius: 999px;
  gap: 4px;
}
.seg button {
  flex: 1 1 0;
  border: 0; background: transparent; color: var(--muted);
  padding: 10px 14px; border-radius: 999px;
  transition: background .2s ease, color .2s ease, transform .2s ease;
}
.seg button.active { background: rgba(47,128,255,.12); color: var(--accent); }
.seg button:active { transform: scale(.98); }

.layout {
  display: grid;
  grid-template-columns: minmax(340px, 430px) 1fr;
  gap: 18px;
  padding: 18px 18px 18px;
  min-height: 0;
}

.panel, .results {
  min-width: 0;
  min-height: 0;
  border-radius: var(--radius);
  background: rgba(255,255,255,.72);
  border: 1px solid rgba(47,128,255,.10);
}

.panel {
  padding: 18px;
  display: flex; flex-direction: column; gap: 14px;
}

.section-title {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: 13px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted);
  margin-bottom: 8px;
}

.field, .card, .upload, .param-group, .results, .viewer, .toast, .dock {
  border-radius: var(--radius-sm);
}

.field {
  background: rgba(255,255,255,.74); border: 1px solid rgba(47,128,255,.10);
  padding: 12px;
}
.field label { display:block; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.field input, .field textarea, .field select {
  width: 100%; border: 0; outline: 0; background: transparent; color: var(--text);
}
.field textarea { min-height: 160px; resize: vertical; line-height: 1.5; }
.field input::placeholder, .field textarea::placeholder { color: rgba(18,48,84,.38); }

.row { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.row.compact { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.models {
  display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr));
}
.model-card {
  padding: 12px; border-radius: 18px; background: rgba(255,255,255,.86); border: 1px solid rgba(47,128,255,.12);
  color: var(--text); text-align: left;
}
.model-card.active {
  background: linear-gradient(180deg, rgba(47,128,255,.18), rgba(122,184,255,.12));
  border-color: rgba(47,128,255,.38);
}
.model-card small { display:block; color: var(--muted); margin-top: 4px; }

.param-head {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px;
}
.param-box {
  overflow: hidden;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.param-card {
  padding: 14px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255,255,255,.96), rgba(243,249,255,.92));
  border: 1px solid rgba(47,128,255,.12);
  box-shadow: 0 10px 30px rgba(52, 115, 210, 0.08);
}

.param-card-wide {
  grid-column: 1 / -1;
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--muted);
}

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

.size-segment {
  min-height: 88px;
  display: grid;
  justify-items: start;
  align-content: center;
  gap: 4px;
  text-align: left;
}

.ratio-title {
  font-size: 13px;
  font-weight: 700;
}

.ratio-size {
  font-size: 12px;
  color: var(--muted);
}

.segmented-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 8px;
}
.segmented-controls-quality {
  grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
}
.segmented-controls-quality-wide {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.segment {
  border: 1px solid rgba(47,128,255,.12);
  border-radius: 14px;
  padding: 11px 12px;
  background: rgba(255,255,255,.88);
  color: var(--muted);
  text-align: center;
}

.segment.active {
  background: rgba(47,128,255,.12);
  color: var(--accent);
  border-color: rgba(47,128,255,.34);
}

.upload-zone {
  display: grid; gap: 10px;
}
.upload {
  padding: 12px; background: rgba(255,255,255,.82); border: 1px dashed rgba(47,128,255,.18);
}
.refs {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px;
}
.ref {
  position: relative; aspect-ratio: 1/1; overflow: hidden; border-radius: 18px;
  background: rgba(255,255,255,.9); border: 1px solid rgba(47,128,255,.10);
}
.ref img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ref button {
  position: absolute; right: 8px; top: 8px; width: 28px; height: 28px; border-radius: 999px;
  border: 0; background: rgba(47,128,255,.82); color: white;
}
.ref.dragging { opacity: .5; transform: scale(.98); }

.actions { display: flex; gap: 10px; align-items: center; }
.generate {
  width: 100%; border: 0; border-radius: 18px;
  padding: 16px 18px; font-weight: 700; letter-spacing: .06em; color: white;
  background: linear-gradient(135deg, #2f80ff, #57a6ff 48%, #7cc3ff);
  box-shadow: 0 18px 36px rgba(47,128,255,.24);
}
.generate.loading { color: rgba(255,255,255,.82); }
.subtle { color: var(--muted); font-size: 12px; }

.results {
  position: relative;
  padding: 14px;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
}

.result-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding-bottom: 10px;
}
.result-head .generate {
  width: auto;
  min-width: 132px;
  padding: 12px 16px;
  border-radius: 999px;
  white-space: nowrap;
}
.result-wall {
  overflow: auto;
  padding-right: 6px;
  min-height: 0;
}
.masonry {
  column-width: 260px;
  column-gap: 14px;
}
.image-card {
  break-inside: avoid;
  margin: 0 0 14px;
  background: rgba(255,255,255,.94);
  border: 1px solid rgba(47,128,255,.10);
  border-radius: 18px;
  overflow: hidden;
}
.image-card img {
  width: 100%; display: block;
}
.image-meta {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 10px 12px; font-size: 12px; color: var(--muted);
}
.image-meta strong { color: var(--text); }
.download {
  border: 0; border-radius: 999px; padding: 8px 12px;
  background: rgba(47,128,255,.10); color: var(--accent);
}
.img-click { cursor: zoom-in; }

.skeleton {
  aspect-ratio: 1 / 1.1;
  background: linear-gradient(90deg, rgba(47,128,255,.06), rgba(122,184,255,.18), rgba(47,128,255,.06));
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}

@keyframes shimmer {
  0% { background-position: 0 0; }
  100% { background-position: 200% 0; }
}

.viewer {
  position: fixed; inset: 0; display: none; align-items: center; justify-content: center;
  padding: 20px; z-index: 40;
}
.viewer.open { display: flex; }
.viewer-backdrop {
  position: absolute; inset: 0; background: rgba(27,59,117,.34); backdrop-filter: blur(18px) saturate(1.08);
}
.viewer-frame {
  position: relative; z-index: 1; max-width: min(96vw, 1400px); max-height: 92vh;
  width: 100%; display: grid; gap: 12px;
}
.viewer-stage {
  position: relative; min-height: 0; border-radius: 26px; overflow: hidden;
  background: rgba(255,255,255,.94); border: 1px solid rgba(47,128,255,.10);
  display: flex; align-items: center; justify-content: center;
}
.viewer-stage img {
  max-width: 100%; max-height: 82vh; transform-origin: center center; user-select: none;
}
.viewer-bar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: 18px;
}
.viewer-controls {
  display: flex; gap: 8px; align-items: center;
}
.viewer-controls input[type="range"] { width: 160px; }
.icon-btn {
  border: 0; border-radius: 999px; padding: 10px 14px;
  background: rgba(47,128,255,.10); color: var(--accent);
}

.toast {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  padding: 12px 16px; min-width: min(560px, calc(100vw - 28px));
  background: rgba(255,255,255,.94); border: 1px solid rgba(47,128,255,.12);
  z-index: 45; display: none; align-items: center; justify-content: space-between; gap: 12px;
}
.toast.show { display: flex; }
.toast .kind { font-size: 12px; color: var(--accent); }
.toast.error .kind { color: var(--danger); }

.dock {
  position: fixed; left: 12px; right: 12px; bottom: 12px; height: var(--dock-h);
  display: none; align-items: center; justify-content: space-between; padding: 10px;
  background: rgba(255,255,255,.9); border: 1px solid rgba(47,128,255,.10); z-index: 20;
}
.dock button {
  flex: 1; border: 0; height: 100%; border-radius: 18px; background: transparent; color: var(--muted);
}
.dock button.active { background: rgba(47,128,255,.12); color: var(--accent); }

.mobile-page {
  display: none;
  padding-bottom: calc(var(--dock-h) + 24px);
}
.mobile-page.active { display: block; }

@media (max-width: 900px) {
  .shell { display: block; }
  .topbar { padding: 14px 14px 0; flex-wrap: wrap; }
  .layout { display: none; }
  .panel, .results { display: none; }
  .mobile-page { display: none; }
  .mobile-page.active { display: block; }
  .dock { display: flex; }
}

@media (max-width: 1100px) {
  .param-box { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
