:root {
  --bg: #0f1220;
  --bg2: #171b2e;
  --panel: #1c2138;
  --panel2: #232a45;
  --line: #2e3860;
  --text: #e8ecf7;
  --muted: #9aa3c4;
  --accent: #6c8bff;
  --accent2: #46d9b0;
  --danger: #ff6b6b;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html { background: var(--bg); }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: radial-gradient(1200px 700px at 70% -10%, #23305c 0%, var(--bg) 55%) fixed, var(--bg);
  color: var(--text);
  font-family: "Pretendard", system-ui, -apple-system, "Segoe UI", "Malgun Gothic", sans-serif;
  line-height: 1.5;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 26px;
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  font-size: 26px;
  color: var(--accent);
  opacity: 0.9;
}
.topbar h1 { margin: 0; font-size: 20px; letter-spacing: 0.3px; }
.topbar p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }

.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  transition: 0.15s;
}
.ghost-btn svg { opacity: 0.9; }
.ghost-btn:hover { border-color: var(--accent); color: #fff; }

/* ---------- layout ---------- */
.wrap {
  max-width: 1080px;
  margin: 26px auto;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.panel {
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg2) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.panel h2 {
  margin: 0 0 18px;
  font-size: 17px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.step {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}
h3 { margin: 0 0 6px; font-size: 15px; }

/* ---------- upload ---------- */
.upload-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .upload-row { grid-template-columns: 1fr; } }
.upload-area {
  border: 2px dashed var(--line);
  border-radius: 14px;
  padding: 22px 18px;
  text-align: center;
  cursor: pointer;
  transition: 0.15s;
  background: rgba(255, 255, 255, 0.015);
}
.upload-area:hover, .upload-area.drag {
  border-color: var(--accent);
  background: rgba(108, 139, 255, 0.08);
}
.upload-icon { font-size: 24px; color: var(--accent); }
.upload-inner p { margin: 5px 0; }
.upload-inner p strong { font-size: 14.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------- hero (top CTA) ---------- */
.hero {
  text-align: center;
  padding: 6px 0 2px;
}
.hero .muted { margin: 12px 0 0; }
.primary.big {
  font-size: 17px;
  padding: 16px 34px;
  border-radius: 14px;
  box-shadow: 0 10px 26px rgba(108, 139, 255, 0.35);
}

/* ---------- buttons ---------- */
.btn-row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 18px; }
button {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 11px;
  padding: 12px 20px;
  font-weight: 600;
  transition: 0.15s;
}
button:active { transform: translateY(1px); }
.primary { background: var(--accent); color: #fff; }
.primary:hover { background: #7d99ff; box-shadow: 0 6px 18px rgba(108, 139, 255, 0.35); }
.secondary { background: var(--panel2); color: var(--text); border: 1px solid var(--line); }
.secondary:hover { border-color: var(--accent); }

/* ---------- result ---------- */
.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
  align-items: start;
}
@media (max-width: 780px) { .result-grid { grid-template-columns: 1fr; } }

.sheet-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 0;              /* square edges — matches the grid */
  overflow: hidden;
  background:
    repeating-conic-gradient(#20263f 0% 25%, #262d4a 0% 50%) 50% / 24px 24px;
  margin-top: 10px;
}
#sheetCanvas, .grid-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
#sheetCanvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.grid-overlay { pointer-events: none; }

/* weapon shown as an extra grid cell below the bottom-left (left leg) cell */
.weapon-cell {
  position: relative;
  width: 33.333%;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-top: none;             /* merge with the grid's bottom border */
  overflow: hidden;
  background: repeating-conic-gradient(#20263f 0% 25%, #262d4a 0% 50%) 50% / 24px 24px;
}
.weapon-cell[hidden] { display: none; }   /* hidden when the weapon is off */
#weaponCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.stage {
  position: relative;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background:
    radial-gradient(120% 80% at 50% 20%, #232a49 0%, #12162a 72%);
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  overflow: hidden;
}
#previewCanvas {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: grab;
}
#previewCanvas.grabbing { cursor: grabbing; }

/* small floating controls, pinned inside the stage edges */
.stage-controls {
  position: absolute;
  left: 10px;
  right: 10px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  pointer-events: none;
  gap: 8px;
}
.stage-controls.top { top: 10px; }
.stage-controls.bottom { bottom: 10px; align-items: center; }
.sc-cluster {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  background: rgba(9, 12, 22, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 9px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.sc-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #dfe4f2;
  font-size: 13px;
  display: grid;
  place-items: center;
  transition: background 0.12s;
}
.sc-btn:hover { background: rgba(255, 255, 255, 0.12); }
.sc-btn.off { color: #6f7796; opacity: 0.55; }
.kbd {
  display: inline-block;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #0c0f1c;
  font-size: 11px;
}
.zoom-group button {
  border: none;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.2px;
  background: transparent;
  color: var(--muted);
  transition: 0.12s;
}
.zoom-group button:hover { color: var(--text); }
.zoom-group button.active { background: rgba(255, 255, 255, 0.14); color: #fff; }

/* motion (top-left) + speed/spacing (top-right) overlays */
.sc-motion { padding: 2px 4px; }
.sc-sliders { flex-direction: column; align-items: stretch; gap: 4px; padding: 6px 9px; }
.sc-row { display: flex; align-items: center; gap: 7px; cursor: pointer; }
.sc-lbl { font-size: 11px; color: #c3cbe4; width: 22px; }
.sc-lbl2 { font-size: 11px; color: #c3cbe4; width: 52px; white-space: nowrap; }
.sc-val { font-size: 11px; color: #eef1fb; width: 46px; text-align: right; font-variant-numeric: tabular-nums; }
.sc-row input[type="range"] { accent-color: var(--accent); width: 74px; }

/* editable number box in the spacing panel */
.sc-num {
  font-family: inherit;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 4px;
  padding: 2px 4px;
  cursor: text;
  -moz-appearance: textfield;
  appearance: textfield;
}
.sc-num:hover { border-color: rgba(255, 255, 255, 0.28); }
.sc-num:focus { outline: none; border-color: var(--accent); background: rgba(0, 0, 0, 0.3); }
.sc-num::-webkit-inner-spin-button,
.sc-num::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* spacing panel collapsible */
.sc-detail-toggle {
  margin-top: 2px;
  border: none;
  background: rgba(255, 255, 255, 0.06);
  color: #c3cbe4;
  font-size: 11px;
  font-weight: 600;
  padding: 5px 6px;
  border-radius: 6px;
  cursor: pointer;
}
.sc-detail-toggle:hover { color: #fff; background: rgba(255, 255, 255, 0.12); }
.sc-detail {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.sc-detail[hidden] { display: none; }  /* toggle actually collapses it */
.sc-detail-reset {
  margin-top: 4px;
  align-self: stretch;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.04);
  color: #c3cbe4;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 5px 6px;
  border-radius: 6px;
  cursor: pointer;
}
.sc-detail-reset:hover { color: #fff; background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.28); }
.motion-select {
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  color: #eef1fb;
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 5px 6px;
  cursor: pointer;
  max-width: 130px;
}
.motion-select:focus { outline: none; }
.motion-select option { background: #12162a; color: var(--text); }
.icon-btn {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 10px;
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 17px;
  display: grid;
  place-items: center;
}
.icon-btn:hover { border-color: var(--accent); }

/* ---------- code block / footer ---------- */
.code-block {
  background: #0c0f1c;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  overflow: auto;
  font-size: 12.5px;
  margin: 0 0 12px;
}
.code-block code { font-family: "JetBrains Mono", "Consolas", monospace; color: #cfe1ff; }
.param-list {
  margin: 14px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}
.param-list li { margin: 2px 0; }
.param-list b { color: var(--text); }
.panel p code {
  font-family: "JetBrains Mono", "Consolas", monospace;
  background: #0c0f1c;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 12px;
  color: #cfe1ff;
}

.foot {
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
  padding: 24px;
}
.foot a { color: var(--text); text-decoration: none; border-bottom: 1px solid var(--line); }
.foot a:hover { color: #fff; border-color: var(--accent); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(20px);
  background: #0c0f1c;
  border: 1px solid var(--accent2);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: 0.25s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
