:root {
  --bg: #0b0e12;
  --bg-soft: #0f1319;
  --panel: #141920;
  --panel-hover: #1a2029;
  --line: #26303c;
  --line-soft: rgba(255, 255, 255, 0.06);
  --text: #e8edf3;
  --muted: #9aa6b5;
  --muted-strong: #b7c1cd;
  --accent: #6cb6ff;
  --accent-soft: rgba(108, 182, 255, 0.14);
  --danger: #ff8a8a;
  --radius: 12px;
  --sidebar-width: 272px;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 85% -10%, rgba(108, 182, 255, 0.08), transparent 30rem),
    var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: rgba(108, 182, 255, 0.3);
}

a {
  color: inherit;
  text-decoration: none;
}

a:hover {
  color: var(--accent);
}

button,
input {
  font: inherit;
}

.icon {
  width: 1.25em;
  height: 1.25em;
  display: block;
  flex: 0 0 auto;
}

.skip {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 20;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 8px;
  transform: translateY(-200%);
}

.skip:focus {
  transform: none;
}

.layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar ----------------------------------------------------------------- */

.sidebar {
  position: sticky;
  top: 0;
  flex: 0 0 var(--sidebar-width);
  width: var(--sidebar-width);
  height: 100vh;
  overflow: auto;
  padding: 18px 12px 28px;
  background: linear-gradient(180deg, #10151b 0%, #0d1117 100%);
  border-right: 1px solid var(--line);
}

.brand {
  display: block;
  padding: 6px 10px 18px;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--text);
}

.brand:hover {
  color: var(--accent);
}

.tree-panel > summary {
  display: none;
}

.tree {
  font-size: 0.9rem;
}

.tree-children {
  margin-left: 13px;
  padding-left: 7px;
  border-left: 1px solid var(--line-soft);
}

.tree-link {
  display: block;
  margin: 1px 0;
  padding: 5px 10px;
  border-radius: 7px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-link:hover {
  background: var(--panel);
  color: var(--text);
}

.tree-link.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.tree-empty {
  margin: 8px 10px;
  color: var(--muted);
  font-size: 0.88rem;
}

/* Main content ------------------------------------------------------------ */

.content {
  flex: 1;
  min-width: 0;
  padding: 26px clamp(18px, 3vw, 44px) 64px;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.crumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.crumbs a {
  color: var(--muted-strong);
  border-radius: 4px;
}

.crumbs a:hover {
  color: var(--accent);
}

.crumbs .sep {
  color: #556273;
}

.crumbs .current {
  color: var(--text);
  overflow-wrap: anywhere;
}

.summary {
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(20, 25, 32, 0.75);
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Grid -------------------------------------------------------------------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 16px;
}

.card {
  position: relative;
  display: block;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.02);
  transition: border-color 120ms ease, background 120ms ease, transform 120ms ease;
}

.card:hover {
  background: var(--panel-hover);
  border-color: #3a4757;
  transform: translateY(-1px);
}

.card-main {
  display: block;
  color: inherit;
}

.card-main:hover {
  color: inherit;
}

.card-media {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.025), transparent 55%),
    var(--bg-soft);
}

.card-media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 180ms ease;
}

.card:hover .card-media img {
  transform: scale(1.02);
}

.folder-media {
  color: #5c7fa8;
}

.folder-media .icon-folder {
  width: 62px;
  height: 62px;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.25));
}

.card-name {
  display: block;
  padding: 10px 11px;
  border-top: 1px solid var(--line-soft);
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-download {
  position: absolute;
  top: 8px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  color: #fff;
  background: rgba(5, 8, 12, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  opacity: 0;
  transition: opacity 120ms ease, background 120ms ease;
}

.card-download .icon {
  width: 17px;
  height: 17px;
}

.card:hover .card-download,
.card:focus-within .card-download {
  opacity: 1;
}

.card-download:hover {
  color: #fff;
  background: rgba(20, 60, 100, 0.95);
}

/* File-type badges -------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  max-width: 84%;
  padding: 11px 13px;
  border-radius: 10px;
  background: var(--badge-bg, #3a4553);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 8px 18px rgba(0, 0, 0, 0.18);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 750;
  letter-spacing: 0.055em;
  line-height: 1;
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge-code { --badge-bg: #386a9e; }
.badge-image { --badge-bg: #2f7d65; }
.badge-pdf { --badge-bg: #b24a4a; }
.badge-archive { --badge-bg: #96682e; }
.badge-audio { --badge-bg: #7859ad; }
.badge-video { --badge-bg: #9d4d78; }
.badge-doc { --badge-bg: #3e6d8c; }
.badge-sheet { --badge-bg: #3e7b4f; }
.badge-slides { --badge-bg: #9c693f; }
.badge-text { --badge-bg: #4d5b6b; }
.badge-generic { --badge-bg: #3a4553; }

/* Empty state ------------------------------------------------------------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 280px;
  margin-top: 8px;
  padding: 40px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.empty .icon-folder {
  width: 48px;
  height: 48px;
  margin-bottom: 8px;
  color: #46566a;
}

.empty p {
  margin: 0;
}

/* Viewer ------------------------------------------------------------------ */

.notice {
  margin: 0 0 16px;
  padding: 11px 14px;
  border: 1px solid rgba(255, 184, 96, 0.28);
  border-radius: 9px;
  background: rgba(255, 184, 96, 0.07);
  color: #d7c19f;
  font-size: 0.9rem;
}

.viewer-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.viewer-figure {
  flex: 1;
  min-width: 0;
  margin: 0;
  text-align: center;
}

.viewer-original {
  display: inline-block;
  max-width: 100%;
  line-height: 0;
}

.viewer-image {
  display: inline-block;
  max-width: 100%;
  max-height: calc(100vh - 245px);
  border-radius: 10px;
  background: #05070a;
  object-fit: contain;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
}

.fallback-thumb {
  width: auto;
  height: auto;
  max-width: min(100%, 640px);
  max-height: none;
  image-rendering: auto;
}

.viewer-missing {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
}

.viewer-missing .icon-image {
  width: 64px;
  height: 64px;
  margin-bottom: 10px;
  color: #46566a;
}

.viewer-missing p {
  margin: 0;
}

.viewer-caption {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 2px 0;
  text-align: left;
}

.viewer-name {
  min-width: 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 0.875rem;
  cursor: pointer;
}

.button:hover {
  color: var(--accent);
  border-color: #3a4a5c;
  background: var(--panel-hover);
}

.button .icon {
  width: 17px;
  height: 17px;
}

.nav-arrow {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
  color: var(--muted);
}

.nav-arrow .icon {
  width: 22px;
  height: 22px;
}

.nav-arrow:hover {
  color: var(--accent);
  border-color: #3a4a5c;
  background: var(--panel-hover);
}

.back-link {
  margin-top: 26px;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Error pages ------------------------------------------------------------- */

.error-page {
  max-width: 680px;
  margin: 10vh auto;
  text-align: center;
}

.error-code {
  color: var(--accent);
  font-size: clamp(4rem, 12vw, 8rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.04em;
}

.error-page h1 {
  margin: 16px 0 24px;
  font-size: clamp(1.1rem, 2.4vw, 1.5rem);
  font-weight: 550;
  color: var(--muted-strong);
}

/* Focus ------------------------------------------------------------------- */

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Responsive -------------------------------------------------------------- */

@media (min-width: 861px) {
  .tree-panel > nav,
  .tree-panel > .tree-empty {
    display: block !important;
  }
}

@media (max-width: 860px) {
  .layout {
    display: block;
  }

  .sidebar {
    position: static;
    width: auto;
    height: auto;
    max-height: 42vh;
    padding: 10px 14px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand {
    padding: 4px 2px 10px;
  }

  .tree-panel > summary {
    display: block;
    padding: 7px 2px;
    color: var(--muted-strong);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
  }

  .tree {
    padding-bottom: 4px;
  }

  .content {
    padding: 18px 16px 48px;
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(142px, 1fr));
    gap: 12px;
  }

  .card-download {
    opacity: 0.88;
  }

  .viewer-stage {
    flex-wrap: wrap;
  }

  .viewer-figure {
    order: 1;
    flex-basis: 100%;
  }

  .nav-arrow {
    order: 2;
  }

  .viewer-image {
    max-height: calc(100vh - 210px);
  }

  .viewer-caption {
    justify-content: center;
  }

  .summary {
    font-size: 0.78rem;
  }
}

@media (hover: none) {
  .card-download {
    opacity: 0.88;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
    scroll-behavior: auto !important;
  }
}
