:root {
  --bg: #f4f4f1;
  --panel: #ffffff;
  --line: #d9d9d2;
  --text: #222;
  --muted: #666;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.08);
  --tile-size: 28px;
  --gap: 2px;
  --index-size: 28px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.wrap {
  max-width: 1700px;
  margin: 0 auto;
  padding: 24px;
}

.layout {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 20px;
  align-items: start;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.side {
  padding: 18px;
  position: sticky;
  top: 18px;
}

.main {
  display: grid;
  gap: 20px;
}

h1 {
  margin: 0 0 8px 0;
  font-size: 1.55rem;
  line-height: 1.1;
}

h2 {
  margin: 0 0 12px 0;
  font-size: 1.05rem;
}

.sub {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

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

.accordion-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.accordion-toggle::after {
  content: "+";
  font-size: 1rem;
  color: var(--muted);
}

.accordion.is-open .accordion-toggle::after {
  content: "-";
}

.accordion-panel {
  margin-top: 12px;
}

.accordion:not(.is-open) .accordion-panel {
  display: none;
}

.control {
  margin-bottom: 14px;
}

label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 0.94rem;
}

.inline {
  display: grid;
  grid-template-columns: 1fr 78px;
  gap: 10px;
  align-items: center;
}

.inline-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

input[type="range"],
input[type="number"],
button,
select {
  width: 100%;
  font: inherit;
}

input[type="range"] {
  accent-color: #444;
}

input[type="number"],
button,
select {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

button {
  cursor: pointer;
  background: #fafaf8;
}

.btnrow {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.checks {
  display: grid;
  gap: 10px;
}

.check {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-weight: 400;
}

.panel {
  padding: 18px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.tab-btn {
  width: auto;
  padding: 9px 14px;
  border-radius: 999px;
}

.tab-btn.is-active {
  background: #e9e1c6;
  border-color: #c7b484;
}

.tab-panel {
  display: block;
}

.stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}

.stat {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fafaf8;
  padding: 12px;
}

.stat strong {
  display: block;
  font-size: 1.12rem;
  margin-bottom: 4px;
}

.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.full-width {
  grid-column: 1 / -1;
}

[hidden] {
  display: none !important;
}

.board-wrap,
.list-wrap,
.preview-wrap {
  border: 1px solid var(--line);
  background: #fcfcfa;
  border-radius: 12px;
  padding: 14px;
  overflow: auto;
}

.preview-wrap {
  min-height: 240px;
  display: grid;
  place-items: center;
}

.preview-wrap img {
  max-width: 100%;
  max-height: 420px;
  display: block;
  border-radius: 10px;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
  max-width: 280px;
}

.board {
  display: grid;
  grid-template-columns: var(--index-size) auto;
  grid-template-rows: var(--index-size) auto;
  gap: var(--gap);
  align-items: start;
  justify-content: start;
}

.corner {
  width: var(--index-size);
  height: var(--index-size);
}

.col-headers {
  display: grid;
  gap: var(--gap);
  justify-content: start;
}

.row-headers {
  display: grid;
  gap: var(--gap);
  justify-content: start;
}

.header-cell {
  width: var(--index-size);
  height: var(--index-size);
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f2f2ee;
  color: #444;
  font-size: 0.8rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  user-select: none;
}

.grid {
  display: grid;
  gap: var(--gap);
  justify-content: start;
}

.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  display: grid;
  place-items: center;
  border: 1px solid rgba(0, 0, 0, 0.1);
  font-weight: 700;
  font-size: calc(var(--tile-size) * 0.23);
  user-select: none;
  cursor: pointer;
}

.tile.hide-labels {
  color: transparent !important;
}

.tile-dimmed {
  opacity: 0.18;
}

.legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
}

.legend-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fafaf8;
  padding: 10px;
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  text-align: left;
}

.legend-item-active {
  border-color: #a58c4b;
  background: #f4efe0;
}

.legend-swatch-btn {
  width: 48px;
  padding: 0;
  border: 0;
  background: transparent;
}

.legend-info {
  display: grid;
  gap: 4px;
}

.legend-hex-btn {
  width: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.legend-colour-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  opacity: 0;
  pointer-events: none;
}

.paint-palette {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(82px, 1fr));
  gap: 8px;
}

.paint-chip {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafaf8;
  display: grid;
  gap: 6px;
  justify-items: center;
  text-align: center;
}

.paint-chip.is-active {
  border-color: #a58c4b;
  background: #f4efe0;
}

.paint-chip .swatch {
  width: 100%;
  min-height: 36px;
}

.paint-selected {
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafaf8;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
  padding: 10px;
}

.swatch {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.14);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.small {
  color: var(--muted);
  font-size: 0.9rem;
}

.list-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.list-table th,
.list-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px 6px;
  text-align: left;
  vertical-align: top;
}

.mini {
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.16);
  vertical-align: middle;
  margin-right: 8px;
}

.footer-note {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.92rem;
}

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

  .side {
    position: static;
  }

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

  .two {
    grid-template-columns: 1fr;
  }

  .inline-2 {
    grid-template-columns: 1fr;
  }
}

/* ── UX Polish ───────────────────────────────────────────── */

/* Clickable accordion headers */
.accordion-toggle {
  cursor: pointer;
  transition: opacity 0.12s ease;
}
.accordion-toggle:hover {
  opacity: 0.72;
}

/* Action button hover feedback */
.btnrow button:hover,
.tab-btn:hover {
  background: #f0f0ec;
  border-color: #c0c0b8;
}

/* Paint palette chip hover */
.paint-chip:hover {
  background: #f0ede6;
  border-color: #c7b484;
}

/* Secondary / muted button (e.g. Reset) */
.btn-muted {
  color: var(--muted);
}
.btn-muted:hover {
  background: #f5f2f0;
  border-color: #c8c0b8;
  color: #555;
}

/* Legend swatch hover — signals clickability */
.legend-swatch-btn:hover .swatch {
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.16);
}

/* Legend hex button — signals it opens colour picker */
.legend-hex-btn:hover {
  color: var(--text);
  text-decoration: underline;
}
.legend-hex-btn::after {
  content: " ✎";
  font-size: 0.78em;
  opacity: 0.45;
}

/* Active tab weight */
.tab-btn.is-active {
  font-weight: 600;
}

/* Stat label hierarchy: muted label, prominent value */
.stat {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.3;
}
.stat strong {
  color: var(--text);
}

/* Paint mode — grid visual feedback */
body.paint-mode-active .board-wrap {
  border-color: #c9a840;
  box-shadow: 0 0 0 3px rgba(165, 140, 75, 0.15);
}
body.paint-mode-active .tile {
  cursor: crosshair;
}

/* Paint active badge in grid heading */
.paint-mode-indicator {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: #f4ede0;
  color: #a58c4b;
  border: 1px solid #dbc893;
  vertical-align: middle;
  margin-left: 8px;
}

/* File input styling */
input[type="file"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
  font-size: 0.9rem;
  color: var(--muted);
  background: #fafaf8;
}
input[type="file"]:hover {
  border-color: #c0c0b8;
  background: #f5f5f0;
}

/* Keyboard focus ring */
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid #c9a840;
  outline-offset: 2px;
}

/* Legend item transitions */
.legend-item,
.paint-chip,
.tab-btn {
  transition: background 0.1s ease, border-color 0.1s ease;
}

/* Sidebar description – slightly smaller */
.sub {
  font-size: 0.9rem;
}

@media (max-width: 680px) {
  .stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .wrap {
    padding: 14px;
  }
}
