:root {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans CJK SC", sans-serif;
  color: #423644;
  background: #fcf9fb;
  --pink: #d969a0;
  --line: #eadfe7;
  --muted: #897c8c;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
button, input, select, textarea { font: inherit; }
button {
  cursor: pointer;
  color: inherit;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
}
button:hover { border-color: #d994b5; }
button:disabled { cursor: not-allowed; opacity: .5; }
.primary {
  color: #fff;
  font-weight: 650;
  border: 0;
  background: linear-gradient(110deg, #df85ae, #b092d9);
}
.secondary { background: #f7eef4; border-color: transparent; }

header {
  max-width: 1360px;
  min-height: 76px;
  margin: auto;
  padding: 14px 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.brand {
  color: #845372;
  font: italic 29px Georgia, serif;
  text-decoration: none;
}
.brand span {
  margin-left: 18px;
  color: var(--muted);
  font: 12px sans-serif;
}
main { max-width: 1260px; margin: auto; padding: 42px 24px 70px; }
.intro { margin-bottom: 30px; }
.eyebrow { color: #ab7f9d; font-size: 10px; font-weight: 700; letter-spacing: 2px; }
.intro h1 { margin: 12px 0; font-size: 36px; font-weight: 500; line-height: 1.4; }
.intro p, .hint { color: var(--muted); font-size: 12px; line-height: 1.8; }

.workspace {
  display: grid;
  grid-template-columns: 420px minmax(0, 1fr);
  gap: 28px;
  align-items: start;
}
.controls, .preview-panel {
  min-width: 0;
  padding: 22px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 8px 30px #6142540a;
}
.preview-panel { position: sticky; top: 20px; }
nav { display: flex; gap: 4px; padding-bottom: 14px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.tab { flex: 1; border: 0; color: var(--muted); font-size: 13px; }
.tab.active { color: #a95e89; background: #f7e9f2; }
.hidden { display: none !important; }
.row { display: flex; gap: 10px; }
.row > label { flex: 1; min-width: 0; }
.presets { flex-wrap: wrap; margin-bottom: 18px; }
label { display: block; margin: 15px 0 8px; color: #685366; font-size: 12px; font-weight: 600; }
label small { margin-left: 5px; color: #9a8b98; font-size: 10px; font-weight: 400; }
textarea, input:not([type=checkbox]):not([type=range]), select {
  display: block;
  width: 100%;
  margin-top: 7px;
  padding: 10px 12px;
  color: #564351;
  background: #fefcfe;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
}
textarea { resize: vertical; line-height: 1.65; }
input[type=range] { width: 100%; margin-top: 10px; accent-color: #c889b0; }
output { float: right; color: #b08a9f; font-weight: 400; }
.motifs { display: flex; flex-wrap: wrap; gap: 7px; }
.motif { padding: 7px 10px; border-radius: 30px; font-size: 12px; }
.motif.selected { color: #a46687; background: #fcf0f7; border-color: #dbb6cd; }
.check { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-weight: 400; }
#shuffle, #compile, #aiGenerate { width: 100%; margin-top: 11px; }
.export-options .export-row { margin-top: 12px; }
summary { cursor: pointer; font-size: 12px; color: #8f7189; }
#previewStage[aria-busy=true] { opacity: .65; }
#openPreview { display: block; width: 100%; padding: 0; border: 0; background: transparent; cursor: zoom-in; }
#openPreview:disabled { opacity: 1; cursor: default; }
#openPreview:focus-visible { outline: 2px solid #a95e89; outline-offset: 4px; }
#previewStage { min-height: 520px; padding: 22px; display: flex; align-items: center; justify-content: center; overflow: hidden; border-radius: 18px; background: radial-gradient(ellipse at top, #f7e8f1, #edf2fa); }
#previewStage img { max-width: 100%; max-height: 660px; object-fit: contain; border-radius: 14px; }
.preview-hint { margin: 8px 0 0; text-align: center; color: var(--muted); font-size: 12px; }
#status { padding: 10px 0; color: #8f7189; font-size: 12px; line-height: 1.6; }
.export-row { display: flex; flex-wrap: wrap; gap: 8px; }
.export-row button { flex: 1; white-space: nowrap; font-size: 12px; }
.image-viewer { width: 100%; max-width: 100%; height: 100vh; height: 100dvh; max-height: 100%; margin: 0; padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom)); border: 0; border-radius: 0; color: #f7f0f6; background: #211d24; overflow: hidden; }
.image-viewer[open] { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 12px; }
.image-viewer::backdrop { background: #211d24; }
body:has(.image-viewer[open]) { overflow: hidden; }
.viewer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.viewer-head h2 { margin: 0; font-size: 16px; }
.viewer-head p { margin: 4px 0 0; color: #c8bbc9; font-size: 11px; }
.viewer-tools { display: flex; gap: 8px; }
.viewer-tools button, #retryImage { min-height: 44px; color: #f7f0f6; background: #39313c; border-color: #67566a; }
.viewer-stage { display: flex; align-items: center; justify-content: center; min-height: 0; overflow: auto; overscroll-behavior: contain; }
#saveImage { display: block; max-width: 100%; max-height: 100%; object-fit: contain; -webkit-touch-callout: default; user-select: auto; }
#saveImage[hidden] { display: none; }
.viewer-stage.is-zoomed { display: block; }
.viewer-stage.is-zoomed #saveImage { max-width: none; max-height: none; height: auto; margin: 0 auto; }
#saveMessage { margin: 0; font-size: 12px; line-height: 1.6; }
#retryImage { margin-top: 10px; }
details { margin-top: 20px; padding-top: 15px; border-top: 1px solid var(--line); }
pre { max-height: 260px; padding: 12px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; background: #faf7fa; border-radius: 10px; font-size: 10px; line-height: 1.7; }
#aiResult img { max-width: 100%; margin-top: 15px; border-radius: 12px; }
footer { max-width: 1260px; margin: auto; padding: 25px; color: #a08197; border-top: 1px solid var(--line); font-size: 12px; }
footer span { float: right; color: #b29faf; font-size: 10px; }

@media (max-width: 850px) {
  .workspace { grid-template-columns: 1fr; gap: 14px; }
  .preview-panel { grid-row: 1; position: sticky; top: 0; z-index: 2; padding: 8px; box-shadow: 0 6px 16px #61425418; }
  .controls { grid-row: 2; padding: 16px; border-radius: 20px; }
  .controls textarea, .controls input, .controls select { scroll-margin-top: calc(var(--mobile-preview-height, 200px) + 52px); }
  .intro { margin-bottom: 14px; }
  .intro h1 { font-size: 20px; margin: 0; }
  .intro h1 br { display: none; }
  .intro p, .intro .eyebrow { display: none; }
  #previewStage { min-height: 0; height: var(--mobile-preview-height, clamp(140px, 24dvh, 240px)); padding: 4px; border-radius: 12px; }
  #previewStage img { max-height: 100%; border-radius: 6px; }
  .preview-hint { margin-top: 6px; font-size: 11px; }
  #status { padding: 8px 0; font-size: 11px; }
  header { min-height: 54px; padding: 8px 18px; }
  .brand span { display: none; }
  main { padding: 16px 14px; }
  nav { margin-bottom: 12px; padding-bottom: 10px; }
  footer span { float: none; display: block; margin-top: 10px; }
  textarea, input:not([type=checkbox]):not([type=range]), select { font-size: 16px; }
}
