:root {
  --bg: #101418;
  --card: #1a2027;
  --card-2: #232b34;
  --text: #e8edf2;
  --muted: #8b98a5;
  --accent: #3b82f6;
  --accent-2: #2563eb;
  --danger: #ef4444;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}
.wrap { max-width: 900px; margin: 0 auto; padding: 16px; }
.center { text-align: center; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); }
h1 { font-size: 24px; margin: 8px 0; }
h2 { font-size: 18px; margin: 0 0 12px; }
em { font-style: normal; }
hr { border: none; border-top: 1px solid var(--card-2); margin: 16px 0; }

/* компактная шапка: логотип и название в левом верхнем углу */
.topbar { display: flex; align-items: baseline; gap: 10px; padding: 8px 0 0; margin-bottom: 14px; }

/* переключатель языка: флаги, активный подсвечен */
.lang-sw { margin-left: auto; display: flex; gap: 2px; align-self: center; }
.lang-sw button {
  background: none; border: none; padding: 2px 4px;
  font-size: 18px; line-height: 1; cursor: pointer;
  opacity: .4; filter: grayscale(.4);
  border-radius: 6px;
  transition: opacity .12s;
}
.lang-sw button:hover { opacity: .8; }
.lang-sw button.on { opacity: 1; filter: none; }

/* главная: инструменты внизу, форма отцентрирована по вертикали.
   margin:auto (а не justify-content) — при нехватке места (клавиатура,
   длинное описание) схлопывается в 0 и остаётся обычный скролл,
   верх карточки не уезжает за экран. */
.page {
  display: flex; flex-direction: column;
  min-height: 100dvh;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}
.stage { margin: auto 0; width: 100%; }
/* фикс-высота строки статуса — включение геометки не дёргает центровку */
.toggles-status { min-height: 1.4em; margin: 6px 0 0; }
.toggles-status:empty::before { content: '\00a0'; }
.logo { font-size: 18px; font-weight: 700; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 10px 0;
  border: 1px solid rgba(139,152,165,.08);
}

.field { display: block; margin-bottom: 10px; }
.field span { display: block; font-size: 14px; margin-bottom: 4px; color: var(--muted); }
input[type="text"], input[type="password"], textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: 9px;
  border: 1px solid var(--card-2);
  background: var(--bg);
  color: var(--text);
  font-size: 16px; /* iOS не зумит поля с 16px+ */
  font-family: inherit;
}
textarea { resize: vertical; line-height: 1.4; }
input:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.album-desc { margin: 2px 0 0; white-space: pre-wrap; }
#geo-status { margin-top: 6px; }
.check { display: flex; gap: 8px; align-items: center; margin: 6px 0; color: var(--muted); }

.drop {
  border: 1px dashed #39434f;
  border-radius: var(--radius);
  text-align: center;
  padding: 14px 16px;
  margin-top: 10px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop:focus-visible, .drop.over { border-color: var(--accent); background: rgba(59,130,246,.06); }
.drop-icon { font-size: 24px; margin-bottom: 2px; }
.camera-btn { margin-top: 10px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid rgba(139,152,165,.25);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: .01em;
  cursor: pointer;
  text-decoration: none;
  user-select: none;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: rgba(139,152,165,.1); border-color: rgba(139,152,165,.45); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.danger { border-color: rgba(239,68,68,.4); color: var(--danger); }
.btn.danger:hover { background: rgba(239,68,68,.08); border-color: var(--danger); }
.btn.wide { width: 100%; }
.small-btn { min-height: 28px; padding: 3px 10px; font-size: 13px; }
/* На узких экранах кнопки выстраиваются ровной сеткой 2×N с равной
   шириной; нечётная последняя занимает всю строку — без «рваных» рядов. */
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0 0; }
.row > :last-child:nth-child(odd) { grid-column: 1 / -1; }
@media (min-width: 600px) {
  .row { display: flex; flex-wrap: wrap; align-items: center; }
}

.bar { height: 10px; border-radius: 5px; background: var(--bg); overflow: hidden; margin: 10px 0; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.errors { color: var(--danger); font-size: 14px; padding-left: 18px; }
.errors:empty { display: none; }

.linkbox { display: flex; gap: 8px; }
.linkbox input { flex: 1; min-width: 0; font-size: 14px; }
.icon-btn { flex: none; width: 40px; padding: 0; }
.icon-btn .ic-check { display: none; }
.icon-btn.ok { border-color: #22c55e; color: #22c55e; }
.icon-btn.ok .ic-copy { display: none; }
.icon-btn.ok .ic-check { display: block; }
.qr-details { margin-top: 14px; }
/* ключ владельца — предупреждающее оформление, чтобы не путать
   с публичной ссылкой для получателей */
.owner-box {
  margin-top: 14px;
  border: 1px solid rgba(245, 158, 11, .35);
  border-radius: 10px;
  padding: 10px 12px;
}
.owner-box summary { cursor: pointer; color: #f59e0b; font-weight: 600; }
.owner-box .linkbox { margin-top: 8px; }
.owner-box .qr-details { margin-top: 8px; }
#owner-qr { margin-top: 10px; }
.qr-details summary { cursor: pointer; color: var(--muted); }
.qr { width: 200px; max-width: 100%; border-radius: 10px; margin-top: 10px; background: #fff; padding: 8px; }

/* список «Мои альбомы» */
.albums { list-style: none; margin: 0; padding: 0; }
.albums a {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 10px 2px;
  color: var(--text); text-decoration: none;
  border-bottom: 1px solid rgba(139,152,165,.12);
  font-size: 15px;
}
.albums li:last-child a { border-bottom: none; }
.albums a:hover .album-name { color: var(--accent); }
.albums a.cur .album-name { color: var(--accent); }
.albums .album-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.albums .muted { flex: none; font-size: 13px; }
#switcher .row { margin-top: 14px; }

/* панель управления альбомом внизу экрана */
#album-root { padding-bottom: 96px; } /* галерея не прячется за панелью */
.toolbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around; align-items: stretch;
  background: rgba(26, 32, 39, .97);
  backdrop-filter: blur(8px);
  border-top: 1px solid rgba(139,152,165,.15);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.tb-btn {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: none; border: none;
  color: var(--muted); font-size: 11px; line-height: 1.2;
  padding: 4px 6px; min-width: 52px;
  cursor: pointer; text-decoration: none;
  border-radius: 10px;
  transition: background .12s, color .12s;
}
.tb-btn:hover { background: rgba(139,152,165,.12); color: var(--text); }
.tb-btn:active { transform: scale(.95); }
.tb-btn .ic { display: flex; align-items: center; justify-content: center; height: 26px; }
.tb-btn .ic svg { display: block; }
/* включённый тумблер подсвечен акцентом */
.tb-btn.on { color: var(--accent); }
.tb-btn.danger { color: var(--danger); opacity: .85; }
.tb-btn.danger:hover { color: var(--danger); opacity: 1; }
@media (min-width: 600px) {
  .toolbar { justify-content: center; gap: 28px; }
}

/* галерея */
.album-head { padding-top: 8px; }
.album-title-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.title-btn {
  display: inline-flex; align-items: baseline; gap: 7px;
  background: none; border: none; padding: 0; margin: 0;
  color: inherit; font: inherit; cursor: pointer; text-align: left;
}
.title-btn .chev { color: var(--muted); font-size: 15px; }
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 6px;
  margin-top: 16px;
}
@media (min-width: 600px) {
  .gallery { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
}
.tile {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  background: var(--card);
  cursor: pointer;
  border: none;
  padding: 0;
}
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile-del {
  position: absolute; top: 4px; right: 4px; z-index: 2;
  width: 26px; height: 26px; border-radius: 50%;
  border: none;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(2px);
  color: #fff; font-size: 13px; line-height: 1;
  cursor: pointer;
}
.tile-del:hover { background: rgba(239,68,68,.9); }
.tile .noimg {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; gap: 6px; color: var(--muted); font-size: 12px; padding: 8px; word-break: break-all;
}
.tile .noimg .ic { font-size: 28px; }

/* оверлеи: margin:auto центрирует карточку, а когда содержимое выше
   экрана (настройки с раскрытым QR владельца) — даёт прокрутку вместо
   обрезания краёв */
.overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,.65);
  display: flex;
  padding: 16px;
  overflow-y: auto;
}
.overlay .card { width: 100%; max-width: 420px; margin: auto; }

/* лайтбокс */
.lightbox {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.92);
  display: flex; align-items: center; justify-content: center;
  touch-action: pan-y;
}
.lightbox img {
  max-width: 100vw;
  max-height: calc(100vh - 70px);
  object-fit: contain;
}
.lb-btn {
  position: absolute; z-index: 51;
  background: rgba(20,24,28,.6);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255,255,255,.35);
  color: #fff;
  width: 46px; height: 46px; border-radius: 50%;
  font-size: 24px; font-weight: 700; line-height: 1;
  cursor: pointer;
  text-shadow: 0 1px 3px rgba(0,0,0,.8);
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
  transition: background .12s, border-color .12s;
}
.lb-btn:hover { background: rgba(59,130,246,.6); border-color: rgba(255,255,255,.6); }
.lb-close { top: max(10px, env(safe-area-inset-top)); right: 12px; }
.lb-prev { left: 8px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 8px; top: 50%; transform: translateY(-50%); }
/* прелоадер лайтбокса: тяжёлое фото на медленной сети — видно, что грузится */
.lb-spin {
  position: absolute; z-index: 52;
  width: 46px; height: 46px;
  border: 3px solid rgba(255,255,255,.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: lb-rotate .8s linear infinite;
  pointer-events: none;
}
@keyframes lb-rotate { to { transform: rotate(360deg); } }
#geo-refresh { margin: 0 0 10px; }
#set-geo-status { margin: -4px 0 8px; }
.lb-bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,.7));
}
.lb-name { flex: 1; font-size: 13px; color: #cbd5e1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* встроенная камера с серийной съёмкой */
.camera {
  position: fixed; inset: 0; z-index: 60;
  background: #000;
  display: flex; align-items: center; justify-content: center;
}
.camera video { width: 100%; height: 100%; object-fit: cover; }
#cam-flash {
  position: absolute; inset: 0;
  background: #fff; opacity: 0; pointer-events: none;
  transition: opacity .1s;
}
#cam-flash.on { opacity: .7; transition: none; }
.cam-count {
  position: absolute; top: max(14px, env(safe-area-inset-top)); left: 0; right: 0;
  text-align: center; color: #fff; font-size: 14px;
  text-shadow: 0 1px 3px rgba(0,0,0,.8);
}
.cam-bar {
  position: absolute; left: 0; right: 0;
  bottom: calc(18px + env(safe-area-inset-bottom));
  display: flex; align-items: center; justify-content: center; gap: 44px;
}
.cam-btn {
  width: 48px; height: 48px; border-radius: 50%;
  border: none; background: rgba(255,255,255,.14);
  backdrop-filter: blur(4px);
  color: #fff; font-size: 20px; cursor: pointer;
}
.cam-shutter {
  width: 68px; height: 68px; border-radius: 50%;
  background: #fff; cursor: pointer;
  border: 4px solid rgba(255,255,255,.35);
  background-clip: padding-box;
  transition: transform .08s;
}
.cam-shutter:active { transform: scale(.9); }
.cam-done {
  width: auto;
  padding: 0 20px;
  border-radius: 24px;
  font-size: 15px;
  font-weight: 600;
}

footer { text-align: center; margin: 14px 0; }
