:root {
  --bg: #0e1116;
  --panel: #171b22;
  --panel-2: #1e242d;
  --line: #2a323d;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #4ea1ff;
  --green: #3fb950;
  --amber: #d29922;
  --red: #f85149;
  --slim: #a371f7;
  --classic: #58a6ff;
  --radius: 10px;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

code {
  background: var(--panel-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.85em;
  color: #c9d6e2;
}

.topbar {
  border-bottom: 1px solid var(--line);
  padding: 18px 24px;
  background: linear-gradient(180deg, #141922, #0e1116);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.topnav { display: flex; gap: 6px; }
.navlink {
  text-decoration: none;
  color: var(--muted);
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13.5px;
  white-space: nowrap;
}
.navlink:hover { color: var(--text); border-color: var(--muted); }
.navlink.active { color: var(--accent); border-color: var(--accent); }
.cube {
  font-size: 34px;
  color: var(--accent);
  line-height: 1;
}
.topbar h1 { margin: 0; font-size: 20px; letter-spacing: 0.2px; }
.tag { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

main {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
.panel h2 { margin: 0 0 14px; font-size: 15px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.mini-btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 7px;
  padding: 6px 12px;
  font-size: 12.5px;
  cursor: pointer;
}
.mini-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.mini-btn:disabled { color: var(--muted); cursor: not-allowed; }
.count-pill {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 1px 10px;
  font-size: 13px;
  color: var(--text);
}

/* generate-from-photo panel */
.ai-tag {
  background: linear-gradient(90deg, #a371f7, #4ea1ff);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 20px;
  vertical-align: middle;
}
.gen-help { color: var(--muted); font-size: 13px; margin: 0 0 14px; max-width: 620px; }
.gen-note {
  width: 100%; box-sizing: border-box; margin: 0 0 12px;
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 11px; font-size: 13px; font-family: inherit;
  resize: vertical;
}
.gen-note:focus { outline: none; border-color: var(--accent); }
.gen-note::placeholder { color: var(--muted); }
.gen-pass-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); margin: 0 0 12px; flex-wrap: wrap; }
.gen-pass {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 11px; font-size: 13px; max-width: 220px; flex: 1 1 160px;
}
.gen-pass:focus { outline: none; border-color: var(--accent); }
.gen-help em { color: var(--text); font-style: normal; font-weight: 600; }
.gen-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.file-btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}
.file-btn:hover { border-color: var(--muted); }
.gen-filename { color: var(--muted); font-size: 13px; flex: 1; min-width: 120px; }
.gen-btn {
  background: linear-gradient(90deg, #a371f7, #4ea1ff);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.gen-btn:disabled { background: var(--panel-2); color: var(--muted); cursor: not-allowed; }
.gen-preview {
  display: none;
  width: 64px; height: 64px;
  image-rendering: pixelated;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #22282f;
}

/* dropzone */
.dropzone {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 34px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone.hover { border-color: var(--accent); background: rgba(78, 161, 255, 0.06); }
.dz-icon { font-size: 30px; color: var(--accent); }
.dropzone p { margin: 6px 0; }
.hint { color: var(--muted); font-size: 12.5px; max-width: 520px; margin: 8px auto 0; }

/* skin list */
.empty { color: var(--muted); font-size: 14px; margin: 0; }
.skin-list { display: flex; flex-direction: column; gap: 10px; }
.skin-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color 0.12s;
}
.skin-card:hover { border-color: var(--accent); }
.skin-card .toggle, .skin-card .del { cursor: pointer; }
.thumb {
  width: 56px; height: 56px;
  image-rendering: pixelated;
  background:
    linear-gradient(45deg, #22282f 25%, transparent 25%, transparent 75%, #22282f 75%),
    linear-gradient(45deg, #22282f 25%, #1a1f26 25%, #1a1f26 75%, #22282f 75%);
  background-size: 12px 12px;
  background-position: 0 0, 6px 6px;
  border-radius: 5px;
  flex: none;
}
.skin-info { flex: 1; min-width: 0; }
.skin-id { font-weight: 600; font-size: 15px; }
.skin-file { color: var(--muted); font-size: 12px; word-break: break-all; }
.skin-warn { color: var(--amber); font-size: 12px; margin-top: 3px; }

.geo-wrap { display: flex; align-items: center; gap: 8px; flex: none; }
.badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  padding: 4px 9px;
  border-radius: 20px;
  white-space: nowrap;
}
.badge.slim { background: rgba(163, 113, 247, 0.15); color: var(--slim); border: 1px solid rgba(163,113,247,.4); }
.badge.classic { background: rgba(88, 166, 255, 0.15); color: var(--classic); border: 1px solid rgba(88,166,255,.4); }
.toggle, .del, .edit {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  padding: 4px 8px;
}
.toggle:hover, .del:hover { color: var(--text); border-color: var(--muted); }
.edit { flex: none; }
.edit:hover { color: var(--accent); border-color: var(--accent); }
.del { flex: none; }

/* build panel */
.fields { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.fields label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); flex: 1; min-width: 160px; }
.fields input {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 14px;
}
.fields input:focus { outline: none; border-color: var(--accent); }

.build-btn {
  background: var(--accent);
  color: #06121f;
  border: none;
  border-radius: 8px;
  padding: 11px 20px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
}
.build-btn:hover:not(:disabled) { opacity: 0.9; }
.build-btn:disabled { background: var(--panel-2); color: var(--muted); cursor: not-allowed; }

.status { margin: 12px 0 0; font-size: 13px; min-height: 18px; }
.status.ok { color: var(--green); }
.status.warn { color: var(--amber); }
.status.err { color: var(--red); }

/* 3D editor modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(6, 9, 14, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal[hidden] { display: none; }
.modal-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  width: 380px;
  max-width: calc(100vw - 32px);
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
/* 3D preview failure (no WebGL / script blocked) — show why, keep 2D usable */
.editor-stage.no3d #editorCanvas { display: none; }
.no3d-msg {
  color: var(--amber);
  font-size: 12px;
  padding: 14px;
  text-align: center;
  line-height: 1.5;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
#editorTitle { font-weight: 700; font-size: 16px; }
.modal-close {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: 6px; width: 28px; height: 28px; cursor: pointer; font-size: 14px;
}
.modal-close:hover { color: var(--text); border-color: var(--muted); }
.editor-stage {
  flex: 1; min-width: 0; min-height: 0;
  background: radial-gradient(circle at 50% 40%, #2a303a, #171b22 70%);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: grab;
}
.editor-stage:active { cursor: grabbing; }
#editorCanvas { display: block; }
.editor-hint { color: var(--muted); font-size: 12px; text-align: center; margin: 10px 0 8px; }
.editor-hint strong { color: var(--text); }
.editor-actions { display: flex; align-items: center; gap: 10px; }
.editor-geo { color: var(--muted); font-size: 12px; margin-left: auto; }

/* full pixel editor — dynamic 80% of the viewport */
.editor-box {
  width: 80vw;
  height: 80vh;
  max-height: none;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.editor-body { display: flex; gap: 16px; flex: 1; min-height: 0; align-items: stretch; }
.editor-main { display: flex; gap: 14px; flex: 1; min-width: 0; min-height: 0; }
.editor-side {
  width: 234px; flex: none; display: flex; flex-direction: column; gap: 10px;
  min-height: 0; overflow-y: auto;
}

/* view-mode toggle */
.view-modes { display: flex; gap: 3px; margin-left: auto; background: var(--panel-2); padding: 3px; border-radius: 9px; border: 1px solid var(--line); }
.vm {
  background: transparent; border: none; color: var(--muted);
  border-radius: 6px; padding: 5px 12px; font-size: 12.5px; cursor: pointer;
}
.vm:hover { color: var(--text); }
.vm.active { background: var(--accent); color: #06121f; font-weight: 700; }
.modal-head .modal-close { margin-left: 10px; }

/* view-mode show/hide */
.editor-body.mode-2d .editor-stage { display: none; }
.editor-body.mode-3d .paint-wrap { display: none; }

.paint-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tool {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  width: 34px; height: 32px;
  font-size: 15px;
  cursor: pointer;
  color: var(--text);
  display: inline-flex; align-items: center; justify-content: center;
}
.tool:hover:not(:disabled) { border-color: var(--muted); }
.tool.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.tool:disabled { opacity: 0.4; cursor: not-allowed; }
.tool-sep { width: 1px; height: 22px; background: var(--line); margin: 0 2px; }
.brush { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 5px; }
.brush select {
  background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 4px; font-size: 12px;
}
.gridtog { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.paint-wrap {
  flex: 1; min-width: 0; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  background: #171b22;
}
/* size set in JS to a square that fits the wrap (keeps texel mapping exact) */
#paintCanvas { display: block; cursor: crosshair; touch-action: none; image-rendering: pixelated; }
.color-row { display: flex; gap: 8px; align-items: center; }
#colorPick {
  width: 42px; height: 34px; padding: 0; border: 1px solid var(--line);
  border-radius: 7px; background: var(--panel-2); cursor: pointer;
}
.hex {
  flex: 1; background: var(--bg); border: 1px solid var(--line); color: var(--text);
  border-radius: 7px; padding: 8px 10px; font-family: ui-monospace, monospace; font-size: 13px;
}
.palette { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; }
.swatch {
  aspect-ratio: 1; border: 1px solid rgba(255,255,255,0.15); border-radius: 5px;
  cursor: pointer; padding: 0;
}
.swatch:hover { border-color: var(--accent); }

@media (max-width: 1120px) {
  .editor-body { flex-direction: column; }
  .editor-side { width: 100%; }
  .editor-main { flex-wrap: wrap; }
}

.foot { max-width: 860px; margin: 0 auto; padding: 8px 24px 40px; }
.foot p { color: var(--muted); font-size: 12px; margin: 0; }

/* ---- mobile / small screens ---- */
@media (max-width: 640px) {
  .topbar { padding: 12px 14px; gap: 10px; }
  .topbar h1 { font-size: 16px; }
  .tag { font-size: 12px; }
  .cube { font-size: 26px; }
  .brand { gap: 10px; }
  .topnav { width: 100%; }
  .topnav .navlink { flex: 1; text-align: center; padding: 9px 6px; font-size: 13px; }
  main { padding-left: 12px; padding-right: 12px; }
  .panel { padding: 14px; }
  .dropzone { padding: 22px 14px; }
  .gen-pass { max-width: none; }
  .fields label { min-width: 120px; }

  /* editor modal → full screen, stacked */
  .modal { padding: 0; }
  .editor-box { width: 100vw; height: 100vh; height: 100dvh; max-width: none; border-radius: 0; }
  .editor-side { width: 100%; max-height: 42vh; }
  .paint-wrap { min-height: 40vh; }
  .palette { grid-template-columns: repeat(10, 1fr); }
  .view-modes { margin-left: 0; }
}
