:root {
  color-scheme: dark light;
  --bg: #000;
  --panel: #111113;
  --hover: #1d1d21;
  --line: #27272c;
  --text: #ededf0;
  --muted: #8e8e98;
  --edge: #fff;
  --edge-fill: rgba(255, 255, 255, 0.14);
  --edge-glow: rgba(255, 255, 255, 0.6);
  --on-edge: #000;
  --danger: #ff8a8a;
  --bar: 44px;
  --lane: 40px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f6f8;
    --panel: #fff;
    --hover: #efeff3;
    --line: #dfdfe6;
    --text: #17171a;
    --muted: #63636e;
    --edge: #17171a;
    --edge-fill: rgba(23, 23, 26, 0.1);
    --edge-glow: rgba(23, 23, 26, 0.3);
    --on-edge: #fff;
    --danger: #b3261e;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; overflow: hidden; }

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button, input { font: inherit; color: inherit; }

button {
  min-height: 32px;
  padding: 4px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  cursor: pointer;
}
button:hover { background: var(--hover); }
button:focus-visible, input:focus-visible { outline: 1.5px solid var(--edge); outline-offset: 1px; }
button:disabled, button[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }

.primary {
  background: var(--edge);
  border-color: var(--edge);
  color: var(--on-edge);
  font-weight: 600;
}
.primary:hover { background: var(--edge); box-shadow: 0 0 12px 1px var(--edge-glow); }

input[type="text"] {
  min-width: 0;
  height: 32px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

header {
  flex: none;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
header .bar {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--bar);
  padding: 0 12px;
}
header .title { font-weight: 600; }
header .brand { display: flex; align-items: center; height: 100%; }
header .bar.branded { height: 88px; }
header .logo { display: block; height: 72px; width: auto; }
header .logo.light { display: none; }
header .spacer { flex: 1; }
@media (prefers-color-scheme: light) {
  header .logo.light { display: block; }
  header .logo.dark { display: none; }
}
header .who {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  white-space: nowrap;
  text-overflow: ellipsis;
}
header .lane { position: relative; height: var(--lane); }

#confirm {
  position: absolute;
  top: 4px;
  width: 22%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  background: var(--edge);
  border-color: var(--edge);
  color: var(--on-edge);
  font-weight: 600;
  box-shadow: 0 0 14px 2px var(--edge-glow);
}
#confirm[data-slot="0"] { left: 2%; }
#confirm[data-slot="1"] { left: 27%; }
#confirm[data-slot="2"] { left: 52%; }
#confirm[data-slot="3"] { left: 76%; }
#confirm[data-slots="2"] { width: 46%; }
#confirm[data-slots="2"][data-slot="1"] { left: 52%; }

#signedout {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  color: var(--muted);
  text-align: center;
}
#signedout p { margin: 0; }

#layout {
  flex: 1;
  min-height: 0;
  display: flex;
}

#tabs {
  flex: none;
  width: 180px;
  padding: 8px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--panel);
}
#tabs [role="tab"] {
  display: block;
  width: 100%;
  margin-bottom: 4px;
  overflow: hidden;
  border-color: transparent;
  background: none;
  color: var(--muted);
  text-align: left;
  white-space: nowrap;
  text-overflow: ellipsis;
}
#tabs [role="tab"]:hover { background: var(--hover); color: var(--text); }
#tabs [role="tab"][aria-selected="true"] {
  background: var(--edge-fill);
  box-shadow: inset 0 0 0 1.5px var(--edge), 0 0 16px 2px var(--edge-glow);
  color: var(--text);
}

main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#toolbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
}
#crumbs {
  flex: 1;
  min-width: 0;
  display: flex;
  gap: 2px;
  overflow: hidden;
  white-space: nowrap;
}
#crumbs button { border-color: transparent; background: none; padding: 4px 6px; }
#crumbs .sep { align-self: center; color: var(--muted); }
#mkdir-form { display: flex; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
#mkdir-form input { flex: 1; }

#list {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 6px 8px;
  overflow-y: auto;
  list-style: none;
}
#list .empty { padding: 24px 8px; color: var(--muted); text-align: center; }

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  padding: 2px 0;
  border-bottom: 1px solid var(--line);
}
.row .open {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 6px 8px;
  border-color: transparent;
  background: none;
  text-align: left;
}
.row .open:hover { background: var(--hover); }
.row .name, .row .meta {
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.row .meta { color: var(--muted); font-size: 12px; }
.row .meta span + span::before { content: " · "; }
.row.folder .name::before { content: "▸ "; color: var(--muted); }
.row .more { flex: none; width: 40px; padding: 4px; }
.row .actions, .row .editor {
  flex-basis: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 8px 8px;
}
.row .editor input { flex: 1 1 160px; }
.danger { color: var(--danger); }

.picker, .versions { flex-basis: 100%; }
.picker ul, .versions ul { margin: 0 0 6px; padding: 0; list-style: none; }
.picker li button, .versions li { width: 100%; }
.picker li button { border-color: transparent; background: none; text-align: left; }
.versions li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  color: var(--muted);
  font-size: 12px;
}
.versions li .when { flex: 1; min-width: 0; color: var(--text); }
.picker .where { color: var(--muted); font-size: 12px; }

#savebar {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}
#savebar label { color: var(--muted); }
#savebar input { flex: 1 1 160px; }

#status {
  flex: none;
  min-height: 0;
  margin: 0;
  padding: 0 12px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  text-overflow: ellipsis;
}
#status:not(:empty) { padding: 4px 12px; border-top: 1px solid var(--line); }
#status[data-kind="error"] { color: var(--danger); }

#tiles {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  align-content: start;
  gap: 8px;
  margin: 0;
  padding: 10px 12px;
  overflow-y: auto;
  list-style: none;
}
.tile {
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px;
  text-align: left;
}
.tile:hover { border-color: var(--edge); box-shadow: 0 0 12px 1px var(--edge-glow); }
.tile .name, .tile .meta { max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.tile .meta { color: var(--muted); font-size: 12px; }
.tile .meta span + span::before { content: " · "; }

@media (max-width: 599px) {
  #layout { flex-direction: column; }
  #tabs {
    width: auto;
    display: flex;
    gap: 4px;
    padding: 6px 8px;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    scrollbar-width: none;
  }
  #tabs [role="tab"] { flex: none; width: auto; margin: 0; }
}

#connect-window {
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  text-align: center;
}
#connect-window h1 { margin: 0; font-size: 18px; font-weight: 600; }
#connect-window p { margin: 0; color: var(--muted); }
#connect-window a { color: var(--text); }
