:root {
  --bg: #0f1115;
  --tile: #171a21;
  --tile-hover: #1f242e;
  --border: #252a36;
  --border-hover: #3b4356;
  --folder: #d4a348;
  --text: #e6e9ef;
  --muted: #8b93a7;
  --danger: #e05d5d;
  --radius: 14px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  min-height: 100%;
  overflow-x: clip;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

button,
a {
  touch-action: manipulation;
}

body.dragover::after {
  content: "";
  position: fixed;
  inset: 12px;
  border: 2px dashed var(--folder);
  border-radius: 16px;
  background: rgba(212, 163, 72, 0.06);
  pointer-events: none;
  z-index: 50;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.hidden {
  display: none !important;
}

/* Minimal Path Topbar */
.path-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: env(safe-area-inset-top, 0px);
  background: rgba(15, 17, 21, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.path-topbar-inner {
  max-width: 960px;
  height: 52px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.back-btn {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--tile);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.14s ease, border-color 0.14s ease, opacity 0.14s ease;
}

.back-btn:hover:not(:disabled),
.back-btn:active:not(:disabled) {
  background: var(--tile-hover);
  border-color: var(--border-hover);
}

.back-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.path-bar {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1rem;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
}

.path-bar::-webkit-scrollbar {
  display: none;
}

.path-sep {
  color: var(--muted);
  opacity: 0.55;
  padding: 0 2px;
  user-select: none;
}

.path-seg {
  min-width: 32px;
  min-height: 36px;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.14s ease, color 0.14s ease;
}

.path-seg:hover,
.path-seg:active {
  background: var(--tile-hover);
  color: var(--text);
}

.path-seg.current {
  color: var(--text);
  font-weight: 600;
}

/* Main Grid Container */
.viewport {
  width: 100%;
  max-width: 960px;
  min-height: calc(100dvh - 53px);
  margin: 0 auto;
  padding: 20px 16px calc(24px + env(safe-area-inset-bottom, 0px));
  display: flex;
  align-items: center;
  justify-content: center;
}

.grid {
  width: 100%;
  display: grid;
  gap: 12px;
}

/* 36-char folder grid: 6x6 on desktop */
.folder-grid {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.folder-tile {
  width: 100%;
  min-height: 96px;
  aspect-ratio: 1 / 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--tile);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.14s ease;
}

.folder-tile:hover,
.folder-tile:focus-visible {
  outline: none;
  background: var(--tile-hover);
  border-color: var(--border-hover);
  transform: translateY(-1px);
}

.folder-tile:active {
  background: var(--tile-hover);
  border-color: var(--folder);
  transform: scale(0.96);
}

.folder-icon {
  width: 42px;
  height: 42px;
  color: var(--folder);
  flex-shrink: 0;
}

.folder-label {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1;
}

/* Innermost vault file grid */
.file-grid {
  align-self: flex-start;
  grid-template-columns: repeat(auto-fill, minmax(156px, 1fr));
  gap: 12px;
}

.upload-tile {
  width: 100%;
  min-height: 140px;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tile);
  border: 1px dashed var(--border-hover);
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease;
}

.upload-tile:hover,
.upload-tile:focus-visible,
.upload-tile:active {
  outline: none;
  background: var(--tile-hover);
  border-color: var(--folder);
  color: var(--folder);
}

.upload-tile.uploading {
  pointer-events: none;
  color: var(--folder);
  border-color: var(--folder);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1.05rem;
  font-weight: 600;
}

.file-tile {
  position: relative;
  width: 100%;
  min-height: 140px;
  aspect-ratio: 1 / 1;
  background: var(--tile);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: border-color 0.14s ease, transform 0.14s ease;
}

.file-tile:hover {
  border-color: var(--border-hover);
  transform: translateY(-1px);
}

.file-tile:active {
  transform: scale(0.98);
}

.file-preview {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #12151b;
  overflow: hidden;
}

.file-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.file-ext {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--folder);
}

.file-caption {
  padding: 9px 10px;
  font-size: 0.82rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: var(--tile);
  border-top: 1px solid var(--border);
}

.file-tools {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.14s ease;
}

.file-tile:hover .file-tools,
.file-tile:focus-within .file-tools {
  opacity: 1;
}

@media (hover: none), (pointer: coarse) {
  .file-tools {
    opacity: 1;
  }
}

.icon-btn {
  width: 32px;
  height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(15, 17, 21, 0.86);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  text-decoration: none;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background 0.14s ease, color 0.14s ease;
}

.icon-btn:hover,
.icon-btn:active {
  background: rgba(31, 36, 46, 0.96);
}

.icon-btn.del:hover,
.icon-btn.del:active {
  color: var(--danger);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 999px;
  background: #1f242e;
  border: 1px solid var(--border-hover);
  color: var(--text);
  font-size: 0.9rem;
  z-index: 100;
  pointer-events: none;
  max-width: 90vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Tablet */
@media (max-width: 900px) {
  .folder-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* Mobile phones */
@media (max-width: 640px) {
  .path-topbar-inner {
    height: 58px;
    padding: 0 14px;
    gap: 10px;
  }

  .back-btn {
    width: 44px;
    height: 44px;
    border-radius: 11px;
  }

  .path-bar {
    font-size: 1.15rem;
  }

  .path-seg {
    min-width: 40px;
    min-height: 44px;
    padding: 8px 10px;
  }

  .viewport {
    min-height: calc(100dvh - 59px);
    padding: 16px 14px calc(28px + env(safe-area-inset-bottom, 0px));
    align-items: flex-start;
  }

  .folder-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
  }

  .folder-tile {
    min-height: 108px;
    gap: 10px;
    border-radius: 15px;
  }

  .folder-icon {
    width: 48px;
    height: 48px;
  }

  .folder-label {
    font-size: 1.35rem;
  }

  .file-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .upload-tile,
  .file-tile {
    min-height: 156px;
    border-radius: 15px;
  }

  .upload-tile svg {
    width: 42px;
    height: 42px;
  }

  .file-caption {
    padding: 10px 12px;
    font-size: 0.9rem;
  }

  .icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 9px;
  }

  .icon-btn svg {
    width: 17px;
    height: 17px;
  }
}

@media (pointer: coarse) {
  .back-btn {
    width: 44px;
    height: 44px;
  }

  .path-seg {
    min-width: 40px;
    min-height: 44px;
  }

  .icon-btn {
    width: 38px;
    height: 38px;
  }
}
