* {
  box-sizing: border-box;
}

html, body, #root {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
}

.app {
  display: grid;
  grid-template-columns: 320px 1fr 380px;
  grid-template-rows: 56px 1fr;
  grid-template-areas:
    "header header header"
    "loader preview options";
  height: 100vh;
}

.header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: #1e293b;
  border-bottom: 1px solid #334155;
}

.header h1 {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
  color: #f1f5f9;
}

.header .meta {
  font-size: 12px;
  color: #94a3b8;
}

.panel {
  padding: 16px;
  overflow-y: auto;
  border-right: 1px solid #334155;
}

.panel.loader {
  grid-area: loader;
}

.panel.options {
  grid-area: options;
  border-right: none;
  border-left: 1px solid #334155;
}

.preview-area {
  grid-area: preview;
  position: relative;
  display: flex;
  flex-direction: column;
  background: #020617;
}

.preview-canvas {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-empty {
  color: #64748b;
  font-size: 14px;
}

.preview-tabs {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  background: #1e293b;
  border-bottom: 1px solid #334155;
}

.tab-btn {
  background: transparent;
  border: 1px solid #334155;
  color: #cbd5e1;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
}

.tab-btn.active {
  background: #6366f1;
  border-color: #6366f1;
  color: white;
}

.section {
  margin-bottom: 20px;
}

.section h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94a3b8;
  margin: 0 0 8px 0;
  font-weight: 600;
}

.btn {
  background: #6366f1;
  color: white;
  border: none;
  padding: 8px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  margin-right: 6px;
  margin-bottom: 6px;
}

.btn:hover {
  background: #4f46e5;
}

.btn.secondary {
  background: transparent;
  border: 1px solid #475569;
  color: #cbd5e1;
}

.btn.secondary:hover {
  background: #1e293b;
}

textarea {
  width: 100%;
  min-height: 100px;
  background: #0f172a;
  color: #e2e8f0;
  border: 1px solid #334155;
  border-radius: 4px;
  padding: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  resize: vertical;
}

input[type="text"] {
  width: 100%;
  background: #0f172a;
  color: #e2e8f0;
  border: 1px solid #334155;
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 13px;
}

input[type="text"]:focus,
textarea:focus {
  outline: none;
  border-color: #6366f1;
}

.layer-control {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 12px;
}

.layer-control .label {
  font-size: 12px;
  font-weight: 600;
  color: #cbd5e1;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.layer-control .label .badge {
  font-size: 10px;
  background: #334155;
  color: #94a3b8;
  padding: 2px 6px;
  border-radius: 3px;
  font-weight: normal;
  text-transform: uppercase;
}

.layer-control .label .required {
  color: #f87171;
  margin-left: 4px;
}

.option-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 6px;
}

.option-tile {
  border: 2px solid #334155;
  border-radius: 4px;
  padding: 4px;
  background: #0f172a;
  cursor: pointer;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: border-color 100ms;
}

.option-tile:hover {
  border-color: #6366f1;
}

.option-tile.active {
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.1);
}

.option-tile img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.option-tile .label-text {
  font-size: 10px;
  text-align: center;
  color: #cbd5e1;
}

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

.template-tile {
  border: 2px solid #334155;
  border-radius: 6px;
  padding: 6px;
  background: #0f172a;
  cursor: pointer;
  text-align: center;
}

.template-tile.active {
  border-color: #22c55e;
}

.template-tile img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  margin-bottom: 4px;
}

.template-tile .name {
  font-size: 11px;
  color: #cbd5e1;
}

.error-box {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid #ef4444;
  color: #fca5a5;
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 12px;
  margin-top: 6px;
}

.success-box {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid #22c55e;
  color: #86efac;
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 12px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

pre.json {
  background: #0f172a;
  border: 1px solid #334155;
  padding: 8px;
  border-radius: 4px;
  font-size: 11px;
  max-height: 240px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0;
}

.group-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  margin-bottom: 8px;
  padding-bottom: 4px;
}

.group-tab {
  flex-shrink: 0;
  border: 2px solid #334155;
  border-radius: 4px;
  padding: 4px;
  background: #0f172a;
  cursor: pointer;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.group-tab.active {
  border-color: #22c55e;
}

.group-tab img {
  max-width: 100%;
  max-height: 100%;
}

.group-tab .name {
  font-size: 9px;
  color: #cbd5e1;
}

.position-debug {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid #334155;
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 11px;
  font-family: ui-monospace, monospace;
  color: #94a3b8;
  pointer-events: none;
}
