:root {
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #101318;
  color: #eef1f5;
  --panel: #181d24;
  --panel-soft: #202733;
  --line: #313947;
  --text-muted: #9aa5b5;
  --accent: #f2b84b;
  --accent-strong: #ffd37a;
  --danger: #d95d5d;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  min-width: 320px;
  min-height: 0;
  overflow: hidden;
  background: #101318;
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: clamp(220px, 22vw, 300px) minmax(0, 1fr) clamp(240px, 24vw, 340px);
  gap: 12px;
  width: 100%;
  height: 100dvh;
  max-width: 100%;
  padding: 12px;
  overflow: hidden;
}

.panel,
.canvas-panel {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 14px;
  overflow: auto;
}

.canvas-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 10px;
  overflow: hidden;
}

.brand-row,
.gallery-header,
.map-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.1;
}

h2 {
  font-size: 16px;
}

.control-group {
  display: grid;
  gap: 8px;
}

.group-label,
.field-label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  text-transform: uppercase;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #11161d;
}

.segment,
.button {
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  color: #eef1f5;
}

.segment {
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
}

.segment.is-active {
  background: var(--panel-soft);
  color: #ffffff;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 12px;
  font-weight: 700;
}

.button.primary {
  width: 100%;
  min-height: 44px;
  background: var(--accent);
  color: #17110a;
}

.button.secondary {
  background: var(--panel-soft);
  border: 1px solid var(--line);
}

.button.compact {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #dbe1ea;
  font-size: 13px;
  white-space: nowrap;
}

.toggle input {
  accent-color: var(--accent);
}

.palette-list {
  display: grid;
  gap: 6px;
}

.palette-row {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.swatch {
  width: 32px;
  height: 32px;
  border: 2px solid transparent;
  border-radius: 6px;
  cursor: pointer;
}

.swatch.is-active {
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 2px rgba(242, 184, 75, 0.28);
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #10151c;
  color: #eef1f5;
  outline: none;
}

input {
  min-height: 34px;
  padding: 0 10px;
}

textarea {
  min-height: 132px;
  resize: vertical;
  padding: 10px;
  line-height: 1.35;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(242, 184, 75, 0.18);
}

.reference-preview {
  display: grid;
  place-items: center;
  min-height: 120px;
  overflow: hidden;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #10151c;
  color: var(--text-muted);
  font-size: 13px;
}

.reference-preview img {
  display: block;
  width: 100%;
  height: 160px;
  object-fit: cover;
}

.map-toolbar {
  padding-bottom: 10px;
}

.map-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.status {
  min-width: 0;
  color: var(--text-muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status.error {
  color: var(--danger);
}

.status.good {
  color: #7ddc92;
}

.map-stage {
  position: relative;
  align-self: center;
  justify-self: center;
  width: min(100%, 1024px);
  height: auto;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid #40495a;
  border-radius: 8px;
  background: #0b0f14;
}

#map-canvas,
#render-image,
.render-empty {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#map-canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

#map-canvas.is-disabled {
  pointer-events: none;
}

#render-image {
  display: none;
  object-fit: contain;
}

#render-image.is-visible {
  display: block;
}

.render-empty {
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(11, 15, 20, 0.86);
  color: var(--text-muted);
  text-align: center;
}

.render-empty[hidden] {
  display: none;
}

.key-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.small-note {
  margin: 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.35;
}

.generation-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.generation-actions .button.secondary {
  min-width: 96px;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px;
  min-height: 110px;
}

.gallery-empty {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  min-height: 108px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

.gallery-card {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.gallery-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 8px;
  background: #10151c;
  cursor: pointer;
}

.gallery-thumb.is-active {
  border-color: var(--accent-strong);
}

.gallery-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px;
}

.download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  color: #eef1f5;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.delete-result {
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #25191b;
  color: #ffb5b5;
  cursor: pointer;
  font-size: 12px;
}

@media (max-width: 980px) {
  html,
  body {
    height: auto;
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(320px, 1fr) auto;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .controls-panel,
  .prompt-panel {
    overflow: visible;
  }

  .map-stage {
    width: min(100%, 1024px);
    min-width: 280px;
  }

  .palette-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 8px;
  }

  .palette-list {
    grid-template-columns: 1fr;
  }

  .brand-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .map-stage {
    width: 100%;
  }
}
