/* Shape Maker — styles.css (dark sidebar + page canvas)
 * Notes:
 * - Drawing colors remain "black on white" (render.js controls that).
 * - UI is dark; canvas area is neutral.
 */

:root {
  --bg: #0f1216;
  --panel: #121821;
  --panel2: #0e141c;
  --fg: #e8eef6;
  --muted: #9aa7b5;
  --line: rgba(255, 255, 255, .10);
  --line2: rgba(255, 255, 255, .16);
  --accent: #00aaff;
  --btn: rgba(255, 255, 255, .20);
  --btnHover: rgba(255, 255, 255, .25);
  --btnActive: rgba(0, 170, 255, .30);
  --radius: 12px;
  --font: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Noto Sans", "Liberation Sans", sans-serif;
}

* {
  box-sizing: border-box
}

html,
body {
  height: 100%
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
}

.app {
  height: calc(100% - 44px);
  display: flex;
}

/* Sidebar */
.sidebar {
  width: 174px;
  background: linear-gradient(180deg, var(--panel), var(--panel2));
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 10px;
  gap: 10px;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 6px 10px 6px;
}

.brand__title {
  font-weight: 700;
  letter-spacing: .2px;
  font-size: 14px;
}

.brand__subtitle {
  color: var(--muted);
  font-size: 12px;
}

.sidebar__section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 6px;
  border-top: 1px solid var(--line);
}

.sidebar__section:first-of-type {
  border-top: none;
}

.sidebar__spacer {
  flex: 1;
}

.toolrow {
  display: flex;
  gap: 10px;
  align-items: center;
}

.btn {
  border: 1px solid var(--line);
  background: var(--btn);
  color: var(--fg);
  padding: 10px 10px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  user-select: none;
}

.btn:hover {
  background: var(--btnHover);
  border-color: var(--line2);
}

.btn:active {
  transform: translateY(1px);
}

.btn--file {
  position: relative;
  overflow: hidden;
}

.btn--file input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.btn--tool {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  font-size: 20px;
}

.btn--icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  font-size: 16px;
}

.btn--wide {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
}

.btn--active {
  border-color: rgba(0, 170, 255, .65);
  background: var(--btnActive);
}

.ctl {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .04);
  border-radius: 12px;
  font-size: 12px;
}

.ctl__label {
  color: var(--muted);
  min-width: 64px;
  text-align: left;
  line-height: 1.15;
}

.ctl__value {
  min-width: 24px;
  text-align: right;
  color: var(--fg);
}

.ctl input[type="range"] {
  width: 92px;
}

/* Dropdown sliders (Lazy / Snap distance) */
.drop {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .04);
  border-radius: 12px;
  padding: 0;
}

.drop__summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  cursor: pointer;
}

.drop__summary::-webkit-details-marker {
  display: none;
}

.drop__label {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.1;
  white-space: nowrap;
}

.drop__value {
  min-width: 28px;
  text-align: right;
  color: var(--fg);
  font-size: 12px;
}

.drop input[type="range"] {
  width: calc(100% - 20px);
  margin: 0 10px 10px 10px;
}

.ctl--check {
  justify-content: space-between;
}

.ctl--check input[type="checkbox"] {
  transform: translateY(1px);
}

/* Minimap block */
.sidebar__section--minimap {
  gap: 8px;
}

.minimap__title {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
  padding: 0 4px 4px 4px;
  position: relative;
  top: 0;
  margin-bottom: 8px;
}

.minimap__frame {
  position: relative;
  align-self: center;
  margin-bottom: 34px;
  margin-top: 34px;
}

.minimap {
  border: 1px solid var(--line2);
  border-radius: 10px;
  background: #fff;
  display: block;
}

.mm {
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 8px;
  border: 1px solid var(--line2);
  background: rgba(0, 0, 0, .65);
  color: var(--fg);
  cursor: pointer;
  font-size: 14px;
  line-height: 20px;
  padding: 0;
}

.mm:hover {
  background: rgba(0, 0, 0, .80);
}

.mm--top {
  left: 50%;
  transform: translateX(-70%);
  top: -40px;
}

.mm--top2 {
  left: 50%;
  transform: translateX(10%);
  top: -40px;
}

.mm--bottom {
  left: 50%;
  transform: translateX(-70%);
  bottom: -26px;
}

.mm--bottom2 {
  left: 50%;
  transform: translateX(10%);
  bottom: -26px;
}

.mm--left {
  left: -26px;
  top: 50%;
  transform: translateY(-70%);
}

.mm--left2 {
  left: -26px;
  top: 50%;
  transform: translateY(10%);
}

.mm--right {
  right: -26px;
  top: 50%;
  transform: translateY(-70%);
}

.mm--right2 {
  right: -26px;
  top: 50%;
  transform: translateY(10%);
}

.zoomrow {
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* Main stage */
.stage {
  flex: 1;
  display: flex;
}

.viewport {
  position: relative;
  flex: 1;
  overflow: hidden;
  background-image:
    linear-gradient(rgba(0, 0, 0, .18), rgba(0, 0, 0, .18)),
    url("./wood3.webp");
  background-repeat: repeat;
  background-position: 0 0;
  background-size: auto;
  /* Сбрасываем фиксированный размер, вызывавший скачок */
  opacity: 0;
  transition: opacity 0.4s ease-out;
}

.viewport.ready {
  opacity: 1;
}

#canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.hint {
  position: absolute;
  left: 12px;
  top: 12px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, .18);
  border-radius: 12px;
  background: rgba(15, 18, 22, .85);
  font-size: 12px;
  color: var(--muted);
  max-width: min(560px, calc(100% - 24px));
  display: none;
}

/* Footer */
.footer {
  height: 22px;
  border-top: 1px solid var(--line);
  background: var(--panel2);
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  font-size: 12px;
  color: var(--muted);
}

.footer__right {
  color: var(--fg);
}


/* Compact row for IO buttons */
.btnrow {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}

.btnrow .btn {
  flex: 1;
  min-width: 0;
}

.btnrow .btn--file {
  flex: 1;
  min-width: 0;
}

.btn--io {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 0;
}

.ico {
  width: 14px;
  height: 14px;
  display: inline-block;
  vertical-align: middle;
}

.btnrow .ico {
  width: 21px;
  height: 21px;
}

.btnrow [data-action="io:exportSvg"] .ico {
  transform: scale(1.12);
  transform-origin: 50% 50%;
}

.tool-ico {
  width: 22px;
  height: 22px;
  display: block;
}

.tool-img {
  width: 22px;
  height: 22px;
  display: block;
  object-fit: contain;
}

.btnrow input[type="file"] {
  display: none;
}

/* === Stage Overlay v12 (relocated original minimap section) === */

.sidebar__section--minimap.stage-overlay {
  position: absolute;
  top: 48px;
  right: 16px;
  width: auto !important;
  max-width: none !important;
  margin: 0 !important;
  z-index: 200;
}

.app {
  position: relative;
}

/* === Stage Overlay v13 (correct anchor) === */
.sidebar__section--minimap.stage-overlay {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 200;
}


/* ===============================
   Compact Right Overlay (v15)
   =============================== */

.sidebar__section--minimap.stage-overlay {
  background: #0f1a26;
  /* same tone as sidebar */
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, .35);
  width: 180px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

/* Canvas label */
.stage-overlay .minimap__title {
  margin: 0 0 8px 0;
  font-size: 12px;
  opacity: 0.85;
}

/* Rotate row (2 buttons only) */
.stage-overlay .toolrow {
  width: 100%;
  display: flex;
  justify-content: flex-start;
  gap: 6px;
  margin-bottom: 8px;
}

/* Minimap frame tightened */
.stage-overlay .minimap__frame {
  width: 100%;
  padding: 0;
  margin: 0 0 8px 0;
}

.stage-overlay .minimap {
  display: block;
}

/* Zoom/Fit row */
.stage-overlay .zoomrow {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 6px;
}

.stage-overlay .zoomrow .btn {
  flex: 1;
}

/* Slightly reduce button padding for compact look */
.stage-overlay .btn {
  padding: 6px 0;
}

.btncol {
  display: flex;
  flex-direction: column;
  gap: 8px;
}


/* Адаптация для планшетов и телефонов */
@media (max-width: 850px) {

  /* Переключаем ориентацию приложения: сайдбар теперь сверху */
  .app {
    flex-direction: column;
  }

  /* Сайдбар превращается в компактную панель управления */
  .sidebar {
    width: 100% !important;
    height: auto;
    padding: 8px;
    border-right: none;
    border-bottom: 1px solid #333;
    flex-direction: row;
    flex-wrap: wrap;
    /* Если кнопок много, они перенесутся */
    justify-content: space-between;
    align-items: center;
  }

  /* Прячем декоративные элементы, чтобы освободить место */
  .brand,
  .sidebar__spacer {
    display: none !important;
  }

  /* Группируем кнопки в аккуратные ряды */
  .sidebar__section {
    margin-bottom: 0;
    padding: 2px;
  }

  .btncol,
  .btnrow,
  .toolrow,
  .zoomrow {
    flex-direction: row !important;
    gap: 8px !important;
    margin: 0 !important;
  }

  .btn--active {
    background: #0088cc !important;
    color: #fff !important;
    border-color: #00aaff !important;
  }

  /* Smart Hiding: panels fade out when drawing */
  .app--drawing .floating-tools,
  .app--drawing .minimap-panel {
    opacity: 0.1;
    pointer-events: none;
    transition: opacity 0.4s ease;
  }

  .floating-tools,
  .minimap-panel {
    transition: opacity 0.2s ease, transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  /* Увеличиваем кнопки, чтобы по ним было легко попадать пальцем */
  .btn {
    width: 44px !important;
    height: 44px !important;
    min-width: 44px;
    font-size: 18px;
    /* Увеличиваем размер символов ⟲ ↷ ✖ */
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: #2a2a2a;
  }

  /* Иконки внутри кнопок тоже масштабируем */
  .btn svg,
  .ico {
    width: 24px !important;
    height: 24px !important;
  }

  /* Зона холста занимает всё оставшееся пространство */
  .stage {
    flex: 1;
    height: calc(100vh - 80px);
    /* Вычитаем высоту панели управления */
  }

  /* Модальное окно Share делаем удобным для мобильных */
  #shareModal>div {
    width: 90% !important;
    max-width: 320px !important;
    padding: 15px !important;
  }

  #shareModal button {
    padding: 14px !important;
    /* Толстые кнопки для мобилок */
    font-size: 16px !important;
  }
}

/* Фикс для работы тач-скрина: запрещаем системные жесты при рисовании */
canvas {
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.info-content {
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  text-align: left;
  line-height: 1.6;
}

.info-content h5 {
  margin-top: 20px;
  color: #333;
  border-bottom: 1px solid #eee;
}

.info-content p,
.info-content li {
  font-size: 14px;
  color: #555;
}

// Логика окна Инфо
const infoBtn=document.getElementById('infoBtn');
const infoModal=document.getElementById('infoModal');
const closeInfoBtn=document.getElementById('closeInfoModalBtn');

if (infoBtn) {
  infoBtn.onclick=()=> {
    infoModal.style.display='flex';
  }

  ;
}

if (closeInfoBtn) {
  closeInfoBtn.onclick=()=> {
    infoModal.style.display='none';
  }

  ;
}

.settings-container {
  display: flex;
  /* Выстраивает кнопки в ряд */
  align-items: center;
  /* Центрирует их по вертикали */
  gap: 4px;
  /* Расстояние между кнопками */
}