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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f1117;
  color: #c9d1d9;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  padding: .7rem 1.2rem;
  background: #161b22;
  border-bottom: 1px solid #30363d;
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-shrink: 0;
}
header svg { width: 24px; height: 24px; fill: #58a6ff; flex-shrink: 0; }
header h1 { font-size: 1.05rem; font-weight: 600; color: #e6edf3; }

.app { display: flex; flex: 1; min-height: 0; }

/* ── Sidebar ─────────────────────────────── */
.sidebar {
  width: 280px;
  min-width: 280px;
  background: #161b22;
  border-right: 1px solid #30363d;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-y: auto;
  flex-shrink: 0;
}
.section-title {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #8b949e;
  margin-bottom: .35rem;
}

/* Upload */
.upload-area {
  border: 2px dashed #30363d;
  border-radius: 8px;
  padding: 1.1rem .8rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.upload-area:hover, .upload-area.dragover {
  border-color: #58a6ff;
  background: rgba(88,166,255,.06);
}
.upload-area input { display: none; }
.upload-area .icon { font-size: 1.4rem; margin-bottom: .3rem; }
.upload-area .label { font-size: .8rem; color: #8b949e; }
.upload-area .filename {
  margin-top: .3rem;
  font-size: .75rem;
  color: #58a6ff;
  word-break: break-all;
}

/* Controls */
.control-group { display: flex; flex-direction: column; gap: .5rem; }
.row { display: flex; gap: .4rem; overflow: hidden; }
.field { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .2rem; }
.field label {
  font-size: .65rem;
  color: #8b949e;
  font-weight: 500;
}
.field input[type="number"] {
  width: 100%;
  min-width: 0;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 5px;
  padding: .35rem .4rem;
  color: #e6edf3;
  font-size: .78rem;
  font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  outline: none;
  transition: border-color .15s;
  -moz-appearance: textfield;
}
.field input[type="number"]::-webkit-inner-spin-button,
.field input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.field input:focus { border-color: #58a6ff; }
.field input::placeholder { color: #484f58; }

/* Toggle buttons (Projection) */
.toggle-row {
  display: flex;
}
.toggle-btn {
  flex: 1;
  padding: .4rem;
  background: #21262d;
  border: 1px solid #30363d;
  color: #8b949e;
  font-size: .75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}
.toggle-btn:first-child {
  border-radius: 5px 0 0 5px;
  border-right: none;
}
.toggle-btn:last-child {
  border-radius: 0 5px 5px 0;
}
.toggle-btn.active {
  background: #1f6feb;
  color: #fff;
  border-color: #1f6feb;
}
.toggle-btn:hover:not(.active) {
  background: #30363d;
}

/* Color picker */
.color-row {
  display: flex;
  align-items: center;
  gap: .6rem;
}
input[type="color"] {
  width: 40px;
  height: 32px;
  border: 1px solid #30363d;
  border-radius: 4px;
  background: none;
  cursor: pointer;
  padding: 2px;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 2px; }
.color-hex {
  font-size: .78rem;
  font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  color: #8b949e;
}

/* Buttons */
.btn-row { display: flex; gap: .5rem; }
button.render-btn, button.dl-btn {
  flex: 1;
  padding: .55rem;
  border: none;
  border-radius: 7px;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
button.render-btn {
  background: #238636;
  color: #fff;
}
button.render-btn:hover { background: #2ea043; }
button.render-btn:disabled {
  background: #21262d;
  color: #484f58;
  cursor: not-allowed;
}
button.dl-btn {
  background: #1f6feb;
  color: #fff;
  display: none;
}
button.dl-btn:hover { background: #388bfd; }

button.reset-btn {
  flex: 1;
  padding: .45rem;
  border: 1px solid #30363d;
  border-radius: 7px;
  font-size: .78rem;
  font-weight: 500;
  cursor: pointer;
  background: #21262d;
  color: #c9d1d9;
  transition: background .15s;
}
button.reset-btn:hover { background: #30363d; }

.status-msg {
  font-size: .72rem;
  color: #8b949e;
  text-align: center;
  min-height: 1.1em;
}

/* Curl preview */
.curl-preview {
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
  padding: .6rem;
  font-size: .68rem;
  font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  color: #7ee787;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 140px;
  overflow-y: auto;
  line-height: 1.5;
}

/* ── Viewport ────────────────────────────── */
.viewport {
  flex: 1;
  position: relative;
  min-width: 0;
}
.viewport > canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}
.viewport .hint {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  color: #30363d;
  text-align: center;
  font-size: .9rem;
  pointer-events: none;
}
.viewport .hint .big { font-size: 3rem; margin-bottom: .4rem; }

/* ── Preview overlay ─────────────────────── */
.preview-overlay {
  position: absolute;
  top: 10px;
  right: 10px;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 6px;
  padding: 4px;
  z-index: 10;
  display: none;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
}
.preview-overlay.visible {
  display: flex;
}
.preview-label {
  font-size: .6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #8b949e;
  margin-bottom: 3px;
}
.preview-overlay canvas {
  display: block;
  border-radius: 3px;
  background-image:
    linear-gradient(45deg, #2a2a2a 25%, transparent 25%),
    linear-gradient(-45deg, #2a2a2a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2a2a 75%),
    linear-gradient(-45deg, transparent 75%, #2a2a2a 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
  background-color: #1a1a1a;
}

/* ── Lightbox for rendered PNG ───────────── */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.8);
  z-index: 100;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.lightbox.active { display: flex; }
.lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 6px;
  box-shadow: 0 8px 40px rgba(0,0,0,.6);
}
.lightbox .close-hint {
  position: absolute;
  top: 1rem;
  right: 1.5rem;
  color: #8b949e;
  font-size: .8rem;
}

/* ── Responsive ──────────────────────────── */
@media (max-width: 720px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%; min-width: 0;
    border-right: none;
    border-bottom: 1px solid #30363d;
    max-height: 45vh;
  }
  .viewport { min-height: 55vh; }
}
