:root {
  color-scheme: dark;
  --ground: #10241c;
  --ground-deep: #0b1a14;
  --panel: rgba(239, 231, 216, 0.05);
  --panel-2: rgba(239, 231, 216, 0.09);
  --line: rgba(176, 141, 87, 0.28);
  --brass: #b08d57;
  --brass-dim: #6d5a3c;
  --gold: #c9a227;
  --vellum: #efe7d8;
  --vellum-dim: rgba(239, 231, 216, 0.66);
  --bad: #e4948a;
  --good: #8fcf9d;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  display: flex;
  flex-direction: column;
  background: radial-gradient(circle at 50% 0%, var(--ground) 0%, var(--ground-deep) 100%) fixed;
  color: var(--vellum);
  font: 300 15px/1.5 'Jost', ui-sans-serif, system-ui, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
.muted { color: var(--vellum-dim); }
.small { font-size: 0.85rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
h2 { font-family: 'Playfair Display', Georgia, serif; font-weight: 500; margin: 0 0 0.4rem; }

/* ---------- top bar ---------- */
.top {
  flex: none;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: max(0.6rem, env(safe-area-inset-top)) 1rem 0.6rem;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 26, 20, 0.6);
}
.brand { display: flex; align-items: center; gap: 0.65rem; color: var(--vellum); text-decoration: none; font: 500 1.05rem 'Playfair Display', Georgia, serif; letter-spacing: 0.1em; text-transform: uppercase; }
.brand svg { width: 32px; height: 32px; border-radius: 6px; }
.searchbox { flex: 1; max-width: 34rem; }
.searchbox input {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--brass-dim);
  border-radius: 999px;
  color: var(--vellum);
  font: inherit;
  padding: 0.5rem 1rem;
  outline: none;
}
.searchbox input:focus { border-color: var(--gold); }
.top-right { display: flex; align-items: center; gap: 0.7rem; margin-left: auto; }
.chip { color: var(--vellum); text-decoration: none; border: 1px solid var(--line); border-radius: 999px; padding: 0.3rem 0.85rem; font-size: 0.8rem; letter-spacing: 0.06em; }
.chip:hover { border-color: var(--gold); }
button.chip { background: none; font-family: inherit; cursor: pointer; }

/* ---------- layout ---------- */
.layout { flex: 1; min-height: 0; display: flex; }
#side {
  flex: none;
  width: 14.5rem;
  padding: 1rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  border-right: 1px solid var(--line);
  background: rgba(11, 26, 20, 0.35);
}
.side-actions { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.8rem; }
.nav {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-align: left;
  width: 100%;
  background: none;
  border: 0;
  color: var(--vellum);
  font: inherit;
  padding: 0.55rem 0.8rem;
  border-radius: 8px;
  cursor: pointer;
}
.nav:hover { background: var(--panel); }
.nav.on { background: var(--panel-2); color: var(--gold); }
.nav-ico { width: 1.2rem; text-align: center; opacity: 0.8; }
.count { margin-left: auto; font-size: 0.75rem; background: var(--gold); color: var(--ground-deep); border-radius: 999px; padding: 0 0.5rem; }
.usage { margin: auto 0.8rem 0.2rem; font-size: 0.8rem; color: var(--vellum-dim); line-height: 1.5; }
#content { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 0.8rem 1.2rem 1rem; overflow: hidden; }
.bar { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
#crumbs { display: flex; align-items: center; gap: 0.2rem; flex-wrap: wrap; min-width: 0; }
.crumb { border: 0; background: none; color: var(--gold); font: inherit; padding: 0.2rem 0.5rem; border-radius: 6px; cursor: pointer; }
.crumb:hover, .crumb.drop { background: var(--panel-2); }
.crumb.drop { outline: 2px dashed var(--gold); }
.crumb.here { color: var(--vellum); font: 500 1.2rem 'Playfair Display', Georgia, serif; cursor: default; }
#crumbs .sep { color: var(--vellum-dim); }
.tools { display: flex; align-items: center; gap: 0.6rem; }
.tools select {
  background: var(--panel);
  border: 1px solid var(--brass-dim);
  color: var(--vellum);
  font: inherit;
  font-size: 0.85rem;
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
}
.tools select option { background: var(--ground-deep); }
.seg { display: inline-flex; border: 1px solid var(--brass-dim); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); color: var(--vellum-dim); padding: 0.3rem 0.65rem; cursor: pointer; font-size: 0.95rem; }
.seg button.on { background: var(--panel-2); color: var(--gold); }

.btn {
  display: inline-block;
  background: transparent;
  border: 1px solid var(--brass);
  color: var(--vellum);
  font: 400 0.72rem 'Jost', sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  padding: 0.6rem 1.1rem;
  border-radius: 3px;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--gold); border-color: var(--gold); color: var(--ground-deep); }
.btn.primary { background: var(--gold); border-color: var(--gold); color: var(--ground-deep); font-weight: 500; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { border-color: #a85a50; color: var(--bad); }
.btn.danger:hover { background: #a85a50; border-color: #a85a50; color: var(--vellum); }
.btn.small { padding: 0.35rem 0.8rem; font-size: 0.66rem; letter-spacing: 0.14em; }
.btn.ghost { border-color: transparent; color: var(--vellum-dim); }
.btn.primary.danger { background: #a85a50; color: var(--vellum); }

.selbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.45rem 0.7rem;
  margin-bottom: 0.6rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.selbar .count { background: none; color: var(--gold); font-size: 0.9rem; padding: 0 0.4rem 0 0; margin: 0; }

/* ---------- items ---------- */
#main { flex: 1; min-height: 0; overflow: auto; padding: 0.2rem 0.2rem 3rem; outline: none; }
.item { position: relative; border-radius: 10px; outline: none; cursor: default; }
.item:focus-visible { box-shadow: 0 0 0 2px var(--gold); }
.item.drop { outline: 2px dashed var(--gold); }
.item .check { position: absolute; z-index: 2; top: 0.55rem; left: 0.55rem; width: 1.05rem; height: 1.05rem; accent-color: var(--gold); opacity: 0; cursor: pointer; }
.item:hover .check, .item.sel .check, #main.selecting .check, .item .check:focus-visible { opacity: 1; }
.more { border: 0; background: transparent; color: var(--vellum-dim); font-size: 1.15rem; line-height: 1; width: 1.9rem; height: 1.9rem; border-radius: 6px; cursor: pointer; }
.more:hover { background: var(--panel-2); color: var(--vellum); }
.ico { display: inline-block; width: 100%; height: 100%; color: var(--vellum-dim); }
.ico.k-folder { color: #d4a63a; }
.ico.k-image { color: #5bb97b; }
.ico.k-pdf { color: #e86b60; }
.ico.k-video, .ico.k-audio { color: #a389e0; }
.ico.k-word, .ico.k-sheet, .ico.k-slides { color: #6a9be0; }
.ico.k-code, .ico.k-html { color: #e8975a; }
.ico.k-archive { color: #c79a5a; }

#main.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr)); gap: 0.9rem; align-content: start; }
.grid .item { display: grid; grid-template-columns: 1fr auto; grid-template-rows: 7rem auto auto; background: var(--panel); border: 1px solid var(--line); padding: 0.5rem 0.4rem 0.5rem 0.8rem; }
.grid .item:hover { background: var(--panel-2); }
.grid .item.sel { border-color: var(--gold); background: rgba(201, 162, 39, 0.12); }
.grid .thumb { grid-column: 1 / span 2; margin: 0 0.4rem 0 -0.3rem; height: 6.6rem; border-radius: 7px; background: rgba(0, 0, 0, 0.22); display: grid; place-items: center; overflow: hidden; }
.grid .thumb .ico { width: 2.8rem; height: 2.8rem; }
.grid .thumb img { width: 100%; height: 100%; object-fit: cover; }
.grid .name { grid-column: 1; font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; align-self: center; margin-top: 0.35rem; }
.grid .meta { grid-column: 1; color: var(--vellum-dim); font-size: 0.75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid .more { grid-column: 2; grid-row: 2 / span 2; align-self: center; }
.grid .when, .grid .num { display: none; }

#main.list { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 0; align-self: start; flex: none; max-height: 100%; }
.list .row, .list .item { display: grid; grid-template-columns: 1.6rem 2.2rem minmax(0, 1fr) 8rem 6rem 2.2rem; align-items: center; gap: 0.6rem; padding: 0.35rem 0.7rem; border-bottom: 1px solid rgba(176, 141, 87, 0.14); border-radius: 0; }
.list .row.head { color: var(--brass); font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.16em; }
.list .item:last-child { border-bottom: 0; }
.list .item:hover { background: var(--panel-2); }
.list .item.sel { background: rgba(201, 162, 39, 0.12); }
.list .item .check { position: static; opacity: 0.35; }
.list .item:hover .check, .list .item.sel .check { opacity: 1; }
.list .thumb { width: 2rem; height: 2rem; display: grid; place-items: center; overflow: hidden; border-radius: 5px; }
.list .thumb .ico { width: 1.5rem; height: 1.5rem; }
.list .thumb img { width: 100%; height: 100%; object-fit: cover; }
.list .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .meta { display: none; }
.list .when, .list .num { color: var(--vellum-dim); font-size: 0.85rem; }
.list .num { text-align: right; }

.empty { grid-column: 1 / -1; max-width: 28rem; margin: 8vh auto 0; text-align: center; color: var(--vellum-dim); }
.empty h2 { color: var(--vellum); font-size: 1.4rem; }

/* ---------- overlays ---------- */
#dropzone { position: fixed; inset: 0; z-index: 800; display: grid; place-items: center; background: rgba(201, 162, 39, 0.1); border: 3px dashed var(--gold); pointer-events: none; }
#dropzone div { background: var(--ground-deep); padding: 1rem 1.6rem; border-radius: 10px; border: 1px solid var(--gold); font-size: 1.05rem; }
#progress { position: fixed; right: 1rem; bottom: 1rem; z-index: 900; width: 20rem; max-width: calc(100% - 2rem); padding: 0.8rem 1rem; background: var(--ground-deep); border: 1px solid var(--brass-dim); border-radius: 10px; box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5); display: flex; flex-direction: column; gap: 0.5rem; font-size: 0.82rem; }
.plabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meter { height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; }
.fill { display: block; height: 100%; background: var(--gold); transition: width 0.15s; }

.toasts { position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%); z-index: 1100; display: flex; flex-direction: column; gap: 0.5rem; align-items: center; }
.toast { display: flex; align-items: center; gap: 1rem; background: var(--ground-deep); border: 1px solid var(--brass); color: var(--vellum); padding: 0.6rem 1rem; border-radius: 8px; box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5); }
.toast-act { background: none; border: 0; color: var(--gold); font: inherit; text-decoration: underline; cursor: pointer; }

.scrim { position: fixed; inset: 0; z-index: 1000; background: rgba(0, 0, 0, 0.6); display: grid; place-items: center; padding: 1rem; }
.dialog { width: 100%; max-width: 30rem; max-height: calc(100vh - 2rem); overflow: auto; background: var(--ground-deep); border: 1px solid var(--brass-dim); border-radius: 12px; padding: 1.3rem 1.4rem; box-shadow: 0 30px 70px rgba(0, 0, 0, 0.6); position: relative; }
.dialog h2 { font-size: 1.2rem; overflow-wrap: anywhere; }
.dlg-body { margin: 0.8rem 0 0; }
.dlg-body label { display: block; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.18em; color: var(--brass); margin-bottom: 0.3rem; }
.field { width: 100%; background: rgba(239, 231, 216, 0.06); border: 1px solid var(--brass-dim); color: var(--vellum); font: inherit; padding: 0.6rem 0.75rem; border-radius: 3px; outline: none; }
.field:focus { border-color: var(--gold); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.2rem; }
.err { color: var(--bad); }
.pick-crumb { display: flex; flex-wrap: wrap; align-items: center; gap: 0.1rem; margin-bottom: 0.5rem; }
.pick-list { border: 1px solid var(--line); border-radius: 8px; max-height: 15rem; overflow: auto; padding: 0.3rem; }
.pick-row { display: flex; align-items: center; gap: 0.6rem; width: 100%; background: none; border: 0; color: var(--vellum); font: inherit; text-align: left; padding: 0.45rem 0.6rem; border-radius: 6px; cursor: pointer; }
.pick-row:hover { background: var(--panel-2); }
.pick-row .ico { width: 1.4rem; height: 1.4rem; flex: none; }
.preview { position: relative; }
.preview-holder { max-height: 66vh; overflow: auto; display: grid; place-items: center; }
.preview-holder img, .preview-holder video { max-width: 100%; max-height: 64vh; border-radius: 6px; }
.preview-holder pre { align-self: start; justify-self: stretch; margin: 0; white-space: pre-wrap; word-break: break-word; font: 12px/1.5 ui-monospace, Consolas, monospace; user-select: text; }
.preview .nav { position: absolute; top: 50%; transform: translateY(-50%); border: 1px solid var(--line); background: rgba(11, 26, 20, 0.75); color: var(--vellum); font-size: 1.6rem; width: 2.4rem; height: 2.4rem; border-radius: 50%; cursor: pointer; }
.preview .prev { left: 0.2rem; }
.preview .next { right: 0.2rem; }

.menu { position: fixed; z-index: 1050; min-width: 11rem; background: var(--ground-deep); border: 1px solid var(--brass-dim); border-radius: 8px; padding: 0.3rem; box-shadow: 0 20px 44px rgba(0, 0, 0, 0.55); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 0.3rem 0; }
.menu-item { display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--vellum); font: inherit; padding: 0.5rem 0.8rem; border-radius: 5px; cursor: pointer; }
.menu-item:hover, .menu-item:focus-visible { background: var(--panel-2); outline: none; }
.menu-item.danger { color: var(--bad); }

@media (max-width: 760px) {
  .top { flex-wrap: wrap; }
  .searchbox { order: 3; flex-basis: 100%; max-width: none; }
  .layout { flex-direction: column; overflow: auto; }
  #side { width: auto; flex-direction: row; flex-wrap: wrap; align-items: center; border-right: 0; border-bottom: 1px solid var(--line); padding: 0.6rem; }
  .side-actions { flex-direction: row; margin: 0; }
  #side nav { display: flex; flex: 1 1 100%; overflow-x: auto; }
  .nav { width: auto; white-space: nowrap; }
  .usage { display: none; }
  #content { padding: 0.6rem 0.7rem; overflow: visible; }
  #main { overflow: visible; }
  #main.grid { grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); }
  .list .row, .list .item { grid-template-columns: 1.6rem 2rem minmax(0, 1fr) 2.2rem; }
  .list .when, .list .num { display: none; }
}
@media (prefers-reduced-motion: reduce) { .fill { transition: none; } }
