:root {
  color-scheme: dark;
  --bg: #020617;
  --panel: rgba(15, 23, 42, .72);
  --panel2: rgba(2, 6, 23, .66);
  --panel-solid: #0b1224;
  --line: rgba(148, 163, 184, .17);
  --line-strong: rgba(148, 163, 184, .3);
  --hover: rgba(148, 163, 184, .08);
  --text: #f8fafc;
  --text-2: #cbd5e1;
  --muted: #94a3b8;
  --cyan: #22d3ee;
  --violet: #8b5cf6;
  --rose: #fb7185;
  --green: #34d399;
  --amber: #fbbf24;
  --blue: #60a5fa;
  --grad: linear-gradient(90deg, #22d3ee, #8b5cf6, #fb7185);
  --grad-soft: linear-gradient(90deg, #67e8f9, #a78bfa, #fb7185);
  --shadow: 0 24px 80px rgba(2, 6, 23, .45);
  --radius: 22px;
  --radius-sm: 12px;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Consolas, monospace;
  --sidebar: 272px;
  --top: 72px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 14% 10%, rgba(34, 211, 238, .17), transparent 480px),
    radial-gradient(circle at 84% 0, rgba(139, 92, 246, .19), transparent 496px),
    radial-gradient(circle at 75% 92%, rgba(251, 113, 133, .15), transparent 448px),
    linear-gradient(180deg, #020617 0%, #0f172a 48%, #020617 100%);
  background-attachment: fixed;
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(148, 163, 184, .07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, .07) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse at 50% 0, #000 20%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse at 50% 0, #000 20%, transparent 75%);
  z-index: 0;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
::selection { background: rgba(139, 92, 246, .45); }

/* ---------- No-JS fallback: plain Apache table, but readable ---------- */
#raw { position: relative; z-index: 1; max-width: 1000px; margin: 40px auto; padding: 0 16px; }
#raw table { width: 100%; border-collapse: collapse; }
#raw th, #raw td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); font-size: 14px; }
#raw a { color: var(--cyan); }
#raw img { display: none; }
#raw hr { display: none; }
.js #raw { display: none; }
html:not(.js) #app { display: none; }

/* ---------- Shell ---------- */
#app { position: relative; z-index: 1; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--top);
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px;
  background: rgba(2, 6, 23, .72);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex-shrink: 0; }
.brand-icon {
  width: 42px; height: 42px; border-radius: 13px; flex-shrink: 0;
  background: linear-gradient(135deg, #22d3ee, #8b5cf6, #fb7185);
  display: grid; place-items: center;
  box-shadow: 0 10px 30px rgba(139, 92, 246, .35);
}
.brand-icon::after { content: ''; width: 13px; height: 13px; background: #fff; transform: rotate(45deg); border-radius: 2px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-name { font-weight: 800; font-size: 16px; letter-spacing: -.01em; }
.brand-tag { font-size: 11.5px; color: var(--muted); white-space: nowrap; }

.search {
  flex: 1; max-width: 560px; margin: 0 auto;
  position: relative;
}
.search input {
  width: 100%; height: 44px;
  padding: 0 44px 0 44px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel2);
  color: var(--text);
  font: inherit; font-size: 14.5px;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.search input::placeholder { color: var(--muted); }
.search input::-webkit-search-cancel-button, .search input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; display: none; }
.search input:focus { border-color: rgba(139, 92, 246, .6); box-shadow: 0 0 0 4px rgba(139, 92, 246, .16); background: rgba(2, 6, 23, .9); }
.search .s-ico { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search kbd {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  font: 500 11px var(--mono); color: var(--muted);
  border: 1px solid var(--line-strong); border-radius: 6px; padding: 2px 7px;
}
.search input:focus ~ kbd, .search input:not(:placeholder-shown) ~ kbd { display: none; }
.search .s-clear {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  display: none; border: 0; background: none; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 8px;
}
.search input:not(:placeholder-shown) ~ .s-clear { display: grid; }
.search .s-clear:hover { color: var(--text); background: var(--hover); }

.top-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.chip-btn {
  height: 40px; padding: 0 14px;
  display: inline-flex; align-items: center; gap: 8px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text-2);
  font-size: 13px; font-weight: 700; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.chip-btn:hover { background: rgba(15, 23, 42, .95); color: var(--text); border-color: var(--line-strong); }
.menu-btn { display: none; width: 40px; padding: 0; justify-content: center; }

.layout { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: calc(100vh - var(--top)); }

/* ---------- Sidebar tree ---------- */
.sidebar {
  position: sticky; top: var(--top);
  height: calc(100vh - var(--top));
  overflow-y: auto; overscroll-behavior: contain;
  padding: 20px 12px 24px 16px;
  border-right: 1px solid var(--line);
  scrollbar-width: thin; scrollbar-color: rgba(148, 163, 184, .25) transparent;
}
.side-label { font-size: 11px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); padding: 4px 10px 10px; }
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { padding-left: 14px; margin-left: 9px; border-left: 1px solid var(--line); }
.tree-row {
  display: flex; align-items: center; gap: 4px;
  height: 34px; padding: 0 6px 0 2px; border-radius: 10px;
  color: var(--text-2); font-size: 13.5px; font-weight: 500;
  cursor: pointer; user-select: none;
}
.tree-row:hover { background: var(--hover); color: var(--text); }
.tree-row.active { background: linear-gradient(90deg, rgba(34, 211, 238, .14), rgba(139, 92, 246, .14)); color: var(--text); box-shadow: inset 0 0 0 1px rgba(139, 92, 246, .28); }
.tree-caret {
  width: 20px; height: 20px; flex-shrink: 0; display: grid; place-items: center;
  border: 0; background: none; padding: 0; color: var(--muted); cursor: pointer; border-radius: 6px;
  transition: transform .15s;
}
.tree-caret:hover { color: var(--text); background: var(--hover); }
.tree-caret.open { transform: rotate(90deg); }
.tree-caret.leaf { visibility: hidden; }
.tree-row .ic { width: 18px; height: 16px; flex-shrink: 0; }
.tree-row .t-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; padding-left: 4px; }
.tree-row a { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1; height: 100%; }
.tree-loading { font-size: 12px; color: var(--muted); padding: 6px 30px; }

/* ---------- Main ---------- */
.main { min-width: 0; padding: 26px 32px 64px; }
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; font-size: 13.5px; color: var(--muted); margin-bottom: 14px; }
.crumbs a { padding: 4px 8px; border-radius: 8px; font-weight: 600; }
.crumbs a:hover { color: var(--text); background: var(--hover); }
.crumbs .sep { opacity: .5; }
.crumbs .here { color: var(--text); font-weight: 700; padding: 4px 8px; }

.head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.head h1 { margin: 0; font-size: clamp(28px, 4vw, 40px); font-weight: 800; letter-spacing: -.035em; line-height: 1.05; word-break: break-word; }
.head h1 .g { background: var(--grad-soft); -webkit-background-clip: text; background-clip: text; color: transparent; }
.head .meta { color: var(--muted); font-size: 13.5px; margin-top: 8px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  height: 28px; padding: 0 12px; border-radius: 999px;
  border: 1px solid rgba(34, 211, 238, .28); background: rgba(34, 211, 238, .08);
  color: #a5f3fc; font-size: 12px; font-weight: 700;
}
.pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 10px var(--green); }
.head-title { flex: 1; min-width: 240px; }
.tools { display: flex; gap: 8px; align-items: center; }
.seg { display: inline-flex; padding: 3px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); }
.seg button { height: 32px; min-width: 36px; padding: 0 10px; border: 0; border-radius: 9px; background: none; color: var(--muted); cursor: pointer; display: grid; place-items: center; font-size: 12.5px; font-weight: 700; }
.seg button:hover { color: var(--text); }
.seg button.on { background: rgba(148, 163, 184, .16); color: var(--text); }
select.sort {
  height: 40px; padding: 0 34px 0 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center;
  color: var(--text-2); font: inherit; font-size: 13px; font-weight: 600; appearance: none; cursor: pointer;
}
select.sort option { background: var(--panel-solid); }

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}

/* readme */
.readme { padding: 20px 24px; margin-bottom: 18px; font-size: 14.5px; line-height: 1.65; color: var(--text-2); }
.readme-h { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.readme h1, .readme h2, .readme h3 { color: var(--text); margin: .6em 0 .3em; line-height: 1.25; letter-spacing: -.02em; }
.readme h1 { font-size: 22px; } .readme h2 { font-size: 18px; } .readme h3 { font-size: 15.5px; }
.readme p { margin: .4em 0; }
.readme a { color: var(--cyan); text-decoration: underline; text-underline-offset: 3px; }
.readme code { font: 13px var(--mono); background: rgba(148, 163, 184, .12); padding: 1px 6px; border-radius: 6px; }
.readme pre { font: 13px/1.55 var(--mono); background: var(--panel2); border: 1px solid var(--line); padding: 12px 14px; border-radius: 12px; overflow-x: auto; white-space: pre-wrap; }
.readme ul { margin: .4em 0; padding-left: 1.3em; }

/* ---------- List view ---------- */
.list { overflow: hidden; }
.l-head, .l-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 170px 96px 92px;
  align-items: center; gap: 12px;
  padding: 0 14px 0 18px;
}
.l-head { height: 44px; border-bottom: 1px solid var(--line); font-size: 11.5px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.l-head button { border: 0; background: none; padding: 0; cursor: pointer; color: inherit; font: inherit; letter-spacing: inherit; text-transform: inherit; display: inline-flex; align-items: center; gap: 5px; justify-self: start; }
.l-head button:hover, .l-head button.on { color: var(--text); }
.l-head .c-size { justify-self: end; }
.l-row { min-height: 58px; border-bottom: 1px solid var(--line); transition: background .12s; position: relative; }
.l-row:last-child { border-bottom: 0; }
.l-row:hover { background: var(--hover); }
.l-row.flash { animation: flash 1.6s ease; }
@keyframes flash { 0%, 40% { background: rgba(139, 92, 246, .2); } 100% { background: transparent; } }
.l-name { display: flex; align-items: center; gap: 14px; min-width: 0; padding: 8px 0; }
.l-name .ic { width: 30px; height: 34px; flex-shrink: 0; }
.l-name .ic.folder { width: 34px; height: 28px; }
.l-name .nm { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.l-name .nm a { font-size: 14.5px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.l-name .nm a::after { content: ''; position: absolute; inset: 0; } /* whole row is clickable */
.l-name .sub { font-size: 12px; color: var(--muted); display: none; }
.l-date { font-size: 13px; color: var(--muted); white-space: nowrap; }
.l-size { font: 500 12.5px var(--mono); color: var(--text-2); text-align: right; white-space: nowrap; }
.l-act { display: flex; justify-content: flex-end; gap: 4px; position: relative; z-index: 2; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid transparent;
  background: none; color: var(--muted); cursor: pointer; display: grid; place-items: center;
  transition: background .12s, color .12s, border-color .12s;
}
.icon-btn:hover { background: rgba(148, 163, 184, .12); color: var(--text); border-color: var(--line); }
.icon-btn.dl:hover { color: #0b1020; background: var(--grad); border-color: transparent; }
.tag {
  display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px; border-radius: 6px;
  font: 700 10.5px var(--mono); letter-spacing: .02em; vertical-align: middle;
  border: 1px solid rgba(52, 211, 153, .35); color: #6ee7b7; background: rgba(52, 211, 153, .08);
  position: relative; z-index: 2; cursor: pointer; margin-left: 8px;
}
.tag:hover { background: rgba(52, 211, 153, .18); }
.tag.site { border-color: rgba(96, 165, 250, .35); color: #93c5fd; background: rgba(96, 165, 250, .08); cursor: default; }

/* ---------- Grid view ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 14px; }
.tile {
  position: relative; padding: 20px 14px 14px; border-radius: 18px;
  border: 1px solid var(--line); background: var(--panel);
  display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center;
  transition: transform .15s, border-color .15s, background .15s;
  min-width: 0;
}
.tile:hover { transform: translateY(-2px); border-color: rgba(139, 92, 246, .45); background: rgba(15, 23, 42, .9); }
.tile .ic { width: 52px; height: 60px; }
.tile .ic.folder { width: 64px; height: 52px; margin: 4px 0; }
.tile .t-nm { font-size: 13.5px; font-weight: 600; line-height: 1.3; width: 100%; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; min-height: 2.6em; }
.tile .t-nm a::after { content: ''; position: absolute; inset: 0; border-radius: 18px; }
.tile .t-meta { font-size: 11.5px; color: var(--muted); font-family: var(--mono); }
.tile .t-act { position: absolute; top: 8px; right: 8px; display: flex; gap: 2px; opacity: 0; transition: opacity .15s; z-index: 2; }
.tile:hover .t-act, .tile:focus-within .t-act { opacity: 1; }
.tile .t-act .icon-btn { width: 30px; height: 30px; background: rgba(2, 6, 23, .7); }

/* ---------- States ---------- */
.empty { padding: 60px 20px; text-align: center; color: var(--muted); }
.empty .big { font-size: 17px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.skel { height: 58px; border-bottom: 1px solid var(--line); background: linear-gradient(90deg, transparent, rgba(148, 163, 184, .06), transparent); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.search-info { font-size: 13px; color: var(--muted); margin: -6px 0 14px; display: flex; align-items: center; gap: 8px; }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--violet); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
mark { background: rgba(139, 92, 246, .35); color: var(--text); border-radius: 3px; padding: 0 1px; }
.path-sub { display: block !important; }
.path-sub a:hover { color: var(--cyan); }

/* ---------- Preview ---------- */
.modal {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: rgba(2, 6, 23, .78);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: min(1100px, 100%); max-height: calc(100vh - 48px);
  display: flex; flex-direction: column; overflow: hidden;
  background: rgba(11, 18, 36, .96);
  animation: pop .18s ease;
}
@keyframes pop { from { transform: translateY(8px) scale(.985); opacity: 0; } }
.sheet-h { display: flex; align-items: center; gap: 14px; padding: 14px 14px 14px 20px; border-bottom: 1px solid var(--line); }
.sheet-h .ic { width: 28px; height: 32px; flex-shrink: 0; }
.sheet-t { flex: 1; min-width: 0; }
.sheet-t .n { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-t .m { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.sheet-b { flex: 1; min-height: 0; overflow: auto; display: flex; align-items: center; justify-content: center; background: rgba(2, 6, 23, .5); }
.sheet-b img, .sheet-b video { max-width: 100%; max-height: calc(100vh - 150px); display: block; }
.sheet-b audio { width: min(520px, 90%); margin: 48px 0; }
.sheet-b iframe { width: 100%; height: calc(100vh - 150px); border: 0; background: #fff; }
.sheet-b pre { align-self: stretch; margin: 0; padding: 20px 24px; font: 13px/1.6 var(--mono); color: var(--text-2); white-space: pre-wrap; word-break: break-word; width: 100%; }
.sheet-b .info { padding: 48px 24px; text-align: center; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 16px; }
.sheet-b .info .ic { width: 72px; height: 84px; }
.sheet-b .info .ic.folder { width: 80px; height: 66px; }
.btn {
  height: 40px; padding: 0 16px; border-radius: 12px;
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 13.5px; font-weight: 800; cursor: pointer; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text);
}
.btn:hover { border-color: var(--line-strong); background: rgba(15, 23, 42, .95); }
.btn-primary { border: 0; background: var(--grad); color: #0b1020; box-shadow: 0 10px 30px rgba(139, 92, 246, .3); }
.btn-primary:hover { filter: brightness(1.08); background: var(--grad); }
.nav-arrow {
  position: fixed; top: 50%; transform: translateY(-50%); z-index: 61;
  width: 46px; height: 46px; border-radius: 50%; border: 1px solid var(--line); background: rgba(2, 6, 23, .8);
  color: var(--text); cursor: pointer; display: grid; place-items: center;
}
.nav-arrow:hover { border-color: var(--line-strong); background: rgba(15, 23, 42, .95); }
.nav-arrow.prev { left: 18px; } .nav-arrow.next { right: 18px; }

.hash-box { font: 12.5px var(--mono); word-break: break-all; color: #6ee7b7; background: rgba(52, 211, 153, .08); border: 1px solid rgba(52, 211, 153, .25); border-radius: 12px; padding: 12px 14px; max-width: 640px; text-align: left; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 80; transform: translateX(-50%);
  padding: 11px 18px; border-radius: 14px; font-size: 13.5px; font-weight: 700;
  background: rgba(15, 23, 42, .96); border: 1px solid rgba(52, 211, 153, .4); color: var(--text);
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 10px;
  animation: toast .2s ease;
}
.toast svg { color: var(--green); }
@keyframes toast { from { opacity: 0; transform: translate(-50%, 10px); } }

.foot { margin-top: 28px; font-size: 12.5px; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; }
.foot a:hover { color: var(--text); }

.scrim { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .l-head, .l-row { grid-template-columns: minmax(0, 1fr) 130px 86px 84px; }
}
@media (max-width: 900px) {
  :root { --top: 64px; }
  .topbar { padding: 0 16px; gap: 10px; }
  .menu-btn { display: inline-flex; }
  .brand-tag, .hide-sm { display: none; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; top: var(--top); left: 0; bottom: 0; height: auto; width: min(300px, 86vw); z-index: 40;
    background: rgba(2, 6, 23, .97); transform: translateX(-100%); transition: transform .22s ease;
  }
  body.drawer .sidebar { transform: none; }
  body.drawer .scrim { display: block; position: fixed; inset: var(--top) 0 0 0; background: rgba(2, 6, 23, .6); z-index: 35; }
  .main { padding: 20px 16px 48px; }
}
@media (max-width: 640px) {
  .brand-text { display: none; }
  .search input { height: 42px; font-size: 16px; padding-right: 40px; }
  .search kbd { display: none; }
  .l-head { display: none; }
  .l-row { grid-template-columns: minmax(0, 1fr) auto; padding: 0 8px 0 12px; }
  .l-date, .l-size { display: none; }
  .l-name .sub { display: block; }
  .l-act .copy { display: none; }
  .head { align-items: stretch; flex-direction: column; }
  .tools { justify-content: space-between; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile .t-act { opacity: 1; }
  .modal { padding: 0; }
  .sheet { max-height: 100vh; height: 100%; border-radius: 0; }
  .nav-arrow { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
