:root {
  --bg: #f3f4f8; --surface: #ffffff; --surface-2: #eceef5; --text: #171a23; --muted: #667085;
  --line: #e1e4ee; --accent: #4f6bff; --accent-text: #ffffff; --danger: #d92d20; --ok: #12805c;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 14px rgba(16,24,40,.06);
  --radius: 18px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1015; --surface: #181b23; --surface-2: #232733; --text: #eef0f6; --muted: #9aa3b6;
    --line: #2a2f3d; --accent: #7089ff; --accent-text: #0b0e18; --danger: #ff6b5e; --ok: #4cd4a1;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.35);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100dvh; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
.boot { padding: 40vh 0 0; text-align: center; color: var(--muted); }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.card { background: var(--surface); border-radius: 24px; box-shadow: var(--shadow); padding: 28px 24px; width: min(380px, 100%); }
.card .logo { width: 64px; height: 64px; border-radius: 16px; display: block; margin: 0 auto 14px; }
.card h1 { margin: 0 0 4px; font-size: 22px; text-align: center; }
.card p.sub { margin: 0 0 20px; color: var(--muted); text-align: center; font-size: 14px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 600; }
.field small { color: var(--muted); font-size: 12px; }
input[type=text], input[type=password], input[type=url], select, textarea {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--bg); outline: none; min-height: 46px;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 10px; margin: 4px 0 16px; font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.err { color: var(--danger); font-size: 14px; min-height: 20px; margin: 0 0 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer;
  border: 0; border-radius: 12px; padding: 0 18px; min-height: 46px; font-weight: 650;
  background: var(--surface-2); color: var(--text);
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.small { min-height: 38px; padding: 0 12px; font-size: 14px; }
.btn[disabled] { opacity: .55; cursor: default; }

/* ---------- main ---------- */
header.top {
  position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  padding: calc(10px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
}
.bar { display: flex; align-items: center; gap: 8px; max-width: 980px; margin: 0 auto; }
.bar h1 { font-size: 20px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; border: 0; cursor: pointer; background: transparent;
  display: grid; place-items: center; color: var(--text);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.on { background: var(--accent); color: var(--accent-text); }
.icon-btn svg { width: 22px; height: 22px; }
.search { max-width: 980px; margin: 6px auto 0; }
.search input { border-radius: 14px; background: var(--surface); }
.tabs { max-width: 980px; margin: 10px auto 0; display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; border: 0; cursor: pointer; padding: 0 16px; min-height: 40px; border-radius: 999px;
  background: var(--surface); color: var(--muted); font-weight: 650; box-shadow: var(--shadow);
}
.tab.active { background: var(--accent); color: var(--accent-text); }
.tab .n { opacity: .7; font-weight: 500; margin-left: 6px; font-size: 13px; }
.tab.add { background: transparent; box-shadow: none; border: 1.5px dashed var(--line); }

main { max-width: 980px; margin: 0 auto; padding: 14px max(16px, env(safe-area-inset-right)) calc(110px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin: 18px 4px 10px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 14px 10px; }
.tile {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
  background: none; border: 0; cursor: pointer; padding: 6px 2px; border-radius: 16px; min-width: 0;
}
.tile:active .ico { transform: scale(.94); }
.ico {
  width: 68px; height: 68px; border-radius: 18px; background: var(--surface); box-shadow: var(--shadow);
  display: grid; place-items: center; overflow: hidden; transition: transform .12s;
}
.ico img { width: 100%; height: 100%; object-fit: contain; padding: 11px; }
.ico.letter { color: #fff; font-weight: 750; font-size: 28px; }
.ico.file { color: #fff; font-weight: 800; font-size: 15px; letter-spacing: .02em; position: relative; }
.tile .name { font-size: 13px; line-height: 1.2; font-weight: 600; max-width: 100%; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.tile .meta { font-size: 11px; color: var(--muted); margin-top: -4px; }
.editing .tile .ico { animation: wiggle .5s ease-in-out infinite alternate; }
@keyframes wiggle { from { transform: rotate(-1.4deg); } to { transform: rotate(1.4deg); } }
@media (prefers-reduced-motion: reduce) { .editing .tile .ico { animation: none; outline: 2px dashed var(--accent); } }
.tile .pen {
  position: absolute; top: 2px; right: calc(50% - 44px); width: 24px; height: 24px; border-radius: 50%;
  background: var(--accent); color: var(--accent-text); display: none; place-items: center;
}
.editing .tile .pen { display: grid; }
.tile .pen svg { width: 14px; height: 14px; }
.empty { text-align: center; color: var(--muted); padding: 56px 16px; }
.empty b { display: block; color: var(--text); font-size: 18px; margin-bottom: 6px; }

.fab {
  position: fixed; right: max(18px, env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom));
  width: 60px; height: 60px; border-radius: 20px; border: 0; cursor: pointer; z-index: 6;
  background: var(--accent); color: var(--accent-text); box-shadow: 0 8px 24px rgba(79,107,255,.45);
  display: grid; place-items: center;
}
.fab svg { width: 28px; height: 28px; }

/* ---------- dialogs ---------- */
dialog {
  border: 0; border-radius: 24px; padding: 0; width: min(460px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  background: var(--surface); color: var(--text); box-shadow: 0 24px 80px rgba(0,0,0,.35); overflow: auto;
}
dialog::backdrop { background: rgba(8,10,16,.55); backdrop-filter: blur(3px); }
.dlg { padding: 22px 20px 20px; }
.dlg h2 { margin: 0 0 14px; font-size: 19px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; margin-bottom: 16px; }
.seg button { flex: 1; border: 0; background: none; padding: 10px; border-radius: 9px; cursor: pointer; font-weight: 650; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.preview { display: flex; gap: 12px; align-items: center; margin: -4px 0 14px; padding: 10px; background: var(--bg); border-radius: 14px; min-height: 64px; }
.preview .ico { width: 48px; height: 48px; border-radius: 12px; flex: none; }
.preview .ico img { padding: 7px; }
.preview .t { font-size: 14px; color: var(--muted); min-width: 0; overflow-wrap: anywhere; }
.preview .t b { color: var(--text); display: block; }
.actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.actions .grow { flex: 1; }
details.more { margin: 0 0 12px; }
details.more summary { cursor: pointer; color: var(--muted); font-size: 14px; font-weight: 600; padding: 6px 0; }
.progress { height: 8px; border-radius: 6px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.upl { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.upl:last-child { border-bottom: 0; }
.upl .s { color: var(--muted); font-size: 12px; }
.dev { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; display: flex; gap: 10px; align-items: center; }
.dev > div { flex: 1; min-width: 0; }
.dev .s { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.pill { font-size: 11px; background: var(--accent); color: var(--accent-text); border-radius: 99px; padding: 2px 8px; margin-left: 6px; }
.big-dl { font-size: 17px; min-height: 54px; }
.kv { color: var(--muted); font-size: 14px; margin: 6px 0; overflow-wrap: anywhere; }

#toasts { position: fixed; left: 0; right: 0; bottom: calc(90px + env(safe-area-inset-bottom)); display: grid; gap: 8px; justify-items: center; z-index: 50; pointer-events: none; padding: 0 16px; }
.toast { background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow); max-width: 480px; }
