* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #121212;
  color: #E6E1E5;
}

.container {
  text-align: center;
  padding: 2rem;
  max-width: 700px;
  width: 100%;
}

h1 {
  font-size: 2rem;
  margin-bottom: 1.5rem;
  color: #D0BCFF;
}

form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

label {
  text-align: left;
  font-size: 0.85rem;
  color: #CAC4D0;
}

input[type="text"] {
  padding: 0.6rem 0.8rem;
  border: 1px solid #49454F;
  border-radius: 6px;
  background: #1e1e1e;
  color: #E6E1E5;
  font-size: 1rem;
  width: 100%;
}

input[type="text"]:focus {
  outline: none;
  border-color: #D0BCFF;
}

.char-count {
  font-size: 0.75rem;
  color: #938F99;
  text-align: right;
  margin-top: -0.5rem;
}

button, .btn {
  padding: 0.7rem;
  border: none;
  border-radius: 6px;
  background: #6750A4;
  color: #FFFFFF;
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 0.2s;
}

button:hover, .btn:hover { background: #7F67BE; }
button:disabled, .btn:disabled { background: #49454F; color: #938F99; cursor: not-allowed; }

.status {
  margin-top: 1rem;
  font-size: 0.9rem;
  min-height: 1.5rem;
}

.status.error { color: #F2B8B5; }
.status.success { color: #A8DAB5; }

/* --- Advanced Features (foldable) --- */
details.advanced {
  margin-top: 1.5rem;
  text-align: left;
}

details.advanced summary {
  cursor: pointer;
  font-size: 0.95rem;
  color: #CAC4D0;
  padding: 0.5rem 0;
  user-select: none;
  list-style: none;
}

details.advanced summary::-webkit-details-marker { display: none; }

details.advanced summary::before {
  content: "\25B6";
  display: inline-block;
  margin-right: 0.5rem;
  font-size: 0.7rem;
  transition: transform 0.2s;
}

details.advanced[open] summary::before {
  transform: rotate(90deg);
}

.advanced-body {
  margin-top: 0.75rem;
}

/* Mode toggle */
.mode-toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #49454F;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #E6E1E5;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
  background: #6750A4;
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
  background: #D0BCFF;
}

.mode-label {
  font-size: 0.85rem;
  color: #CAC4D0;
}

/* --- Bitmap Editor --- */
.bitmap-editor {
  display: none;
  flex-direction: column;
  gap: 0.75rem;
}

.bitmap-editor.active {
  display: flex;
}

.editor-layout {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

.grid-wrapper {
  flex-shrink: 0;
  border: 1px solid #49454F;
  border-radius: 4px;
  overflow: hidden;
  line-height: 0;
  cursor: crosshair;
}

.pixel-grid {
  display: grid;
  grid-template-columns: repeat(32, 14px);
  grid-template-rows: repeat(8, 14px);
  gap: 0;
}

.pixel {
  width: 14px;
  height: 14px;
  background: #000;
  border: 0.5px solid rgba(255,255,255,0.08);
}

.pixel:hover {
  outline: 1.5px solid rgba(208,188,255,0.5);
  outline-offset: -1px;
  z-index: 1;
  position: relative;
}

/* Sidebar: color picker + palette */
.color-sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 90px;
}

.current-color-preview {
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid #49454F;
  border-radius: 6px;
}

.color-sidebar label {
  font-size: 0.75rem;
  color: #938F99;
  margin-bottom: -0.4rem;
}

input[type="color"] {
  width: 100%;
  height: 32px;
  border: 1px solid #49454F;
  border-radius: 4px;
  background: #1e1e1e;
  cursor: pointer;
  padding: 2px;
}

input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 2px; }

.palette {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
}

.palette-color {
  aspect-ratio: 1;
  border: 1.5px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}

.palette-color:hover {
  transform: scale(1.15);
}

.palette-color.selected {
  border-color: #D0BCFF;
}

/* Toolbar */
.editor-toolbar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.tool-btn {
  padding: 0.3rem 0.6rem;
  font-size: 0.75rem;
  background: #1e1e1e;
  border: 1px solid #49454F;
  color: #CAC4D0;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s;
}

.tool-btn:hover { background: #2d2d2d; }
button.tool-btn:disabled { background: #1e1e1e; border-color: #2d2d2d; color: #49454F; cursor: not-allowed; }
button.tool-btn:disabled:hover { background: #1e1e1e; }
.tool-btn.active { background: #6750A4; border-color: #6750A4; color: #FFFFFF; }

/* Array preview */
.array-preview {
  margin-top: 0.75rem;
}

.array-preview label {
  display: block;
  font-size: 0.75rem;
  color: #938F99;
  margin-bottom: 0.35rem;
}

.array-preview pre {
  background: #1e1e1e;
  border: 1px solid #49454F;
  border-radius: 4px;
  padding: 0.5rem 0.65rem;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: 0.6rem;
  line-height: 1.4;
  color: #938F99;
  max-height: 120px;
  overflow-y: auto;
  word-wrap: break-word;
  white-space: pre-wrap;
  text-align: left;
  user-select: all;
}

/* Import / Export */
.import-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.import-error {
  font-size: 0.7rem;
  color: #F2B8B5;
}

/* Text input section */
.text-input-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.text-input-section.hidden { display: none; }
