:root {
  color-scheme: dark;
  --ink: #0c0e0f;
  --surface: #121617;
  --surface-raised: #181d1e;
  --surface-hover: #1d2425;
  --line: #2b3334;
  --line-soft: #202728;
  --text: #edf1ec;
  --muted: #87918d;
  --accent: #d9ee69;
  --accent-ink: #171b08;
  --danger: #ff8c76;
  --warm: #f3a95f;
  --shadow: 0 16px 44px rgb(0 0 0 / 28%);
  font-family: "Manrope", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  min-width: 1180px;
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background: var(--ink);
}

button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: 344px minmax(590px, 1fr) 324px;
  gap: 12px;
  min-height: 100dvh;
  padding: 12px;
}

.control-panel, .canvas-panel, .history-panel {
  min-height: 0;
  border: 1px solid var(--line);
  background: rgb(18 22 23 / 92%);
  box-shadow: var(--shadow);
}

.control-panel {
  display: flex;
  flex-direction: column;
  padding: 24px;
}

.brand-row, .canvas-header, .history-header, .section-heading, .prompt-foot,
.result-meta, .dialog-heading, .dialog-actions, .connection-status, .history-item {
  display: flex;
  align-items: center;
}

.brand-row { gap: 12px; margin-bottom: 24px; }
.brand-mark {
  display: grid;
  grid-template-columns: repeat(3, 5px);
  gap: 3px;
  width: 36px;
  height: 36px;
  padding: 7px;
  border: 1px solid #596463;
  background: #202727;
}
.brand-mark span { background: var(--accent); }
.brand-mark span:nth-child(2) { align-self: center; height: 12px; }
.brand-mark span:nth-child(3) { align-self: end; height: 7px; }
.brand-kicker, .eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font: 500 10px/1 "DM Mono", monospace;
}
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 21px; line-height: 1; }
h2 { margin: 0; font-size: 18px; }

.connection-status {
  width: 100%;
  gap: 9px;
  padding: 12px 13px;
  margin-bottom: 22px;
  border: 1px solid var(--line);
  color: var(--muted);
  text-align: left;
  background: transparent;
}
.connection-status i { margin-left: auto; width: 16px; }
.status-dot { width: 8px; height: 8px; background: var(--muted); border-radius: 50%; }
.connection-status.is-connected { color: var(--text); border-color: #536253; }
.connection-status.is-connected .status-dot { background: var(--accent); }

.form-section { padding: 18px 0; border-top: 1px solid var(--line-soft); }
.section-heading { justify-content: space-between; margin-bottom: 11px; color: var(--muted); font-size: 12px; }
.section-heading label { color: var(--text); }
textarea, input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0;
  color: var(--text);
  background: #111516;
}
textarea { min-height: 128px; padding: 13px; resize: vertical; line-height: 1.55; }
textarea::placeholder, input::placeholder { color: #68716e; }
.prompt-foot { justify-content: space-between; margin-top: 8px; }
.mono { font-family: "DM Mono", monospace; font-size: 11px; }
.muted { color: var(--muted); }
.text-button, .icon-button, .secondary-button, .primary-button {
  border: 0;
  color: inherit;
  background: transparent;
}
.text-button { color: var(--accent); font-size: 11px; }
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
}
.icon-button:hover, .secondary-button:hover { background: var(--surface-hover); }
.icon-button i { width: 16px; height: 16px; }
.icon-button.subtle { width: 26px; height: 26px; border-color: transparent; color: var(--muted); }

.reference-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.reference-add, .reference-thumb {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 78px;
  overflow: hidden;
  border: 1px dashed #4b5655;
  color: var(--muted);
  background: #111516;
}
.reference-grid:not(.has-references) .reference-add { grid-column: 1 / -1; min-height: 104px; }
.reference-add { gap: 6px; padding: 8px; cursor: pointer; font-size: 11px; text-align: center; }
.reference-add i { width: 22px; }
.reference-thumb img { width: 100%; height: 78px; object-fit: cover; }
.reference-thumb button {
  position: absolute;
  top: 3px;
  right: 3px;
  display: grid;
  place-items: center;
  width: 19px;
  height: 19px;
  border: 0;
  color: var(--text);
  background: rgb(12 14 15 / 80%);
}

.controls-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 12px; }
.controls-grid label, #settings-form label { display: grid; gap: 7px; color: var(--muted); font-size: 11px; }
input { height: 40px; padding: 0 11px; }
.select-control { position: relative; width: 100%; }
.native-select.is-enhanced {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}
.select-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 40px;
  padding: 0 11px;
  border: 1px solid var(--line);
  color: var(--text);
  text-align: left;
  background: #111516;
}
.select-trigger:hover, .select-control.is-open .select-trigger { border-color: #68746e; background: #151a1a; }
.select-trigger i { width: 16px; color: var(--muted); transition: transform 160ms ease-out; }
.select-control.is-open .select-trigger i { transform: rotate(180deg); color: var(--accent); }
.select-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.select-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  right: 0;
  left: 0;
  display: none;
  max-height: 292px;
  padding: 5px;
  overflow: auto;
  border: 1px solid #58625d;
  box-shadow: 0 18px 34px rgb(0 0 0 / 38%);
  background: #151a1a;
}
.select-control.is-open .select-menu { display: grid; gap: 2px; }
.select-option {
  width: 100%;
  min-height: 34px;
  padding: 7px 9px;
  border: 0;
  color: #d9dfda;
  text-align: left;
  background: transparent;
}
.select-option:hover, .select-option:focus-visible { color: var(--accent-ink); outline: 0; background: var(--accent); }
.select-option.is-selected { color: var(--accent); background: #252c1b; }
.select-option.is-selected::before { content: "✓"; display: inline-block; width: 17px; color: var(--accent); }
.field-note { min-height: 16px; margin: 9px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.custom-size {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18px minmax(0, 1fr);
  gap: 7px;
  align-items: end;
  margin-top: 10px;
}
.custom-size label { display: grid; gap: 6px; color: var(--muted); font-size: 10px; }
.size-divider { display: grid; place-items: center; height: 39px; color: var(--muted); font-family: "DM Mono", monospace; }
.compatibility-control {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 0;
  border-top: 1px solid var(--line-soft);
  cursor: pointer;
}
.compatibility-control + .compatibility-control { padding-top: 0; border-top: 0; }
.compatibility-control input {
  width: 15px;
  height: 15px;
  margin: 2px 0 0;
  accent-color: var(--accent);
}
.compatibility-control span { display: grid; gap: 3px; }
.compatibility-control strong { color: var(--text); font-size: 12px; }
.compatibility-control small { color: var(--muted); font-size: 11px; line-height: 1.45; }

.generate-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  min-height: 48px;
  margin-top: 9px;
  border: 0;
  color: var(--accent-ink);
  font-weight: 800;
  background: var(--accent);
}
.generate-button:hover { background: #e6fa79; }
.generate-button:disabled { cursor: wait; color: #646a41; background: #a2ad65; }
.generate-button i { width: 17px; }
kbd { margin-left: auto; padding: 2px 5px; color: #68712f; font: 10px "DM Mono", monospace; border: 1px solid #a9ba4f; }
.form-error, .dialog-error { min-height: 17px; margin: 9px 0 0; color: var(--danger); font-size: 11px; }
.request-diagnostics {
  margin-top: 10px;
  border: 1px solid #5a3c35;
  color: #d7c2b9;
  background: #1b1716;
}
.request-diagnostics summary { padding: 9px 10px; color: var(--warm); font-size: 11px; cursor: pointer; }
.request-diagnostics pre {
  max-height: 180px;
  margin: 0;
  padding: 0 10px 10px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #c6b3ab;
  font: 10px/1.55 "DM Mono", monospace;
}
.privacy-note { display: flex; gap: 8px; align-items: center; margin-top: auto; padding-top: 20px; color: var(--muted); font-size: 10px; }
.privacy-note i { width: 15px; color: var(--accent); }

.canvas-panel { display: flex; flex-direction: column; padding: 20px; }
.canvas-header, .history-header { justify-content: space-between; padding-bottom: 17px; border-bottom: 1px solid var(--line-soft); }
.canvas-actions { gap: 7px; }
.empty-stage, .loading-stage, .result-stage {
  flex: 1;
  min-height: 0;
  margin-top: 20px;
  border: 1px dashed #394240;
}
.empty-stage, .loading-stage {
  display: grid;
  place-content: center;
  justify-items: center;
  padding: 30px;
  text-align: center;
}
.stage-symbol {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-bottom: 15px;
  border: 1px solid #4a5854;
  color: var(--accent);
  background: #1b2221;
}
.stage-symbol i { width: 24px; height: 24px; }
.empty-stage h3, .loading-stage h3 { margin-bottom: 7px; font-size: 18px; }
.empty-stage p { max-width: 250px; margin-bottom: 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.loading-track { width: 190px; height: 5px; overflow: hidden; background: #28302e; }
.loading-track span { display: block; width: 45%; height: 100%; background: var(--accent); animation: slide 1.1s ease-in-out infinite alternate; }
@keyframes slide { to { transform: translateX(120px); } }
.loading-stage .mono { margin: 18px 0 7px; color: var(--accent); }

.result-stage { position: relative; display: grid; place-items: center; overflow: hidden; background: #0b0d0e; }
.result-stage img { display: block; max-width: 100%; max-height: calc(100dvh - 105px); object-fit: contain; }
.result-meta {
  position: absolute;
  right: 10px;
  bottom: 10px;
  gap: 8px;
  padding: 8px 9px;
  color: #c4ccc7;
  font-size: 10px;
  background: rgb(12 14 15 / 86%);
}

.history-panel { display: flex; flex-direction: column; padding: 20px; }
.history-list { display: grid; gap: 9px; padding-top: 16px; overflow: auto; }
.history-empty { padding: 30px 8px; color: var(--muted); font-size: 12px; line-height: 1.6; text-align: center; }
.history-item { gap: 9px; min-width: 0; padding: 7px; border: 1px solid var(--line-soft); background: #141819; }
.history-item:hover { border-color: #495451; }
.history-preview { flex: 0 0 54px; width: 54px; height: 54px; padding: 0; overflow: hidden; border: 0; background: #262d2d; }
.history-preview img { width: 100%; height: 100%; object-fit: cover; }
.history-copy { min-width: 0; flex: 1; }
.history-copy p { display: -webkit-box; margin: 0 0 6px; overflow: hidden; color: #dfe5df; font-size: 10px; line-height: 1.35; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.history-copy span { color: var(--muted); }

dialog { width: min(450px, calc(100vw - 32px)); padding: 0; border: 1px solid #495552; color: var(--text); background: #141919; box-shadow: var(--shadow); }
dialog::backdrop { background: rgb(0 0 0 / 65%); }
.settings-card { display: grid; gap: 16px; padding: 22px; }
.secret-field { display: flex; border: 1px solid var(--line); background: #111516; }
.secret-field input { border: 0; }
.dialog-actions { justify-content: flex-end; gap: 8px; padding-top: 5px; }
.secondary-button, .primary-button { min-height: 36px; padding: 0 14px; border: 1px solid var(--line); font-size: 12px; }
.primary-button { border-color: var(--accent); color: var(--accent-ink); font-weight: 800; background: var(--accent); }
.settings-hint { margin: -4px 0 0; color: var(--muted); font-size: 10px; line-height: 1.6; }
.settings-hint code { color: var(--accent); font-family: "DM Mono", monospace; }

@media (max-width: 1240px) {
  body { min-width: 0; }
  .app-shell { grid-template-columns: 306px minmax(460px, 1fr); }
  .history-panel { grid-column: 1 / -1; max-height: 240px; }
  .history-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .app-shell { display: flex; flex-direction: column; min-height: 100dvh; padding: 9px; }
  .control-panel { order: 2; }
  .canvas-panel { order: 1; min-height: 62dvh; }
  .history-panel { order: 3; }
  .result-stage img { max-height: 55dvh; }
  .history-list { grid-template-columns: 1fr; max-height: 330px; }
  .controls-grid { gap: 9px; }
  .reference-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .loading-track span { animation: none; transform: translateX(80px); }
}
