:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1c1e21;
  --sub: #5a5f66;
  --accent: #2563eb;
  --border: #e2e4e8;
  --hover: #eef1f6;
  --sidebar-hover: #e6e9f0;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --panel: #1f2226;
    --text: #f0f1f3;
    --sub: #a3a8b0;
    --accent: #5b9bff;
    --border: #2c2f34;
    --hover: #2a2d33;
    --sidebar-hover: #454a53;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  font-weight: 700;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

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

.sidebar {
  width: 200px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--panel);
}

.search {
  flex-shrink: 0;
  margin: 12px 8px;
  font: inherit;
  font-weight: 700;
  font-size: 16px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.search:focus {
  outline: 2px solid var(--accent);
}

.sidebar-tree {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: none;
  padding: 0 8px 12px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.sidebar-tree::-webkit-scrollbar {
  display: none;
}

.tree-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-item:hover {
  background: var(--sidebar-hover);
}

.tree-item.active {
  background: var(--accent);
  color: #fff;
}

.tree-children {
  margin-left: 18px;
  border-left: 1px solid var(--border);
  padding-left: 6px;
}

.back-btn {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 26px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  z-index: 500;
}

.back-btn[hidden] {
  display: none;
}

/* 戻るボタンはサイドバーが隠れるスマホ幅でのみ使う */
@media (min-width: 701px) {
  .back-btn {
    display: none !important;
  }
}

.content {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: none;
  padding: 24px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.content::-webkit-scrollbar {
  display: none;
}

.grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
}

.card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  cursor: pointer;
  min-width: 0;
  user-select: none;
  -webkit-user-select: none;
}

.card:hover {
  border-color: var(--accent);
  background: var(--hover);
  box-shadow: 0 0 0 5px var(--accent) inset;
}

.card .icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 6px;
  object-fit: contain;
  -webkit-user-drag: none;
  pointer-events: none;
}

.card .folder-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.card .label {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: calc(1.3em * 2);
  min-width: 0;
}

.card .label-text {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  white-space: normal;
  word-break: break-word;
}

.empty {
  color: var(--sub);
  font-size: 17px;
  padding: 40px 0;
  text-align: center;
}

@media (max-width: 700px) {
  .layout {
    flex-direction: column;
  }
  .sidebar {
    width: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 4px 8px;
  }
  .search {
    margin: 8px 0;
  }
  .sidebar-tree {
    display: none;
  }
  .content {
    padding: 16px;
  }
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 12px;
  }
  .card {
    flex-direction: column;
    text-align: center;
    padding: 14px 10px;
  }
  .card .label {
    min-height: 0;
    align-items: center;
  }
}
