:root {
  color-scheme: light;
  --ink: #171715;
  --muted: #74746d;
  --line: #d9d9d2;
  --line-strong: #b7b7af;
  --paper: #ffffff;
  --ground: #f2f2ee;
  --soft: #e9e9e3;
  --accent: #e85f3d;
  --accent-dark: #c94023;
  --teal: #19766f;
  --danger: #bd352f;
  --radius: 6px;
  font-family: "Noto Sans SC", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--ground);
  color: var(--ink);
}

button, textarea, input { font: inherit; }
button { color: inherit; }
button:focus-visible, textarea:focus-visible, input:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(360px, 410px) minmax(0, 1fr);
  min-height: 100vh;
}

.control-panel {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--paper);
}

.brand-row {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  align-items: center;
  gap: 11px;
  min-height: 76px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  background: var(--ink);
  color: white;
  border-radius: 4px;
}
.brand-mark svg { width: 20px; }
.brand-row strong { display: block; font-size: 15px; letter-spacing: 0; }
.brand-row > div:nth-child(2) span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font: 500 9px/1.2 "DM Mono", monospace;
}

.api-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}
.api-state span { width: 7px; height: 7px; border-radius: 50%; background: #bbb; }
.api-state.ready span { background: var(--teal); box-shadow: 0 0 0 3px rgba(25, 118, 111, .12); }
.api-state.error span { background: var(--danger); }

.generator-form { padding: 0 22px 24px; }
.form-section { padding: 20px 0; border-bottom: 1px solid var(--line); }
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 20px;
  margin-bottom: 10px;
}
.section-heading label, .section-heading > span:first-child { font-size: 12px; font-weight: 700; }
.section-heading > span:last-child { color: var(--muted); font: 400 10px/1.2 "DM Mono", monospace; }

.prompt-box { position: relative; }
.prompt-box textarea {
  display: block;
  width: 100%;
  min-height: 148px;
  resize: vertical;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 13px 38px 13px 14px;
  background: #fbfbf8;
  color: var(--ink);
  line-height: 1.7;
}
.prompt-box textarea::placeholder { color: #aaa9a2; }
.prompt-clear { position: absolute; top: 8px; right: 8px; opacity: 0; }
.prompt-box:focus-within .prompt-clear, .prompt-box:hover .prompt-clear { opacity: 1; }

.icon-button {
  display: inline-grid;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper);
  cursor: pointer;
}
.icon-button:hover { border-color: var(--line-strong); background: var(--soft); }
.icon-button svg { width: 15px; height: 15px; }

.size-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}
.size-choice {
  display: grid;
  grid-template-columns: 24px 1fr;
  grid-template-rows: auto auto;
  column-gap: 8px;
  align-items: center;
  min-height: 52px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--paper);
  text-align: left;
  cursor: pointer;
}
.size-choice:hover { border-color: var(--line-strong); }
.size-choice.active { border-color: var(--ink); background: var(--ink); color: white; }
.size-choice strong { align-self: end; font: 500 11px/1.2 "DM Mono", monospace; }
.size-choice small { align-self: start; color: var(--muted); font-size: 9px; }
.size-choice.active small { color: #bdbdb8; }
.size-choice > svg { grid-row: 1 / 3; width: 20px; }
.ratio {
  grid-row: 1 / 3;
  display: block;
  justify-self: center;
  border: 1px solid currentColor;
  opacity: .75;
}
.ratio-square { width: 18px; height: 18px; }
.ratio-landscape { width: 23px; height: 16px; }
.ratio-portrait { width: 15px; height: 22px; }
.ratio-wide { width: 24px; height: 14px; }

.custom-size {
  display: grid;
  grid-template-columns: 1fr 32px 1fr;
  gap: 8px;
  align-items: end;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  background: #f7f7f3;
  border-radius: var(--radius);
}
.custom-size[hidden] { display: none; }
.custom-size label { color: var(--muted); font-size: 10px; }
.custom-size input {
  width: 100%;
  height: 32px;
  margin-top: 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 8px;
  background: var(--paper);
  font: 500 11px/1 "DM Mono", monospace;
}

.two-column-settings {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 104px;
  gap: 16px;
}
.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--soft);
}
.segmented button {
  min-width: 0;
  height: 30px;
  padding: 0 4px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  cursor: pointer;
}
.segmented button.active { background: var(--paper); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); font-weight: 700; }
.stepper {
  display: grid;
  grid-template-columns: 32px 1fr 32px;
  align-items: center;
}
.stepper output { text-align: center; font: 500 13px/1 "DM Mono", monospace; }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.toggle-row strong { display: block; font-size: 12px; }
.toggle-row > div span { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }
.switch { position: relative; display: inline-flex; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch > span { width: 38px; height: 22px; border-radius: 12px; background: #d2d2cc; transition: .2s; }
.switch > span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .24);
  transition: .2s;
}
.switch input:checked + span { background: var(--teal); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--teal); outline-offset: 2px; }

.upload-area { margin-top: 14px; }
.upload-area[hidden] { display: none; }
.upload-trigger {
  display: flex;
  width: 100%;
  min-height: 68px;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: #fafaf7;
  text-align: left;
  cursor: pointer;
}
.upload-trigger:hover, .upload-area.dragging .upload-trigger { border-color: var(--teal); background: #f1f8f7; }
.upload-trigger svg { width: 21px; color: var(--teal); }
.upload-trigger strong, .upload-trigger small { display: block; }
.upload-trigger strong { font-size: 11px; }
.upload-trigger small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.reference-list { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin-top: 8px; }
.reference-item { position: relative; aspect-ratio: 1; overflow: hidden; border: 1px solid var(--line); border-radius: 4px; background: var(--soft); }
.reference-item img { width: 100%; height: 100%; object-fit: cover; }
.reference-item button { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border: 0; background: rgba(17,17,15,.84); color: white; }

.generate-button {
  display: grid;
  grid-template-columns: 20px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 50px;
  margin-top: 20px;
  padding: 0 14px;
  border: 1px solid var(--accent-dark);
  border-radius: var(--radius);
  background: var(--accent);
  color: white;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--accent-dark);
}
.generate-button:hover { background: #ee6848; }
.generate-button:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--accent-dark); }
.generate-button:disabled { cursor: wait; opacity: .68; transform: none; box-shadow: none; }
.generate-button svg { width: 18px; }
.generate-button span { justify-self: start; font-size: 13px; font-weight: 700; }
.generate-button kbd { border: 1px solid rgba(255,255,255,.35); border-radius: 3px; padding: 3px 6px; font: 500 9px/1 "DM Mono", monospace; }
.form-error { margin: 12px 0 0; color: var(--danger); font-size: 11px; line-height: 1.5; }

.workspace { min-width: 0; min-height: 100vh; }
.workspace-header {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  min-height: 76px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 13px clamp(20px, 3vw, 42px);
  border-bottom: 1px solid var(--line);
  background: rgba(242, 242, 238, .94);
  backdrop-filter: blur(10px);
}
.eyebrow { color: var(--muted); font: 500 9px/1.2 "DM Mono", monospace; }
.workspace-header h1 { margin: 3px 0 0; font-size: 20px; letter-spacing: 0; }
.workspace-meta { display: flex; align-items: center; gap: 8px; }
.model-chip, .timer-chip {
  display: flex;
  height: 36px;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper);
}
.model-chip span { color: var(--muted); font: 500 8px/1 "DM Mono", monospace; }
.model-chip strong { font: 500 10px/1 "DM Mono", monospace; }
.timer-chip { color: var(--teal); font: 500 11px/1 "DM Mono", monospace; }
.timer-chip svg { width: 15px; }

.workspace-body { padding: 24px clamp(20px, 3vw, 42px) 44px; }
.status-strip {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(160px, 1fr);
  align-items: center;
  gap: 24px;
  margin-bottom: 20px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--teal);
  border-radius: 4px;
  background: var(--paper);
}
.status-strip[hidden] { display: none; }
.status-strip > div:first-child { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.status-strip strong { font-size: 11px; }
.status-strip span:not(.status-pulse) { color: var(--muted); font-size: 10px; }
.status-pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--teal); animation: pulse 1.4s infinite; }
.progress-track { height: 4px; overflow: hidden; border-radius: 3px; background: var(--soft); }
.progress-track span { display: block; width: 0; height: 100%; background: var(--teal); transition: width .25s ease; }

.empty-state { display: grid; min-height: calc(100vh - 150px); place-items: center; align-content: center; text-align: center; }
.empty-state[hidden] { display: none; }
.empty-visual {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 64px);
  gap: 7px;
  padding: 28px;
  margin-bottom: 20px;
}
.canvas-tile { display: grid; height: 82px; place-items: center; border: 1px solid var(--line-strong); background: var(--paper); box-shadow: 4px 4px 0 var(--line); }
.canvas-tile svg { width: 23px; color: var(--muted); }
.tile-a { transform: translateY(10px); background: #f4d8a6; }
.tile-b { background: #b8d5d2; }
.tile-c { transform: translateY(10px); background: #d9d4e8; }
.focus-corner { position: absolute; width: 18px; height: 18px; border-color: var(--accent); border-style: solid; }
.corner-one { top: 8px; left: 8px; border-width: 2px 0 0 2px; }
.corner-two { right: 8px; bottom: 8px; border-width: 0 2px 2px 0; }
.empty-state h2 { margin: 0; font-size: 16px; }
.empty-state p { max-width: 390px; margin: 8px 0 0; color: var(--muted); font-size: 11px; line-height: 1.7; }

.result-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.result-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
}
.result-media { position: relative; display: grid; aspect-ratio: var(--result-ratio, 1); overflow: hidden; place-items: center; background: #e8e8e2; }
.result-media img { width: 100%; height: 100%; object-fit: contain; background: #dddcd5; cursor: zoom-in; }
.result-index {
  position: absolute;
  top: 10px;
  left: 10px;
  display: grid;
  min-width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 3px;
  background: rgba(17,17,15,.88);
  color: white;
  font: 500 10px/1 "DM Mono", monospace;
}
.result-info { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; min-height: 66px; padding: 11px 12px; border-top: 1px solid var(--line); }
.result-meta { display: flex; flex-wrap: wrap; gap: 5px; }
.meta-tag { padding: 4px 6px; border: 1px solid var(--line); border-radius: 3px; color: var(--muted); font: 500 8px/1 "DM Mono", monospace; }
.time-tag { color: var(--teal); border-color: rgba(25,118,111,.35); background: rgba(25,118,111,.06); }
.result-actions { display: flex; gap: 5px; }
.result-placeholder .result-media::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 20%, rgba(255,255,255,.55) 40%, transparent 60%);
  animation: shimmer 1.4s infinite linear;
}
.placeholder-content { position: relative; z-index: 1; display: grid; place-items: center; gap: 10px; color: var(--muted); font: 500 10px/1 "DM Mono", monospace; }
.placeholder-content svg { width: 24px; animation: spin 1.8s linear infinite; }
.result-error .result-media { background: #f2e7e5; color: var(--danger); padding: 24px; text-align: center; }
.result-error .result-media svg { width: 26px; margin-bottom: 10px; }
.result-error .result-media p { max-width: 330px; margin: 0; font-size: 11px; line-height: 1.6; }

.image-dialog {
  width: min(92vw, 1200px);
  max-width: none;
  max-height: 92vh;
  padding: 0;
  border: 1px solid #4c4c49;
  border-radius: 6px;
  background: #1b1b19;
  color: white;
}
.image-dialog::backdrop { background: rgba(11,11,10,.78); backdrop-filter: blur(5px); }
.image-dialog img { display: block; width: 100%; max-height: calc(92vh - 48px); object-fit: contain; }
.dialog-close { position: absolute; z-index: 1; top: 10px; right: 10px; border-color: rgba(255,255,255,.35); background: rgba(0,0,0,.6); color: white; }
.dialog-caption { min-height: 48px; padding: 13px 16px; color: #c7c7c1; font: 400 10px/1.5 "DM Mono", monospace; }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .32; } }
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 1320px) {
  .result-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .app-shell { display: block; }
  .control-panel { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .workspace-header { position: static; }
  .empty-state { min-height: 460px; }
}

@media (max-width: 560px) {
  .brand-row, .generator-form { padding-left: 16px; padding-right: 16px; }
  .size-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two-column-settings { grid-template-columns: 1fr; }
  .workspace-header { align-items: flex-start; padding: 15px 16px; }
  .model-chip span { display: none; }
  .workspace-body { padding: 16px; }
  .status-strip { grid-template-columns: 1fr; gap: 10px; }
  .result-grid { grid-template-columns: 1fr; }
  .empty-visual { grid-template-columns: repeat(3, 52px); }
  .workspace-meta { flex-wrap: wrap; justify-content: flex-end; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
