: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 {
  appearance: none;
  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; padding: 0; border: 0; border-radius: 0; box-shadow: none; }
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; }
.preset-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; color: #685366; font-size: 12px; }
.controls button[aria-pressed=true] { color: #a46687; background: #fcf0f7; border-color: #dbb6cd; }
.presets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; margin-bottom: 18px; }
.presets button { min-width: 0; min-height: 36px; padding: 8px 3px; font-size: 13px; line-height: 1.4; overflow-wrap: anywhere; }
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%;
  min-width: 0;
  max-width: 100%;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 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; }
textarea::placeholder, input::placeholder { color: #9a8b98; opacity: 1; }
textarea:focus, input:not([type=range]):focus { border-color: #c889b0; box-shadow: 0 0 0 2px #fcf0f7; }
input[type=range] { width: 100%; min-width: 0; max-width: 100%; margin: 10px 0 0; 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; }
.preview-image-wrap { position: relative; min-width: 0; }
.preview-feedback { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; max-width: calc(100% - 24px); padding: 7px 12px; border: 1px solid var(--line); border-radius: 20px; color: #78536e; background: #fffef7ee; font-size: 12px; white-space: nowrap; pointer-events: none; }
.preview-spinner { flex: 0 0 14px; height: 14px; border: 2px solid #eadfe7; border-top-color: #ac618d; border-radius: 50%; animation: preview-spin .8s linear infinite; }
.preview-fresh { animation: preview-appear .18s ease-out; }
@keyframes preview-spin { to { transform: rotate(360deg); } }
@keyframes preview-appear { from { opacity: .4; } to { opacity: 1; } }
#openPreview { display: block; width: 100%; padding: 0; border: 0; border-radius: 0; background: transparent; cursor: zoom-in; }
#openPreview:disabled { opacity: 1; cursor: default; }
#openPreview:focus-visible { outline: 2px solid #a95e89; outline-offset: 4px; }
#previewStage { position: relative; display: block; height: min(72vh, 660px); overflow: hidden; padding: 0; border: 0; border-radius: 0; background: #f5eff3; touch-action: none; transition: opacity .16s ease; }
#previewStage img { position: absolute; left: 50%; top: 50%; width: 100%; height: 100%; object-fit: contain; transform: translate(-50%, -50%); border: 0; border-radius: 0; user-select: none; -webkit-touch-callout: none; }
#previewStage img[data-original] { -webkit-touch-callout: default; user-select: auto; }
.preview-hint { margin: 0; padding: 6px 0; text-align: center; font-size: 11px; color: var(--muted); background: #fcf9fb; }
.save-bar { display: flex; justify-content: center; gap: 8px; margin-top: 18px; }
.save-bar button { flex: 0 1 124px; min-width: 0; height: 40px; padding: 8px 12px; border-radius: 10px; font-size: 13px; font-weight: 500; line-height: 1.35; white-space: nowrap; }
.save-bar .primary { background: #ac618d; }
#previewResize { display: none; }
#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; min-width: 0; overflow-wrap: anywhere; font-size: 12px; }
.image-viewer { width: 100%; max-width: 100%; height: 100vh; height: 100dvh; max-height: 100%; margin: 0; padding: 0; border: 0; border-radius: 0; outline: none; color: #f7f0f6; background: #211d24; overflow: hidden; touch-action: auto; }
.image-viewer::backdrop { background: #211d24; }
body:has(.image-viewer[open]) { overflow: hidden; }
#saveImage { display: block; width: 100%; height: 100%; object-fit: contain; -webkit-touch-callout: default; user-select: auto; touch-action: auto; }
#saveImage[data-preview] { -webkit-touch-callout: none; }
.viewer-feedback { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 12px; pointer-events: none; }
#saveMessage { margin: 0; font-size: 13px; }
#retryImage { min-height: 44px; color: #f7f0f6; background: #39313c; border-color: #67566a; pointer-events: auto; }
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) {
  body { padding-bottom: calc(58px + env(safe-area-inset-bottom, 0px)); }
  .save-bar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 3; margin: 0; padding: 6px 12px calc(6px + env(safe-area-inset-bottom, 0px)); background: #fcf9fb; border-top: 1px solid var(--line); }
  .save-bar button { flex-basis: 112px; height: 36px; padding: 6px 10px; }
  body.keyboard-open .save-bar { display: none; }
  .workspace { grid-template-columns: minmax(0, 1fr); gap: 14px; margin-inline: -14px; }
  .preview-panel { grid-row: 1; position: sticky; top: 0; z-index: 2; margin: 0; width: 100%; padding: 0; border: 0; border-radius: 0; box-shadow: none; }
  .controls { grid-row: 2; margin-inline: 14px; padding: 16px; border-radius: 20px; }
  .controls button { scroll-margin-top: calc(var(--mobile-preview-height, 420px) + 60px); scroll-margin-bottom: calc(58px + env(safe-area-inset-bottom, 0px)); }
  .controls textarea, .controls input, .controls select { scroll-margin-top: calc(var(--mobile-preview-height, 420px) + 60px); }
  .intro { margin-bottom: 14px; }
  .intro h1 { font-size: 20px; margin: 0; }
  .intro h1 br { display: none; }
  .intro p, .intro .eyebrow { display: none; }
  #previewStage { height: var(--mobile-preview-height, clamp(220px, 50dvh, 560px)); }
  #previewResize { display: flex; height: 28px; justify-content: center; align-items: center; background: #fcf9fb; cursor: ns-resize; touch-action: none; user-select: none; }
  #previewResize span { width: 40px; height: 4px; border-radius: 4px; background: #c8b4c2; }
  #previewResize:focus-visible { outline: 2px solid #a95e89; outline-offset: -3px; }
  #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: 18px; }
}

@media (max-width: 850px) {
  #openPreview:focus-visible { outline: none; }
}

@media (prefers-reduced-motion: reduce) {
  .preview-spinner, .preview-fresh { animation: none; }
  #previewStage { transition: none; }
}


/* Language controls and variable-length translations fit without clipping. */
header { gap: 18px; }
.brand { flex-shrink: 0; }
.brand span, label small { margin-left: 0; margin-inline-start: 5px; }
.brand span { margin-inline-start: 18px; }
.tab, .preset-heading, label, .hint, .preview-hint, footer { overflow-wrap: anywhere; }
.tab { min-width: 0; padding-inline: 8px; }
.save-bar button { min-height: 40px; height: auto; white-space: normal; overflow-wrap: anywhere; }
.preview-feedback { white-space: normal; text-align: center; }
footer .footer-heading { float: none; color: inherit; font-size: 12px; }
[dir=rtl] output { float: left; }
[dir=rtl] #footerPrivacy { float: left; }
[dir=rtl] .eyebrow { letter-spacing: normal; }
input[dir=auto], textarea[dir=auto] { text-align: start; }
@media (max-width: 850px) {
 .brand { font-size: 25px; }
 .save-bar button { min-height: 36px; max-width: 46%; }
 [dir=rtl] #footerPrivacy { float: none; }
}
