/* Замеры. Сначала телефон: работают на объекте, с одной рукой занятой рулеткой. */

* { box-sizing: border-box; }

html {
  /* страницу не масштабируем: щипок нужен редактору, а не тексту */
  touch-action: pan-x pan-y;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #eef1f5;
  color: #16181d;
  padding-bottom: env(safe-area-inset-bottom);
}

h1 { font-size: 18px; margin: 0; }

/* ---------- Вход ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #5b6ee1, #7b4fd0);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.login-card h1 { text-align: center; font-size: 24px; margin-bottom: 4px; }
.login-hint { text-align: center; color: #7a8190; font-size: 13px; margin: 0 0 20px; }
.login-card label { display: block; font-size: 13px; color: #5b6270; margin-bottom: 14px; }

.login-card input {
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  min-height: 48px;
  border: 2px solid #e3e6ec;
  border-radius: 10px;
  font-size: 16px;   /* меньше 16px — айфон масштабирует страницу при вводе */
}

.login-card button {
  width: 100%;
  min-height: 48px;
  border: none;
  border-radius: 10px;
  background: #4f7cff;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}

.error-line {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #ffeaea;
  color: #c62828;
  font-size: 14px;
}

/* ---------- Шапка ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: #0a0a0a;
  color: #f4d67a;
}

.topbar h1 { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
  color: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.icon-btn.danger { color: #ff8a80; }

.text-btn {
  min-height: 44px;
  padding: 0 12px;
  border: none;
  border-radius: 10px;
  background: none;
  color: inherit;
  font-size: 14px;
  cursor: pointer;
}

.text-btn.danger { color: #d32f2f; }

/* ---------- Общее ---------- */
.view { padding: 14px; max-width: 1100px; margin: 0 auto; }

.row-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  background: #fff;
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 14px;
}

.row-form input[type="text"] {
  flex: 1 1 220px;
  min-width: 0;
  padding: 10px 12px;
  min-height: 44px;
  border: 2px solid #e3e6ec;
  border-radius: 10px;
  font-size: 16px;
}

.primary-btn {
  min-height: 44px;
  padding: 0 18px;
  border: none;
  border-radius: 10px;
  background: #0a0a0a;
  color: #f4d67a;
  font-size: 15px;
  cursor: pointer;
}

.file-btn { display: inline-flex; align-items: center; }

.progress { color: #5b6270; font-size: 13px; }

.empty {
  background: #fff;
  border-radius: 12px;
  padding: 26px;
  color: #6b7280;
  line-height: 1.5;
}

/* ---------- Папки ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}

.card {
  background: #fff;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.07);
  cursor: pointer;
  display: flex;
  flex-direction: column;
}

.card-cover {
  position: relative;
  height: 120px;
  background: #dfe3ea;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  color: #9aa2b1;
  overflow: hidden;
}

.card-cover img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.card-body { padding: 10px 12px 12px; }
.card-name { font-weight: 600; word-break: break-word; }
.card-sub { color: #8b93a1; font-size: 12px; margin-top: 4px; }

/* ---------- Фотографии ---------- */
.photos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.photo-tile {
  position: relative;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  cursor: pointer;
}

/* contain, а не cover: на замере важен весь кадр, обрезать нельзя */
.tile-shot { position: relative; }

.photo-tile img {
  width: 100%;
  height: 150px;
  object-fit: contain;
  background: #f3f4f6;
  display: block;
}

/* разметку видно прямо на миниатюре — не нужно заходить внутрь снимка.
   Размер и положение слоя задаёт paintPreview: при object-fit: contain
   картинка меньше своей рамки, и слой во всю рамку уехал бы. */
.tile-marks {
  position: absolute;
  pointer-events: none;
  overflow: visible;
}

.photo-badge {
  position: absolute;
  left: 8px;
  top: 8px;
  padding: 2px 8px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
  font-size: 11px;
}

/* ---------- Редактор ---------- */
.editor {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #101216;
  display: flex;
  flex-direction: column;
  touch-action: none;   /* жесты внутри редактора обрабатываем сами */
}

.editor-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: calc(8px + env(safe-area-inset-top)) 10px 8px;
  background: #0a0a0a;
  color: #f0f0f0;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* «Размер» одной ручкой на всю разметку: мельче — мельче у всех стрелок */
.size-ctl {
  display: flex;
  align-items: center;
  gap: 2px;
  border: 1px solid #3a3f49;
  border-radius: 10px;
  padding: 0 4px;
}

.size-label { color: #9aa2b1; font-size: 12px; padding: 0 4px; }
.size-value { min-width: 44px; text-align: center; font-size: 13px; }

.file-btn { cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }

.tools { display: flex; gap: 6px; }

.tool {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid #3a3f49;
  border-radius: 10px;
  background: #1b1f26;
  color: #e6e8ec;
  font-size: 14px;
  cursor: pointer;
}

.tool.active { background: #4f7cff; border-color: #4f7cff; color: #fff; }

.colors { display: flex; gap: 6px; }

/* Зона нажатия 44×44, а сам кружок меньше: пальцем попасть легко,
   а панель не превращается в пять огромных пятен. */
.color-dot {
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: none !important;
  cursor: pointer;
  position: relative;
}

.color-dot::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border-radius: 50%;
  background: var(--dot);
  border: 2px solid transparent;
}

.color-dot.active::after { border-color: #fff; box-shadow: 0 0 0 2px #4f7cff; }

.ed-status { color: #9aa2b1; font-size: 12px; margin-left: auto; }

.editor-stage {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

/* Рамка ровно по снимку: разметка ложится поверх пиксель в пиксель.
   Положение и масштаб задаёт transform от левого верхнего угла сцены,
   поэтому никакого центрирования флексом — иначе сдвиг был бы двойным. */
.editor-frame {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.editor-frame img { display: block; width: 100%; height: 100%; }

/* Лупа над пальцем: место, куда ставят точку, закрыто самим пальцем */
.loupe {
  position: absolute;
  width: 128px;
  height: 128px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.55);
  background-repeat: no-repeat;
  background-color: #000;
  pointer-events: none;
  z-index: 4;
}

/* перекрестие — видно точную точку под пальцем */
.loupe::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  border: 2px solid rgba(79, 124, 255, 0.95);
  border-radius: 50%;
}

.editor-frame svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.editor-hint {
  padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
  background: #0a0a0a;
  color: #8b93a1;
  font-size: 13px;
  text-align: center;
}

.label-box {
  position: absolute;
  left: 50%;
  bottom: calc(60px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  z-index: 3;
}

.label-box input {
  width: 190px;
  padding: 10px;
  min-height: 44px;
  border: 2px solid #e3e6ec;
  border-radius: 10px;
  font-size: 16px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 10000;
  padding: 10px 16px;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  font-size: 14px;
}

/* Атрибут hidden не спрячет элемент, которому задан display —
   поэтому у каждого такого класса своё правило. Наступали на это не раз. */
.toast[hidden],
.editor[hidden],
.label-box[hidden],
.size-ctl[hidden],
.loupe[hidden],
.bar-row .icon-btn[hidden],
.login-screen[hidden],
.topbar .icon-btn[hidden],
.row-form .progress[hidden] { display: none !important; }

@media (max-width: 640px) {
  .photos { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .photo-tile img { height: 130px; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .tool { padding: 0 10px; font-size: 13px; }
}
