:root {
  --bg: #eef2f6;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #58677a;
  --accent: #ff6a13;
  --line: #d8dde6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at top right, #ffffff 0%, #eef2f6 56%, #e8edf3 100%);
  color: var(--ink);
  font-family: 'Avenir Next', 'Trebuchet MS', 'Segoe UI', sans-serif;
}

.hero {
  padding: 1.25rem 1.5rem 0.75rem;
}

.hero h1 {
  margin: 0;
  font-size: 2rem;
  letter-spacing: 0.02em;
}

.hero p {
  margin: 0.4rem 0 0;
  color: var(--muted);
}

.layout {
  display: grid;
  gap: 1rem;
  padding: 0.75rem 1rem 1.25rem;
  grid-template-columns: 320px minmax(420px, 1fr) 320px;
  grid-template-areas:
    'controls grid palette'
    'exports grid counts';
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 10px 24px rgba(34, 48, 74, 0.08);
  padding: 0.85rem;
}

.controls {
  grid-area: controls;
}

.canvasPanel {
  grid-area: grid;
}

.palettePanel {
  grid-area: palette;
}

.exports {
  grid-area: exports;
}

.counts {
  grid-area: counts;
}

h2 {
  margin: 0 0 0.6rem;
  font-size: 1.1rem;
}

label {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.44rem 0.5rem;
  background: #fff;
}

button {
  border: 1px solid #d3d8e1;
  border-radius: 8px;
  background: linear-gradient(#fff, #f2f5f9);
  padding: 0.45rem 0.55rem;
  cursor: pointer;
}

button:hover {
  border-color: #b4becd;
}

.buttonRow {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.grid {
  display: grid;
  gap: 3px;
  justify-content: start;
  -webkit-user-select: none;
  user-select: none;
  border-radius: 6px;
  padding: 3px;
}

.cell {
  width: 24px;
  height: 24px;
  border: 1px solid #c7ccd6;
  background: #fff;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-weight: 700;
  color: #14181f;
}

.cell:hover {
  outline: 2px solid #9ab2d9;
}

.palette {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(94px, 1fr));
  gap: 0.4rem;
  max-height: 55vh;
  overflow: auto;
  padding-right: 2px;
}

.swatch {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 0.4rem;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.35rem;
  background: #fff;
  font-size: 0.75rem;
  text-align: left;
}

.swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 106, 19, 0.16);
}

.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.35);
}

.caption {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font-size: 0.86rem;
}

.status {
  min-height: 5.8rem;
  margin: 0.6rem 0 0;
  padding: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f9fc;
  white-space: pre-wrap;
}

.countsList {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.42rem;
  font-size: 0.9rem;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      'controls'
      'palette'
      'grid'
      'exports'
      'counts';
  }

  .palette {
    max-height: 280px;
  }
}

/* ---- Load a Kit gallery ---- */
.gallerySection {
  padding: 0 1rem 1.5rem;
}

.gallery {
  padding: 0.85rem 1rem 1rem;
}

.galleryHead {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.galleryHead h2 {
  margin: 0;
}

.muted {
  color: var(--muted);
  font-weight: 400;
  font-size: 0.85rem;
}

.galleryTools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

#gallerySearch {
  min-width: 220px;
}

.sizeFilter {
  display: inline-flex;
  gap: 2px;
  background: #eef2f7;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 2px;
}

.sizeFilter button {
  border: 0;
  background: transparent;
  border-radius: 7px;
  padding: 0.35rem 0.6rem;
  font-size: 0.82rem;
}

.sizeFilter button.active {
  background: var(--accent);
  color: #fff;
}

.galleryGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 0.7rem;
  max-height: 62vh;
  overflow: auto;
  padding: 2px;
}

.kitCard {
  display: grid;
  gap: 0.3rem;
  padding: 0.4rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  text-align: left;
}

.kitCard:hover {
  border-color: var(--accent);
  box-shadow: 0 6px 16px rgba(255, 106, 19, 0.14);
}

.kitThumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  image-rendering: pixelated;
  background: #000;
  display: block;
}

.kitCard .kitName {
  font-size: 0.76rem;
  font-weight: 700;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kitCard .kitMeta {
  font-size: 0.68rem;
  color: var(--muted);
}

.galleryEmpty {
  color: var(--muted);
  padding: 1rem;
}
