/* ============================================
   YesCoding3D — основные стили интерфейса
   ============================================ */

/* CSS-переменные: цвета и общие значения */
:root {
  --blue: #4A90E2; --blue-d: #3b79c4; --blue-t: #eaf3fc;
  --teal: #1ABC9C; --teal-d: #149b81; --teal-t: #e4f8f4;
  --orange: #F5A623; --orange-d: #dd9110; --yellow: #F8E71C;
  --gray: #9B9B9B; --ink: #33414f; --line: #dde8f2;
  --panel: #ffffff; --bg: #f2f7fc;
  --r: 14px; --shadow: 0 2px 10px rgba(51, 88, 128, .08);
}

/* Сброс отступов и базовые правила */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'Open Sans', system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}
button {
  font-family: 'Roboto', sans-serif;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}
input {
  font-family: 'Open Sans', sans-serif;
  color: var(--ink);
}

/* Сетка всего приложения: топбар / библиотека+сцена+инспектор / статусбар */
#app {
  display: grid;
  height: 100vh;
  grid-template-columns: 236px 1fr 272px;
  grid-template-rows: 56px 1fr 32px;
  grid-template-areas: "top top top" "lib view insp" "status status status";
}

/* ---------- Верхняя панель (topbar) ---------- */
#topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 20;
  overflow-x: auto;
}

/* Логотип */
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: 10px;
  flex: none;
}
.logo-cube { width: 30px; height: 30px; }
.logo-text {
  font-family: 'Roboto', sans-serif;
  font-size: 19px;
  letter-spacing: .2px;
  white-space: nowrap;
}
.logo-text b { color: var(--blue); font-weight: 700; }
.logo-text i { color: var(--teal); font-style: normal; font-weight: 700; }
.logo-text em { color: var(--orange); font-style: normal; font-weight: 900; margin-left: 1px; }

/* Группы кнопок на панели */
.tb-group { display: flex; gap: 6px; flex: none; }
.tb {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink);
  background: #f3f7fb;
  border: 1px solid var(--line);
  transition: background .12s, transform .06s;
}
.tb:hover { background: var(--blue-t); border-color: #c4dcf5; }
.tb:active { transform: translateY(1px); }
.tb:disabled { opacity: .38; pointer-events: none; }
.tb-icon { padding: 0; width: 36px; justify-content: center; font-size: 17px; }

/* Иконки в кнопках тулбара (PNG) */
.iconsImage {
  width: 16px;
  height: 16px;
  object-fit: contain;
  flex: none;
  pointer-events: none;
}
.tb-icon .iconsImage {
  width: 18px;
  height: 18px;
}
.tb-primary .iconsImage {
  filter: brightness(0) invert(1);
}
.tb-primary:hover .iconsImage {
  filter: none;
}
.seg-b.on .iconsImage {
  filter: brightness(0) invert(1);
}

.tb-primary {
  background: var(--orange);
  border-color: var(--orange);
  color: #fff;
  font-weight: 700;
}
.tb-primary:hover {
  background: var(--yellow);
  border-color: var(--yellow);
  color: #6b5a00;
}
.tb-sep { width: 1px; height: 24px; background: var(--line); flex: none; }

/* Сегментированный переключатель режимов (двигать/вращать/масштаб) */
.seg {
  background: #f3f7fb;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}
.seg-b {
  height: 28px;
  border-radius: 7px;
  border: none;
  background: none;
}
.seg-b.on {
  background: var(--blue);
  color: #fff;
  font-weight: 600;
}

/* ---------- Левая панель: библиотека фигур ---------- */
#library {
  grid-area: lib;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Вкладки категорий */
.lib-tabs {
  display: flex;
  gap: 2px;
  padding: 10px 10px 0;
  border-bottom: 1px solid var(--line);
  flex: none;
}
.lib-tab {
  flex: 1;
  height: 34px;
  border-radius: 8px 8px 0 0;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--gray);
  background: transparent;
}
.lib-tab.on {
  background: var(--bg);
  color: var(--blue);
  border: 1px solid var(--line);
  border-bottom-color: var(--bg);
}
.lib-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  background: var(--bg);
}

/* Сетка кнопок фигур */
.shape-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.shape-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 6px;
  border-radius: 12px;
  background: var(--panel);
  border: 1.5px solid var(--line);
  font-size: 12px;
  font-weight: 600;
  transition: border-color .12s, box-shadow .12s;
}
.shape-btn:hover {
  border-color: var(--blue);
  box-shadow: 0 2px 8px rgba(74, 144, 226, .18);
}
.shape-btn img {
  width: 72px;
  height: 72px;
  object-fit: contain;
}

/* Подзаголовки и поле текста в библиотеке */
.lib-sub {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--gray);
  margin: 14px 0 8px;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.text-row {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  align-items: center;
}
.text-row input {
  flex: 1;
  min-width: 0;
  height: 34px;
  padding: 0 10px;
  border: 1.5px solid var(--line);
  border-radius: 9px;
  font-size: 13.5px;
  outline: none;
}
.text-row button,
.text-add {
  flex: none;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 9px;
  background: var(--blue);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.text-add:hover {
  background: var(--blue-d);
}
.char-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 5px;
}
.char-btn {
  height: 34px;
  border-radius: 8px;
  background: var(--panel);
  border: 1.5px solid var(--line);
  font-size: 15px;
  font-weight: 600;
}
.char-btn:hover {
  background: var(--blue-t);
  border-color: var(--blue);
}

/* ---------- Центральная область: 3D-вьюпорт ---------- */
#viewport {
  grid-area: view;
  position: relative;
  background: #e8f0f8;
  overflow: hidden;
}
#gl {
  display: block;
  width: 100%;
  height: 100%;
}

/* Кнопки смены вида камеры */
#view-chips {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  background: rgba(255, 255, 255, .92);
  border-radius: 10px;
  padding: 4px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.chip {
  height: 28px;
  padding: 0 12px;
  border-radius: 7px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink);
}
.chip:hover { background: var(--blue-t); }

/* Подсказка редактирования группы и toast-сообщения */
#edit-hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(51, 65, 79, .9);
  color: #fff;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  white-space: nowrap;
}
#toast {
  position: absolute;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--blue);
  color: #fff;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .15);
  z-index: 30;
  transition: opacity .25s;
}
#toast.warn { background: #e74c3c; }
.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

/* ---------- Правая панель: инспектор параметров ---------- */
#inspector {
  grid-area: insp;
  background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.insp-head {
  height: 42px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 700;
  border-bottom: 1px solid var(--line);
  flex: none;
}
#insp-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
}
.insp-empty {
  font-size: 13px;
  line-height: 1.55;
  color: var(--gray);
}
.insp-title {
  font-family: 'Roboto', sans-serif;
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 2px;
}
.insp-sub {
  font-size: 12px;
  color: var(--gray);
  margin-bottom: 14px;
}

/* Секции полей (размеры, позиция, поворот и т.д.) */
.f-sec {
  font-size: 11px;
  font-weight: 700;
  color: var(--gray);
  text-transform: uppercase;
  letter-spacing: .3px;
  margin: 14px 0 8px;
}
.f-row3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.f-cell label {
  display: block;
  font-size: 11px;
  color: var(--gray);
  margin-bottom: 3px;
}
.f-cell input {
  width: 100%;
  height: 32px;
  padding: 0 8px;
  border: 1.5px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  outline: none;
}
.f-range {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.f-range label { flex: none; width: 80px; font-size: 12.5px; }
.f-range input[type=range] { flex: 1; }
.f-range output {
  width: 36px;
  text-align: right;
  font-size: 13px;
  font-weight: 600;
}
.f-text input {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  font-size: 14px;
  border: 1.5px solid var(--line);
  border-radius: 9px;
  outline: none;
}

/* Палитра цветов */
.swatches {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}
.sw {
  aspect-ratio: 1;
  border-radius: 8px;
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08);
}
.sw:hover { transform: scale(1.1); }
.sw.on { border-color: var(--ink); }
.sw-custom {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--gray);
}
.sw-custom input {
  width: 34px;
  height: 26px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
}

/* Чекбокс «отверстие» */
.hole-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 13px;
  padding: 10px;
  background: #f6f9fc;
  border: 1.5px dashed var(--line);
  border-radius: var(--r);
  cursor: pointer;
}
.hole-row input {
  width: 17px;
  height: 17px;
  accent-color: var(--orange);
  cursor: pointer;
}
.hole-row span { font-size: 13.5px; font-weight: 600; }
.hole-row small {
  display: block;
  font-weight: 400;
  font-size: 11px;
  color: var(--gray);
}

/* Широкие кнопки в инспекторе */
.btn-wide {
  width: 100%;
  height: 36px;
  margin-top: 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  background: var(--blue-t);
  border: 1.5px solid #c4dcf5;
  color: var(--blue-d);
}
.btn-wide:hover { background: var(--blue); color: #fff; }
.multi-count {
  font-family: 'Roboto', sans-serif;
  font-size: 22px;
  font-weight: 800;
  color: var(--blue);
}

/* ---------- Нижняя строка состояния ---------- */
#statusbar {
  grid-area: status;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--gray);
  overflow: hidden;
  white-space: nowrap;
}
#statusbar b { color: var(--ink); font-weight: 700; }

/* ---------- Экран загрузки ---------- */
#loading {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 99;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity .3s;
}
#loading.hidden {
  opacity: 0;
  visibility: hidden;
}
.load-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  font-family: 'Roboto', sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: var(--blue-d);
}
.spin {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 4px solid var(--blue-t);
  border-top-color: var(--blue);
  animation: sp 1s linear infinite;
}
@keyframes sp { to { transform: rotate(360deg); } }

/* Экран фатальной ошибки (нет WebGL / сбой при запуске) */
#fatal-error {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#fatal-error.hidden { display: none; }
.error-card {
  max-width: 420px;
  text-align: center;
  font-family: 'Roboto', sans-serif;
  color: var(--ink);
  background: var(--panel);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 28px 24px;
}
.error-card h1 { font-size: 17px; color: var(--blue-d); margin-bottom: 10px; }
.error-card p { font-size: 14px; line-height: 1.5; color: var(--gray); }
.error-card button {
  margin-top: 16px;
  padding: 9px 18px;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
}

/* Уважение к prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  .spin { animation-duration: 2.5s; }
  .tb, .shape-btn { transition: none; }
}

/* Скроллбар */
::-webkit-scrollbar { width: 9px; }
::-webkit-scrollbar-thumb {
  background: #cdd9e5;
  border-radius: 9px;
  border: 2px solid var(--panel);
}
::-webkit-scrollbar-track { background: transparent; }
