:root {
  color-scheme: light;
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-2: #efeee9;
  --hover: #00000009;
  --border: #e3e1da;
  --text: #1c1c1a;
  --muted: #6d6c66;
  --accent: #b06f00;
  --accent-soft: #f2b84b2e;
  --on-accent: #1d1503;
  --button: #f2b84b;
  --folder: #e0a02c;
  --shadow: 0 12px 40px #1c1c1a26;
  --kind-image: #0e8a6d;
  --kind-video: #b6456f;
  --kind-audio: #7c56c9;
  --kind-pdf: #c9472f;
  --kind-archive: #a8701a;
  --kind-disk: #3f7fbf;
  --kind-exe: #4f6d8a;
  --kind-code: #2f8591;
  --kind-text: #6d6c66;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111214;
    --surface: #18191c;
    --surface-2: #232428;
    --hover: #ffffff0a;
    --border: #2a2b30;
    --text: #ecebe6;
    --muted: #94938c;
    --accent: #f2b84b;
    --accent-soft: #f2b84b1f;
    --folder: #f2b84b;
    --shadow: 0 16px 48px #00000080;
    --kind-image: #4fc9a8;
    --kind-video: #ea7fa6;
    --kind-audio: #ac8df0;
    --kind-pdf: #f08068;
    --kind-archive: #d9a558;
    --kind-disk: #76b0ea;
    --kind-exe: #93aec9;
    --kind-code: #62bdc9;
    --kind-text: #a5a49d;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111214;
  --surface: #18191c;
  --surface-2: #232428;
  --hover: #ffffff0a;
  --border: #2a2b30;
  --text: #ecebe6;
  --muted: #94938c;
  --accent: #f2b84b;
  --accent-soft: #f2b84b1f;
  --folder: #f2b84b;
  --shadow: 0 16px 48px #00000080;
  --kind-image: #4fc9a8;
  --kind-video: #ea7fa6;
  --kind-audio: #ac8df0;
  --kind-pdf: #f08068;
  --kind-archive: #d9a558;
  --kind-disk: #76b0ea;
  --kind-exe: #93aec9;
  --kind-code: #62bdc9;
  --kind-text: #a5a49d;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 6px; }

.icon { display: inline-flex; width: 18px; height: 18px; flex: none; }
.icon svg { width: 100%; height: 100%; }

.icon-button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; flex: none; border-radius: 8px; color: var(--muted);
  transition: background-color .12s, color .12s;
}
.icon-button:hover { background: var(--hover); color: var(--text); }
.primary-button, .secondary-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px; border-radius: 8px; font-weight: 550; white-space: nowrap;
  transition: filter .12s, background-color .12s;
}
.primary-button { background: var(--button); color: var(--on-accent); }
.primary-button:hover { filter: brightness(1.07); }
.secondary-button { background: var(--surface-2); }
.secondary-button:hover { background: var(--border); }
.text-link { color: var(--accent); font-weight: 550; }
.text-link:hover { text-decoration: underline; }

/* ------- shell ------- */

.app { display: flex; height: 100dvh; overflow: hidden; }
.progress {
  position: fixed; inset: 0 0 auto; height: 2px; z-index: 50; background: var(--accent);
  transform-origin: left; animation: progress 1s ease-in-out infinite alternate;
}
@keyframes progress { from { transform: scaleX(.15); } to { transform: scaleX(.85); } }

.sidebar {
  display: none; flex-direction: column; width: 272px; flex: none;
  background: var(--surface); border-right: 1px solid var(--border);
}
.sidebar-open .sidebar { display: flex; }
.brand {
  display: flex; align-items: center; gap: 10px; height: 57px; padding: 0 16px; flex: none;
  font-weight: 650; letter-spacing: -.01em; border-bottom: 1px solid var(--border);
}
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scrim { display: none; }

.tree { flex: 1; overflow: auto; padding: 10px 8px 24px; }
.credit { flex: none; padding: 10px 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; text-align: center; }
.credit:hover { color: var(--text); }
.tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul ul { padding-left: 14px; }
.tree-link {
  display: flex; align-items: center; gap: 6px; height: 30px; padding-right: 8px;
  border-radius: 7px; color: var(--muted);
}
.tree-link:hover { background: var(--hover); color: var(--text); }
.tree-link.active { background: var(--accent-soft); color: var(--text); font-weight: 550; }
.tree-link > .icon { width: 16px; height: 16px; color: var(--folder); }
.tree-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-toggle, .tree-toggle-space { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; flex: none; border-radius: 5px; }
.tree-toggle:hover { background: var(--hover); }
.tree-toggle .icon { width: 13px; height: 13px; transition: transform .12s; }
.tree-toggle.open .icon { transform: rotate(90deg); }

.content { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 8px; height: 57px; padding: 0 14px; flex: none;
  border-bottom: 1px solid var(--border); background: var(--bg);
}
.crumbs {
  display: flex; align-items: center; gap: 2px; flex: 1; min-width: 0; overflow-x: auto;
  scrollbar-width: none; white-space: nowrap; color: var(--muted);
}
.crumbs::-webkit-scrollbar { display: none; }
.crumbs > .icon { width: 13px; height: 13px; opacity: .6; }
.crumb { display: inline-flex; align-items: center; height: 28px; padding: 0 7px; border-radius: 6px; }
.crumb:hover { background: var(--hover); color: var(--text); }
.crumb[aria-current] { color: var(--text); font-weight: 550; }

.search {
  display: flex; align-items: center; gap: 8px; width: min(300px, 30vw); height: 34px; padding: 0 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; color: var(--muted); cursor: text;
}
.search:focus-within { border-color: var(--accent); }
.search > .icon { width: 15px; height: 15px; }
.search-input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--text); }
.search-input::-webkit-search-cancel-button { display: none; }
.search kbd {
  font: 11px/1 ui-monospace, Consolas, monospace; padding: 3px 6px; border: 1px solid var(--border); border-radius: 4px;
}
.search:focus-within kbd { display: none; }
.segmented { display: flex; padding: 2px; background: var(--surface-2); border-radius: 9px; }
.segmented .icon-button { width: 30px; height: 30px; }
.segmented .icon-button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px #0000001f; }

.main { flex: 1; overflow-y: auto; padding: 24px 28px 96px; outline: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
h1 { margin: 0; font-size: 24px; line-height: 1.25; font-weight: 650; letter-spacing: -.02em; overflow-wrap: anywhere; }
.stats { margin: 2px 0 0; min-height: 21px; color: var(--muted); font-variant-numeric: tabular-nums; }
.grid-sort { display: flex; align-items: center; gap: 2px; flex: none; }
.grid-sort select {
  height: 34px; padding: 0 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}

/* ------- list view ------- */

.items-list { --columns: 34px minmax(0, 1fr) 170px 96px 76px; }
.list-head, .items-list .item {
  display: grid; grid-template-columns: var(--columns); align-items: center; column-gap: 4px;
}
.list-head {
  position: sticky; top: -24px; z-index: 2; height: 36px; background: var(--bg);
  border-bottom: 1px solid var(--border); color: var(--muted); font-size: 12.5px;
}
.sort-button { display: inline-flex; align-items: center; gap: 4px; height: 100%; font-weight: 500; }
.sort-button:hover, .sort-button.active { color: var(--text); }
.sort-button .icon { width: 13px; height: 13px; }
.sort-button.col-size { justify-content: flex-end; }

.items-list .item {
  min-height: 44px; border-bottom: 1px solid color-mix(in srgb, var(--border) 55%, transparent);
  border-radius: 0; cursor: pointer; content-visibility: auto; contain-intrinsic-size: auto 44px;
}
.items-list .item:hover { background: var(--hover); }
.item.focused { box-shadow: inset 2px 0 var(--accent); background: var(--hover); }
.item.selected { background: var(--accent-soft); }
.item-link { display: flex; align-items: center; gap: 11px; min-width: 0; padding: 6px 8px 6px 0; }
.item-text { display: flex; flex-direction: column; min-width: 0; }
.item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item[data-index] .item-link:hover .item-name { color: var(--accent); }
.item-location { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; color: var(--muted); }
.col-mtime, .col-size { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.col-size { text-align: right; }
.col-actions { display: flex; justify-content: flex-end; opacity: 0; }
.col-actions .icon-button { width: 30px; height: 30px; }
.item:hover .col-actions, .item:focus-within .col-actions, .item.focused .col-actions { opacity: 1; }

.check { display: flex; align-items: center; justify-content: center; height: 100%; min-height: 30px; cursor: pointer; }
.check input { width: 15px; height: 15px; margin: 0; accent-color: var(--accent); cursor: pointer; opacity: .35; }
.item:hover .check input, .list-head .check input, .check input:checked, .check input:focus-visible { opacity: 1; }

.file-icon {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; flex: none; border-radius: 7px; overflow: hidden; color: var(--kind-text);
}
.file-icon > .icon { width: 20px; height: 20px; }
.kind-folder { color: var(--folder); }
.kind-folder > .icon { width: 24px; height: 24px; }
.kind-image { color: var(--kind-image); }
.kind-video { color: var(--kind-video); }
.kind-audio { color: var(--kind-audio); }
.kind-pdf { color: var(--kind-pdf); }
.kind-archive { color: var(--kind-archive); }
.kind-disk { color: var(--kind-disk); }
.kind-exe { color: var(--kind-exe); }
.kind-code { color: var(--kind-code); }
.thumb { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: var(--surface-2); }

.thumb[src$=".svg"] { object-fit: contain; padding: 8%; }

/* ------- grid view ------- */

.items-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(164px, 1fr)); gap: 12px; }
.card {
  position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; cursor: pointer; transition: border-color .12s, transform .12s;
}
.card:hover { border-color: var(--muted); }
.card.focused { box-shadow: 0 0 0 2px var(--accent); }
.card.selected { border-color: var(--accent); }
.card .item-link { flex-direction: column; align-items: stretch; gap: 0; padding: 0; }
.card .file-icon { width: 100%; height: auto; aspect-ratio: 4 / 3; border-radius: 0; background: var(--surface-2); }
.card .file-icon > .icon { width: 44px; height: 44px; }
.card .item-text { padding: 9px 11px 10px; }
.item-meta { font-size: 12px; text-align: left; }
.card .check {
  position: absolute; top: 6px; left: 6px; z-index: 1; width: 26px; height: 26px; min-height: 0;
  background: var(--surface); border-radius: 7px; opacity: 0;
}
.card-info { position: absolute; top: 6px; right: 6px; z-index: 1; width: 26px; height: 26px; background: var(--surface); opacity: 0; }
.card-info:hover { background: var(--surface); }
.card-info .icon { width: 15px; height: 15px; }
.card:hover .check, .card:hover .card-info, .card.selected .check, .card:focus-within .check, .card:focus-within .card-info { opacity: 1; }

/* ------- messages and readme ------- */

.message { padding: 56px 16px; text-align: center; color: var(--muted); }
.message p { margin: 0 0 10px; }
.message .hint { font-size: 13px; }
.message:has(.hint) { padding: 16px; }

.readme { margin-top: 32px; padding: 24px 28px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; max-width: 860px; }
.markdown { line-height: 1.65; overflow-wrap: anywhere; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { margin: 1.4em 0 .5em; line-height: 1.3; font-weight: 650; letter-spacing: -.01em; }
.markdown h1 { font-size: 22px; }
.markdown h2 { font-size: 18px; }
.markdown h3 { font-size: 15px; }
.markdown a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.markdown code { font: 12.5px ui-monospace, Consolas, monospace; padding: 2px 5px; background: var(--surface-2); border-radius: 4px; }
.markdown pre { padding: 12px 14px; background: var(--surface-2); border-radius: 8px; overflow-x: auto; }
.markdown pre code { padding: 0; background: none; }
.markdown blockquote { margin: 1em 0; padding-left: 14px; border-left: 3px solid var(--border); color: var(--muted); }
.markdown img { max-width: 100%; border-radius: 6px; }
.markdown hr { border: 0; border-top: 1px solid var(--border); margin: 1.5em 0; }
.table-wrap { overflow-x: auto; }
.markdown table { border-collapse: collapse; }
.markdown th, .markdown td { padding: 6px 12px; border: 1px solid var(--border); text-align: left; }
.readme pre { margin: 0; white-space: pre-wrap; font: 12.5px/1.6 ui-monospace, Consolas, monospace; }

/* ------- selection bar and toast ------- */

.selection-bar {
  position: fixed; left: 50%; bottom: 20px; z-index: 20; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 16px; max-width: calc(100vw - 24px);
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.selection-count { font-weight: 550; white-space: nowrap; font-variant-numeric: tabular-nums; }
.toast {
  position: fixed; left: 50%; bottom: 76px; z-index: 40; transform: translateX(-50%); max-width: calc(100vw - 32px);
  padding: 8px 14px; background: var(--text); color: var(--bg); border-radius: 8px; font-weight: 500; overflow-wrap: anywhere;
}

/* ------- details panel ------- */

dialog { color: inherit; }
.details {
  position: fixed; inset: 0 0 0 auto; width: min(380px, 100vw); height: 100dvh; max-height: none; margin: 0; padding: 0;
  background: var(--surface); border: 0; border-left: 1px solid var(--border); box-shadow: var(--shadow);
}
.details[open] { animation: slide-in .16s ease-out; }
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }
.details::backdrop { background: #0000004d; }
.details-panel { display: flex; flex-direction: column; gap: 16px; padding: 12px 20px 24px; }
.details-panel header { display: flex; align-items: center; justify-content: space-between; margin-right: -8px; }
.details-panel h2 { margin: 0; font-size: 14px; font-weight: 600; color: var(--muted); }
.details-visual {
  position: relative; display: flex; align-items: center; justify-content: center; aspect-ratio: 16 / 10;
  background: var(--surface-2); border-radius: 10px; overflow: hidden; color: var(--kind-text);
}
.details-visual.kind-folder { color: var(--folder); }
.details-visual > .icon { width: 56px; height: 56px; }
.details-visual .thumb { object-fit: contain; }
.details-name { margin: 0; font-size: 16px; font-weight: 600; overflow-wrap: anywhere; line-height: 1.35; }
.details dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.details-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ------- preview ------- */

.preview {
  width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0;
  background: #0c0d0ff5; color: #ecebe6; overflow: hidden;
}
.preview[open] { display: flex; flex-direction: column; animation: fade-in .12s ease-out; }
@keyframes fade-in { from { opacity: 0; } }
.preview .icon-button { color: #b4b3ac; }
.preview .icon-button:hover { background: #ffffff1a; color: #fff; }
.preview-bar { display: flex; align-items: center; gap: 4px; flex: none; height: 56px; padding: 0 12px 0 20px; }
.preview-title { display: flex; flex-direction: column; flex: 1; min-width: 0; line-height: 1.3; }
.preview-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.preview-meta { font-size: 12px; color: #94938c; font-variant-numeric: tabular-nums; }
.preview-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 0 64px 24px; overflow: auto; }
.preview-image { max-width: 100%; max-height: 100%; object-fit: contain; cursor: zoom-in; border-radius: 4px; background: repeating-conic-gradient(#ffffff0f 0 25%, transparent 0 50%) 0 0 / 16px 16px; }
.preview-image.zoomed { max-width: none; max-height: none; cursor: zoom-out; margin: auto; }
.preview-media { max-width: 100%; max-height: 100%; border-radius: 6px; background: #000; }
.preview-audio { display: flex; flex-direction: column; align-items: center; gap: 24px; width: min(480px, 100%); }
.preview-audio .file-icon { width: 96px; height: 96px; background: #ffffff0f; border-radius: 20px; color: #ac8df0; }
.preview-audio .file-icon > .icon { width: 44px; height: 44px; }
.preview-audio audio { width: 100%; }
.preview-frame { width: 100%; height: 100%; border: 0; border-radius: 6px; background: #fff; }
.preview-text {
  align-self: stretch; width: min(960px, 100%); margin: 0 auto; padding: 20px 24px; overflow: auto;
  background: var(--surface); color: var(--text); border-radius: 10px;
}
.preview-code pre { display: flex; gap: 16px; margin: 0; font: 12.5px/1.6 ui-monospace, Consolas, monospace; }
.line-numbers { flex: none; text-align: right; color: var(--muted); opacity: .7; user-select: none; }
.preview-note { margin: 0 0 12px; font-size: 13px; color: var(--muted); }
.preview-failure { text-align: center; color: #b4b3ac; }
.preview-failure p { margin: 0 0 14px; }
.preview-nav { position: absolute; top: 50%; width: 44px; height: 44px; margin-top: -22px; border-radius: 50%; background: #ffffff14; }
.preview-prev { left: 12px; }
.preview-next { right: 12px; }

/* ------- no JavaScript ------- */

.fallback { max-width: 900px; margin: 0 auto; padding: 24px 16px; }
.fallback table { width: 100%; border-collapse: collapse; }
.fallback td { padding: 6px 8px; border-bottom: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.fallback td:first-child { width: 100%; white-space: normal; overflow-wrap: anywhere; color: var(--text); }

/* ------- small screens ------- */

@media (max-width: 800px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 30; width: min(300px, 84vw); box-shadow: var(--shadow); }
  .sidebar-open .scrim { display: block; position: fixed; inset: 0; z-index: 29; background: #00000066; }
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 12px; }
  .crumbs { order: 1; flex-basis: calc(100% - 92px); }
  .topbar > .icon-button:last-child { order: 2; }
  .search { order: 3; flex: 1 1 calc(100% - 92px); width: auto; }
  .segmented { order: 4; }
  .search kbd { display: none; }
  .main { padding: 18px 16px 96px; }
  .list-head { top: -18px; }
  .items-list { --columns: 30px minmax(0, 1fr) 76px 34px; }
  .items-list .col-mtime { display: none; }
  .items-list .col-actions { opacity: 1; }
  .items-list .col-actions > a, .items-list .col-actions > [data-action="zip"] { display: none; }
  .items-list .check input { opacity: 1; }
  .items-grid { grid-template-columns: repeat(auto-fill, minmax(136px, 1fr)); }
  .card .check, .card-info { opacity: 1; }
  .preview-stage { padding: 0 8px 12px; }
  .preview-nav { top: auto; bottom: 16px; }
  .readme { padding: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
