:root {
  --tw: 150px;             /* ширина плитки; у Atavi было около 200 */
  --gap: 14px;
  --bar-h: 48px;
  /* светлая салатовая гамма, как у Home (home.smanek.online, светлая тема) */
  --bg: #bfd093;
  --bg2: #e6efcd;
  --bg3: #cfdfa6;
  --fg: #232a13;
  --dim: #5c6845;
  --panel: rgba(232, 240, 208, .97);
  --line: #bfd488;
  --hover: rgba(90, 110, 30, .12);
  --shade: rgba(60, 70, 20, .22);
  --accent: #6f9a12;
  --danger: #c0392b;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* --- космос ---------------------------------------------------------------- */
#sky {
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(ellipse 60% 45% at 80% 15%, rgba(230, 240, 200, .45), transparent 70%),
    radial-gradient(ellipse 55% 50% at 10% 90%, rgba(150, 180, 95, .45), transparent 70%),
    linear-gradient(160deg, #cbdaa5 0%, #bfd093 55%, #b4c787 100%);
}

/* --- поиск ----------------------------------------------------------------- */
#top { display: flex; justify-content: center; padding: 28px 16px 22px; }
#search {
  display: flex; width: min(620px, 100%); height: 44px;
  background: #fff; border: 1px solid var(--line); border-radius: 22px; overflow: hidden;
  box-shadow: 0 4px 16px var(--shade);
}
#engine {
  width: 48px; border: 0; background: transparent; cursor: pointer;
  font-weight: 700; font-size: 18px; color: #d33;
}
#engine.g { color: #4285f4; }
#q { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: #111; padding: 0 16px 0 0; font-size: 16px; }

/* --- сетка плиток ---------------------------------------------------------- */
#main { padding: 0 12px calc(var(--bar-h) + 40px); }
.grid {
  display: grid; justify-content: center; gap: var(--gap);
  grid-template-columns: repeat(auto-fill, var(--tw));
  max-width: 1400px; margin: 0 auto;
}
#empty { text-align: center; color: var(--dim); margin-top: 30px; }

.tile {
  display: block; width: var(--tw); color: var(--fg); text-decoration: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation; position: relative;
}
.thumb {
  position: relative; aspect-ratio: 16 / 10; border-radius: 8px; overflow: hidden;
  background: var(--bg3);
  box-shadow: 0 3px 10px var(--shade);
  transition: transform .15s ease, box-shadow .15s ease, outline-color .15s;
  outline: 3px solid transparent; outline-offset: 0;
}
.thumb img.shot { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; pointer-events: none; }
.thumb .ph {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--tw) * .22); font-weight: 700; color: rgba(255, 255, 255, .85);
}
.thumb .ph img { width: 36%; height: auto; max-height: 60%; object-fit: contain; filter: drop-shadow(0 2px 6px rgba(0,0,0,.4)); }
.thumb .spin {
  position: absolute; right: 6px; bottom: 6px; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .3); border-top-color: #fff; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (hover: hover) {
  .tile:hover .thumb { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(60, 70, 20, .32); }
}
.cap { display: flex; align-items: center; gap: 6px; margin-top: 6px; padding: 0 2px; min-width: 0; }
.cap img { width: 16px; height: 16px; flex: none; border-radius: 3px; }
.cap span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }

/* папка: мозаика из миниатюр детей */
.folder .thumb.mosaic {
  display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 3px; padding: 4px;
  background: var(--bg2); border: 1px solid var(--line);
}
.mosaic > div { border-radius: 4px; overflow: hidden; background: var(--bg3); display: flex; align-items: center; justify-content: center; }
.mosaic > div img { width: 100%; height: 100%; object-fit: cover; object-position: top; }
.mosaic > div img.fav { width: 45%; height: auto; object-fit: contain; }
.folder .count {
  position: absolute; top: 5px; right: 5px; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: rgba(35, 42, 19, .75); color: #fff; font-size: 12px; line-height: 20px; text-align: center;
}

/* плитка «добавить» */
.tile.add .thumb {
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  background: rgba(255, 255, 255, .45); border: 2px dashed #a9c46a; box-shadow: none;
}
.tile.add svg { width: 34%; height: 34%; stroke: #7d9442; stroke-width: 2; fill: none; }

/* перетаскивание */
body.is-dragging { cursor: grabbing; }
body.is-dragging .tile { cursor: grabbing; }
.tile.dragging { opacity: .25; }
.tile.ghost {
  position: fixed; z-index: 1000; pointer-events: none; margin: 0; opacity: .92;
  transform: scale(1.06); transition: none;
}
.tile.ghost .thumb { box-shadow: 0 14px 30px rgba(60, 70, 20, .4); }
.tile.merge .thumb { outline-color: var(--accent); transform: scale(1.08); }
.tile.found { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 8px; }

/* --- нижняя панель --------------------------------------------------------- */
#bar {
  position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--bar-h) + env(safe-area-inset-bottom));
  padding: 0 8px env(safe-area-inset-bottom); display: flex; align-items: center; gap: 4px;
  background: rgba(214, 227, 180, .9); backdrop-filter: blur(10px); border-top: 1px solid var(--line); z-index: 50;
}
#tabs { flex: 1; min-width: 0; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; justify-content: center; }
#tabs::-webkit-scrollbar { display: none; }
.gtab {
  flex: none; height: 34px; padding: 0 14px; border-radius: 17px; border: 1px solid transparent;
  background: transparent; color: var(--dim); cursor: pointer; white-space: nowrap;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.gtab.on { background: var(--bg3); color: var(--fg); }
.gtab.drop { border-color: var(--accent); background: #c8de7a; color: var(--fg); }
.barbtn { flex: none; width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.barbtn:hover { background: var(--hover); }
.barbtn svg { width: 22px; height: 22px; stroke: var(--dim); stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; }

/* --- окна ------------------------------------------------------------------ */
.overlay {
  position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center;
  background: rgba(40, 50, 15, .3); backdrop-filter: blur(3px); padding: 16px;
}
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 20px 50px rgba(60, 70, 20, .35); padding: 16px; width: min(760px, 100%);
  max-height: calc(100vh - 32px); overflow: auto;
}
.panel.small { width: min(380px, 100%); display: flex; flex-direction: column; gap: 10px; }
.panel h2 { margin: 0 0 4px; font-size: 18px; font-weight: 600; }
.phead { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; }
#folderTitle { flex: 1; min-width: 0; background: transparent; border: 0; border-bottom: 1px solid transparent; font-size: 18px; font-weight: 600; padding: 4px 2px; outline: 0; }
#folderTitle:focus { border-bottom-color: var(--accent); }
#folderGrid { justify-content: start; min-height: 60px; }
.hint { color: var(--dim); font-size: 12px; margin-top: 14px; text-align: center; }
.icon { border: 0; background: transparent; cursor: pointer; width: 34px; height: 34px; border-radius: 50%; color: var(--dim); font-size: 16px; }
.icon:hover { background: var(--hover); }

.panel input:not([type=checkbox]):not([type=range]):not([type=file]), .panel select {
  width: 100%; height: 40px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; padding: 0 12px; outline: 0;
}
.panel input:focus, .panel select:focus { border-color: var(--accent); }
.panel select option { background: #fff; }
.panel label.f { display: flex; flex-direction: column; gap: 4px; color: var(--dim); font-size: 12px; }
.panel .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; flex-wrap: wrap; }
.panel .opt { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.panel .opt input[type=range] { flex: 1; max-width: 220px; }
button.primary, button.plain, a.plain {
  height: 38px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line); cursor: pointer;
  background: var(--bg3); text-decoration: none; display: inline-flex; align-items: center; color: var(--fg);
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.danger { color: var(--danger); }
.err { color: var(--danger); font-size: 13px; }

/* контекстное меню */
#menu {
  position: fixed; z-index: 300; min-width: 210px; padding: 6px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--line); box-shadow: 0 12px 34px rgba(60, 70, 20, .35);
}
#menu button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 9px 12px; border-radius: 6px; cursor: pointer;
}
#menu button:hover { background: var(--hover); }
#menu button.danger { color: var(--danger); }
#menu .sep { height: 1px; background: var(--line); margin: 4px 6px; }
#menu .lbl { padding: 6px 12px 2px; color: var(--dim); font-size: 12px; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--bar-h) + 18px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 400; background: var(--bg2); box-shadow: 0 6px 20px var(--shade); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px;
  max-width: calc(100% - 32px);
}

@media (max-width: 600px) {
  :root { --gap: 10px; }
  #top { padding: 16px 12px 14px; }
  #main { padding-left: 12px; padding-right: 12px; }
  .cap span { font-size: 12px; }
  .cap img { width: 14px; height: 14px; }
  #tabs { justify-content: flex-start; }
}
