:root {
  --bg: #14161a;
  --panel: #1d2026;
  --panel2: #23272f;
  --line: #33383f;
  --text: #e6e8ec;
  --muted: #9aa2ad;
  --accent: #6ab04c;
  --accent2: #4a8f38;
  --danger: #d9534f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font: 15px/1.5 system-ui, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  background: #0000003a;
  padding: 0.05em 0.35em;
  border-radius: 4px;
  font-size: 0.9em;
}

header {
  padding: 2rem 1.5rem 1rem;
  text-align: center;
}
header h1 {
  margin: 0;
  font-size: 2.4rem;
  letter-spacing: -0.02em;
}
header h1 span { color: var(--accent); }
header p { color: var(--muted); margin: 0.5rem auto 0; max-width: 42rem; }

main { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 1rem 1.5rem 4rem; }

/* Sidebar */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 220px;
  height: 100vh;
  padding: 1.5rem 1rem;
  border-right: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-y: auto;
}
#sidebar h2 {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
#sidebar nav { display: grid; gap: 0.5rem; }
#sidebar a {
  display: block;
  padding: 0.6rem 0.7rem;
  border-radius: 10px;
  background: var(--panel2);
  color: var(--text);
  text-decoration: none;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}
#sidebar a:hover { border-color: var(--accent); }
#sidebar a .tool { display: block; font-weight: 600; color: var(--accent); }
#sidebar a .desc { display: block; font-size: 0.78rem; color: var(--muted); margin-top: 0.1rem; }

@media (max-width: 1560px) {
  #sidebar {
    position: static;
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  #sidebar nav { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}

footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0 1.5rem 2rem;
}

.hidden { display: none !important; }

/* Drop zone */
.drop {
  border: 2px dashed var(--line);
  border-radius: 14px;
  background: var(--panel);
  padding: 3rem 1.5rem;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.drop.drag { border-color: var(--accent); background: #1f2620; }
.drop .big { font-size: 1.4rem; margin: 0 0 0.4rem; }
.drop .hint { color: var(--muted); margin: 0 auto 1.4rem; max-width: 34rem; }

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  padding: 0.55rem 1.1rem;
  border-radius: 8px;
  transition: background 0.12s, border-color 0.12s;
}
button:hover { border-color: var(--accent); }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #10230a;
  font-weight: 600;
  width: 100%;
  margin-top: 1rem;
}
button.primary:hover { background: var(--accent2); }
button.primary:disabled { opacity: 0.5; cursor: not-allowed; }
button.ghost { background: transparent; }

/* Workspace */
.bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  gap: 1rem;
  flex-wrap: wrap;
}
.pick-row { display: flex; gap: 0.6rem; justify-content: center; }

.dimpick {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.dimpick select { min-width: 10rem; }

.map-tools {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}
.map-tools .spacer { flex: 1; }
.map-tools button { padding: 0.35rem 0.7rem; }
.seg.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #10230a;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 800px) { .grid { grid-template-columns: 1fr; } }

.map-wrap {
  position: relative;
  background: #0c0d10 repeating-conic-gradient(#181a1e 0% 25%, transparent 0% 50%) 50% / 20px 20px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  line-height: 0;
}
#map {
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  display: block;
}
#overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1.1rem;
}
.panel h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 0.6rem;
}
.panel h2:not(:first-child) { margin-top: 1.4rem; }

.coords {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}
.coords label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.85rem;
}
.coords input {
  width: 100%;
  min-width: 0;
}
input, select {
  font: inherit;
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
}
input:focus, select:focus { outline: 1px solid var(--accent); }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}
.row select { flex: 1; }
.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  color: var(--muted);
}
.check input { accent-color: var(--accent); }

.muted { color: var(--muted); font-size: 0.85rem; }
.status { margin-top: 0.8rem; font-size: 0.85rem; min-height: 1.2em; }
.status.err { color: var(--danger); }
.status.ok { color: var(--accent); }

/* Curtain */
.curtain {
  position: fixed;
  inset: 0;
  background: #0b0c0fcc;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 10;
}
.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
