:root {
  --bg: #f4f6fb;
  --card: #fff;
  --border: #e2e6ef;
  --brand: #2563eb;
  --text: #1f2937;
  --muted: #6b7280;
  --ok: #047857;
  --err: #b91c1c;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: 56px;
  background: var(--card); border-bottom: 1px solid var(--border);
}
nav .brand { font-weight: 700; color: var(--brand); text-decoration: none; font-size: 18px; }
nav .menu { display: flex; gap: 18px; align-items: center; }
nav a { color: var(--text); text-decoration: none; }
nav a:hover { color: var(--brand); }
main { max-width: 860px; margin: 32px auto; padding: 0 16px; }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 24px; margin-bottom: 20px;
}
.auth-card { max-width: 380px; margin: 10vh auto 0; }
h1 { font-size: 22px; margin-top: 0; }
label { display: block; margin-bottom: 14px; font-size: 14px; color: var(--muted); }
input {
  width: 100%; margin-top: 6px; padding: 10px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
button {
  width: 100%; padding: 11px; border: 0; border-radius: 8px;
  background: var(--brand); color: #fff; font-size: 15px; cursor: pointer;
}
button:hover { opacity: .9; }
.role {
  background: #eef2ff; color: var(--brand);
  padding: 2px 8px; border-radius: 999px; font-size: 12px;
}
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-top: 16px; }
.widget { background: var(--bg); border-radius: 10px; padding: 16px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
.error { color: var(--err); font-size: 14px; }
.fielderror { color: var(--err); font-size: 12px; display: block; margin-top: 4px; }
.ok { color: var(--ok); font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 16px; }
.hint a { color: var(--brand); }

/* Глубокий космос — фон страницы входа/регистрации */
.deep-space {
  min-height: 100vh;
  background:
    radial-gradient(1200px 800px at 20% -10%, rgba(88, 101, 242, 0.18), transparent 60%),
    radial-gradient(1000px 700px at 85% 0%, rgba(56, 189, 248, 0.12), transparent 55%),
    radial-gradient(900px 900px at 50% 120%, rgba(168, 85, 247, 0.16), transparent 60%),
    linear-gradient(180deg, #05050f 0%, #0b0b1f 45%, #0a0a18 100%);
  background-attachment: fixed;
}
.deep-space:not(.home) {
  display: flex;
  align-items: center;
  justify-content: center;
}
.deep-space:not(.home) main {
  width: 100%;
  max-width: 380px;
}
.deep-space main {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
}
.deep-space .auth-card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.deep-space .auth-card h1 {
  color: #eef2ff;
}
.deep-space .auth-card input {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.18);
  color: #eef2ff;
}
.deep-space .auth-card label,
.deep-space .auth-card .hint,
.deep-space .auth-card .fielderror {
  color: #cbd5e1;
}
.deep-space .auth-card .hint a {
  color: #93c5fd;
}
.deep-space .auth-card button {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
}

/* Стартовая страница — панель инструментов */
.home-top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  justify-content: flex-end;
  padding: 20px 28px;
}
.login-link {
  font-size: 15px;
  font-weight: 600;
  color: #eef2ff;
  text-decoration: underline;
  text-underline-offset: 3px;
  transition: color .15s ease;
}
.login-link:hover {
  color: #93c5fd;
}
.home-panel {
  max-width: 460px;
  text-align: center;
  padding: 36px 28px;
}
.home-panel h1 {
  margin-bottom: 4px;
}
.home-sub {
  color: #cbd5e1;
  font-size: 14px;
  margin: 0 0 24px;
}

/* Стартовая страница — 3 вертикальные колонки 1/4 · 2/4 · 1/4 */
.home-cols {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  gap: 0;
  min-height: 100vh;
  padding-top: 84px;
}
.home-col {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.home-col-left {
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}
.home-col-right {
  border-left: 1px solid rgba(255, 255, 255, 0.08);
}
.home-col-title {
  position: absolute;
  top: 24px;
  left: 0;
  right: 0;
  text-align: center;
  color: rgba(203, 213, 225, 0.6);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.home-col-main {
  align-items: stretch;
  justify-content: flex-start;
  padding: 56px 24px 24px;
}
.home-col-main .home-panel {
  max-width: 100%;
  width: 100%;
}
.home-tools {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.tool {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #eef2ff;
  text-decoration: none;
  text-align: left;
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}
.tool:hover {
  transform: translateY(-2px);
  border-color: rgba(147, 197, 253, 0.6);
  background: rgba(255, 255, 255, 0.1);
}
.tool-icon {
  flex: 0 0 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
}
.tool-body {
  display: flex;
  flex-direction: column;
}
.tool-name {
  font-weight: 600;
  font-size: 15px;
}
.tool-desc {
  font-size: 13px;
  color: #cbd5e1;
  margin-top: 2px;
}

/* ===== Конструктор: Примитивы ===== */
.primitives {
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-items: center;
  width: 100%;
}
.part-wrap {
  position: relative;
  display: inline-block;
  width: 78%;
  max-width: 260px;
}
.part-wrap:active {
  cursor: grabbing;
}
.jeans-part {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
  cursor: grab;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.14);
  user-select: none;
}
.part-wrap:hover .jeans-part {
  filter: brightness(1.08);
}
.part-label {
  display: block;
  text-align: center;
  margin-top: 4px;
  font-size: 12px;
  color: rgba(203, 213, 225, 0.7);
}

/* ===== Ручка изменения размера ===== */
.resize-handle {
  position: absolute;
  right: -6px;
  bottom: -6px;
  width: 16px;
  height: 16px;
  background: #eef2ff;
  border: 2px solid #6366f1;
  border-radius: 3px;
  cursor: nwse-resize;
  opacity: 0.9;
  z-index: 5;
  touch-action: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

/* ===== Объект: сцена с сеткой см ===== */
.object-stage {
  position: relative;
  width: 100%;
  height: 72vh;
  --cm: 24px; /* пикселей на 1 см */
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 10px;
  background-color: rgba(10, 12, 25, 0.72);
  /* сетка в сантиметрах: крупная линия каждый см, мелкая каждые 0.5 см */
  background-image:
    repeating-linear-gradient(90deg,
      rgba(148, 163, 184, 0.55) 0 calc(var(--cm) - 1px),
      transparent calc(var(--cm) - 1px) var(--cm)),
    repeating-linear-gradient(0deg,
      rgba(148, 163, 184, 0.55) 0 calc(var(--cm) - 1px),
      transparent calc(var(--cm) - 1px) var(--cm)),
    repeating-linear-gradient(90deg,
      rgba(148, 163, 184, 0.22) 0 calc(var(--cm) / 2 - 1px),
      transparent calc(var(--cm) / 2 - 1px) calc(var(--cm) / 2)),
    repeating-linear-gradient(0deg,
      rgba(148, 163, 184, 0.22) 0 calc(var(--cm) / 2 - 1px),
      transparent calc(var(--cm) / 2 - 1px) calc(var(--cm) / 2));
  overflow: hidden;
}
.object-stage-label {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  transform: translateY(-50%);
  text-align: center;
  color: rgba(203, 213, 225, 0.4);
  font-size: 14px;
  pointer-events: none;
}
.stage-item-wrap {
  position: absolute;
  cursor: move;
  width: 180px;
  border-radius: 6px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.6);
  touch-action: none;
  user-select: none;
}
.stage-item {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  pointer-events: none;
}
.stage-item-wrap .resize-handle {
  right: -6px;
  bottom: -6px;
}
.remove-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
}
.remove-btn:hover {
  background: #dc2626;
}

/* ===== Линейки ОСИ X (сверху) и ОСИ Y (слева) ===== */
.object-stage::before,
.object-stage::after {
  position: absolute;
  pointer-events: none;
  z-index: 2;
}
/* ось X — горизонтальная линейка вверху: риски каждый см */
.object-stage::before {
  content: "";
  top: 0;
  left: 0;
  right: 0;
  height: 22px;
  background:
    repeating-linear-gradient(90deg,
      rgba(226, 232, 240, 0.85) 0 1px,
      transparent 1px var(--cm)),
    repeating-linear-gradient(90deg,
      rgba(255, 255, 255, 0.95) 0 2px,
      transparent 2px calc(var(--cm) * 5));
  border-bottom: 1px solid rgba(226, 232, 240, 0.5);
}
/* ось Y — вертикальная линейка слева: риски каждый см */
.object-stage::after {
  content: "";
  top: 0;
  left: 0;
  bottom: 0;
  width: 22px;
  background:
    repeating-linear-gradient(0deg,
      rgba(226, 232, 240, 0.85) 0 1px,
      transparent 1px var(--cm)),
    repeating-linear-gradient(0deg,
      rgba(255, 255, 255, 0.95) 0 2px,
      transparent 2px calc(var(--cm) * 5));
  border-right: 1px solid rgba(226, 232, 240, 0.5);
}

/* ===== Строка координат в см ===== */
.object-readout {
  width: 100%;
  margin-top: 10px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  color: #cbd5e1;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 8px 12px;
  min-height: 32px;
}