:root {
  --bg: #f4f3f0;
  --panel: #ffffff;
  --ink: #14130f;
  --ink-soft: #5c5a53;
  --line: #e0ddd5;
  --accent: #14130f;
  --accent-contrast: #ffffff;
  --mono: "SFMono-Regular", "JetBrains Mono", "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
}

.app-header {
  padding: 28px 32px 8px;
}

.app-header h1 {
  margin: 0;
  font-family: var(--mono);
  font-size: 22px;
  letter-spacing: -0.02em;
  font-weight: 600;
}

.app-header h1 span {
  color: var(--ink-soft);
  font-weight: 400;
}

.subtitle {
  margin: 6px 0 0;
  color: var(--ink-soft);
  font-size: 14px;
}

.layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  padding: 20px 32px 40px;
  align-items: start;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px;
}

.panel h2 {
  font-family: var(--mono);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 12px;
  color: var(--ink-soft);
}

.block {
  margin-bottom: 26px;
}
.block:last-child {
  margin-bottom: 0;
}

.hint {
  font-size: 12px;
  color: var(--ink-soft);
  margin: 4px 0 10px;
  line-height: 1.4;
}

/* Dropzone */

.dropzone {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  border: 1.5px dashed var(--line);
  border-radius: 8px;
  padding: 22px 12px;
  cursor: pointer;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.5;
  transition: border-color 0.15s ease, background 0.15s ease;
  min-height: 96px;
  position: relative;
  overflow: hidden;
}

.dropzone:hover {
  border-color: var(--ink);
  background: #fafaf8;
}

.dropzone.dragover {
  border-color: var(--accent);
  background: #eeeee9;
}

.dropzone small {
  color: #a3a096;
}

.dropzone-small {
  min-height: 52px;
  padding: 12px;
  font-size: 12px;
}

.dropzone-thumb {
  max-width: 100%;
  max-height: 140px;
  border-radius: 4px;
  object-fit: contain;
}

.hidden {
  display: none !important;
}

/* Icon grid */

.icon-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}

.icon-slot {
  position: relative;
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
}

.icon-slot:hover {
  border-color: var(--ink);
}

.icon-slot img {
  width: 70%;
  height: 70%;
  object-fit: contain;
}

.icon-slot input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.icon-slot .slot-index {
  position: absolute;
  top: 2px;
  left: 4px;
  font-family: var(--mono);
  font-size: 9px;
  color: #b8b5aa;
}

.icon-slot-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  padding: 0;
  border: none;
  border-radius: 3px;
  background: rgba(20, 19, 15, 0.75);
  color: #fff;
  font-size: 11px;
  line-height: 14px;
  text-align: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.icon-slot:hover .icon-slot-remove {
  opacity: 1;
}

.icon-add-tile {
  color: var(--ink-soft);
  font-size: 20px;
  font-weight: 300;
  border-style: dashed;
  background: transparent;
}

.icon-add-tile:hover {
  color: var(--ink);
  border-color: var(--ink);
}

.icon-sorted-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sorted-item {
  flex: 0 0 46px;
  width: 46px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.sorted-item .swatch {
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.sorted-item .swatch img {
  width: 72%;
  height: 72%;
  object-fit: contain;
}

/* Presets */

.preset-box {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.preset-box .field-row {
  margin-bottom: 8px;
}

.preset-box .field-row:last-of-type {
  margin-bottom: 0;
}

#preset-select {
  flex: 1;
  min-width: 0;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 12.5px;
}

#preset-name {
  flex: 1;
  min-width: 0;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 12.5px;
}

#preset-name::placeholder {
  color: #b8b5aa;
}

.btn-secondary {
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.btn-secondary:hover {
  border-color: var(--ink);
  background: #fafaf8;
}

.btn-secondary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-danger {
  color: #b3261e;
  border-color: #ecdad8;
}

.btn-danger:hover {
  border-color: #b3261e;
  background: #fdf4f3;
}

.preset-status {
  min-height: 14px;
  margin: 6px 0 0;
  font-size: 11.5px;
  color: var(--ink-soft);
  font-family: var(--mono);
}

.sorted-item .lum {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--ink-soft);
}

/* Fields */

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 13px;
  margin-bottom: 6px;
  color: var(--ink);
}

.field-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.field-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.field-value {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-soft);
  min-width: 52px;
  text-align: right;
}

.field-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.field-inline label {
  margin-bottom: 0;
}

.field-inline input[type="color"] {
  width: 36px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: none;
  cursor: pointer;
}

.field-inline input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Buttons */

.btn-primary {
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 7px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.btn-primary:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-primary:not(:disabled):hover {
  opacity: 0.85;
}

/* Preview */

.preview {
  min-height: 520px;
  display: flex;
  flex-direction: column;
}

.canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(45deg, #eae8e2 25%, transparent 25%),
    linear-gradient(-45deg, #eae8e2 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eae8e2 75%),
    linear-gradient(-45deg, transparent 75%, #eae8e2 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
  border-radius: 8px;
  min-height: 460px;
  position: relative;
}

#output-canvas {
  max-width: 100%;
  max-height: 70vh;
  border-radius: 4px;
}

.empty-state {
  position: absolute;
  color: var(--ink-soft);
  font-size: 13px;
}
