:root {
  color-scheme: light dark;
  --bg: #1c1e26;
  --panel: #262933;
  --panel-alt: #2f3340;
  --text: #eceef2;
  --text-dim: #9aa0ad;
  --accent: #6aa9ff;
  --border: #3a3e4c;
}

* { box-sizing: border-box; }

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

header {
  padding: 1.25rem 1.5rem 0.5rem;
}

h1 {
  margin: 0;
  font-size: 1.4rem;
}

.subtitle {
  margin: 0.25rem 0 0;
  color: var(--text-dim);
  font-size: 0.9rem;
}

main {
  display: flex;
  gap: 1rem;
  padding: 1rem 1.5rem;
  align-items: flex-start;
}

#class-panel {
  flex: 0 0 240px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  max-height: 75vh;
  display: flex;
  flex-direction: column;
}

#search {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

#class-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

#class-list li {
  padding: 0.4rem 0.5rem;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.9rem;
}

#class-list li:hover {
  background: var(--panel-alt);
}

#class-list li.selected {
  background: var(--accent);
  color: #0b1220;
  font-weight: 600;
}

#editor-panel {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  min-height: 400px;
}

#empty-state {
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 350px;
  text-align: center;
}

#empty-state[hidden],
#editor[hidden] {
  display: none;
}

#editor-title {
  margin: 0 0 1rem;
  font-size: 1.15rem;
}

.preview-wrap {
  display: flex;
  justify-content: center;
  padding: 1rem;
  background: repeating-conic-gradient(#3a3e4c 0% 25%, #2a2d38 0% 50%) 50% / 16px 16px;
  border-radius: 8px;
  margin-bottom: 1rem;
}

#preview {
  image-rendering: pixelated;
  cursor: crosshair;
}

#active-color-editor {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.active-color-label {
  font-size: 0.8rem;
  color: var(--text-dim);
  white-space: nowrap;
}

#active-color-hex {
  width: 5.5rem;
  padding: 0.3rem 0.5rem;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
}

#active-color-editor label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--text-dim);
}

#active-color-editor input[type="range"] {
  width: 90px;
}

#active-color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 2px solid var(--border);
  margin-left: auto;
}

#swatches {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.swatch input[type="color"] {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: none;
  cursor: pointer;
}

.swatch input[type="color"].active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}

.swatch span {
  font-size: 0.65rem;
  color: var(--text-dim);
}

.base-palette-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.base-palette-row label {
  font-size: 0.8rem;
  color: var(--text-dim);
  white-space: nowrap;
}

#base-palette-select {
  flex: 0 1 auto;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-size: 0.85rem;
}

.actions {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

button {
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
}

button:hover {
  border-color: var(--accent);
}

#download-btn {
  background: var(--accent);
  color: #0b1220;
  border-color: var(--accent);
  font-weight: 600;
}

.io-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.export-box,
.import-box {
  flex: 1 1 260px;
}

.export-box label,
.import-box label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 0.35rem;
}

.hex-row {
  display: flex;
  gap: 0.5rem;
}

#hex-output,
#import-input {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
}

#import-status {
  margin: 0.4rem 0 0;
  font-size: 0.75rem;
}

#import-status.success {
  color: #5fd888;
}

#import-status.error {
  color: #ff8a8a;
}

footer {
  padding: 0.5rem 1.5rem 1.5rem;
  color: var(--text-dim);
  font-size: 0.8rem;
  max-width: 60rem;
}

@media (max-width: 700px) {
  main { flex-direction: column; }
  #class-panel { flex: 1 1 auto; width: 100%; max-height: 40vh; }
}
