/* Background Maker layout */
.background-layout .panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.background-layout .panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
}

.background-layout .panel-head h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  font-family: var(--font-display);
  letter-spacing: 0.01em;
}

.background-layout .panel-hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
  font-family: var(--font-ui);
}

.background-layout {
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  grid-template-rows: minmax(0, 1fr);
  gap: 12px;
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  padding: 12px;
  background: var(--navy);
  max-height: none;
  overflow: hidden;
}

.background-presets {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.preset-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.preset-btn:hover {
  border-color: var(--accent);
  background: rgba(217, 70, 168, 0.08);
}

.preset-btn.is-active {
  border-color: var(--accent);
  background: rgba(217, 70, 168, 0.14);
  box-shadow: 0 0 0 1px var(--accent);
}

.preset-btn .preset-emoji {
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
}

.background-controls {
  padding: 12px 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  max-height: 42%;
}

.background-controls label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

.background-controls input[type="color"] {
  width: 100%;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
}

.background-controls input[type="range"],
.background-controls select {
  width: 100%;
}

.color-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.color-field {
  display: flex;
  align-items: center;
  gap: 6px;
}

.color-field input[type="color"] {
  width: 40px;
  flex: 0 0 auto;
}

.hex-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.2);
  color: var(--text, #f5f0e6);
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.hex-input:focus {
  outline: none;
  border-color: var(--pink, #e8748a);
}

.hex-input.invalid {
  border-color: #c0392b;
}

.bg-preview-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  min-height: 0;
  overflow: auto;
}

.bg-preview-wrap {
  position: relative;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 4px;
  line-height: 0;
}

#bgPreviewCanvas {
  display: block;
  max-width: min(100%, 520px);
  max-height: min(60vh, 520px);
  width: auto;
  height: auto;
}

.bg-preview-label {
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
}

.bg-repeat-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#bgRepeatPreview {
  flex: 1;
  min-height: 200px;
  background-repeat: repeat;
  background-position: center;
  margin: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.bg-repeat-controls {
  padding: 0 14px 14px;
}

.bg-repeat-controls label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.bg-repeat-controls input[type="range"] {
  flex: 1;
}

.bg-recipe-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  background: rgba(217, 70, 168, 0.15);
  border: 1px solid rgba(217, 70, 168, 0.35);
  color: var(--text);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bg-recipe-badge.hidden { display: none !important; }

.hidden { display: none !important; }

@media (min-width: 641px) and (max-width: 960px) {
  .background-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    overflow-y: auto;
  }

  .background-presets {
    flex-direction: row;
    flex-wrap: wrap;
    max-height: 140px;
  }

  .preset-btn {
    width: auto;
    flex: 1 1 140px;
  }
}
