:root {
  --bg: #f3f5f8;
  --bg2: #e9edf3;
  --panel: #ffffff;
  --text: #17202c;
  --muted: #667085;
  --line: #dde3ea;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --accent-soft: #e5efff;
  --danger: #d1242f;
  --tile: #ffffff;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 14px rgba(16,24,40,.06);
  --shadow-hi: 0 2px 4px rgba(16,24,40,.08), 0 14px 32px rgba(16,24,40,.14);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b; --bg2: #141b24; --panel: #18202b; --text: #e6edf5; --muted: #8b98a8;
    --line: #26313f; --accent: #4c8dff; --accent-soft: #1b2c47; --danger: #ff6b6b; --tile: #1a2330;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.25);
    --shadow-hi: 0 2px 4px rgba(0,0,0,.4), 0 16px 36px rgba(0,0,0,.45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 600px at 10% -10%, var(--bg2), transparent 60%), var(--bg);
  min-height: 100vh;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- шапка ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 18px;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 650; white-space: nowrap; }
.brand-mark { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; width: 22px; height: 22px; }
.brand-mark i { border-radius: 3px; background: var(--accent); }
.brand-mark i:nth-child(2), .brand-mark i:nth-child(3) { opacity: .55; }

.tabs { display: flex; gap: 4px; overflow-x: auto; flex: 1; min-width: 0; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0; background: transparent; padding: 7px 14px; border-radius: 999px; cursor: pointer;
  color: var(--muted); white-space: nowrap; font-weight: 500; transition: background .15s, color .15s;
}
.tab:hover { background: var(--bg2); color: var(--text); }
.tab.on { background: var(--accent-soft); color: var(--accent); }
.tab.drop { outline: 2px dashed var(--accent); outline-offset: -2px; }
.tab .count { font-size: 12px; opacity: .7; margin-left: 4px; }
.tab-add { color: var(--accent); font-size: 18px; line-height: 1; padding: 6px 12px; }

.top-tools { display: flex; align-items: center; gap: 10px; position: relative; }
.search { display: flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 0 10px; height: 36px; }
.search svg { width: 16px; height: 16px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.search input { border: 0; outline: 0; background: transparent; width: 150px; }
.size { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 2px; }
.size button { border: 0; background: transparent; width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 12px; font-weight: 600; color: var(--muted); }
.size button.on { background: var(--accent-soft); color: var(--accent); }
.icon-btn { border: 1px solid var(--line); background: var(--panel); width: 36px; height: 36px; border-radius: 10px; cursor: pointer; display: grid; place-items: center; }
.icon-btn svg { width: 18px; height: 18px; fill: var(--text); }
.menu {
  position: absolute; right: 0; top: 44px; min-width: 220px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow-hi); padding: 6px; display: flex; flex-direction: column;
}
.menu button { text-align: left; border: 0; background: transparent; padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--bg2); }
.menu .danger { color: var(--danger); }
.menu-user { padding: 8px 12px 10px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; }

/* ---------- сетка плиток ---------- */
main { padding: 28px 24px 60px; max-width: 1480px; margin: 0 auto; }
.grid { --min: 210px; display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--min), 1fr)); gap: 22px; }
.grid[data-size="s"] { --min: 160px; gap: 16px; }
.grid[data-size="l"] { --min: 280px; gap: 26px; }

.tile {
  position: relative; display: flex; flex-direction: column; text-decoration: none; color: var(--text);
  background: var(--tile); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
  transition: transform .18s ease, box-shadow .18s ease, opacity .15s;
  -webkit-user-drag: element;
}
.tile > a { display: flex; flex-direction: column; color: inherit; text-decoration: none; outline: none; }
.tile:hover, .tile:focus-within { transform: translateY(-3px); box-shadow: var(--shadow-hi); outline: none; }
.tile.dragging { opacity: .35; }
.tile.ph { outline: 2px dashed var(--accent); outline-offset: 3px; }

.tile .pic { position: relative; aspect-ratio: 16 / 10; overflow: hidden; background: var(--bg2); }
.tile .pic img.cover { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .pic.icon, .tile .pic.mono {
  display: grid; place-items: center;
  background: linear-gradient(145deg, color-mix(in srgb, var(--c) 22%, var(--tile)), color-mix(in srgb, var(--c) 10%, var(--tile)));
}
.tile .pic.icon img { width: 34%; max-width: 72px; aspect-ratio: 1; object-fit: contain; filter: drop-shadow(0 6px 14px rgba(0,0,0,.18)); }
.tile .pic.mono span {
  width: 34%; max-width: 72px; aspect-ratio: 1; border-radius: 22%; display: grid; place-items: center;
  background: var(--c); color: #fff; font-weight: 700; font-size: clamp(18px, 2.4vw, 30px); box-shadow: 0 6px 14px rgba(0,0,0,.18);
}
.tile .pic.pending::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(255,255,255,.35) 50%, transparent 70%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite linear;
}
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -50% 0; } }

.tile .cap { display: flex; flex-direction: column; padding: 9px 12px 11px; min-width: 0; }
.tile .t { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .d { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid[data-size="s"] .tile .d { display: none; }

.tile .edit {
  position: absolute; top: 8px; right: 8px; width: 30px; height: 30px; border-radius: 9px; border: 0; cursor: pointer;
  background: rgba(15,20,27,.62); backdrop-filter: blur(6px); display: grid; place-items: center;
  opacity: 0; transform: scale(.9); transition: opacity .15s, transform .15s;
}
.tile .edit svg { width: 15px; height: 15px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tile:hover .edit, .tile:focus-within .edit { opacity: 1; transform: none; }
@media (hover: none) { .tile .edit { opacity: .9; transform: none; } }

.tile.add {
  box-shadow: none; background: transparent; border: 2px dashed var(--line); cursor: pointer;
  align-items: center; justify-content: center; min-height: 100%; color: var(--muted); font-weight: 500; gap: 6px;
  aspect-ratio: auto;
}
.tile.add .plus { font-size: 34px; line-height: 1; font-weight: 300; color: var(--accent); }
.tile.add:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.empty { text-align: center; color: var(--muted); margin-top: 40px; }

/* ---------- вход ---------- */
.auth { display: grid; place-items: center; min-height: calc(100vh - 160px); }
.auth-card { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow-hi); padding: 28px; }
.auth-preview { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 22px; }
.auth-preview i { aspect-ratio: 16/10; border-radius: 8px; background: linear-gradient(145deg, var(--accent-soft), var(--bg2)); }
.auth-preview i:nth-child(2) { background: linear-gradient(145deg, #ffe7d6, #fff3ea); }
.auth-preview i:nth-child(4) { background: linear-gradient(145deg, #dff5e6, #f0faf3); }
.auth-preview i:nth-child(6) { background: linear-gradient(145deg, #f1e4ff, #f8f1ff); }
@media (prefers-color-scheme: dark) { .auth-preview i:nth-child(n) { background: linear-gradient(145deg, var(--accent-soft), var(--bg2)); } }
.auth h1 { font-size: 22px; line-height: 1.25; margin: 0 0 8px; }
.lead { color: var(--muted); margin: 0 0 20px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg2); border-radius: 10px; padding: 3px; margin-bottom: 16px; }
.seg button { border: 0; background: transparent; padding: 8px; border-radius: 8px; cursor: pointer; font-weight: 500; color: var(--muted); }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }

/* ---------- формы ---------- */
label { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 12px; }
label .hint { font-weight: 400; opacity: .8; }
input[type=text], input[type=email], input[type=password], select {
  display: block; width: 100%; margin-top: 5px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 15px; outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--panel);
  padding: 9px 16px; border-radius: 10px; cursor: pointer; font-weight: 550; text-decoration: none; color: var(--text);
  transition: filter .15s, background .15s;
}
.btn:hover { background: var(--bg2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.wide { width: 100%; margin-top: 6px; }
.btn.small { padding: 6px 12px; font-size: 13px; margin: 0; color: var(--text); }
.btn.danger-text { border-color: transparent; background: transparent; color: var(--danger); padding-left: 0; }
.btn[disabled] { opacity: .6; pointer-events: none; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 0 0 6px; }

dialog {
  border: 1px solid var(--line); border-radius: 18px; padding: 24px; width: min(460px, calc(100vw - 32px));
  background: var(--panel); color: var(--text); box-shadow: var(--shadow-hi);
}
dialog::backdrop { background: rgba(10,14,20,.45); backdrop-filter: blur(3px); }
dialog h2 { margin: 0 0 16px; font-size: 19px; }
.dlg-foot { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.spacer { flex: 1; }
.thumb-edit { display: flex; gap: 14px; align-items: center; margin-bottom: 12px; }
.thumb-prev { width: 150px; flex: none; }
.thumb-prev .tile { box-shadow: none; border: 1px solid var(--line); pointer-events: none; }
.thumb-prev .tile .cap { display: none; }
.thumb-actions { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; transition: .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- мобильные ---------- */
@media (max-width: 760px) {
  .top { flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .brand-text { display: none; }
  .tabs { order: 3; flex-basis: 100%; }
  .top-tools { margin-left: auto; }
  .search input { width: 110px; }
  .size { display: none; }
  main { padding: 18px 16px 50px; }
  .grid, .grid[data-size] { --min: 140px; gap: 12px; }
  .tile .d { display: none; }
}

/* ---------- гостевой режим ---------- */
.guest-only { display: none; }
body.is-guest .guest-only { display: block; }
.guest-bar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  color: var(--text); border-radius: 12px; padding: 10px 12px 10px 16px; margin-bottom: 22px; font-size: 14px;
}
.guest-bar > span:first-child { flex: 1; min-width: 240px; }
.gb-actions { display: flex; align-items: center; gap: 8px; }
.btn.small.primary { color: var(--accent-ink); }
.gb-close { border: 0; background: transparent; font-size: 20px; line-height: 1; cursor: pointer; color: var(--muted); padding: 2px 6px; border-radius: 6px; }
.gb-close:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.guest-start { margin-top: 14px; text-align: center; }
.guest-start .or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.guest-start .or::before, .guest-start .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.note { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
dialog .note { margin: 0 0 14px; }
.btn.link { border-color: transparent; background: transparent; color: var(--accent); margin-top: 10px; }
.key-row { display: flex; gap: 8px; margin-bottom: 14px; }
.key-row input { margin: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

/* ---------- восстановление пароля ---------- */
.auth h2.sub { font-size: 20px; margin: 0 0 6px; }
#forgotForm .note, #resetBad .note { margin: 0 0 16px; }
.sent { text-align: center; }
.sent .note { margin: 0 0 16px; }
.sent-icon { font-size: 40px; line-height: 1; margin-bottom: 10px; color: var(--accent); }
#authForm .btn.link { margin-top: 4px; font-weight: 500; font-size: 14px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; color: var(--text); }
label.check input { width: 16px; height: 16px; margin: 0; }
