/* Lumi — молочно-пастельный мобильный стиль v0.6+ */
:root{
  --bg: #FBF6F0;
  --surface: #FFFDF9;
  --surface-2: #F7EFE5;
  --ink: #3A2E2A;
  --ink-soft: #6B5C56;
  --line: #EFE2D5;
  --accent: #E89BB6;
  --accent-soft: #FBE2EA;
  --lav: #B7A6E0;
  --lav-soft: #ECE6FA;
  --mint: #A8D6C2;
  --peach: #F4C9A8;
  --ok: #6FBF9B;
  --warn: #E89B6A;
  --shadow: 0 8px 24px rgba(110, 80, 60, 0.08), 0 2px 6px rgba(110, 80, 60, 0.05);
  --shadow-strong: 0 14px 36px rgba(110, 80, 60, 0.12), 0 4px 10px rgba(110, 80, 60, 0.06);
  --radius-lg: 28px;
  --radius-md: 20px;
  --radius-sm: 14px;
  --checker-a: #FFFFFF;
  --checker-b: #E7E7EA;
}

*{box-sizing:border-box;-webkit-tap-highlight-color:transparent;}
html,body{margin:0;padding:0;}
html{scroll-behavior:smooth;}
body{
  font-family:-apple-system,BlinkMacSystemFont,"SF Pro Display","Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height:100vh;
  -webkit-font-smoothing:antialiased;
  text-rendering:optimizeLegibility;
  font-size:17px;
  line-height:1.45;
  overflow-x:hidden;
  padding-bottom: env(safe-area-inset-bottom);
}

[hidden]{display:none !important;}

/* ===== звёздочки вокруг логотипа и заголовка ===== */
.stars{
  position: fixed;
  inset: 0 0 auto 0;
  height: 360px;
  pointer-events: none;
  z-index: 0;
}
.star{
  position: absolute;
  width: 16px; height: 16px;
  fill: var(--accent);
  opacity: 0.5;
  filter: drop-shadow(0 0 5px rgba(232,155,182,.4));
  animation: twinkle 5s ease-in-out infinite;
  transform-origin: center;
}
.star.s1{ top: 18px; left: 14%; animation-delay: 0s; width: 14px; height: 14px; }
.star.s2{ top: 52px; right: 18%; animation-delay: 0.7s; width: 10px; height: 10px; fill: var(--lav); filter: drop-shadow(0 0 5px rgba(183,166,224,.4)); }
.star.s3{ top: 90px; left: 32%; animation-delay: 1.4s; width: 18px; height: 18px; }
.star.s4{ top: 132px; right: 34%; animation-delay: 2.1s; width: 12px; height: 12px; fill: var(--lav); filter: drop-shadow(0 0 5px rgba(183,166,224,.4)); }
.star.s5{ top: 42px; left: 6%; animation-delay: 2.8s; width: 9px; height: 9px; }
.star.s6{ top: 158px; right: 10%; animation-delay: 3.5s; width: 14px; height: 14px; }
.star.s7{ top: 200px; left: 22%; animation-delay: 1s; width: 8px; height: 8px; fill: var(--lav); filter: drop-shadow(0 0 5px rgba(183,166,224,.4)); }
.star.s8{ top: 230px; right: 24%; animation-delay: 2.4s; width: 10px; height: 10px; }
@keyframes twinkle{
  0%, 100% { opacity: 0.2;  transform: scale(0.85) rotate(0deg); }
  50%      { opacity: 0.85; transform: scale(1.1)  rotate(18deg); }
}
@media (prefers-reduced-motion: reduce){
  .star{ animation: none; opacity: 0.5; }
}

/* ===== шапка ===== */
.topbar{
  display:flex;align-items:center;
  padding: 18px 22px 4px;
  position: relative; z-index: 1;
}
.brand{display:flex;align-items:center;gap:10px;}
.logo-mark{width:36px;height:36px;display:block;}
.logo-text{font-weight:700;font-size:20px;letter-spacing:0.2px;}

.page{padding: 8px 18px 32px;max-width:560px;margin:0 auto;position:relative;z-index:1;}

/* hero */
.hero{ text-align:center; padding: 16px 4px 28px; position:relative; }
.title{
  font-size:44px; line-height:1.05; margin: 6px 0 6px;
  letter-spacing:-0.5px; font-weight:700;
  background: linear-gradient(135deg,#E89BB6 0%,#B7A6E0 100%);
  -webkit-background-clip:text; background-clip:text; color:transparent;
}
.tagline{ margin:0 0 14px; font-size:17px; color: var(--ink-soft); }
.tagline .sparkle{ display:inline-block; transform: translateY(-1px); }
.lede{ margin:0 auto 22px; max-width:36ch; color: var(--ink-soft); font-size:15px; }

/* кнопки */
.btn{
  appearance:none;border:0;cursor:pointer;
  display:inline-flex;align-items:center;justify-content:center;gap:10px;
  font: inherit; color: inherit;
  padding: 14px 20px;
  min-height: 52px;
  border-radius: var(--radius-md);
  transition: transform .15s ease, box-shadow .25s ease, background .25s ease, color .25s ease, opacity .25s ease;
  user-select:none; -webkit-user-select:none;
}
.btn:active{ transform: translateY(1px) scale(0.98); }
.btn:disabled{ opacity:.45; cursor:not-allowed; transform:none; }
.btn-icon{ font-size:18px; line-height:1; }

.btn-primary{
  background: linear-gradient(135deg,#F2A8C2 0%,#C5B2EA 100%);
  color:#FFF; box-shadow: var(--shadow);
}
.btn-primary:hover{ box-shadow: var(--shadow-strong); }
.btn-primary:active{ box-shadow: 0 2px 8px rgba(180,120,160,.25); }

.btn-secondary{
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.btn-secondary:hover{ background: var(--surface-2); }

.btn-ghost{
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--line);
}
.btn-ghost:hover{ background: var(--surface); color: var(--ink); }

.btn-xl{
  width: 100%;
  padding: 18px 22px;
  font-size: 17px;
  font-weight: 600;
  border-radius: var(--radius-lg);
  min-height: 60px;
}
.btn-process{ margin-top: 6px; }

.btn-mini{ padding:10px 14px; min-height:44px; font-size:14px; border-radius: 14px; background: var(--accent-soft); color: var(--ink); }
.btn-mini:hover{ background:#F7D2DF; }

.hint{
  margin: 14px 0 0; color: var(--ink-soft); font-size:14px;
}

/* workspace */
.workspace-head{
  display:flex;align-items:center;justify-content:space-between;gap:10px;
  margin: 6px 2px 12px;
}
.counter{ display:flex; align-items:baseline; gap:8px; }
.counter-label{ font-size:13px; color: var(--ink-soft); }
.counter-value{ font-size:17px; font-weight:600; }
#addMoreBtn{ min-height:44px; padding: 10px 14px; border-radius: 14px; }

/* сетка фото */
.photo-grid{
  list-style:none;margin:0 0 18px;padding:0;
  display:grid;grid-template-columns:1fr 1fr;gap:12px;
}
.photo-card{
  background: var(--surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 10px 10px 12px;
  position:relative;
  display:flex;flex-direction:column;gap:8px;
  transition: transform .25s ease, box-shadow .25s ease;
  animation: cardIn .35s ease both;
}
@keyframes cardIn{
  from{ opacity:0; transform: translateY(6px) scale(.98); }
  to{ opacity:1; transform: none; }
}
/* сам холст фото — без скруглений, прямые углы */
.photo-thumb-canvas{
  width:100%;
  border-radius: 0;
  background: #FFFFFF;
  display:block;
}
.photo-name{
  font-size:13px; font-weight:600; word-break:break-all;
  display:-webkit-box;-webkit-line-clamp:1;-webkit-box-orient:vertical;overflow:hidden;
}
.photo-meta{ font-size:12px; color: var(--ink-soft); display:flex; gap:8px; flex-wrap:wrap; }
.photo-meta .fmt{ background: var(--accent-soft); color: var(--ink); padding:2px 8px; border-radius: 999px; font-weight:600; }
.photo-status{
  font-size:12px; display:flex; align-items:center; gap:6px;
  padding: 6px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-soft);
  align-self:flex-start;
}
.photo-status.is-ok{ background:#E2F4EB; color:#2F7A55; }
.photo-status.is-warn{ background:#FCE7D7; color:#B05A2A; }
.photo-status.is-done{ background:#E2F4EB; color:#2F7A55; }

.card-remove{
  position:absolute; top:6px; right:6px;
  width: 44px; height:44px; border-radius:999px;
  background: rgba(255,255,255,.92); color: var(--ink);
  border:1px solid var(--line); box-shadow: var(--shadow);
  display:flex;align-items:center;justify-content:center;
  font-size:18px; cursor:pointer;
  z-index: 2;
}
.card-remove:hover{ background:#FBE2EA; color:#A24A6E; }

.card-retry{
  align-self:flex-start;
  margin-top:-2px;
  background: var(--surface-2); color: var(--ink);
  border:1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; font-size:14px; cursor:pointer; min-height:44px;
}

/* настройки */
.settings-card{
  background: var(--surface);
  border-radius: var(--radius-lg);
  border:1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 18px 16px 18px;
  margin-top: 6px;
}
.settings-title{
  margin: 0 0 14px; font-size: 16px; font-weight: 700; letter-spacing:.2px;
}
.field-group{ margin-bottom: 16px; }
.field-label{
  display:block; font-size:13px; color: var(--ink-soft);
  margin-bottom: 8px; letter-spacing:.3px;
}

.size-presets, .format-chips{
  display:flex; flex-wrap:wrap; gap:8px;
}
.chip{
  appearance:none;border:1px solid var(--line); background: var(--surface);
  color: var(--ink); font: inherit; cursor:pointer;
  padding: 10px 14px; min-height:44px; border-radius: 14px;
  font-size:14px; transition: background .2s ease, border-color .2s ease, color .2s ease, box-shadow .2s ease;
}
.chip:hover{ background: var(--surface-2); }
.chip.is-active{
  background: var(--accent-soft); border-color:#F2C0CF; color:#A24A6E;
  box-shadow: inset 0 0 0 2px rgba(232,155,182,.15);
}
.chip:disabled{ opacity:.4; cursor:not-allowed; }
.chip-custom{ color: var(--ink-soft); }

.custom-size{
  display:flex; align-items:flex-end; gap:10px; margin-top:10px;
  background: var(--surface-2); padding: 12px; border-radius: 16px;
}
.custom-input{ display:flex; flex-direction:column; gap:4px; flex:1; min-width:0; }
.custom-input label{ font-size:12px; color: var(--ink-soft); }
.custom-input input{
  appearance:none; border:1px solid var(--line); background:#FFF;
  border-radius: 12px; padding: 10px 12px; font-size:15px; min-height:44px;
  width:100%; color: var(--ink);
}
.custom-input input:focus{ outline:none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(232,155,182,.18); }
.custom-x{ font-size:18px; color: var(--ink-soft); padding-bottom:10px; }

.mode-toggle{ display:grid; grid-template-columns:1fr 1fr; gap:10px; }
.mode-btn{
  appearance:none;border:1px solid var(--line); background: var(--surface);
  border-radius: 16px; padding: 12px; text-align:left; cursor:pointer;
  display:flex; flex-direction:column; gap:4px; min-height:64px;
  transition: background .2s, border-color .2s, box-shadow .2s;
}
.mode-btn:hover{ background: var(--surface-2); }
.mode-btn.is-active{
  background: var(--lav-soft); border-color:#D2C7F0; box-shadow: inset 0 0 0 2px rgba(183,166,224,.15);
}
.mode-title{ font-weight:600; font-size:14px; }
.mode-sub{ font-size:12px; color: var(--ink-soft); }

.mode-note{ margin: 10px 0 0; font-size:13px; color: var(--ink-soft); }

.progress-wrap{ margin-top: 14px; }
.progress-text{ margin:0 0 6px; font-size:13px; color: var(--ink-soft); }
.progress-bar{ width:100%; height:8px; background: var(--surface-2); border-radius:999px; overflow:hidden; }
.progress-fill{ height:100%; width:0%; background: linear-gradient(90deg,#F2A8C2,#C5B2EA); transition: width .25s ease; }

/* результаты */
.results{ margin-top: 22px; }
.results-head{ margin-bottom: 12px; }
.results-title{ margin:0 0 4px; font-size:18px; font-weight:700; }
.results-sub{ margin:0; color: var(--ink-soft); font-size:14px; }

.results-grid{
  list-style:none;margin:0;padding:0;
  display:grid;grid-template-columns:1fr 1fr;gap:12px;
}
.result-card{
  background: var(--surface);
  border-radius: var(--radius-md);
  border:1px solid var(--line);
  box-shadow: var(--shadow);
  padding:10px 10px 12px;
  display:flex;flex-direction:column;gap:8px;
  transition: transform .15s ease, box-shadow .2s ease;
}
.result-card:hover{ box-shadow: var(--shadow-strong); }
/* само готовое фото — без скруглений */
.result-thumb{
  width:100%;aspect-ratio: 4/5; border-radius:0;
  background: var(--surface-2); object-fit:cover; display:block;
}
.result-meta{ font-size:12px; color: var(--ink-soft); display:flex; gap:8px; flex-wrap:wrap; }
.result-meta .fmt{ background: var(--lav-soft); color:#5A4A8C; padding:2px 8px; border-radius:999px; font-weight:600; }
.result-name{ font-size:13px; font-weight:600; word-break:break-all;
  display:-webkit-box;-webkit-line-clamp:1;-webkit-box-orient:vertical;overflow:hidden; }
.result-status{ font-size:12px; padding:6px 10px; border-radius:999px; align-self:flex-start; }
.result-status.is-done{ background:#E2F4EB; color:#2F7A55; }
.result-status.is-saved{ background:#DBE9F8; color:#2A5A8C; }
.result-status.is-saving{ background: var(--lav-soft); color:#5A4A8C; }
.result-status.is-warn{ background:#FCE7D7; color:#B05A2A; }

/* footer */
.footer{ display:flex; justify-content:center; margin-top: 18px; }
.btn-clear{ width: 100%; }

/* toast */
.toast{
  position: fixed; left: 50%; bottom: 24px;
  transform: translateX(-50%) translateY(10px);
  background: var(--ink); color:#FFF;
  padding: 12px 16px; border-radius: 14px;
  box-shadow: var(--shadow-strong);
  font-size: 14px; max-width: 86vw; text-align:center;
  opacity:0; pointer-events:none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 80;
}
.toast.is-show{ opacity:1; transform: translateX(-50%) translateY(0); }
.toast.is-warn{ background:#B05A2A; }
.toast.is-ok{ background:#2F7A55; }

/* ===== модалка просмотра — бежевая, без модального окна, фото на весь экран ===== */
.modal{
  position:fixed;inset:0;
  display:flex; flex-direction:column;
  z-index: 70;
  animation: fadeIn .2s ease both;
}
@keyframes fadeIn{ from{opacity:0} to{opacity:1} }

.modal-view{
  background: var(--bg);
  color: var(--ink);
  transition: transform .25s ease, opacity .25s ease;
}
.modal-view.is-swiping{ transition: none; }
.view-close{
  position: absolute; top: 14px; right: 14px; z-index: 2;
  width: 44px; height:44px; border-radius: 999px;
  background: rgba(255,255,255,.92); color: var(--ink);
  border:1px solid var(--line); box-shadow: var(--shadow);
  display:flex; align-items:center; justify-content:center;
  font-size:18px; cursor:pointer;
}
.view-close:active{ transform: translateY(1px) scale(0.98); }

.view-stage{
  flex:1;
  position:relative;
  overflow:hidden;
  display:flex; align-items:center; justify-content:center;
  touch-action: pan-y;
  user-select:none; -webkit-user-select:none;
  padding: 16px;
}
.view-image{
  max-width:100%; max-height:100%;
  display:block;
  transform-origin: 0 0;
  will-change: transform;
  user-select:none; -webkit-user-drag:none;
  -webkit-user-select:none;
  pointer-events: auto;
  transition: transform .2s ease, opacity .2s ease;
}
.view-hint{
  position: absolute; bottom: 14px; left: 50%;
  transform: translateX(-50%);
  margin: 0;
  font-size: 12px; color: var(--ink-soft);
  background: rgba(255,253,249,.85);
  padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line);
  pointer-events: none;
  z-index: 2;
}

/* ===== модалка кадрирования — бежевый фон + белый холст выбранного размера с шахматкой на пустых местах ===== */
.modal-crop{
  background: var(--bg);
  color: var(--ink);
}
.crop-stage{
  flex:1;
  position:relative;
  background: var(--bg);
  overflow:hidden;
  touch-action: none;
  user-select:none; -webkit-user-select:none;
}
/* холст кадрирования: белая подложка + плотная светло-серая шахматка */
.crop-frame{
  position:absolute; inset:0;
  overflow:hidden;
  /* чёткая светло-серая шахматка — видна на пустых местах, не сливается с бежевым */
  background-color: #FFFFFF;
  background-image:
    linear-gradient(45deg, #E7E7EA 25%, transparent 25%),
    linear-gradient(-45deg, #E7E7EA 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #E7E7EA 75%),
    linear-gradient(-45deg, transparent 75%, #E7E7EA 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  box-shadow:
    0 0 0 1px rgba(58,46,42,.08),
    0 12px 36px rgba(110, 80, 60, 0.14);
}
.crop-image{
  position:absolute; left:0; top:0;
  transform-origin: 0 0;
  will-change: transform;
  user-select:none; -webkit-user-drag:none;
  -webkit-user-select:none;
  pointer-events: auto;
}

.crop-controls{
  position: relative;
  display:flex; gap:10px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: var(--bg);
  flex-shrink:0;
}
.btn-half{ flex:1; }
.crop-close{
  position: absolute; top: -56px; right: 14px;
  width: 44px; height:44px; border-radius: 999px;
  background: rgba(255,255,255,.92); color: var(--ink);
  border:1px solid var(--line); box-shadow: var(--shadow);
  display:flex; align-items:center; justify-content:center;
  font-size:18px; cursor:pointer;
}
.crop-close:active{ transform: translateY(1px) scale(0.98); }

/* ===== превью-обёртка + одна большая фирменная розовая кнопка ✂️ Кадрировать ===== */
.photo-thumb-wrap{
  appearance:none;border:0;padding:0;background:transparent;cursor:pointer;
  display:block; width:100%; border-radius: 0; overflow:hidden;
}
.photo-thumb-wrap:active{ transform: translateY(1px) scale(0.99); }

.photo-target{
  display:flex; align-items:center; justify-content:space-between;
  gap:6px; font-size:12px; color: var(--ink-soft);
  margin-top: -2px;
}
.photo-target .dot{ opacity:.55; margin: 0 2px; }
.photo-cropped{ background:#E2F4EB; color:#2F7A55; padding:2px 8px; border-radius:999px; font-weight:600; font-size:11px; }
.photo-empty{ background:#E7E7EA; color:#5A4A8C; padding:2px 8px; border-radius:999px; font-weight:600; font-size:11px; }

/* единственная кнопка под фото — фирменная розовая */
.card-actions{ display:flex; margin-top: 6px; }
.btn-mini-crop{
  width:100%;
  min-height: 52px;
  padding: 14px 16px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 18px;
  background: linear-gradient(135deg,#F2A8C2 0%,#C5B2EA 100%);
  color: #FFF;
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(180,120,160,.22);
  text-shadow: 0 1px 0 rgba(0,0,0,.04);
  transition: transform .15s ease, box-shadow .25s ease, filter .25s ease;
}
.btn-mini-crop:hover{
  filter: brightness(1.03);
  box-shadow: 0 10px 26px rgba(180,120,160,.32);
}
.btn-mini-crop:active{
  transform: translateY(1px) scale(0.985);
  box-shadow: 0 3px 10px rgba(180,120,160,.22);
}
.btn-mini-crop:disabled{ opacity:.55; cursor:not-allowed; filter: grayscale(.1); }
.btn-mini-crop .crop-ico{
  width: 18px; height: 18px; display: inline-block;
  stroke: #FFF; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round;
}

.btn-save-all{ margin: 6px 0 12px; }
.save-progress{ margin: -6px 0 12px; }
.save-progress-text{ margin:0 0 6px; font-size:13px; color: var(--ink-soft); }
.save-progress-done{
  margin: -6px 0 12px; font-size:14px; font-weight:600;
  padding: 10px 14px; border-radius: 14px;
}
.save-progress-done.is-ok{ background:#E2F4EB; color:#2F7A55; }
.save-progress-done.is-warn{ background:#FCE7D7; color:#B05A2A; }

.btn-mini-save{
  width:100%; margin-top: 6px;
  min-height:44px; padding: 10px 12px;
  background: var(--accent-soft); color:#A24A6E;
  border:1px solid #F2C0CF; border-radius: 14px;
  font-size:14px; font-weight:600; cursor:pointer;
  display:inline-flex; align-items:center; justify-content:center;
  transition: background .2s ease, transform .1s ease, opacity .2s ease;
}
.btn-mini-save:hover{ background:#F7D2DF; }
.btn-mini-save:active{ transform: translateY(1px) scale(0.98); }
.btn-mini-save:disabled{ opacity:.6; cursor:default; }

.result-thumb-wrap{
  appearance:none;border:0;padding:0;background:transparent;cursor:pointer;
  display:block; width:100%; border-radius: 0; overflow:hidden;
}
.result-thumb-wrap:active{ transform: translateY(1px) scale(0.99); }

@media (min-width: 720px){
  .photo-grid, .results-grid{ grid-template-columns: repeat(3, 1fr); }
}
@media (prefers-reduced-motion: reduce){
  *, *::before, *::after{ animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* скрытый file input — кликается программно, но iPhone Safari не блокирует change */
.file-hidden{
  position: fixed;
  left: -10000px;
  top: 0;
  width: 44px;
  height: 44px;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

/* Focused repair: full viewport viewer and one clear crop action. */
.btn-mini-crop{width:100%;min-height:48px;background:#F0B5CC;color:#573E47;border:1px solid #E5A0BA;border-radius:14px;font-size:15px;font-weight:700;box-shadow:0 4px 12px #e89bb633;}
.card-actions{display:block;}
.photo-thumb-wrap{overflow:hidden;border-radius:0;min-width:0;width:100%;padding:0;}
.view-stage{padding:0;display:block;}
.view-image{position:absolute;left:0;top:0;max-width:none;max-height:none;pointer-events:none;}
.crop-image{pointer-events:none;max-width:none;max-height:none;}
.crop-frame{touch-action:none;}
@media(prefers-reduced-motion:reduce){.stars .star,.star{animation:none!important}}

.view-hint{display:none;} /* No swipe instruction until a swipe handler exists. */
