/* foto — мобильный UI в духе iOS, тёмная тема, safe-area под «чёлку» и жест-бар */

:root {
  /* палитра «Кадра на мягких лапах» */
  --ink:        #14100E; /* фон */
  --coal:       #241C17; /* поверхности */
  --surface:    #2E251E; /* приподнятые поверхности */
  --cream:      #F2E8DC; /* основной текст */
  --amber:      #E8A33D; /* акцент на тёмном */
  --amber-deep: #8A4F10; /* акцент на светлом */
  --honey:      #F6C86A; /* hover, подсветка */
  --warm-gray:  #A2938A; /* вторичный текст */
  --moss:       #3E8E7E; /* успех */
  --brick:      #C4553B; /* ошибка */
  --line:       #3A2F27; /* границы поверхностей */

  /* рабочие алиасы (унаследованные имена) */
  --bg: var(--ink);
  --bg-elev: var(--coal);
  --bg-elev2: var(--surface);
  --text: var(--cream);
  --text-dim: var(--warm-gray);
  --accent: var(--amber);
  --accent-press: #C9882C;
  --danger: var(--brick);

  --radius: 14px;
  --radius-lg: 20px;
  --tabbar-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body { touch-action: manipulation; }
body.locked { overflow: hidden; }

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
}

/* --------------------------------------------------- каркас */

#app {
  height: 100dvh;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.view {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
}
.view.active { display: flex; }

.view-header {
  padding: calc(var(--safe-top) + 12px) 16px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  background: rgba(20, 16, 14, 0.9);
  position: sticky;
  top: 0;
  z-index: 10;
}

.view-header h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.2px;
}

.view-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
}

/* --------------------------------------------------- таб-бар */

#tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: rgba(36, 28, 23, 0.94);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--line);
  z-index: 50;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-dim);
  font-size: 10.5px;
  min-height: 44px;
}
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--accent); }

/* --------------------------------------------------- элементы форм */

.field { margin-bottom: 18px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

input[type="text"], input[type="url"], input[type="password"], textarea {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 16px; /* меньше — iOS зумит при фокусе */
  padding: 12px 14px;
  outline: none;
  appearance: none;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, textarea:focus { border-color: var(--accent); }

.hint {
  font-size: 12.5px;
  color: var(--text-dim);
  margin: 8px 2px 0;
  line-height: 1.45;
}
.hint.warn { color: var(--honey); }
.hint.center { text-align: center; }

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--ink);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: var(--radius);
  background: var(--bg-elev2);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  border: 1px solid var(--line);
  transition: transform 0.06s ease;
}
.btn:active { transform: scale(0.97); }
.btn svg { width: 18px; height: 18px; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--ink);
}
.btn.primary:active { background: var(--accent-press); }

.btn.big {
  width: 100%;
  min-height: 52px;
  font-size: 17px;
  border-radius: var(--radius-lg);
}

.btn.small { min-height: 38px; padding: 6px 14px; font-size: 13.5px; }

.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: rgba(196, 85, 59, 0.45); }
.btn[disabled] { opacity: 0.5; pointer-events: none; }

.ghost-chip {
  font-size: 12.5px;
  color: var(--text-dim);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  background: rgba(242, 232, 220, 0.04);
  max-width: 55%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --------------------------------------------------- генерация */

#gen-form { margin-bottom: 22px; }

.profile-hint {
  background: var(--bg-elev);
  border: 1px dashed var(--line);
  border-radius: var(--radius-lg);
  padding: 22px 18px;
  text-align: center;
  margin-bottom: 20px;
}
.profile-hint p { margin: 0 0 14px; color: var(--text-dim); line-height: 1.5; }

.results {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.result-card {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-elev);
  min-height: 120px;
}

.result-card img {
  display: block;
  width: 100%;
  height: auto;
}

.result-card .skeleton {
  width: 100%;
  aspect-ratio: 1;
  background: linear-gradient(110deg, var(--bg-elev) 30%, var(--bg-elev2) 50%, var(--bg-elev) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
}
@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

.result-actions {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-around;
  padding: 8px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.82));
}
.result-actions button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(46, 37, 31, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
}
.result-actions svg { width: 20px; height: 20px; }

/* --------------------------------------------------- галерея */

.gallery-grid {
  column-count: 2;
  column-gap: 8px;
}
.gallery-item {
  break-inside: avoid;
  margin-bottom: 8px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-elev);
}
.gallery-item img {
  display: block;
  width: 100%;
  height: auto;
}

.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 60px 20px;
}
.empty-avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 14px;
  border: 1px solid var(--line);
}
.empty p { margin: 0 0 16px; }

/* --------------------------------------------------- оверлеи */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.94);
  display: flex;
  flex-direction: column;
}
.overlay.hidden, .hidden { display: none !important; }

.overlay-close {
  position: absolute;
  top: calc(var(--safe-top) + 10px);
  right: 14px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(64, 52, 42, 0.8);
  color: var(--text);
  font-size: 24px;
  line-height: 1;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* просмотр */
.viewer-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 50px) 0 calc(var(--safe-bottom) + 100px);
  min-height: 0;
}
.viewer-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
}
.viewer-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--safe-bottom);
  display: flex;
  justify-content: space-around;
  padding: 10px 6px;
  background: rgba(30, 24, 20, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.viewer-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--text);
  font-size: 10.5px;
  min-height: 44px;
  min-width: 64px;
}
.viewer-action svg { width: 22px; height: 22px; }
.viewer-action.danger { color: var(--danger); }

.viewer-meta {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  left: 16px;
  right: 64px;
  font-size: 12px;
  color: var(--text-dim);
  background: rgba(30, 24, 20, 0.72);
  border-radius: 10px;
  padding: 6px 10px;
  max-height: 3.2em;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* шиты снизу */
.sheet {
  margin-top: auto;
  background: var(--bg-elev);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--safe-bottom) + 12px);
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
}
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet-head .overlay-close { position: static; width: 32px; height: 32px; font-size: 20px; }
.sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 16px 8px;
}

.edit-source img {
  display: block;
  max-height: 200px;
  max-width: 100%;
  margin: 0 auto 10px;
  border-radius: var(--radius);
}
.edit-source-actions { text-align: center; margin-bottom: 14px; }

/* прогресс */
.progress {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 0 4px;
  color: var(--text-dim);
  font-size: 14px;
}
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------- локальный редактор */

#editor { background: #000; }

.editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(var(--safe-top) + 8px) 14px 10px;
  border-bottom: 1px solid var(--line);
}
.editor-head h2 { margin: 0; font-size: 17px; }

.editor-stage {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#editor-canvas { max-width: 100%; max-height: 100%; object-fit: contain; }

.crop-rect {
  position: absolute;
  border: 2px solid #fff;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
  touch-action: none;
}
.crop-handle {
  position: absolute;
  width: 26px;
  height: 26px;
}
.crop-handle::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
}
.crop-handle[data-handle="tl"] { left: -13px; top: -13px; }
.crop-handle[data-handle="tr"] { right: -13px; top: -13px; }
.crop-handle[data-handle="bl"] { left: -13px; bottom: -13px; }
.crop-handle[data-handle="br"] { right: -13px; bottom: -13px; }

.editor-tools {
  padding: 10px 14px calc(var(--safe-bottom) + 14px);
  background: var(--bg-elev);
  border-top: 1px solid var(--line);
  max-height: 45dvh;
  overflow-y: auto;
}
.editor-tools .chip-row { margin-bottom: 10px; }

.slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.slider-row span {
  width: 92px;
  font-size: 13px;
  color: var(--text-dim);
  flex-shrink: 0;
}
.slider-row input[type="range"] {
  flex: 1;
  height: 32px;
  accent-color: var(--accent);
}

/* --------------------------------------------------- подсказка сохранения */

.hint-card {
  margin: auto;
  background: var(--bg-elev);
  border-radius: var(--radius-lg);
  padding: 18px;
  max-width: min(92vw, 420px);
  text-align: center;
}
.hint-card img {
  display: block;
  max-width: 100%;
  max-height: 40dvh;
  margin: 0 auto 14px;
  border-radius: var(--radius);
}
.hint-card p { color: var(--text-dim); line-height: 1.5; margin: 0 0 16px; font-size: 14.5px; }

/* --------------------------------------------------- вход по токену */

#auth { background: var(--bg); }

.auth-card {
  margin: auto;
  width: min(92vw, 380px);
  text-align: center;
  padding-bottom: var(--safe-bottom);
}
.auth-hero {
  display: block;
  width: 172px;
  height: 229px; /* 3:4 — как у оригинала */
  object-fit: cover;
  border-radius: 28px;
  margin: 0 auto 16px;
  border: 1px solid var(--line);
  box-shadow: 0 12px 40px rgba(232, 163, 61, 0.18), 0 4px 14px rgba(0, 0, 0, 0.5);
}
.auth-card h1 {
  margin: 0 0 6px;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0.5px;
}
.auth-slogan {
  color: var(--text);
  font-size: 16px;
  font-weight: 500;
  letter-spacing: 0.3px;
  margin: 0 0 8px;
  opacity: 0.9;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
.auth-slogan .paw {
  width: 17px;
  height: 17px;
  color: var(--accent);
  flex-shrink: 0;
}
.auth-sub {
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.5;
  margin: 0 0 22px;
}
.auth-card .token-row { margin-bottom: 12px; }
.auth-error {
  color: var(--danger);
  font-size: 13.5px;
  margin: 12px 0 0;
  line-height: 1.45;
}

/* --------------------------------------------------- токен и прочее */

.token-row { display: flex; gap: 8px; }
.token-row input { flex: 1; }
.token-row .btn { flex-shrink: 0; border-radius: var(--radius); min-width: 44px; padding: 0 12px; }
.token-row .btn svg { width: 20px; height: 20px; }

#pf-check { width: 100%; margin-top: 10px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  transform: translateX(-50%) translateY(20px);
  background: rgba(46, 37, 31, 0.95);
  color: var(--cream);
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 200;
  max-width: 88vw;
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

@media (min-width: 640px) {
  .view-body, .view-header { max-width: 680px; margin: 0 auto; width: 100%; }
  .view-header { position: sticky; left: 0; right: 0; }
  .results { grid-template-columns: repeat(3, 1fr); }
}
