:root {
  --bg: #0b0a14;
  --bg-2: #14121f;
  --card: #1a1826;
  --card-2: #221f31;
  --line: #2d2a3e;
  --text: #f4f2fb;
  --muted: #9a96ad;
  --accent: #a855f7;
  --accent-2: #22d3ee;
  --danger: #f43f5e;
  --ok: #34d399;
  --grad: linear-gradient(100deg, #5eead4 0%, #60a5fa 35%, #a855f7 70%, #db2777 100%);
  --radius: 22px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: radial-gradient(120% 60% at 50% -10%, #2a1650 0%, var(--bg) 55%) fixed, var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(110px + var(--safe-b));
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
h1, h2, h3 { margin: 0; letter-spacing: -0.02em; }
.muted { color: var(--muted); }

main { max-width: 640px; margin: 0 auto; padding: 24px 16px 0; }

/* Headers */
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.brand img { width: 40px; height: 40px; }
.brand h1 { font-size: 30px; flex: 1; }
.page-title { font-size: 40px; font-weight: 800; }
.page-sub { color: var(--muted); margin: 2px 0 20px; }
.icon-btn {
  width: 48px; height: 48px; border-radius: 16px; display: grid; place-items: center;
  background: var(--card); border: 1px solid var(--line);
}
.icon-btn svg { width: 22px; height: 22px; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }
.storage { display: flex; align-items: center; gap: 14px; }
.bar { flex: 1; height: 8px; border-radius: 99px; background: #000; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: inherit; background: var(--grad); min-width: 4px; transition: width .4s; }
.storage b { white-space: nowrap; }
.storage span { color: var(--muted); white-space: nowrap; font-size: 14px; }

.section-label { font-size: 13px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin: 22px 4px 10px; }

/* Chips */
.chips { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; margin: 0 -16px 14px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 9px 18px; border-radius: 99px; background: var(--card); border: 1px solid var(--line); color: var(--muted); font-weight: 600; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Lists */
.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 12px 14px;
}
.item:active { background: var(--card-2); }
.thumb { flex: none; width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; }
.thumb svg { width: 22px; height: 22px; }
.k-video { background: #2b1d4a; color: #c4a1ff; }
.k-audio { background: #12324a; color: #7dd3fc; }
.k-image { background: #133a31; color: #6ee7b7; }
.k-doc { background: #3a2a14; color: #fcd34d; }
.k-folder { background: #2b1d4a; color: #c4a1ff; }
.item-body { flex: 1; min-width: 0; }
.item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; }
.item-meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.item-actions { display: flex; gap: 6px; flex: none; }
.mini { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--card-2); }
.mini svg { width: 20px; height: 20px; }
.mini.danger { color: var(--danger); }

/* Empty state */
.empty { text-align: center; padding: 48px 20px; }
.empty .halo { width: 110px; height: 110px; border-radius: 50%; background: var(--card); display: grid; place-items: center; margin: 0 auto 18px; color: var(--muted); }
.empty .halo svg { width: 40px; height: 40px; }
.empty h3 { font-size: 22px; margin-bottom: 8px; }
.empty p { color: var(--muted); margin: 0 auto 24px; max-width: 320px; }
.empty-icons { display: flex; justify-content: center; gap: 12px; margin-bottom: 18px; }
.empty-icons span { width: 56px; height: 56px; border-radius: 16px; background: var(--card-2); border: 1px solid var(--line); display: grid; place-items: center; color: var(--muted); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 54px; padding: 0 26px; border-radius: 18px; font-weight: 700; font-size: 17px; }
.btn.grad { background: var(--grad); color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.25); }
.btn.ghost { background: var(--card-2); border: 1px solid var(--line); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 10px; }
.row .btn.grad { flex: 1; }

/* Search */
.search { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 0 16px; height: 56px; margin-bottom: 14px; }
.search svg { color: var(--muted); flex: none; }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; color: var(--text); font: inherit; font-size: 17px; }

/* Transfers */
.transfer .bar { margin: 10px 0 6px; height: 6px; background: var(--bg); }
.transfer-top { display: flex; gap: 12px; align-items: flex-start; }
.transfer-stats { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; gap: 10px; }
.state { font-weight: 600; }
.state.dl { color: var(--accent-2); }
.state.stop { color: var(--muted); }
.state.err { color: var(--danger); }

/* Folder view */
.back { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.back h2 { flex: 1; font-size: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Tab bar */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(14px + var(--safe-b));
  width: min(608px, calc(100% - 28px)); height: 76px; padding: 0 10px;
  display: grid; grid-template-columns: repeat(4, 1fr); align-items: center; justify-items: center;
  background: rgba(26, 24, 38, .92); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: 28px; z-index: 10;
}
.tabbar button { position: relative; width: 72px; height: 52px; border-radius: 22px; display: grid; place-items: center; color: var(--muted); }
.tabbar button.on { background: #2c1d4d; color: var(--accent); }
.tabbar button.add { width: 76px; height: 60px; background: var(--grad); color: #fff; border-radius: 22px; box-shadow: 0 6px 24px rgba(168, 85, 247, .35); }
.tabbar button.add svg { width: 30px; height: 30px; stroke-width: 2.4; }
.badge { position: absolute; top: 6px; right: 14px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent-2); color: #000; font-size: 11px; font-weight: 800; display: grid; place-items: center; }

/* Sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-width: 640px; margin: 0 auto;
  background: var(--bg-2); border: 1px solid var(--line); border-bottom: 0; border-radius: 28px 28px 0 0;
  padding: 10px 20px calc(24px + var(--safe-b));
  animation: up .22s ease-out;
}
@keyframes up { from { transform: translateY(40%); opacity: 0; } }
.grip { width: 48px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 14px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { font-size: 28px; }
.sheet textarea {
  width: 100%; margin: 6px 0 14px; padding: 16px; border-radius: 18px; resize: vertical;
  background: var(--card); color: var(--text); border: 1.5px dashed #4b4566; outline: 0;
  font: 15px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.sheet textarea:focus { border-color: var(--accent); }
.form-msg { min-height: 1.4em; margin: 12px 0 0; font-size: 14px; color: var(--muted); }
.form-msg.err { color: var(--danger); }

/* Viewer */
.viewer { position: fixed; inset: 0; z-index: 30; background: #000; display: flex; flex-direction: column; }
.viewer-top { display: flex; align-items: center; gap: 10px; padding: 12px; padding-top: max(12px, env(safe-area-inset-top)); background: linear-gradient(#000c, transparent); }
.viewer-top .title { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-top .icon-btn { background: rgba(255,255,255,.08); border-color: transparent; }
.viewer-stage { flex: 1; display: grid; place-items: center; min-height: 0; padding: 8px; }
.viewer-stage video, .viewer-stage img { max-width: 100%; max-height: 100%; }
.viewer-stage video { width: 100%; background: #000; }
.viewer-stage audio { width: min(520px, 100%); }
.viewer-bottom { display: flex; gap: 10px; padding: 14px 16px calc(18px + var(--safe-b)); }
.viewer-bottom .btn { flex: 1; height: 50px; font-size: 15px; padding: 0 12px; }
.viewer-note { color: var(--muted); text-align: center; font-size: 14px; padding: 0 20px; }
.audio-art { text-align: center; }
.audio-art .thumb { width: 160px; height: 160px; border-radius: 40px; margin: 0 auto 24px; }
.audio-art .thumb svg { width: 64px; height: 64px; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: calc(108px + var(--safe-b)); transform: translateX(-50%); z-index: 40; background: var(--card-2); border: 1px solid var(--line); padding: 12px 18px; border-radius: 14px; font-weight: 600; max-width: calc(100% - 32px); }

.spin { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 60px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Login */
.locked .tabbar { display: none; }
.login { max-width: 400px; margin: 8vh auto 0; display: flex; flex-direction: column; }
.login-logo { width: 72px; height: 72px; margin-bottom: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 14px; color: var(--muted); font-weight: 600; }
.field input {
  height: 54px; padding: 0 16px; border-radius: 16px; background: var(--card); color: var(--text);
  border: 1px solid var(--line); outline: 0; font: inherit; font-size: 17px; font-weight: 400;
}
.field input:focus { border-color: var(--accent); }
.login .btn { margin-top: 8px; }

/* Links styled as buttons */
a.btn, a.mini { text-decoration: none; color: inherit; }

/* Library / web switch on the Search tab */
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin: 14px 0; background: var(--card); border: 1px solid var(--line); border-radius: 16px; }
.segmented button { height: 42px; border-radius: 12px; color: var(--muted); font-weight: 700; }
.segmented button.on { background: var(--accent); color: #fff; }
.add-mini { background: var(--grad); color: #fff; }

/* Switch (merge duplicates) */
.toggle { display: flex; align-items: center; gap: 12px; margin: 0 4px 16px; color: var(--muted); font-size: 14px; font-weight: 600; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle span { flex: none; width: 44px; height: 26px; border-radius: 13px; background: var(--card-2); border: 1px solid var(--line); position: relative; transition: background .2s; }
.toggle span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--muted); transition: transform .2s, background .2s; }
.toggle input:checked + span { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + span::after { transform: translateX(18px); background: #fff; }
