:root {
  --bg: #0b0b0d;
  --bg-blur: rgba(11, 11, 13, 0.82);
  --surface: #151518;
  --surface-2: #1d1d21;
  --surface-3: #26262b;
  --line: rgba(255, 255, 255, 0.08);
  --text: #f3f3f0;
  --muted: #8e8e95;
  --accent: #d4ff3f;
  --accent-ink: #111114;
  --accent-fg: #d4ff3f;
  --danger: #ff5c55;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  --radius: 14px;
  --tile-radius: 6px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f5f2;
    --bg-blur: rgba(245, 245, 242, 0.85);
    --surface: #ffffff;
    --surface-2: #ebebe7;
    --surface-3: #e0e0db;
    --line: rgba(0, 0, 0, 0.08);
    --text: #141416;
    --muted: #6b6b72;
    --accent-fg: #5c7d00;
    --danger: #e0362e;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.16);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.ic {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 18px; border-radius: 12px;
  background: var(--surface-2); font-weight: 600;
  transition: transform .12s, background .15s;
}
.btn:active { transform: scale(.97); }
.btn-accent { background: var(--accent); color: var(--accent-ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-width: 40px; height: 40px; border-radius: 12px; color: var(--text);
  transition: background .15s;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.active { background: var(--accent); color: var(--accent-ink); }
.danger { color: var(--danger); }

/* ---------- вход ---------- */

.login {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(60% 40% at 50% 0%, rgba(212, 255, 63, 0.10), transparent 70%),
    var(--bg);
}
.login-card { width: min(360px, 100%); text-align: center; }
.login-logo { border-radius: 18px; box-shadow: 0 10px 40px rgba(212, 255, 63, 0.18); }
.login h1 { margin: 18px 0 4px; font-size: 28px; letter-spacing: -0.02em; }
.login .muted { margin: 0 0 28px; }
.field { display: block; text-align: left; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px 2px; }
.field input, .modal input[type=text] {
  width: 100%; height: 48px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); outline: none;
  font-size: 16px;
}
.field input:focus, .modal input[type=text]:focus { border-color: var(--accent-fg); }
.error { color: var(--danger); font-size: 14px; margin: -4px 0 12px; text-align: left; }

/* ---------- шапка ---------- */

.app { min-height: 100dvh; padding-bottom: calc(120px + var(--safe-b)); }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(8px + var(--safe-t)) 12px 8px 14px;
  background: var(--bg-blur);
  backdrop-filter: saturate(1.4) blur(18px);
  -webkit-backdrop-filter: saturate(1.4) blur(18px);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 750; font-size: 19px; letter-spacing: -0.02em; flex: none; }
.brand img { border-radius: 8px; }
.search {
  flex: 1; display: flex; align-items: center; gap: 8px; max-width: 520px; margin: 0 auto;
  height: 42px; padding: 0 6px 0 12px; border-radius: 12px; background: var(--surface-2);
  color: var(--muted);
}
.search input { flex: 1; min-width: 0; border: 0; outline: none; background: none; color: var(--text); font-size: 16px; }
.search input::-webkit-search-cancel-button { display: none; }
.search-close { display: none; width: 34px; min-width: 34px; height: 34px; }
.top-actions { display: flex; gap: 2px; margin-left: auto; flex: none; }
.only-mobile { display: none; }

.menu {
  position: absolute; right: 12px; top: calc(56px + var(--safe-t));
  min-width: 240px; padding: 6px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  animation: pop .14s ease-out;
}
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 12px; border-radius: 10px; text-align: left;
}
.menu button:hover { background: var(--surface-2); }
.menu button[aria-checked=true] { color: var(--accent-fg); font-weight: 600; }
.menu button[aria-checked=true]::after { content: "✓"; margin-left: auto; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 4px; }
.menu-label { font-size: 12px; color: var(--muted); padding: 8px 12px 4px; text-transform: uppercase; letter-spacing: .06em; }
.menu-stats { padding: 10px 12px 8px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu-stats b { display: block; color: var(--text); font-size: 20px; letter-spacing: -0.02em; }

@media (max-width: 719px) {
  .search { display: none; }
  .only-mobile { display: inline-flex; }
  .app.searching .brand, .app.searching .top-actions { display: none; }
  .app.searching .search { display: flex; max-width: none; }
  .app.searching .search-close { display: inline-flex; }
}

/* ---------- путь ---------- */

.crumbs {
  display: flex; align-items: center; gap: 2px; overflow-x: auto; scrollbar-width: none;
  padding: 4px 12px 10px; white-space: nowrap;
}
.crumbs::-webkit-scrollbar { display: none; }
.crumbs button {
  padding: 6px 10px; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: 15px;
}
.crumbs button:hover { background: var(--surface-2); color: var(--text); }
.crumbs button:last-child { color: var(--text); }
.crumbs .sep { color: var(--muted); opacity: .5; }
.crumbs .crumb-title { font-size: 22px; font-weight: 750; letter-spacing: -0.02em; color: var(--text); padding: 4px 10px 4px 4px; }

/* ---------- содержимое ---------- */

.content { padding: 0 12px; }
.section-label { font-size: 13px; color: var(--muted); margin: 6px 4px 8px; font-weight: 600; }

.folders {
  display: grid; gap: 8px; margin-bottom: 16px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.folders:empty { display: none; }
.folder {
  position: relative; display: flex; align-items: center; gap: 10px; min-width: 0;
  padding: 13px 14px; border-radius: 13px; background: var(--surface); text-align: left;
  border: 1px solid var(--line); transition: background .15s, transform .12s;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.folder:hover { background: var(--surface-2); }
.folder:active { transform: scale(.98); }
.folder .ic { color: var(--accent-fg); }
.folder-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.folder small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; overflow: hidden; text-overflow: ellipsis; }
.folder.selected { border-color: var(--accent-fg); box-shadow: inset 0 0 0 1px var(--accent-fg); }

.grid { display: grid; gap: 3px; grid-template-columns: repeat(3, 1fr); }
@media (min-width: 600px) {
  :root { --tile-radius: 14px; }
  .grid { gap: 12px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .content { padding: 0 20px; }
  .topbar { padding-left: 20px; padding-right: 16px; }
  .crumbs { padding-left: 18px; padding-right: 18px; }
}

.tile {
  position: relative; aspect-ratio: 9 / 16; overflow: hidden; border-radius: var(--tile-radius);
  background: var(--surface-2); display: block; width: 100%; text-align: left;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transition: transform .15s;
}
.tile:active { transform: scale(.98); }
.tile img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  opacity: 0; transition: opacity .25s;
}
.tile img.loaded { opacity: 1; }
.tile-ph {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  color: var(--muted);
}
.tile-ph .ic { width: 34px; height: 34px; stroke-width: 1.4; }
.tile-ext {
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  padding: 3px 7px; border-radius: 6px; background: var(--surface-3); color: var(--text);
}
.tile-info {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 26px 8px 7px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .72));
  color: #fff; font-size: 12px; line-height: 1.25;
}
.tile-name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.tile-size { opacity: .72; font-size: 11px; }
.tile-badge {
  position: absolute; top: 7px; right: 7px; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; background: rgba(0, 0, 0, .45); color: #fff;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.tile-badge .ic { width: 12px; height: 12px; stroke: none; }
@media (max-width: 599px) {
  .tile-info { padding: 20px 6px 5px; font-size: 11px; }
  .tile-size { display: none; }
}

.check {
  position: absolute; top: 7px; left: 7px; z-index: 2; width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .85); background: rgba(0, 0, 0, .25);
  display: grid; place-items: center; color: var(--accent-ink);
  opacity: 0; transition: opacity .15s, background .15s;
}
.check .ic { width: 14px; height: 14px; stroke-width: 3; opacity: 0; }
.folder .check { position: static; flex: none; border-color: var(--muted); display: none; }
.selecting .check { opacity: 1; }
.selecting .folder .check { display: grid; }
@media (hover: hover) {
  .tile:hover .check { opacity: 1; }
}
.selected .check { background: var(--accent); border-color: var(--accent); opacity: 1; }
.selected .check .ic { opacity: 1; }
.tile.selected { outline: 3px solid var(--accent); outline-offset: -3px; }
.tile.selected img { transform: scale(.94); border-radius: calc(var(--tile-radius) - 2px); }
.tile img { transition: opacity .25s, transform .15s; }

.skeleton { background: linear-gradient(100deg, var(--surface-2) 30%, var(--surface-3) 50%, var(--surface-2) 70%); background-size: 300% 100%; animation: shimmer 1.4s infinite linear; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 70px 24px; color: var(--muted);
}
.empty > .ic { width: 56px; height: 56px; stroke-width: 1.2; color: var(--accent-fg); margin-bottom: 14px; }
.empty b { color: var(--text); font-size: 18px; margin-bottom: 6px; }
.empty .btn { margin-top: 20px; }

.offline {
  position: fixed; left: 50%; top: calc(64px + var(--safe-t)); transform: translateX(-50%); z-index: 25;
  padding: 7px 14px; border-radius: 99px; background: var(--surface-3); font-size: 13px; box-shadow: var(--shadow);
}

/* ---------- FAB ---------- */

.fab {
  position: fixed; right: 18px; bottom: calc(20px + var(--safe-b)); z-index: 30;
  width: 62px; height: 62px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 10px 30px rgba(212, 255, 63, .28), 0 4px 12px rgba(0, 0, 0, .35);
  transition: transform .15s;
}
.fab:active { transform: scale(.93); }
.fab > .ic { width: 28px; height: 28px; stroke-width: 2.4; }
.fab-ring { position: absolute; inset: -5px; width: 72px; height: 72px; transform: rotate(-90deg); pointer-events: none; }
.fab-ring circle {
  fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round;
  stroke-dasharray: 188.5; stroke-dashoffset: 188.5; opacity: 0; transition: stroke-dashoffset .3s, opacity .3s;
}
.fab.busy .fab-ring circle { opacity: 1; }
.app.selecting .fab { display: none; }

/* ---------- выделение ---------- */

.selbar {
  position: fixed; z-index: 35; left: 50%; transform: translateX(-50%);
  bottom: calc(16px + var(--safe-b));
  display: flex; align-items: center; gap: 4px;
  padding: 6px; border-radius: 18px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  animation: rise .18s ease-out;
  max-width: calc(100% - 24px);
}
.sel-count { font-weight: 700; padding: 0 6px; min-width: 24px; font-variant-numeric: tabular-nums; }
.sel-all { padding: 8px 10px; border-radius: 10px; color: var(--accent-fg); font-weight: 600; }
.sel-all:hover { background: var(--surface-2); }
.sel-actions { display: flex; gap: 2px; margin-left: 4px; padding-left: 6px; border-left: 1px solid var(--line); }
.sel-actions .icon-btn { padding: 0 12px; font-size: 14px; font-weight: 600; }
.sel-actions .icon-btn:disabled { opacity: .3; pointer-events: none; }
@media (max-width: 599px) {
  .selbar { left: 8px; right: 8px; transform: none; max-width: none; justify-content: space-between; }
  .sel-actions span { display: none; }
  .sel-actions .icon-btn { padding: 0 10px; }
}

/* ---------- загрузки ---------- */

.uploads {
  position: fixed; z-index: 28; right: 16px; bottom: calc(96px + var(--safe-b));
  width: min(390px, calc(100% - 24px));
  border-radius: 18px; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  animation: rise .2s ease-out;
}
.app.selecting .uploads { bottom: calc(84px + var(--safe-b)); }
@media (max-width: 599px) {
  .uploads { left: 12px; right: 12px; width: auto; }
}
.uploads-head { display: flex; align-items: center; gap: 2px; padding: 8px 8px 8px 16px; cursor: pointer; }
.uploads-title { flex: 1; font-weight: 650; font-size: 14px; font-variant-numeric: tabular-nums; }
.uploads-title small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.uploads-bar { height: 3px; background: var(--surface-3); }
.uploads-bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.uploads-list { list-style: none; margin: 0; padding: 4px 0; max-height: min(46vh, 340px); overflow-y: auto; }
.uploads.collapsed .uploads-list { display: none; }
.uploads.collapsed #uploadsToggle .ic { transform: rotate(180deg); }
.up {
  display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 10px;
  padding: 8px 8px 8px 14px;
}
.up-thumb {
  width: 40px; height: 52px; border-radius: 7px; background: var(--surface-2); overflow: hidden;
  display: grid; place-items: center; color: var(--muted);
}
.up-thumb img { width: 100%; height: 100%; object-fit: cover; }
.up-thumb .ic { width: 18px; height: 18px; }
.up-main { min-width: 0; }
.up-name { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-meta { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 2px; }
.up-meta.err { color: var(--danger); }
.up-meta.ok { color: var(--accent-fg); }
.up-prog { height: 3px; border-radius: 3px; background: var(--surface-3); margin-top: 6px; overflow: hidden; }
.up-prog i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .25s; }
.up .icon-btn { width: 36px; min-width: 36px; height: 36px; color: var(--muted); }

/* ---------- drag & drop ---------- */

.drop {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: rgba(11, 11, 13, .7); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  pointer-events: none;
}
.drop-card {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 40px 56px; border-radius: 24px; border: 2px dashed var(--accent);
  color: var(--text); font-size: 18px; font-weight: 650;
}
.drop-card .ic { width: 56px; height: 56px; color: var(--accent); stroke-width: 1.4; }

/* ---------- диалоги ---------- */

dialog { color: var(--text); padding: 0; border: 0; }
dialog::backdrop { background: rgba(0, 0, 0, .55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }

.sheet {
  margin: auto auto 0; width: min(480px, 100%); max-width: 100%;
  background: transparent;
}
.sheet[open] { animation: sheetUp .22s cubic-bezier(.2, .8, .2, 1); }
.sheet-body { padding: 8px 8px calc(8px + var(--safe-b)); display: flex; flex-direction: column; gap: 8px; }
.sheet-item {
  display: flex; align-items: center; gap: 14px; text-align: left;
  padding: 16px 18px; border-radius: 16px; background: var(--surface);
}
.sheet-item:hover { background: var(--surface-2); }
.sheet-item .ic { width: 26px; height: 26px; color: var(--accent-fg); }
.sheet-item b { display: block; font-size: 16px; }
.sheet-item small { color: var(--muted); font-size: 13px; }
.sheet-cancel { padding: 16px; border-radius: 16px; background: var(--surface); font-weight: 650; font-size: 16px; }
@media (min-width: 600px) {
  .sheet { margin: auto; }
  .sheet-body { padding: 8px; }
}

.modal {
  width: min(420px, calc(100% - 32px)); border-radius: 20px; background: var(--surface);
  box-shadow: var(--shadow);
}
.modal[open] { animation: pop .16s ease-out; }
.modal-body { padding: 22px; }
.modal h2 { margin: 0 0 14px; font-size: 19px; letter-spacing: -0.01em; }
.modal p { margin: -6px 0 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.move-crumbs { display: flex; flex-wrap: wrap; gap: 2px; margin: -4px 0 8px; font-size: 14px; }
.move-crumbs button { padding: 4px 8px; border-radius: 8px; color: var(--muted); }
.move-crumbs button:last-child { color: var(--text); font-weight: 600; }
.move-list {
  list-style: none; margin: 0; padding: 4px; border-radius: 12px; background: var(--bg);
  height: min(320px, 45vh); overflow-y: auto;
}
.move-list button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 11px 10px; border-radius: 9px; text-align: left;
}
.move-list button:hover { background: var(--surface-2); }
.move-list button:disabled { opacity: .35; pointer-events: none; }
.move-list .ic { color: var(--accent-fg); }
.move-list .muted { padding: 12px 10px; font-size: 14px; }

/* ---------- просмотр ---------- */

.viewer {
  width: 100%; height: 100%; max-width: 100%; max-height: 100%; margin: 0;
  background: #000; color: #fff;
}
.viewer[open] { display: grid; grid-template-rows: auto 1fr auto; animation: fade .18s ease-out; }
.viewer::backdrop { background: #000; }
.v-top {
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + var(--safe-t)) 12px 8px;
}
.v-top .icon-btn { color: #fff; }
.v-top .icon-btn:hover { background: rgba(255, 255, 255, .1); }
.v-title { min-width: 0; }
.v-title b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.v-title small { color: rgba(255, 255, 255, .6); font-size: 12px; }
.v-stage { position: relative; min-height: 0; display: grid; place-items: center; padding: 0 8px; touch-action: pan-y; }
.v-stage video, .v-stage img { max-width: 100%; max-height: 100%; border-radius: 10px; background: #000; }
.v-stage video { width: 100%; height: 100%; object-fit: contain; }
.v-placeholder { display: flex; flex-direction: column; align-items: center; gap: 14px; color: rgba(255, 255, 255, .7); text-align: center; padding: 20px; }
.v-placeholder .ic { width: 64px; height: 64px; stroke-width: 1.2; }
.v-placeholder .btn { background: var(--accent); color: var(--accent-ink); }
.v-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(255, 255, 255, .1); color: #fff;
}
.v-nav:hover { background: rgba(255, 255, 255, .2); }
.v-nav:disabled { opacity: 0; pointer-events: none; }
.v-prev { left: 16px; }
.v-next { right: 16px; }
@media (hover: none), (max-width: 599px) { .v-nav { display: none; } }
.v-actions {
  display: flex; justify-content: center; gap: 4px;
  padding: 10px 8px calc(10px + var(--safe-b));
}
.v-actions button {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  min-width: 68px; padding: 8px 10px; border-radius: 12px; font-size: 12px; color: rgba(255, 255, 255, .9);
}
.v-actions button:hover { background: rgba(255, 255, 255, .1); }
.v-actions .danger { color: #ff6b64; }

/* ---------- тост ---------- */

.toast {
  position: fixed; left: 50%; bottom: calc(100px + var(--safe-b)); z-index: 100;
  transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 14px;
  background: var(--text); color: var(--bg); font-weight: 600; font-size: 14px;
  box-shadow: var(--shadow); animation: rise .2s ease-out;
}
.toast.err { background: var(--danger); color: #fff; }

@keyframes pop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; translate: 0 12px; } to { opacity: 1; translate: 0 0; } }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
